Bug fix
This commit is contained in:
@@ -99,7 +99,7 @@ dependencies {
|
||||
implementation ("xyz.quaver:libpupil:1.3") {
|
||||
exclude group: 'org.jetbrains.kotlinx', module: 'kotlinx-serialization-core-jvm'
|
||||
}
|
||||
implementation "xyz.quaver:documentfilex:0.2.11"
|
||||
implementation "xyz.quaver:documentfilex:0.2.13"
|
||||
testImplementation 'junit:junit:4.13'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||
androidTestImplementation 'androidx.test:rules:1.3.0'
|
||||
|
||||
1
app/proguard-rules.pro
vendored
1
app/proguard-rules.pro
vendored
@@ -21,6 +21,7 @@
|
||||
#-renamesourcefileattribute SourceFile
|
||||
|
||||
-dontobfuscate
|
||||
-dontoptimize
|
||||
|
||||
-keep public class * implements com.bumptech.glide.module.GlideModule
|
||||
-keep class * extends com.bumptech.glide.module.AppGlideModule {
|
||||
|
||||
@@ -23,6 +23,8 @@ import android.app.Notification
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.core.content.ContextCompat
|
||||
@@ -95,6 +97,12 @@ class Pupil : Application() {
|
||||
|
||||
try {
|
||||
Preferences.get<String>("download_folder").also {
|
||||
if (Build.VERSION.SDK_INT > 19)
|
||||
contentResolver.takePersistableUriPermission(
|
||||
Uri.parse(it),
|
||||
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||
)
|
||||
|
||||
if (!FileX(this, it).canWrite())
|
||||
throw Exception()
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ class UpdateBroadcastReciever : BroadcastReceiver() {
|
||||
val downloadID: Long = Preferences["update_download_id"]
|
||||
val downloadManager = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
|
||||
|
||||
if (intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1) != downloadID)
|
||||
if (intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -2) != downloadID)
|
||||
return
|
||||
|
||||
// Get target uri
|
||||
|
||||
@@ -24,9 +24,13 @@ import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import xyz.quaver.io.FileX
|
||||
import xyz.quaver.io.util.deleteRecursively
|
||||
import xyz.quaver.pupil.R
|
||||
import xyz.quaver.pupil.histories
|
||||
import xyz.quaver.pupil.util.byteToString
|
||||
import xyz.quaver.pupil.util.downloader.DownloadManager
|
||||
import xyz.quaver.pupil.util.getDownloadDirectory
|
||||
import java.io.BufferedReader
|
||||
@@ -35,22 +39,14 @@ import java.io.InputStreamReader
|
||||
|
||||
class ManageStorageFragment : PreferenceFragmentCompat(), Preference.OnPreferenceClickListener {
|
||||
|
||||
private var job: Job? = null
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
setPreferencesFromResource(R.xml.manage_storage_preferences, rootKey)
|
||||
|
||||
initPreferences()
|
||||
}
|
||||
|
||||
private fun getDirSize(dir: File) : String {
|
||||
return context?.getString(R.string.settings_storage_usage,
|
||||
Runtime.getRuntime().exec("du -hs " + dir.canonicalPath).let {
|
||||
BufferedReader(InputStreamReader(it.inputStream)).use { reader ->
|
||||
reader.readLine()?.split('\t')?.firstOrNull() ?: "0"
|
||||
}
|
||||
}
|
||||
) ?: ""
|
||||
}
|
||||
|
||||
override fun onPreferenceClick(preference: Preference?): Boolean {
|
||||
with(preference) {
|
||||
this ?: return false
|
||||
@@ -66,12 +62,15 @@ class ManageStorageFragment : PreferenceFragmentCompat(), Preference.OnPreferenc
|
||||
if (dir.exists())
|
||||
dir.deleteRecursively()
|
||||
|
||||
summary = getString(R.string.settings_storage_usage_loading)
|
||||
|
||||
summary = getString(R.string.settings_storage_usage, byteToString(0))
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
getDirSize(dir).let {
|
||||
var size = 0L
|
||||
|
||||
dir.walk().forEach {
|
||||
size += it.length()
|
||||
|
||||
launch(Dispatchers.Main) {
|
||||
this@with.summary = it
|
||||
summary = getString(R.string.settings_storage_usage, byteToString(size))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,15 +85,27 @@ class ManageStorageFragment : PreferenceFragmentCompat(), Preference.OnPreferenc
|
||||
setTitle(R.string.warning)
|
||||
setMessage(R.string.settings_clear_downloads_alert_message)
|
||||
setPositiveButton(android.R.string.yes) { _, _ ->
|
||||
if (dir.exists())
|
||||
dir.deleteRecursively()
|
||||
|
||||
summary = getString(R.string.settings_storage_usage_loading)
|
||||
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
getDirSize(dir).let {
|
||||
job?.cancel()
|
||||
launch(Dispatchers.Main) {
|
||||
summary = getString(R.string.settings_storage_usage_loading)
|
||||
}
|
||||
|
||||
if (dir.exists())
|
||||
dir.listFiles()?.forEach { (it as FileX).deleteRecursively() }
|
||||
|
||||
job = launch {
|
||||
var size = 0L
|
||||
|
||||
launch(Dispatchers.Main) {
|
||||
this@with.summary = it
|
||||
summary = getString(R.string.settings_storage_usage, byteToString(size))
|
||||
}
|
||||
dir.walk().forEach {
|
||||
size += it.length()
|
||||
|
||||
launch(Dispatchers.Main) {
|
||||
summary = getString(R.string.settings_storage_usage, byteToString(size))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,11 +137,15 @@ class ManageStorageFragment : PreferenceFragmentCompat(), Preference.OnPreferenc
|
||||
|
||||
val dir = File(requireContext().cacheDir, "imageCache")
|
||||
|
||||
summary = getString(R.string.settings_storage_usage_loading)
|
||||
summary = getString(R.string.settings_storage_usage, byteToString(0))
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
getDirSize(dir).let {
|
||||
var size = 0L
|
||||
|
||||
dir.walk().forEach {
|
||||
size += it.length()
|
||||
|
||||
launch(Dispatchers.Main) {
|
||||
this@with.summary = it
|
||||
summary = getString(R.string.settings_storage_usage, byteToString(size))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -143,12 +158,17 @@ class ManageStorageFragment : PreferenceFragmentCompat(), Preference.OnPreferenc
|
||||
|
||||
val dir = DownloadManager.getInstance(context).downloadFolder
|
||||
|
||||
summary = getString(R.string.settings_storage_usage_loading)
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
getDirSize(dir).let {
|
||||
summary = getString(R.string.settings_storage_usage, byteToString(0))
|
||||
job?.cancel()
|
||||
job = CoroutineScope(Dispatchers.IO).launch {
|
||||
var size = 0L
|
||||
|
||||
dir.walk().forEach {
|
||||
launch(Dispatchers.Main) {
|
||||
this@with.summary = it
|
||||
summary = getString(R.string.settings_storage_usage, byteToString(size))
|
||||
}
|
||||
|
||||
size += it.length()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,4 +184,9 @@ class ManageStorageFragment : PreferenceFragmentCompat(), Preference.OnPreferenc
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
job?.cancel()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,7 +28,7 @@ object Preferences: SharedPreferences by preferences {
|
||||
val defMap = mapOf(
|
||||
String::class to "",
|
||||
Int::class to -1,
|
||||
Long::class to -1,
|
||||
Long::class to -1L,
|
||||
Boolean::class to false,
|
||||
Set::class to emptySet<Any>()
|
||||
)
|
||||
|
||||
@@ -20,6 +20,7 @@ package xyz.quaver.pupil.util.downloader
|
||||
|
||||
import android.content.Context
|
||||
import android.content.ContextWrapper
|
||||
import android.util.Log
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import kotlinx.serialization.encodeToString
|
||||
|
||||
@@ -53,15 +53,15 @@ fun String.wordCapitalize() : String {
|
||||
return result.joinToString(" ")
|
||||
}
|
||||
|
||||
fun byteToString(byte: Long, precision : Int = 1) : String {
|
||||
private val suffix = listOf(
|
||||
"B",
|
||||
"kB",
|
||||
"MB",
|
||||
"GB",
|
||||
"TB" //really?
|
||||
)
|
||||
|
||||
val suffix = listOf(
|
||||
"B",
|
||||
"kB",
|
||||
"MB",
|
||||
"GB",
|
||||
"TB" //really?
|
||||
)
|
||||
fun byteToString(byte: Long, precision : Int = 1) : String {
|
||||
var size = byte.toDouble(); var suffixIndex = 0
|
||||
|
||||
while (size >= 1024) {
|
||||
@@ -70,7 +70,6 @@ fun byteToString(byte: Long, precision : Int = 1) : String {
|
||||
}
|
||||
|
||||
return "%.${precision}f ${suffix[suffixIndex]}".format(size)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -138,13 +138,11 @@ fun checkUpdate(context: Context, force: Boolean = false) {
|
||||
setMessage(Markwon.create(context).toMarkdown(msg))
|
||||
setPositiveButton(android.R.string.yes) { _, _ ->
|
||||
|
||||
val preference = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
|
||||
val downloadManager = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
|
||||
|
||||
//Cancel any download queued before
|
||||
|
||||
val id = preference.getLong("update_download_id", -1)
|
||||
val id: Long = Preferences["update_download_id"]
|
||||
|
||||
if (id != -1L)
|
||||
downloadManager.remove(id)
|
||||
@@ -158,7 +156,7 @@ fun checkUpdate(context: Context, force: Boolean = false) {
|
||||
.setDestinationUri(Uri.fromFile(target))
|
||||
|
||||
downloadManager.enqueue(request).also {
|
||||
preference.edit().putLong("update_download_id", it).apply()
|
||||
Preferences["update_download_id"] = it
|
||||
}
|
||||
}
|
||||
setNegativeButton(if (force) android.R.string.no else R.string.ignore_update) { _, _ ->
|
||||
|
||||
@@ -49,8 +49,6 @@
|
||||
<string name="main_jump_message">現ページ番号: %1$d\nページ数: %2$d</string>
|
||||
<string name="unable_to_connect">hitomi.laに接続できません</string>
|
||||
<string name="main_move">%1$dページへ移動</string>
|
||||
<string name="https_block_alert_title">(Korean only)</string>
|
||||
<string name="https_block_alert">(Korean only)</string>
|
||||
<string name="settings_clear_downloads">ダウンロード削除</string>
|
||||
<string name="settings_clear_downloads_alert_message">ダウンロードしたギャラリーを全て削除します。\n実行しますか?</string>
|
||||
<string name="settings_mirror_summary">ミラーサーバからイメージをロード</string>
|
||||
|
||||
@@ -48,8 +48,6 @@
|
||||
<string name="main_jump_message">현재 페이지: %1$d\n페이지 수: %2$d</string>
|
||||
<string name="unable_to_connect">hitomi.la에 연결할 수 없습니다</string>
|
||||
<string name="main_move">%1$d 페이지로 이동</string>
|
||||
<string name="https_block_alert_title">접속 불가 현상 안내</string>
|
||||
<string name="https_block_alert">최근 https 차단으로 접속이 안 되는 경우가 발생하고 있습니다 이 경우 플레이스토어에서 Intra앱을 이용하시면 정상이용이 가능합니다.</string>
|
||||
<string name="settings_clear_downloads">다운로드 삭제</string>
|
||||
<string name="settings_clear_downloads_alert_message">다운로드 된 만화를 모두 삭제합니다.\n계속하시겠습니까?</string>
|
||||
<string name="main_drawer_favorite">즐겨찾기</string>
|
||||
|
||||
@@ -21,9 +21,6 @@
|
||||
|
||||
<string name="warning">Warning</string>
|
||||
|
||||
<string name="https_block_alert_title">(Korean only)</string>
|
||||
<string name="https_block_alert">(Korean only)</string>
|
||||
|
||||
<string name="ignore_update">Ignore</string>
|
||||
|
||||
<string name="channel_download">Download</string>
|
||||
|
||||
Reference in New Issue
Block a user