From 268e2bcd5e71c43a5cb53fc966128dc19144c330 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Fri, 21 Oct 2016 21:54:15 +0200 Subject: Retain TextView selection after list updating --- .../messenger/ui/adapter/MessageAdapter.java | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/main/java/de/pixart/messenger/ui/adapter') diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java index b53622984..6dc6a9ed1 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java @@ -57,6 +57,7 @@ import de.pixart.messenger.persistance.FileBackend; import de.pixart.messenger.ui.ConversationActivity; import de.pixart.messenger.ui.ShowFullscreenMessageActivity; import de.pixart.messenger.ui.widget.ClickableMovementMethod; +import de.pixart.messenger.ui.widget.ListSelectionManager; import de.pixart.messenger.utils.CryptoHelper; import de.pixart.messenger.utils.GeoHelper; import de.pixart.messenger.utils.UIHelper; @@ -83,6 +84,7 @@ public class MessageAdapter extends ArrayAdapter { private OnContactPictureLongClicked mOnContactPictureLongClickedListener; private boolean mIndicateReceived = false; + private final ListSelectionManager listSelectionManager = new ListSelectionManager(); private HashMap audioPlayer; private boolean mUseWhiteBackground = false; @@ -365,7 +367,9 @@ public class MessageAdapter extends ArrayAdapter { viewHolder.messageBody.setText(formattedBody); viewHolder.messageBody.setTextIsSelectable(true); viewHolder.messageBody.setMovementMethod(ClickableMovementMethod.getInstance()); - } else { + listSelectionManager.onUpdate(viewHolder.messageBody, message); + + } else { viewHolder.messageBody.setText(""); viewHolder.messageBody.setTextIsSelectable(false); } @@ -587,6 +591,7 @@ public class MessageAdapter extends ArrayAdapter { viewHolder = null; break; } + if (viewHolder.messageBody != null) listSelectionManager.onCreate(viewHolder.messageBody); view.setTag(viewHolder); if (viewHolder == null) { return view; @@ -743,6 +748,13 @@ public class MessageAdapter extends ArrayAdapter { return view; } + @Override + public void notifyDataSetChanged() { + listSelectionManager.onBeforeNotifyDataSetChanged(); + super.notifyDataSetChanged(); + listSelectionManager.onAfterNotifyDataSetChanged(); + } + public void openDownloadable(Message message) { DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message); if (!file.exists()) { @@ -814,6 +826,15 @@ public class MessageAdapter extends ArrayAdapter { this.mUseWhiteBackground = activity.useWhiteBackground(); } + public TextView getMessageBody(View view) { + final Object tag = view.getTag(); + if (tag instanceof ViewHolder) { + final ViewHolder viewHolder = (ViewHolder) tag; + return viewHolder.messageBody; + } + return null; + } + public interface OnContactPictureClicked { void onContactPictureClicked(Message message); } -- cgit v1.2.3