SearchGridView: don't crash if column preference is faulty

This commit is contained in:
MM20 2022-01-29 19:57:02 +01:00
parent a4b6212a7e
commit a4ead54329
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389

View File

@ -35,19 +35,28 @@ class SearchGridView : ViewGroup, KoinComponent {
val dataStore: LauncherDataStore by inject()
private val columnCountPreference = dataStore.data
.map { it.grid.columnCount.takeIf { it > 0 } ?: 5 }
.distinctUntilChanged()
var job: Job? = null
override fun onAttachedToWindow() {
super.onAttachedToWindow()
job?.cancel()
lifecycleScope.launch {
lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
dataStore.data.map { it.grid.columnCount }.distinctUntilChanged().collectLatest {
columnCountPreference.collectLatest {
columnCount = it
}
}
}
}
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
job?.cancel()
}
var columnCount: Int = 1
set(value) {
@ -116,7 +125,7 @@ class SearchGridView : ViewGroup, KoinComponent {
init {
columnCount = runBlocking {
dataStore.data.map { it.grid.columnCount }.first().takeIf { it > 0 } ?: 5
columnCountPreference.first()
}
}