mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-09-20 00:49:43 +02:00
Fixing a few tracepot crashes
This commit is contained in:
parent
6b0813928a
commit
3d2eac7772
@ -14,6 +14,7 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import timber.log.Timber
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -127,21 +128,25 @@ class CoverCache(val context: Context) {
|
|||||||
fun deleteCachedCovers() {
|
fun deleteCachedCovers() {
|
||||||
if (lastClean + renewInterval < System.currentTimeMillis()) {
|
if (lastClean + renewInterval < System.currentTimeMillis()) {
|
||||||
GlobalScope.launch(Dispatchers.IO) {
|
GlobalScope.launch(Dispatchers.IO) {
|
||||||
val directory = onlineCoverDirectory
|
try {
|
||||||
val size = DiskUtil.getDirectorySize(directory)
|
val directory = onlineCoverDirectory
|
||||||
if (size <= maxOnlineCacheSize) {
|
val size = DiskUtil.getDirectorySize(directory)
|
||||||
return@launch
|
if (size <= maxOnlineCacheSize) {
|
||||||
}
|
return@launch
|
||||||
var deletedSize = 0L
|
|
||||||
val files = directory.listFiles()?.sortedBy { it.lastModified() }?.iterator()
|
|
||||||
?: return@launch
|
|
||||||
while (files.hasNext()) {
|
|
||||||
val file = files.next()
|
|
||||||
deletedSize += file.length()
|
|
||||||
file.delete()
|
|
||||||
if (size - deletedSize <= maxOnlineCacheSize) {
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
var deletedSize = 0L
|
||||||
|
val files = directory.listFiles()?.sortedBy { it.lastModified() }?.iterator()
|
||||||
|
?: return@launch
|
||||||
|
while (files.hasNext()) {
|
||||||
|
val file = files.next()
|
||||||
|
deletedSize += file.length()
|
||||||
|
file.delete()
|
||||||
|
if (size - deletedSize <= maxOnlineCacheSize) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Timber.e(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastClean = System.currentTimeMillis()
|
lastClean = System.currentTimeMillis()
|
||||||
|
@ -1079,7 +1079,7 @@ class MangaDetailsController :
|
|||||||
} else {
|
} else {
|
||||||
val favButton = getHeader()?.binding?.favoriteButton ?: return
|
val favButton = getHeader()?.binding?.favoriteButton ?: return
|
||||||
val popup = makeFavPopup(favButton, manga, categories)
|
val popup = makeFavPopup(favButton, manga, categories)
|
||||||
popup.show()
|
popup?.show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1091,11 +1091,12 @@ class MangaDetailsController :
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
val popup = makeFavPopup(popupView, manga, presenter.getCategories())
|
val popup = makeFavPopup(popupView, manga, presenter.getCategories())
|
||||||
popupView.setOnTouchListener(popup.dragToOpenListener)
|
popupView.setOnTouchListener(popup?.dragToOpenListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun makeFavPopup(popupView: View, manga: Manga, categories: List<Category>): PopupMenu {
|
private fun makeFavPopup(popupView: View, manga: Manga, categories: List<Category>): PopupMenu? {
|
||||||
val popup = PopupMenu(view!!.context, popupView)
|
val view = view ?: return null
|
||||||
|
val popup = PopupMenu(view.context, popupView)
|
||||||
popup.menu.add(0, 1, 0, R.string.remove_from_library)
|
popup.menu.add(0, 1, 0, R.string.remove_from_library)
|
||||||
if (categories.isNotEmpty()) {
|
if (categories.isNotEmpty()) {
|
||||||
popup.menu.add(0, 0, 1, R.string.edit_categories)
|
popup.menu.add(0, 0, 1, R.string.edit_categories)
|
||||||
|
Loading…
Reference in New Issue
Block a user