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
targetSdkVersion 29
versionCode 57
versionName "5.0-beta1"
versionName "5.0-beta2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}

View File

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

View File

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

View File

@@ -103,7 +103,7 @@ class DownloadService : Service() {
@SuppressLint("RestrictedApi")
private fun notify(galleryID: Int) {
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
@@ -196,7 +196,7 @@ class DownloadService : Service() {
*/
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 {
@@ -308,10 +308,10 @@ class DownloadService : Service() {
}
if (progress.indexOfKey(galleryID) < 0)
progress.put(galleryID, mutableListOf())
progress.put(galleryID, MutableList(reader.galleryInfo.files.size) { 0F })
cache.metadata.imageList?.forEach {
progress[galleryID]?.add(if (it != null) Float.POSITIVE_INFINITY else 0F)
cache.metadata.imageList?.forEachIndexed { index, image ->
progress[galleryID]?.set(index, if (image != null) Float.POSITIVE_INFINITY else 0F)
}
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)
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
if (FileX(context, uri).canWrite())
if (kotlin.runCatching { FileX(context, uri).canWrite() }.getOrDefault(false))
Preferences["download_folder"] = uri.toString()
else {
Snackbar.make(

View File

@@ -66,7 +66,7 @@ class ManageFavoritesFragment : PreferenceFragmentCompat() {
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, response.body()?.use { it.string() }?.replace("\n", ""))
}.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())
dir.listFiles()?.forEach { (it as FileX).deleteRecursively() }
dir.listFiles()?.forEach { (it as? FileX)?.deleteRecursively() }
job = launch {
var size = 0L

View File

@@ -113,6 +113,7 @@ class DownloadManager private constructor(context: Context) : ContextWrapper(con
downloadFolderMap[galleryID] = folder.name
downloadFolder.getChild(".download").let { if (!it.exists()) it.createNewFile() }
downloadFolder.getChild(".download").writeText(Json.encodeToString(downloadFolderMap))
}
@@ -126,6 +127,7 @@ class DownloadManager private constructor(context: Context) : ContextWrapper(con
downloadFolder.getChild(it).delete()
downloadFolderMap.remove(galleryID)
downloadFolder.getChild(".download").let { if (!it.exists()) it.createNewFile() }
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)) {
onFailure?.invoke(IllegalArgumentException())
return
@@ -206,10 +206,12 @@ fun restore(favorites: GalleryList, url: String, onFailure: ((Exception) -> Unit
}
override fun onResponse(call: Call, response: Response) {
kotlin.runCatching {
Json.decodeFromString<List<Int>>(response.body().use { it?.string() } ?: "[]").let {
favorites.addAll(it)
onSuccess?.invoke(it)
}
}.onFailure { onFailure?.invoke(it) }
}
})
}