SearchGridView: don't crash if column preference is faulty
This commit is contained in:
parent
a4b6212a7e
commit
a4ead54329
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user