This commit is contained in:
tom5079
2020-09-05 12:51:41 +09:00
parent 86d528ba13
commit 081c890b4e
9 changed files with 22 additions and 20 deletions

View File

@@ -20,7 +20,7 @@ android {
minSdkVersion 16 minSdkVersion 16
targetSdkVersion 29 targetSdkVersion 29
versionCode 57 versionCode 57
versionName "5.0-beta1" versionName "5.0-beta2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true vectorDrawables.useSupportLibrary = true
} }

View File

@@ -12,7 +12,7 @@
"filters": [], "filters": [],
"properties": [], "properties": [],
"versionCode": 57, "versionCode": 57,
"versionName": "5.0-beta1", "versionName": "5.0-beta2",
"enabled": true, "enabled": true,
"outputFile": "app-release.apk" "outputFile": "app-release.apk"
} }

View File

@@ -138,7 +138,7 @@ class ReaderAdapter(private val activity: ReaderActivity,
if (progress?.isInfinite() == true && image != null) { if (progress?.isInfinite() == true && image != null) {
holder.view.reader_item_progressbar.visibility = View.INVISIBLE holder.view.reader_item_progressbar.visibility = View.INVISIBLE
holder.view.image.post { CoroutineScope(Dispatchers.IO).launch {
glide glide
.load(image.readBytes()) .load(image.readBytes())
.diskCacheStrategy(DiskCacheStrategy.NONE) .diskCacheStrategy(DiskCacheStrategy.NONE)
@@ -155,16 +155,14 @@ class ReaderAdapter(private val activity: ReaderActivity,
cache!!.metadata.imageList?.set(position, null) cache!!.metadata.imageList?.set(position, null)
image.delete() image.delete()
DownloadService.cancel(holder.view.context, galleryID) DownloadService.cancel(holder.view.context, galleryID)
DownloadService.delete(holder.view.context, galleryID) DownloadService.download(holder.view.context, galleryID, true)
return true return true
} }
override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean) = override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean) =
false false
}) }).let { launch(Dispatchers.Main) { it.into(holder.view.image) } }
.into(holder.view.image)
} }
} else { } else {
holder.view.reader_item_progressbar.visibility = View.VISIBLE holder.view.reader_item_progressbar.visibility = View.VISIBLE

View File

@@ -103,7 +103,7 @@ class DownloadService : Service() {
@SuppressLint("RestrictedApi") @SuppressLint("RestrictedApi")
private fun notify(galleryID: Int) { private fun notify(galleryID: Int) {
val max = progress[galleryID]?.size ?: 0 val max = progress[galleryID]?.size ?: 0
val progress = progress[galleryID]?.count { it.isInfinite() } ?: 0 val progress = progress[galleryID]?.count { it == Float.POSITIVE_INFINITY } ?: 0
val notification = notification[galleryID] ?: return val notification = notification[galleryID] ?: return
@@ -196,7 +196,7 @@ class DownloadService : Service() {
*/ */
val progress = SparseArray<MutableList<Float>?>() val progress = SparseArray<MutableList<Float>?>()
fun isCompleted(galleryID: Int) = progress[galleryID]?.toList()?.all { it.isInfinite() } == true fun isCompleted(galleryID: Int) = progress[galleryID]?.toList()?.all { it == Float.POSITIVE_INFINITY } == true
private val callback = object: Callback { private val callback = object: Callback {
@@ -308,10 +308,10 @@ class DownloadService : Service() {
} }
if (progress.indexOfKey(galleryID) < 0) if (progress.indexOfKey(galleryID) < 0)
progress.put(galleryID, mutableListOf()) progress.put(galleryID, MutableList(reader.galleryInfo.files.size) { 0F })
cache.metadata.imageList?.forEach { cache.metadata.imageList?.forEachIndexed { index, image ->
progress[galleryID]?.add(if (it != null) Float.POSITIVE_INFINITY else 0F) progress[galleryID]?.set(index, if (image != null) Float.POSITIVE_INFINITY else 0F)
} }
notification[galleryID]?.setContentTitle(reader.galleryInfo.title?.ellipsize(30)) notification[galleryID]?.setContentTitle(reader.galleryInfo.title?.ellipsize(30))

View File

@@ -146,7 +146,7 @@ class DownloadLocationDialogFragment : DialogFragment() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
context.contentResolver.takePersistableUriPermission(uri, takeFlags) context.contentResolver.takePersistableUriPermission(uri, takeFlags)
if (FileX(context, uri).canWrite()) if (kotlin.runCatching { FileX(context, uri).canWrite() }.getOrDefault(false))
Preferences["download_folder"] = uri.toString() Preferences["download_folder"] = uri.toString()
else { else {
Snackbar.make( Snackbar.make(

View File

@@ -66,7 +66,7 @@ class ManageFavoritesFragment : PreferenceFragmentCompat() {
type = "text/plain" type = "text/plain"
putExtra(Intent.EXTRA_TEXT, response.body()?.use { it.string() }?.replace("\n", "")) putExtra(Intent.EXTRA_TEXT, response.body()?.use { it.string() }?.replace("\n", ""))
}.let { }.let {
context.startActivity(Intent.createChooser(it, getString(R.string.settings_backup_share))) getContext()?.startActivity(Intent.createChooser(it, getString(R.string.settings_backup_share)))
} }
} }
}) })

View File

@@ -91,7 +91,7 @@ class ManageStorageFragment : PreferenceFragmentCompat(), Preference.OnPreferenc
} }
if (dir.exists()) if (dir.exists())
dir.listFiles()?.forEach { (it as FileX).deleteRecursively() } dir.listFiles()?.forEach { (it as? FileX)?.deleteRecursively() }
job = launch { job = launch {
var size = 0L var size = 0L

View File

@@ -113,6 +113,7 @@ class DownloadManager private constructor(context: Context) : ContextWrapper(con
downloadFolderMap[galleryID] = folder.name downloadFolderMap[galleryID] = folder.name
downloadFolder.getChild(".download").let { if (!it.exists()) it.createNewFile() }
downloadFolder.getChild(".download").writeText(Json.encodeToString(downloadFolderMap)) downloadFolder.getChild(".download").writeText(Json.encodeToString(downloadFolderMap))
} }
@@ -126,6 +127,7 @@ class DownloadManager private constructor(context: Context) : ContextWrapper(con
downloadFolder.getChild(it).delete() downloadFolder.getChild(it).delete()
downloadFolderMap.remove(galleryID) downloadFolderMap.remove(galleryID)
downloadFolder.getChild(".download").let { if (!it.exists()) it.createNewFile() }
downloadFolder.getChild(".download").writeText(Json.encodeToString(downloadFolderMap)) downloadFolder.getChild(".download").writeText(Json.encodeToString(downloadFolderMap))
} }
} }

