fix various timeline related crashes (#2369)

* fix various timeline related crashes

* fix ktlint
This commit is contained in:
Konrad Pozniak 2022-03-06 17:40:24 +01:00 committed by GitHub
parent 73e9338f3c
commit 841373e947
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 3 deletions

View File

@ -217,7 +217,7 @@ class TimelineFragment :
}
})
lifecycleScope.launch {
viewLifecycleOwner.lifecycleScope.launch {
viewModel.statuses.collectLatest { pagingData ->
adapter.submitData(pagingData)
}
@ -271,7 +271,11 @@ class TimelineFragment :
private fun setupRecyclerView() {
binding.recyclerView.setAccessibilityDelegateCompat(
ListStatusAccessibilityDelegate(binding.recyclerView, this) { pos ->
adapter.peek(pos)
if (pos in 0 until adapter.itemCount) {
adapter.peek(pos)
} else {
null
}
}
)
binding.recyclerView.setHasFixedSize(true)

View File

@ -70,7 +70,14 @@ class CachedTimelineViewModel @Inject constructor(
override val statuses = Pager(
config = PagingConfig(pageSize = LOAD_AT_ONCE),
remoteMediator = CachedTimelineRemoteMediator(accountManager, api, db, gson),
pagingSourceFactory = { db.timelineDao().getStatuses(accountManager.activeAccount!!.id) }
pagingSourceFactory = {
val activeAccount = accountManager.activeAccount
if (activeAccount == null) {
EmptyTimelinePagingSource()
} else {
db.timelineDao().getStatuses(activeAccount.id)
}
}
).flow
.map { pagingData ->
pagingData.map { timelineStatus ->

View File

@ -0,0 +1,11 @@
package com.keylesspalace.tusky.components.timeline.viewmodel
import androidx.paging.PagingSource
import androidx.paging.PagingState
import com.keylesspalace.tusky.db.TimelineStatusWithAccount
class EmptyTimelinePagingSource : PagingSource<Int, TimelineStatusWithAccount>() {
override fun getRefreshKey(state: PagingState<Int, TimelineStatusWithAccount>): Int? = null
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, TimelineStatusWithAccount> = LoadResult.Page(emptyList(), null, null)
}