This commit is contained in:
tom5079
2020-09-02 20:15:26 +09:00
parent ead68b5201
commit 37be8ccf7f
12 changed files with 76 additions and 51 deletions

View File

@@ -99,7 +99,7 @@ dependencies {
implementation ("xyz.quaver:libpupil:1.3") { implementation ("xyz.quaver:libpupil:1.3") {
exclude group: 'org.jetbrains.kotlinx', module: 'kotlinx-serialization-core-jvm' 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' testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test:rules:1.3.0' androidTestImplementation 'androidx.test:rules:1.3.0'

View File

@@ -21,6 +21,7 @@
#-renamesourcefileattribute SourceFile #-renamesourcefileattribute SourceFile
-dontobfuscate -dontobfuscate
-dontoptimize
-keep public class * implements com.bumptech.glide.module.GlideModule -keep public class * implements com.bumptech.glide.module.GlideModule
-keep class * extends com.bumptech.glide.module.AppGlideModule { -keep class * extends com.bumptech.glide.module.AppGlideModule {

View File

@@ -23,6 +23,8 @@ import android.app.Notification
import android.app.NotificationChannel import android.app.NotificationChannel
import android.app.NotificationManager import android.app.NotificationManager
import android.content.Context import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build import android.os.Build
import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
@@ -95,6 +97,12 @@ class Pupil : Application() {
try { try {
Preferences.get<String>("download_folder").also { 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()) if (!FileX(this, it).canWrite())
throw Exception() throw Exception()
} }

View File

@@ -44,7 +44,7 @@ class UpdateBroadcastReciever : BroadcastReceiver() {
val downloadID: Long = Preferences["update_download_id"] val downloadID: Long = Preferences["update_download_id"]
val downloadManager = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager 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 return
// Get target uri // Get target uri

View File

@@ -24,9 +24,13 @@ import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import xyz.quaver.io.FileX
import xyz.quaver.io.util.deleteRecursively
import xyz.quaver.pupil.R import xyz.quaver.pupil.R
import xyz.quaver.pupil.histories import xyz.quaver.pupil.histories
import xyz.quaver.pupil.util.byteToString
import xyz.quaver.pupil.util.downloader.DownloadManager import xyz.quaver.pupil.util.downloader.DownloadManager
import xyz.quaver.pupil.util.getDownloadDirectory import xyz.quaver.pupil.util.getDownloadDirectory
import java.io.BufferedReader import java.io.BufferedReader
@@ -35,22 +39,14 @@ import java.io.InputStreamReader
class ManageStorageFragment : PreferenceFragmentCompat(), Preference.OnPreferenceClickListener { class ManageStorageFragment : PreferenceFragmentCompat(), Preference.OnPreferenceClickListener {
private var job: Job? = null
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.manage_storage_preferences, rootKey) setPreferencesFromResource(R.xml.manage_storage_preferences, rootKey)
initPreferences() 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 { override fun onPreferenceClick(preference: Preference?): Boolean {
with(preference) { with(preference) {
this ?: return false this ?: return false
@@ -66,12 +62,15 @@ class ManageStorageFragment : PreferenceFragmentCompat(), Preference.OnPreferenc
if (dir.exists()) if (dir.exists())
dir.deleteRecursively() dir.deleteRecursively()
summary = getString(R.string.settings_storage_usage_loading) summary = getString(R.string.settings_storage_usage, byteToString(0))
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
getDirSize(dir).let { var size = 0L
dir.walk().forEach {
size += it.length()
launch(Dispatchers.Main) { 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) setTitle(R.string.warning)
setMessage(R.string.settings_clear_downloads_alert_message) setMessage(R.string.settings_clear_downloads_alert_message)
setPositiveButton(android.R.string.yes) { _, _ -> setPositiveButton(android.R.string.yes) { _, _ ->
if (dir.exists())
dir.deleteRecursively()
summary = getString(R.string.settings_storage_usage_loading)
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
getDirSize(dir).let { job?.cancel()
launch(Dispatchers.Main) { launch(Dispatchers.Main) {
this@with.summary = it 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) {
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") 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 { CoroutineScope(Dispatchers.IO).launch {
getDirSize(dir).let { var size = 0L
dir.walk().forEach {
size += it.length()
launch(Dispatchers.Main) { 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 val dir = DownloadManager.getInstance(context).downloadFolder
summary = getString(R.string.settings_storage_usage_loading) summary = getString(R.string.settings_storage_usage, byteToString(0))
CoroutineScope(Dispatchers.IO).launch { job?.cancel()
getDirSize(dir).let { job = CoroutineScope(Dispatchers.IO).launch {
var size = 0L
dir.walk().forEach {
launch(Dispatchers.Main) { 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()
}
} }

View File

@@ -28,7 +28,7 @@ object Preferences: SharedPreferences by preferences {
val defMap = mapOf( val defMap = mapOf(
String::class to "", String::class to "",
Int::class to -1, Int::class to -1,
Long::class to -1, Long::class to -1L,
Boolean::class to false, Boolean::class to false,
Set::class to emptySet<Any>() Set::class to emptySet<Any>()
) )

View File

@@ -20,6 +20,7 @@ package xyz.quaver.pupil.util.downloader
import android.content.Context import android.content.Context
import android.content.ContextWrapper import android.content.ContextWrapper
import android.util.Log
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import kotlinx.serialization.decodeFromString import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString import kotlinx.serialization.encodeToString

View File

@@ -53,15 +53,15 @@ fun String.wordCapitalize() : String {
return result.joinToString(" ") return result.joinToString(" ")
} }
fun byteToString(byte: Long, precision : Int = 1) : String { private val suffix = listOf(
val suffix = listOf(
"B", "B",
"kB", "kB",
"MB", "MB",
"GB", "GB",
"TB" //really? "TB" //really?
) )
fun byteToString(byte: Long, precision : Int = 1) : String {
var size = byte.toDouble(); var suffixIndex = 0 var size = byte.toDouble(); var suffixIndex = 0
while (size >= 1024) { while (size >= 1024) {
@@ -70,7 +70,6 @@ fun byteToString(byte: Long, precision : Int = 1) : String {
} }
return "%.${precision}f ${suffix[suffixIndex]}".format(size) return "%.${precision}f ${suffix[suffixIndex]}".format(size)
} }
/** /**

View File

@@ -138,13 +138,11 @@ fun checkUpdate(context: Context, force: Boolean = false) {
setMessage(Markwon.create(context).toMarkdown(msg)) setMessage(Markwon.create(context).toMarkdown(msg))
setPositiveButton(android.R.string.yes) { _, _ -> setPositiveButton(android.R.string.yes) { _, _ ->
val preference = PreferenceManager.getDefaultSharedPreferences(context)
val downloadManager = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager val downloadManager = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
//Cancel any download queued before //Cancel any download queued before
val id = preference.getLong("update_download_id", -1) val id: Long = Preferences["update_download_id"]
if (id != -1L) if (id != -1L)
downloadManager.remove(id) downloadManager.remove(id)
@@ -158,7 +156,7 @@ fun checkUpdate(context: Context, force: Boolean = false) {
.setDestinationUri(Uri.fromFile(target)) .setDestinationUri(Uri.fromFile(target))
downloadManager.enqueue(request).also { 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) { _, _ -> setNegativeButton(if (force) android.R.string.no else R.string.ignore_update) { _, _ ->

View File

@@ -49,8 +49,6 @@
<string name="main_jump_message">現ページ番号: %1$d\nページ数: %2$d</string> <string name="main_jump_message">現ページ番号: %1$d\nページ数: %2$d</string>
<string name="unable_to_connect">hitomi.laに接続できません</string> <string name="unable_to_connect">hitomi.laに接続できません</string>
<string name="main_move">%1$dページへ移動</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">ダウンロード削除</string>
<string name="settings_clear_downloads_alert_message">ダウンロードしたギャラリーを全て削除します。\n実行しますか</string> <string name="settings_clear_downloads_alert_message">ダウンロードしたギャラリーを全て削除します。\n実行しますか</string>
<string name="settings_mirror_summary">ミラーサーバからイメージをロード</string> <string name="settings_mirror_summary">ミラーサーバからイメージをロード</string>

View File

@@ -48,8 +48,6 @@
<string name="main_jump_message">현재 페이지: %1$d\n페이지 수: %2$d</string> <string name="main_jump_message">현재 페이지: %1$d\n페이지 수: %2$d</string>
<string name="unable_to_connect">hitomi.la에 연결할 수 없습니다</string> <string name="unable_to_connect">hitomi.la에 연결할 수 없습니다</string>
<string name="main_move">%1$d 페이지로 이동</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">다운로드 삭제</string>
<string name="settings_clear_downloads_alert_message">다운로드 된 만화를 모두 삭제합니다.\n계속하시겠습니까?</string> <string name="settings_clear_downloads_alert_message">다운로드 된 만화를 모두 삭제합니다.\n계속하시겠습니까?</string>
<string name="main_drawer_favorite">즐겨찾기</string> <string name="main_drawer_favorite">즐겨찾기</string>

View File

@@ -21,9 +21,6 @@
<string name="warning">Warning</string> <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="ignore_update">Ignore</string>
<string name="channel_download">Download</string> <string name="channel_download">Download</string>