bugfix on lib startup

This commit is contained in:
firelight 2024-07-05 15:26:44 +02:00 committed by GitHub
parent c1b5f5c128
commit e1d4a46309
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1112,23 +1112,6 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCa
MainAPI.settingsForProvider = settingsForProvider MainAPI.settingsForProvider = settingsForProvider
// Change library icon with logo of current api in sync
libraryViewModel = ViewModelProvider(this)[LibraryViewModel::class.java]
libraryViewModel?.currentApiName?.observe(this) {
val syncAPI = libraryViewModel?.currentSyncApi
Log.i("SYNC_API", "${syncAPI?.name}, ${syncAPI?.idPrefix}")
val icon = if (syncAPI?.idPrefix == localListApi.idPrefix) {
R.drawable.library_icon
} else {
syncAPI?.icon ?: R.drawable.library_icon
}
binding?.apply {
navRailView.menu.findItem(R.id.navigation_library)?.setIcon(icon)
navView.menu.findItem(R.id.navigation_library)?.setIcon(icon)
}
}
loadThemes(this) loadThemes(this)
updateLocale() updateLocale()
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -1538,6 +1521,26 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCa
logError(e) logError(e)
} }
} }
// we need to run this after we init all apis, otherwise currentSyncApi will fuck itself
this@MainActivity.runOnUiThread {
// Change library icon with logo of current api in sync
libraryViewModel = ViewModelProvider(this@MainActivity)[LibraryViewModel::class.java]
libraryViewModel?.currentApiName?.observe(this@MainActivity) {
val syncAPI = libraryViewModel?.currentSyncApi
Log.i("SYNC_API", "${syncAPI?.name}, ${syncAPI?.idPrefix}")
val icon = if (syncAPI?.idPrefix == localListApi.idPrefix) {
R.drawable.library_icon
} else {
syncAPI?.icon ?: R.drawable.library_icon
}
binding?.apply {
navRailView.menu.findItem(R.id.navigation_library)?.setIcon(icon)
navView.menu.findItem(R.id.navigation_library)?.setIcon(icon)
}
}
}
} }
SearchResultBuilder.updateCache(this) SearchResultBuilder.updateCache(this)