Replace App.applicationScope with processLifecycleScope
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package org.xtimms.tokusho
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageInfo
|
||||
@@ -10,15 +9,14 @@ import android.os.StrictMode
|
||||
import com.google.android.material.color.DynamicColors
|
||||
import com.tencent.mmkv.MMKV
|
||||
import dagger.hilt.android.HiltAndroidApp
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.launch
|
||||
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
||||
import org.xtimms.tokusho.core.database.MangaDatabase
|
||||
import org.xtimms.tokusho.core.updates.Updater
|
||||
import org.xtimms.tokusho.crash.CrashActivity
|
||||
import org.xtimms.tokusho.crash.GlobalExceptionHandler
|
||||
import org.xtimms.tokusho.utils.lang.processLifecycleScope
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Provider
|
||||
|
||||
@@ -31,18 +29,16 @@ class App : Application() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
MMKV.initialize(this)
|
||||
context = applicationContext
|
||||
packageInfo = packageManager.run {
|
||||
if (Build.VERSION.SDK_INT >= 33) getPackageInfo(
|
||||
packageName, PackageManager.PackageInfoFlags.of(0)
|
||||
) else getPackageInfo(packageName, 0)
|
||||
}
|
||||
applicationScope = CoroutineScope(SupervisorJob())
|
||||
DynamicColors.applyToActivitiesIfAvailable(this)
|
||||
|
||||
applicationScope.launch((Dispatchers.IO)) {
|
||||
processLifecycleScope.launch((Dispatchers.IO)) {
|
||||
try {
|
||||
Updater.deleteOutdatedApk()
|
||||
Updater.deleteOutdatedApk(this@App)
|
||||
} catch (_: Throwable) {
|
||||
|
||||
}
|
||||
@@ -76,9 +72,9 @@ class App : Application() {
|
||||
|
||||
companion object {
|
||||
|
||||
lateinit var applicationScope: CoroutineScope
|
||||
lateinit var packageInfo: PackageInfo
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
fun getVersionReport(): String {
|
||||
val versionName = packageInfo.versionName
|
||||
val versionCode = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
@@ -95,9 +91,6 @@ class App : Application() {
|
||||
.append("Device information: Android $release (API ${Build.VERSION.SDK_INT})\n")
|
||||
.append("Supported ABIs: ${Build.SUPPORTED_ABIS.contentToString()}\n").toString()
|
||||
}
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
lateinit var context: Context
|
||||
}
|
||||
|
||||
}
|
||||
@@ -44,6 +44,7 @@ import org.xtimms.tokusho.core.Navigation
|
||||
import org.xtimms.tokusho.core.components.BottomNavBar
|
||||
import org.xtimms.tokusho.core.components.TopAppBar
|
||||
import org.xtimms.tokusho.ui.theme.TokushoTheme
|
||||
import org.xtimms.tokusho.utils.lang.processLifecycleScope
|
||||
import javax.inject.Inject
|
||||
|
||||
@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
|
||||
@@ -83,7 +84,7 @@ class MainActivity : ComponentActivity() {
|
||||
val localeListCompat =
|
||||
if (locale.isEmpty()) LocaleListCompat.getEmptyLocaleList()
|
||||
else LocaleListCompat.forLanguageTags(locale)
|
||||
App.applicationScope.launch(Dispatchers.Main) {
|
||||
processLifecycleScope.launch(Dispatchers.Main) {
|
||||
AppCompatDelegate.setApplicationLocales(localeListCompat)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,9 @@ import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import org.xtimms.shiki.ui.theme.SEED
|
||||
import org.xtimms.tokusho.App.Companion.applicationScope
|
||||
import org.xtimms.tokusho.R
|
||||
import org.xtimms.tokusho.ui.monet.PaletteStyle
|
||||
import org.xtimms.tokusho.utils.lang.processLifecycleScope
|
||||
import org.xtimms.tokusho.utils.system.languageMap
|
||||
|
||||
private const val DYNAMIC_COLOR = "dynamic_color"
|
||||
@@ -85,7 +85,7 @@ object AppSettings {
|
||||
fun encodeString(key: String, string: String) = key.updateString(string)
|
||||
fun containsKey(key: String) = kv.containsKey(key)
|
||||
|
||||
fun isAutoUpdateEnabled() = AUTO_UPDATE.getBoolean(true)
|
||||
fun isAutoUpdateEnabled() = AUTO_UPDATE.getBoolean(false)
|
||||
|
||||
fun getLanguageConfiguration(languageNumber: Int = kv.decodeInt(LANGUAGE)) =
|
||||
languageMap.getOrElse(languageNumber) { "" }
|
||||
@@ -129,7 +129,7 @@ object AppSettings {
|
||||
darkThemeValue: Int = AppSettingsStateFlow.value.darkTheme.darkThemeValue,
|
||||
isHighContrastModeEnabled: Boolean = AppSettingsStateFlow.value.darkTheme.isHighContrastModeEnabled
|
||||
) {
|
||||
applicationScope.launch(Dispatchers.IO) {
|
||||
processLifecycleScope.launch(Dispatchers.IO) {
|
||||
mutableAppSettingsStateFlow.update {
|
||||
it.copy(
|
||||
darkTheme = AppSettingsStateFlow.value.darkTheme.copy(
|
||||
@@ -144,7 +144,7 @@ object AppSettings {
|
||||
}
|
||||
|
||||
fun modifyThemeSeedColor(colorArgb: Int, paletteStyleIndex: Int) {
|
||||
applicationScope.launch(Dispatchers.IO) {
|
||||
processLifecycleScope.launch(Dispatchers.IO) {
|
||||
mutableAppSettingsStateFlow.update {
|
||||
it.copy(seedColor = colorArgb, paletteStyleIndex = paletteStyleIndex)
|
||||
}
|
||||
@@ -154,7 +154,7 @@ object AppSettings {
|
||||
}
|
||||
|
||||
fun switchDynamicColor(enabled: Boolean = !mutableAppSettingsStateFlow.value.isDynamicColorEnabled) {
|
||||
applicationScope.launch(Dispatchers.IO) {
|
||||
processLifecycleScope.launch(Dispatchers.IO) {
|
||||
mutableAppSettingsStateFlow.update {
|
||||
it.copy(isDynamicColorEnabled = enabled)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import android.widget.Toast
|
||||
import androidx.annotation.StringRes
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import org.xtimms.tokusho.App.Companion.applicationScope
|
||||
import org.xtimms.tokusho.utils.lang.processLifecycleScope
|
||||
|
||||
fun Context.toast(message: String) {
|
||||
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
|
||||
@@ -16,7 +16,7 @@ fun Context.toast(@StringRes stringRes: Int) {
|
||||
}
|
||||
|
||||
fun Context.suspendToast(@StringRes stringRes: Int) {
|
||||
applicationScope.launch(Dispatchers.Main) {
|
||||
processLifecycleScope.launch(Dispatchers.Main) {
|
||||
toast(getString(stringRes))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user