Don't assume non null: API can send bad responses

This commit is contained in:
Matthieu 2021-06-27 10:56:52 +02:00
parent b462ed0904
commit 358e1f7323
2 changed files with 4 additions and 7 deletions

View File

@ -88,8 +88,8 @@ class PostFeedFragment<T: FeedContentDatabase>: CachedFeedFragment<T>() {
} }
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
val uiModel = getItem(position) as Status val uiModel = getItem(position) as Status?
uiModel.let { uiModel?.let {
(holder as StatusViewHolder).bind(it, apiHolder, db, lifecycleScope, displayDimensionsInPx) (holder as StatusViewHolder).bind(it, apiHolder, db, lifecycleScope, displayDimensionsInPx)
} }
} }

View File

@ -91,13 +91,10 @@ class UncachedPostsFragment : UncachedFeedFragment<Status>() {
return StatusViewHolder.create(parent) return StatusViewHolder.create(parent)
} }
override fun getItemViewType(position: Int): Int { override fun getItemViewType(position: Int): Int = R.layout.post_fragment
return R.layout.post_fragment
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
val uiModel = getItem(position) as Status getItem(position)?.let {
uiModel.let {
(holder as StatusViewHolder).bind(it, apiHolder, db, lifecycleScope, displayDimensionsInPx) (holder as StatusViewHolder).bind(it, apiHolder, db, lifecycleScope, displayDimensionsInPx)
} }
} }