e684bef35d
Replaces SharedPreferences with MMKV for all settings by introducing MmkvPreferenceDataStore and updating SettingsActivity to use it. Adds encode/decode helpers for more types in MmkvManager, ensures default settings are initialized in SettingsManager, and removes the unused FragmentAdapter. This change improves consistency and reliability of settings storage.
50 lines
1.4 KiB
Kotlin
50 lines
1.4 KiB
Kotlin
package com.v2ray.ang
|
|
|
|
import android.content.Context
|
|
import androidx.multidex.MultiDexApplication
|
|
import androidx.work.Configuration
|
|
import androidx.work.WorkManager
|
|
import com.tencent.mmkv.MMKV
|
|
import com.v2ray.ang.AppConfig.ANG_PACKAGE
|
|
import com.v2ray.ang.handler.SettingsManager
|
|
|
|
class AngApplication : MultiDexApplication() {
|
|
companion object {
|
|
lateinit var application: AngApplication
|
|
}
|
|
|
|
/**
|
|
* Attaches the base context to the application.
|
|
* @param base The base context.
|
|
*/
|
|
override fun attachBaseContext(base: Context?) {
|
|
super.attachBaseContext(base)
|
|
application = this
|
|
}
|
|
|
|
private val workManagerConfiguration: Configuration = Configuration.Builder()
|
|
.setDefaultProcessName("${ANG_PACKAGE}:bg")
|
|
.build()
|
|
|
|
/**
|
|
* Initializes the application.
|
|
*/
|
|
override fun onCreate() {
|
|
super.onCreate()
|
|
|
|
MMKV.initialize(this)
|
|
|
|
// Ensure critical preference defaults are present in MMKV early
|
|
SettingsManager.ensureDefaultSettings()
|
|
SettingsManager.setNightMode()
|
|
// Initialize WorkManager with the custom configuration
|
|
WorkManager.initialize(this, workManagerConfiguration)
|
|
|
|
SettingsManager.initRoutingRulesets(this)
|
|
|
|
es.dmoral.toasty.Toasty.Config.getInstance()
|
|
.setGravity(android.view.Gravity.BOTTOM, 0, 200)
|
|
.apply()
|
|
}
|
|
}
|