VancedManager/app/src/main/java/com/vanced/manager/core/App.kt

56 lines
2.0 KiB
Kotlin
Raw Normal View History

package com.vanced.manager.core
import android.app.Application
2020-09-16 05:18:07 +00:00
import android.content.res.Configuration
2020-09-25 17:01:24 +00:00
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
2020-07-06 11:38:00 +00:00
import com.crowdin.platform.Crowdin
import com.crowdin.platform.CrowdinConfig
2020-11-02 15:53:12 +00:00
import com.crowdin.platform.data.model.AuthConfig
2020-07-06 11:38:00 +00:00
import com.crowdin.platform.data.remote.NetworkType
2020-11-03 07:28:18 +00:00
import com.vanced.manager.BuildConfig.*
2021-02-03 18:24:28 +00:00
import com.vanced.manager.utils.AppUtils.log
2021-01-16 17:00:38 +00:00
import com.vanced.manager.utils.loadJson
import com.vanced.manager.utils.managerAccent
import com.vanced.manager.utils.mutableAccentColor
2020-11-15 17:04:23 +00:00
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
2021-04-19 15:57:14 +00:00
open class App : Application() {
2020-11-02 15:53:12 +00:00
private val prefs by lazy { getDefaultSharedPreferences(this) }
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
2020-11-02 15:53:12 +00:00
override fun onCreate() {
scope.launch { loadJson(this@App) }
2020-09-20 14:41:28 +00:00
super.onCreate()
mutableAccentColor.value = prefs.managerAccent
2021-04-19 15:57:14 +00:00
Crowdin.init(
this,
2020-11-02 15:53:12 +00:00
CrowdinConfig.Builder().apply {
2020-11-03 07:28:18 +00:00
withDistributionHash(CROWDIN_HASH)
2020-11-02 15:53:12 +00:00
withNetworkType(NetworkType.WIFI)
2020-11-03 07:28:18 +00:00
if (ENABLE_CROWDIN_AUTH) {
if (prefs.getBoolean("crowdin_real_time", false))
withRealTimeUpdates()
2020-11-02 15:53:12 +00:00
withSourceLanguage("en")
2020-11-03 07:28:18 +00:00
withAuthConfig(AuthConfig(CROWDIN_CLIENT_ID, CROWDIN_CLIENT_SECRET, null))
2020-11-02 15:53:12 +00:00
withScreenshotEnabled()
2021-02-03 18:24:28 +00:00
log("test", "crowdin credentials")
2020-11-02 15:53:12 +00:00
}
}.build()
2020-09-20 14:41:28 +00:00
)
2020-11-03 07:28:18 +00:00
2020-11-02 15:53:12 +00:00
if (prefs.getBoolean("crowdin_upload_screenshot", false))
Crowdin.registerScreenShotContentObserver(this)
2020-08-23 00:24:43 +00:00
2020-07-06 11:38:00 +00:00
}
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
Crowdin.onConfigurationChanged()
}
2020-08-12 13:40:13 +00:00
}