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()
|
val dataStore: LauncherDataStore by inject()
|
||||||
|
|
||||||
|
private val columnCountPreference = dataStore.data
|
||||||
|
.map { it.grid.columnCount.takeIf { it > 0 } ?: 5 }
|
||||||
|
.distinctUntilChanged()
|
||||||
|
|
||||||
var job: Job? = null
|
var job: Job? = null
|
||||||
override fun onAttachedToWindow() {
|
override fun onAttachedToWindow() {
|
||||||
super.onAttachedToWindow()
|
super.onAttachedToWindow()
|
||||||
job?.cancel()
|
job?.cancel()
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
|
lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||||
dataStore.data.map { it.grid.columnCount }.distinctUntilChanged().collectLatest {
|
columnCountPreference.collectLatest {
|
||||||
columnCount = it
|
columnCount = it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onDetachedFromWindow() {
|
||||||
|
super.onDetachedFromWindow()
|
||||||
|
job?.cancel()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var columnCount: Int = 1
|
var columnCount: Int = 1
|
||||||
set(value) {
|
set(value) {
|
||||||
@ -116,7 +125,7 @@ class SearchGridView : ViewGroup, KoinComponent {
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
columnCount = runBlocking {
|
columnCount = runBlocking {
|
||||||
dataStore.data.map { it.grid.columnCount }.first().takeIf { it > 0 } ?: 5
|
columnCountPreference.first()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user