aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/ui/adapter
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2016-10-21 21:54:15 +0200
committerChristian Schneppe <christian@pix-art.de>2016-10-21 21:54:15 +0200
commit268e2bcd5e71c43a5cb53fc966128dc19144c330 (patch)
treeb686078f5b9710e540acae3f6b27292f54ff6488 /src/main/java/de/pixart/messenger/ui/adapter
parent925fb008fed0d490a238169e07d862957ad93efa (diff)
Retain TextView selection after list updating
Diffstat (limited to 'src/main/java/de/pixart/messenger/ui/adapter')
-rw-r--r--src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java23
1 files changed, 22 insertions, 1 deletions
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<Message> {
private OnContactPictureLongClicked mOnContactPictureLongClickedListener;
private boolean mIndicateReceived = false;
+ private final ListSelectionManager listSelectionManager = new ListSelectionManager();
private HashMap<Integer, AudioWife> audioPlayer;
private boolean mUseWhiteBackground = false;
@@ -365,7 +367,9 @@ public class MessageAdapter extends ArrayAdapter<Message> {
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<Message> {
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<Message> {
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<Message> {
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);
}