Don't assume non null for discover

This commit is contained in:
Matthieu 2021-06-27 10:57:36 +02:00
parent 358e1f7323
commit d3db8e944e
1 changed files with 3 additions and 3 deletions

View File

@ -100,7 +100,7 @@ class SearchDiscoverFragment : BaseFragment() {
* [RecyclerView.Adapter] that can display a list of [Status]s' thumbnails for the discover view * [RecyclerView.Adapter] that can display a list of [Status]s' thumbnails for the discover view
*/ */
class DiscoverRecyclerViewAdapter: RecyclerView.Adapter<ProfilePostViewHolder>() { class DiscoverRecyclerViewAdapter: RecyclerView.Adapter<ProfilePostViewHolder>() {
private val posts: ArrayList<Status> = ArrayList() private val posts: ArrayList<Status?> = ArrayList()
fun addPosts(newPosts : List<Status>) { fun addPosts(newPosts : List<Status>) {
posts.clear() posts.clear()
@ -116,12 +116,12 @@ class SearchDiscoverFragment : BaseFragment() {
override fun onBindViewHolder(holder: ProfilePostViewHolder, position: Int) { override fun onBindViewHolder(holder: ProfilePostViewHolder, position: Int) {
val post = posts[position] val post = posts[position]
if(post.media_attachments?.size ?: 0 > 1) { if(post?.media_attachments?.size ?: 0 > 1) {
holder.albumIcon.visibility = View.VISIBLE holder.albumIcon.visibility = View.VISIBLE
} else { } else {
holder.albumIcon.visibility = View.GONE holder.albumIcon.visibility = View.GONE
} }
ImageConverter.setSquareImageFromURL(holder.postView, post.media_attachments?.firstOrNull()?.preview_url, holder.postPreview, post.media_attachments?.firstOrNull()?.blurhash) ImageConverter.setSquareImageFromURL(holder.postView, post?.media_attachments?.firstOrNull()?.preview_url, holder.postPreview, post?.media_attachments?.firstOrNull()?.blurhash)
holder.postPreview.setOnClickListener { holder.postPreview.setOnClickListener {
val intent = Intent(holder.postView.context, PostActivity::class.java) val intent = Intent(holder.postView.context, PostActivity::class.java)
intent.putExtra(Status.POST_TAG, post) intent.putExtra(Status.POST_TAG, post)