fix memory leak
This commit is contained in:
parent
3db7c2c3da
commit
94d9b69c6c
|
@ -1511,6 +1511,11 @@ public class ConversationFragment extends XmppFragment
|
||||||
Log.d(Config.LOGTAG, "ConversationFragment.onDestroyView()");
|
Log.d(Config.LOGTAG, "ConversationFragment.onDestroyView()");
|
||||||
messageListAdapter.setOnContactPictureClicked(null);
|
messageListAdapter.setOnContactPictureClicked(null);
|
||||||
messageListAdapter.setOnContactPictureLongClicked(null);
|
messageListAdapter.setOnContactPictureLongClicked(null);
|
||||||
|
messageListAdapter.setOnMessageBoxSwiped(null);
|
||||||
|
messageListAdapter.setMessageEmptyPartLongClickListener(null);
|
||||||
|
messageListAdapter.setReplyClickListener(null);
|
||||||
|
messageListAdapter.setSelectionStatusProvider(null);
|
||||||
|
binding.messagesView.clearDragHelper();
|
||||||
binding.conversationViewPager.setAdapter(null);
|
binding.conversationViewPager.setAdapter(null);
|
||||||
if (conversation != null) conversation.setupViewPager(null, null, null);
|
if (conversation != null) conversation.setupViewPager(null, null, null);
|
||||||
binding.tabLayout.setListener(null);
|
binding.tabLayout.setListener(null);
|
||||||
|
|
|
@ -18,6 +18,10 @@ class DraggableListView : ListView {
|
||||||
|
|
||||||
private var dragHelper: ViewDragHelper? = null
|
private var dragHelper: ViewDragHelper? = null
|
||||||
|
|
||||||
|
fun clearDragHelper() {
|
||||||
|
dragHelper = null;
|
||||||
|
}
|
||||||
|
|
||||||
override fun setAdapter(adapter: ListAdapter?) {
|
override fun setAdapter(adapter: ListAdapter?) {
|
||||||
super.setAdapter(adapter)
|
super.setAdapter(adapter)
|
||||||
val dragHelperCallback = if (adapter is DraggableAdapter) {
|
val dragHelperCallback = if (adapter is DraggableAdapter) {
|
||||||
|
|
|
@ -43,6 +43,7 @@ import androidx.customview.widget.ViewDragHelper;
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -502,19 +503,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements DraggableLi
|
||||||
DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
|
DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
|
||||||
body.setSpan(new QuoteSpan(color, highlightReply ? ContextCompat.getColor(activity, R.color.blue_a100) : -1, metrics), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
body.setSpan(new QuoteSpan(color, highlightReply ? ContextCompat.getColor(activity, R.color.blue_a100) : -1, metrics), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
if (highlightReply) {
|
if (highlightReply) {
|
||||||
body.setSpan(new ClickableSpan() {
|
body.setSpan(new ReplyClickableSpan(new WeakReference(replyClickListener), new WeakReference(message)), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
@Override
|
|
||||||
public void onClick(@NonNull View widget) {
|
|
||||||
if (replyClickListener != null) {
|
|
||||||
replyClickListener.onReplyClick(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateDrawState(@NonNull TextPaint ds) {
|
|
||||||
ds.setUnderlineText(false);
|
|
||||||
}
|
|
||||||
}, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1252,6 +1241,30 @@ public class MessageAdapter extends ArrayAdapter<Message> implements DraggableLi
|
||||||
void onReplyClick(Message message);
|
void onReplyClick(Message message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class ReplyClickableSpan extends ClickableSpan {
|
||||||
|
private WeakReference<ReplyClickListener> replyClickListener;
|
||||||
|
private WeakReference<Message> message;
|
||||||
|
|
||||||
|
public ReplyClickableSpan(WeakReference<ReplyClickListener> replyClickListener, WeakReference<Message> message) {
|
||||||
|
this.replyClickListener = replyClickListener;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(@NonNull View widget) {
|
||||||
|
ReplyClickListener listener = replyClickListener.get();
|
||||||
|
Message message = this.message.get();
|
||||||
|
if (listener != null && message != null) {
|
||||||
|
listener.onReplyClick(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateDrawState(@NonNull TextPaint ds) {
|
||||||
|
ds.setUnderlineText(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class ViewHolder {
|
private static class ViewHolder {
|
||||||
public View root;
|
public View root;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue