Cache formatted bodies

This commit is contained in:
M66B 2018-12-22 08:48:23 +01:00
parent 90f52c6696
commit 852c489ad7
2 changed files with 26 additions and 4 deletions

View File

@ -490,11 +490,12 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
tvBody.setTextSize(textSize / context.getResources().getDisplayMetrics().density);
ta.recycle();
tvBody.setText(null);
tvBody.setMovementMethod(null);
Spanned body = properties.getBody(message.id);
tvBody.setText(body);
tvBody.setMovementMethod(new UrlHandler());
pbBody.setVisibility(View.VISIBLE);
if (message.content) {
if (body == null && message.content) {
Bundle args = new Bundle();
args.putSerializable("message", message);
bodyTask.load(context, owner, args);
@ -580,7 +581,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
Helper.unexpectedError(context, owner, ex);
}
}.load(context, owner, sargs);
}
} else
properties.setBody(message.id, null);
itemView.setActivated(selectionTracker != null && selectionTracker.isSelected(message.id));
}
@ -850,6 +852,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
tvBody.setText(body);
tvBody.setMovementMethod(new UrlHandler());
pbBody.setVisibility(View.GONE);
properties.setBody(message.id, body);
}
@Override
@ -1755,6 +1758,10 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
boolean getValue(String name, long id);
void setBody(long id, Spanned body);
Spanned getBody(long id);
void move(long id, String target, boolean type);
}
}

View File

@ -29,6 +29,7 @@ import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.text.Spanned;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
@ -119,6 +120,7 @@ public class FragmentMessages extends FragmentEx {
private int autoCloseCount = 0;
private boolean autoExpand = true;
private Map<String, List<Long>> values = new HashMap<>();
private Map<Long, Spanned> bodies = new HashMap<>();
private BoundaryCallbackMessages searchCallback = null;
@ -319,6 +321,19 @@ public class FragmentMessages extends FragmentEx {
return false;
}
@Override
public void setBody(long id, Spanned body) {
if (body == null)
bodies.remove(id);
else
bodies.put(id, body);
}
@Override
public Spanned getBody(long id) {
return bodies.get(id);
}
@Override
public void move(long id, String name, boolean type) {
Bundle args = new Bundle();