View File

@@ -189,7 +189,7 @@ fun checkUpdate(context: Context, force: Boolean = false) {
} }
} }
fun restore(favorites: GalleryList, url: String, onFailure: ((Exception) -> Unit)? = null, onSuccess: ((List<Int>) -> Unit)? = null) { fun restore(favorites: GalleryList, url: String, onFailure: ((Throwable) -> Unit)? = null, onSuccess: ((List<Int>) -> Unit)? = null) {
if (!URLUtil.isValidUrl(url)) { if (!URLUtil.isValidUrl(url)) {
onFailure?.invoke(IllegalArgumentException()) onFailure?.invoke(IllegalArgumentException())
return return
@@ -206,10 +206,12 @@ fun restore(favorites: GalleryList, url: String, onFailure: ((Exception) -> Unit
} }
override fun onResponse(call: Call, response: Response) { override fun onResponse(call: Call, response: Response) {
Json.decodeFromString<List<Int>>(response.body().use { it?.string() } ?: "[]").let { kotlin.runCatching {
favorites.addAll(it) Json.decodeFromString<List<Int>>(response.body().use { it?.string() } ?: "[]").let {
onSuccess?.invoke(it) favorites.addAll(it)
} onSuccess?.invoke(it)
}
}.onFailure { onFailure?.invoke(it) }
} }
}) })
} }