0
0
mirror of https://github.com/florisboard/florisboard.git synced 2024-09-20 12:02:19 +02:00

Fix prefs getting reset when loaded in direct boot mode (#1304)

This commit is contained in:
Patrick Goldinger 2021-10-31 17:03:44 +01:00
parent 510f2cc120
commit 41a6ab36ea
4 changed files with 22 additions and 36 deletions

View File

@ -142,8 +142,8 @@ tasks.withType<Test> {
}
dependencies {
implementation("androidx.activity:activity-compose:1.3.1")
implementation("androidx.activity:activity-ktx:1.3.1") // possibly remove after settings rework
implementation("androidx.activity:activity-compose:1.4.0")
implementation("androidx.activity:activity-ktx:1.4.0") // possibly remove after settings rework
implementation("androidx.appcompat:appcompat:1.3.1") // possibly remove after settings rework
implementation("androidx.autofill:autofill:1.1.0")
implementation("androidx.compose.material:material:1.1.0-beta01")
@ -161,8 +161,8 @@ dependencies {
implementation("com.google.android.material:material:1.4.0") // possibly remove after settings rework
implementation("com.jaredrummler:colorpicker:1.1.0") // possibly remove after settings rework
implementation("com.nambimobile.widgets:expandable-fab:1.0.2") // possibly remove after settings rework
implementation("dev.patrickgold.jetpref:jetpref-datastore-model:0.1.0-alpha11")
implementation("dev.patrickgold.jetpref:jetpref-ui-compose:0.1.0-alpha11")
implementation("dev.patrickgold.jetpref:jetpref-datastore-model:0.1.0-alpha12")
implementation("dev.patrickgold.jetpref:jetpref-ui-compose:0.1.0-alpha12")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.0")
implementation("androidx.room:room-runtime:2.3.0")

View File

@ -58,7 +58,7 @@ class FlorisApplication : Application() {
}
}
val prefs by florisPreferenceModel()
private val prefs by florisPreferenceModel()
val assetManager by lazy { AssetManager(this) }
val extensionManager by lazy { ExtensionManager(this) }
@ -68,7 +68,7 @@ class FlorisApplication : Application() {
override fun onCreate() {
super.onCreate()
try {
JetPrefManager.init(this, saveIntervalMs = 1_000)
JetPrefManager.init(saveIntervalMs = 1_000)
Flog.install(
context = this,
isFloggingEnabled = BuildConfig.DEBUG,
@ -76,9 +76,18 @@ class FlorisApplication : Application() {
flogLevels = Flog.LEVEL_ALL,
flogOutputs = Flog.OUTPUT_CONSOLE,
)
initICU()
CrashUtility.install(this)
if (AndroidVersion.ATLEAST_N && !UserManagerCompat.isUserUnlocked(this)) {
val context = createDeviceProtectedStorageContext()
initICU(context)
prefs.initializeForContext(context)
registerReceiver(BootComplete(), IntentFilter(Intent.ACTION_USER_UNLOCKED))
} else {
initICU(this)
prefs.initializeForContext(this)
}
Preferences.initDefault(this)
SubtypeManager.init(this)
DictionaryManager.init(this)
@ -87,26 +96,17 @@ class FlorisApplication : Application() {
CrashUtility.stageException(e)
return
}
/*Register a receiver so user config can be applied once device protracted storage is available*/
if (!UserManagerCompat.isUserUnlocked(this) && AndroidVersion.ATLEAST_N) {
registerReceiver(BootComplete(), IntentFilter(Intent.ACTION_USER_UNLOCKED))
}
}
fun initICU(): Boolean {
fun initICU(context: Context): Boolean {
try {
val context = if (AndroidVersion.ATLEAST_N) {
createDeviceProtectedStorageContext()
} else {
this
}
val androidAssetManager = context.assets ?: return false
val dstDataFile = File(context.cacheDir, "icudt.dat")
dstDataFile.outputStream().use { os ->
val icuTmpDataFile = File(context.cacheDir, "icudt.dat")
icuTmpDataFile.outputStream().use { os ->
androidAssetManager.open(ICU_DATA_ASSET_PATH).use { it.copyTo(os) }
}
val status = nativeInitICUData(dstDataFile.absolutePath.toNativeStr())
val status = nativeInitICUData(icuTmpDataFile.absolutePath.toNativeStr())
icuTmpDataFile.delete()
return if (status != 0) {
flogError { "Native ICU data initializing failed with error code $status!" }
false
@ -129,6 +129,7 @@ class FlorisApplication : Application() {
} catch (e: Exception) {
flogError { e.toString() }
}
prefs.initializeForContext(this@FlorisApplication)
}
}
}

View File

@ -19,7 +19,6 @@ package dev.patrickgold.florisboard.oldsettings
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.View
import androidx.annotation.IdRes
@ -127,11 +126,6 @@ class ThemeEditorActivity : AppCompatActivity() {
buildUi()
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.help_menu, menu)
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
android.R.id.home -> {

View File

@ -21,7 +21,6 @@ import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
@ -253,14 +252,6 @@ class UdmActivity : FlorisActivity<UdmActivityBinding>() {
return UdmActivityBinding.inflate(layoutInflater)
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.udm_extra_menu, menu)
if (userDictionaryType == USER_DICTIONARY_TYPE_FLORIS) {
menu?.findItem(R.id.udm__open_system_manager_ui)?.isVisible = false
}
return true
}
override fun onDestroy() {
super.onDestroy()
activeDialogWindow?.dismiss()