Reset swiped views when canceling a swipe action in the confirmation dialog

This commit is contained in:
cketti 2022-11-14 14:05:35 +01:00
parent 30a2126fcb
commit e17459f210
2 changed files with 30 additions and 8 deletions

View file

@ -76,6 +76,7 @@ class MessageListFragment :
private lateinit var fragmentListener: MessageListFragmentListener
private var recyclerView: RecyclerView? = null
private var itemTouchHelper: ItemTouchHelper? = null
private var swipeRefreshLayout: SwipeRefreshLayout? = null
private lateinit var adapter: MessageListAdapter
@ -278,6 +279,7 @@ class MessageListFragment :
recyclerView.adapter = adapter
this.recyclerView = recyclerView
this.itemTouchHelper = itemTouchHelper
}
private fun initializeSortSettings() {
@ -421,6 +423,7 @@ class MessageListFragment :
override fun onDestroyView() {
recyclerView = null
itemTouchHelper = null
swipeRefreshLayout = null
if (isNewMessagesView && !requireActivity().isChangingConfigurations) {
@ -1108,8 +1111,25 @@ class MessageListFragment :
override fun doNegativeClick(dialogId: Int) {
if (dialogId == R.id.dialog_confirm_spam || dialogId == R.id.dialog_confirm_delete) {
// No further need for this reference
activeMessages = null
val activeMessages = this.activeMessages ?: return
if (activeMessages.size == 1) {
// List item might have been swiped and is still showing the "swipe action background"
resetSwipedView(activeMessages.first())
}
this.activeMessages = null
}
}
private fun resetSwipedView(messageReference: MessageReference) {
val recyclerView = this.recyclerView ?: return
val itemTouchHelper = this.itemTouchHelper ?: return
adapter.getItem(messageReference)?.let { messageListItem ->
recyclerView.findViewHolderForItemId(messageListItem.uniqueId)?.let { viewHolder ->
itemTouchHelper.stopSwipe(viewHolder)
notifyItemChanged(messageListItem)
}
}
}
@ -1491,15 +1511,9 @@ class MessageListFragment :
onArchive(item.messageReference)
}
SwipeAction.Delete -> {
if (K9.isConfirmDelete) {
notifyItemChanged(item)
}
onDelete(listOf(item.messageReference))
}
SwipeAction.Spam -> {
if (K9.isConfirmSpam) {
notifyItemChanged(item)
}
onSpam(listOf(item.messageReference))
}
SwipeAction.Move -> {

View file

@ -938,6 +938,10 @@ public class ItemTouchHelper extends RecyclerView.ItemDecoration
@Override
public void onChildViewDetachedFromWindow(@NonNull View view) {
resetSwipeView(view);
}
private void resetSwipeView(@NonNull View view) {
removeChildDrawingOrderCallbackIfNecessary(view);
final ViewHolder holder = mRecyclerView.getChildViewHolder(view);
if (holder == null) {
@ -953,6 +957,10 @@ public class ItemTouchHelper extends RecyclerView.ItemDecoration
}
}
public void stopSwipe(@NonNull ViewHolder viewHolder) {
resetSwipeView(viewHolder.itemView);
}
/**
* Returns the animation type or 0 if cannot be found.
*/