mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2025-01-11 03:39:15 +01: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.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import timber.log.Timber
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import java.io.File
|
||||
@ -127,21 +128,25 @@ class CoverCache(val context: Context) {
|
||||
fun deleteCachedCovers() {
|
||||
if (lastClean + renewInterval < System.currentTimeMillis()) {
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
val directory = onlineCoverDirectory
|
||||
val size = DiskUtil.getDirectorySize(directory)
|
||||
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
|
||||
try {
|
||||
val directory = onlineCoverDirectory
|
||||
val size = DiskUtil.getDirectorySize(directory)
|
||||
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
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e)
|
||||
}
|
||||
}
|
||||
lastClean = System.currentTimeMillis()
|
||||
|
@ -1079,7 +1079,7 @@ class MangaDetailsController :
|
||||
} else {
|
||||
val favButton = getHeader()?.binding?.favoriteButton ?: return
|
||||
val popup = makeFavPopup(favButton, manga, categories)
|
||||
popup.show()
|
||||
popup?.show()
|
||||
}
|
||||
}
|
||||
|
||||
@ -1091,11 +1091,12 @@ class MangaDetailsController :
|
||||
return
|
||||
}
|
||||
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 {
|
||||
val popup = PopupMenu(view!!.context, popupView)
|
||||
private fun makeFavPopup(popupView: View, manga: Manga, categories: List<Category>): PopupMenu? {
|
||||
val view = view ?: return null
|
||||
val popup = PopupMenu(view.context, popupView)
|
||||
popup.menu.add(0, 1, 0, R.string.remove_from_library)
|
||||
if (categories.isNotEmpty()) {
|
||||
popup.menu.add(0, 0, 1, R.string.edit_categories)
|
||||
|
Loading…
x
Reference in New Issue
Block a user