Alternate method of avoiding LazyColumn key conflict crashes

Co-authored-by: ivaniskandar <ivaniskandar@users.noreply.github.com>
This commit is contained in:
arkon 2022-10-27 23:26:34 -04:00
parent 187e9f94aa
commit c50b1a5c66
4 changed files with 7 additions and 8 deletions

View File

@ -118,10 +118,9 @@ fun LazyListScope.updatesUiItems(
} }
is UpdatesUiModel.Item -> { is UpdatesUiModel.Item -> {
val updatesItem = item.item val updatesItem = item.item
val update = updatesItem.update
UpdatesUiItem( UpdatesUiItem(
modifier = Modifier.animateItemPlacement(), modifier = Modifier.animateItemPlacement(),
update = update, update = updatesItem.update,
selected = updatesItem.selected, selected = updatesItem.selected,
onLongClick = { onLongClick = {
onUpdateSelected(updatesItem, !updatesItem.selected, true, true) onUpdateSelected(updatesItem, !updatesItem.selected, true, true)

View File

@ -20,9 +20,9 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update import kotlinx.coroutines.flow.update
import rx.Observable import rx.Observable
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
@ -116,7 +116,7 @@ class ExtensionsPresenter(
items items
} }
.debounce(500) // Avoid crashes due to LazyColumn rendering .stateIn(presenterScope)
.collectLatest { .collectLatest {
state.isLoading = false state.isLoading = false
state.items = it state.items = it

View File

@ -16,8 +16,8 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.flow.stateIn
import logcat.LogPriority import logcat.LogPriority
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
@ -39,11 +39,11 @@ class SourcesPresenter(
fun onCreate() { fun onCreate() {
presenterScope.launchIO { presenterScope.launchIO {
getEnabledSources.subscribe() getEnabledSources.subscribe()
.debounce(500) // Avoid crashes due to LazyColumn rendering
.catch { exception -> .catch { exception ->
logcat(LogPriority.ERROR, exception) logcat(LogPriority.ERROR, exception)
_events.send(Event.FailedFetchingSources) _events.send(Event.FailedFetchingSources)
} }
.stateIn(presenterScope)
.collectLatest(::collectLatestSources) .collectLatest(::collectLatestSources)
} }
} }

View File

@ -33,9 +33,9 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import logcat.LogPriority import logcat.LogPriority
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
@ -87,11 +87,11 @@ class UpdatesPresenter(
getUpdates.subscribe(calendar).distinctUntilChanged(), getUpdates.subscribe(calendar).distinctUntilChanged(),
downloadCache.changes, downloadCache.changes,
) { updates, _ -> updates } ) { updates, _ -> updates }
.debounce(500) // Avoid crashes due to LazyColumn rendering
.catch { .catch {
logcat(LogPriority.ERROR, it) logcat(LogPriority.ERROR, it)
_events.send(Event.InternalError) _events.send(Event.InternalError)
} }
.stateIn(presenterScope)
.collectLatest { updates -> .collectLatest { updates ->
state.items = updates.toUpdateItems() state.items = updates.toUpdateItems()
state.isLoading = false state.isLoading = false