Move some temporary code to separated package

This commit is contained in:
tarsin committed 2023-03-07 10:53:25 +08:00
1 parent d5e1f8814f
commit 29c97b9d79
2 files changed
+30 -24

No files matched your search

@@ -37,6 +37,7 @@ import com.hippo.ehviewer.coil.MergeInterceptor
import com.hippo.ehviewer.dailycheck.checkDawn
import com.hippo.ehviewer.dao.buildMainDB
import com.hippo.ehviewer.download.DownloadManager
import com.hippo.ehviewer.legacy.cleanObsoleteCache
import com.hippo.ehviewer.ui.CommonOperations
import com.hippo.ehviewer.ui.EhActivity
import com.hippo.util.ExceptionUtils
@@ -51,7 +52,6 @@ import io.ktor.client.engine.okhttp.OkHttp
import kotlinx.coroutines.DelicateCoroutinesApi
import okhttp3.OkHttpClient
import okio.Path.Companion.toOkioPath
import java.io.File
import java.net.Proxy
import java.security.KeyStore
import javax.net.ssl.TrustManagerFactory
@@ -109,24 +109,11 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor
checkDawn()
}
}
launchIO {
cleanObsoleteCache()
}
}
cleanObsoleteCache(this)
mIdGenerator.setNextId(Settings.getInt(KEY_GLOBAL_STUFF_NEXT_ID, 0))
}
// TODO: Remove this after a few releases
private fun cleanObsoleteCache() {
val dir = cacheDir
for (subdir in OBSOLETE_CACHE_DIRS) {
val file = File(dir, subdir)
if (file.exists()) {
file.deleteRecursively()
}
}
}
private fun cleanupDownload() {
try {
val downloadLocation = Settings.downloadLocation
@@ -219,15 +206,6 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor
var locked = true
var locked_last_leave_time: Long = 0
private val OBSOLETE_CACHE_DIRS = arrayOf(
"image",
"thumb",
"http_cache",
"image_cache",
"gallery_image",
"spider_info"
)
@JvmStatic
lateinit var application: EhApplication
private set
@@ -0,0 +1,28 @@
package com.hippo.ehviewer.legacy
import android.app.Application
import eu.kanade.tachiyomi.util.lang.launchIO
import kotlinx.coroutines.DelicateCoroutinesApi
import java.io.File
private val OBSOLETE_CACHE_DIRS = arrayOf(
"image",
"thumb",
"http_cache",
"image_cache",
"gallery_image",
"spider_info"
)
@OptIn(DelicateCoroutinesApi::class)
fun cleanObsoleteCache(application: Application) {
launchIO {
val dir = application.cacheDir
for (subdir in OBSOLETE_CACHE_DIRS) {
val file = File(dir, subdir)
if (file.exists()) {
file.deleteRecursively()
}
}
}
}