From c0ad50b6e61bd6da9db58b815688331cd5b25d15 Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Sun, 30 Jun 2024 16:51:58 +0200 Subject: [PATCH] fix displaying filtered notifications (#4535) ``` java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference at com.keylesspalace.tusky.adapter.StatusBaseViewHolder.setupFilterPlaceholder(StatusBaseViewHolder.java:894) at com.keylesspalace.tusky.adapter.StatusBaseViewHolder.setupWithStatus(StatusBaseViewHolder.java:825) at com.keylesspalace.tusky.adapter.StatusViewHolder.setupWithStatus(StatusViewHolder.java:91) at com.keylesspalace.tusky.components.notifications.StatusViewHolder.bind(StatusViewHolder.kt:46) at com.keylesspalace.tusky.components.notifications.NotificationsPagingAdapter.bindViewHolder(NotificationsPagingAdapter.kt:150) at com.keylesspalace.tusky.components.notifications.NotificationsPagingAdapter.onBindViewHolder(NotificationsPagingAdapter.kt:143) at androidx.recyclerview.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:7847) at androidx.recyclerview.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:6646) at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6917) at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6757) at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6753) at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2362) at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1662) at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1622) at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:687) at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4645) at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:4348) at androidx.recyclerview.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:2106) at androidx.recyclerview.widget.RecyclerView$1.run(RecyclerView.java:468) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1231) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1239) at android.view.Choreographer.doCallbacks(Choreographer.java:899) at android.view.Choreographer.doFrame(Choreographer.java:827) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1214) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7872) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) ``` --- .../NotificationsPagingAdapter.kt | 28 +++++++++++++------ .../notifications/StatusViewHolder.kt | 6 ++-- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/components/notifications/NotificationsPagingAdapter.kt b/app/src/main/java/com/keylesspalace/tusky/components/notifications/NotificationsPagingAdapter.kt index c3d00c142..309f17b72 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/notifications/NotificationsPagingAdapter.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/notifications/NotificationsPagingAdapter.kt @@ -29,7 +29,9 @@ import com.keylesspalace.tusky.databinding.ItemReportNotificationBinding import com.keylesspalace.tusky.databinding.ItemStatusBinding import com.keylesspalace.tusky.databinding.ItemStatusNotificationBinding import com.keylesspalace.tusky.databinding.ItemStatusPlaceholderBinding +import com.keylesspalace.tusky.databinding.ItemStatusWrapperBinding import com.keylesspalace.tusky.databinding.ItemUnknownNotificationBinding +import com.keylesspalace.tusky.entity.Filter import com.keylesspalace.tusky.entity.Notification import com.keylesspalace.tusky.interfaces.AccountActionListener import com.keylesspalace.tusky.interfaces.StatusActionListener @@ -77,7 +79,11 @@ class NotificationsPagingAdapter( is NotificationViewData.Concrete -> { when (notification.type) { Notification.Type.MENTION, - Notification.Type.POLL -> VIEW_TYPE_STATUS + Notification.Type.POLL -> if (notification.statusViewData?.filterAction == Filter.Action.WARN) { + VIEW_TYPE_STATUS_FILTERED + } else { + VIEW_TYPE_STATUS + } Notification.Type.STATUS, Notification.Type.FAVOURITE, Notification.Type.REBLOG, @@ -97,7 +103,12 @@ class NotificationsPagingAdapter( val inflater = LayoutInflater.from(parent.context) return when (viewType) { VIEW_TYPE_STATUS -> StatusViewHolder( - ItemStatusBinding.inflate(inflater, parent, false), + ItemStatusBinding.inflate(inflater, parent, false).root, + statusListener, + accountId + ) + VIEW_TYPE_STATUS_FILTERED -> StatusViewHolder( + ItemStatusWrapperBinding.inflate(inflater, parent, false).root, statusListener, accountId ) @@ -157,12 +168,13 @@ class NotificationsPagingAdapter( companion object { private const val VIEW_TYPE_STATUS = 0 - private const val VIEW_TYPE_STATUS_NOTIFICATION = 1 - private const val VIEW_TYPE_FOLLOW = 2 - private const val VIEW_TYPE_FOLLOW_REQUEST = 3 - private const val VIEW_TYPE_PLACEHOLDER = 4 - private const val VIEW_TYPE_REPORT = 5 - private const val VIEW_TYPE_UNKNOWN = 6 + private const val VIEW_TYPE_STATUS_FILTERED = 1 + private const val VIEW_TYPE_STATUS_NOTIFICATION = 2 + private const val VIEW_TYPE_FOLLOW = 3 + private const val VIEW_TYPE_FOLLOW_REQUEST = 4 + private const val VIEW_TYPE_PLACEHOLDER = 5 + private const val VIEW_TYPE_REPORT = 6 + private const val VIEW_TYPE_UNKNOWN = 7 val NotificationsDifferCallback = object : DiffUtil.ItemCallback() { override fun areItemsTheSame( diff --git a/app/src/main/java/com/keylesspalace/tusky/components/notifications/StatusViewHolder.kt b/app/src/main/java/com/keylesspalace/tusky/components/notifications/StatusViewHolder.kt index fcc289e5c..19ec41608 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/notifications/StatusViewHolder.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/notifications/StatusViewHolder.kt @@ -17,18 +17,18 @@ package com.keylesspalace.tusky.components.notifications +import android.view.View import com.keylesspalace.tusky.adapter.StatusViewHolder -import com.keylesspalace.tusky.databinding.ItemStatusBinding import com.keylesspalace.tusky.entity.Notification import com.keylesspalace.tusky.interfaces.StatusActionListener import com.keylesspalace.tusky.util.StatusDisplayOptions import com.keylesspalace.tusky.viewdata.NotificationViewData internal class StatusViewHolder( - binding: ItemStatusBinding, + itemView: View, private val statusActionListener: StatusActionListener, private val accountId: String -) : NotificationsViewHolder, StatusViewHolder(binding.root) { +) : NotificationsViewHolder, StatusViewHolder(itemView) { override fun bind( viewData: NotificationViewData.Concrete,