Set web view scroll position

pull/162/head
M66B 5 years ago
parent 7799aebfab
commit 86c7fcfbc7

@ -64,6 +64,7 @@ import android.text.style.DynamicDrawableSpan;
import android.text.style.ImageSpan;
import android.text.style.QuoteSpan;
import android.text.style.URLSpan;
import android.util.Pair;
import android.util.TypedValue;
import android.view.KeyEvent;
import android.view.LayoutInflater;
@ -1248,6 +1249,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
boolean show_quotes = (properties.getValue("quotes", message.id) || !collapse_quotes);
float size = properties.getSize(message.id, show_full ? 0 : textSize);
int height = properties.getHeight(message.id, dp60);
Pair<Integer, Integer> position = properties.getPosition(message.id);
Log.i("Bind size=" + size + " height=" + height);
if (show_full) {
@ -1315,6 +1317,14 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
webView.setOnScrollChangeListener(new View.OnScrollChangeListener() {
@Override
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
properties.setPosition(message.id, new Pair<Integer, Integer>(scrollX, scrollY));
}
});
webView.setDownloadListener(new DownloadListener() {
public void onDownloadStart(
String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
@ -1376,6 +1386,10 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
if (size != 0)
webView.setInitialScale(Math.round(size * 100));
wvBody.setMinimumHeight(height);
if (position != null) {
wvBody.setScrollX(position.first);
wvBody.setScrollY(position.second);
}
tvBody.setVisibility(View.GONE);
wvBody.setVisibility(View.VISIBLE);
@ -4016,6 +4030,10 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
int getHeight(long id, int defaultHeight);
void setPosition(long id, Pair<Integer, Integer> position);
Pair<Integer, Integer> getPosition(long id);
void setAttachments(long id, List<EntityAttachment> attachments);
List<EntityAttachment> getAttachments(long id);

@ -51,6 +51,7 @@ import android.print.PrintManager;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.util.LongSparseArray;
import android.util.Pair;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.Menu;
@ -232,6 +233,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
private Map<String, List<Long>> values = new HashMap<>();
private LongSparseArray<Float> sizes = new LongSparseArray<>();
private LongSparseArray<Integer> heights = new LongSparseArray<>();
private LongSparseArray<Pair<Integer, Integer>> positions = new LongSparseArray<>();
private LongSparseArray<List<EntityAttachment>> attachments = new LongSparseArray<>();
private LongSparseArray<TupleAccountSwipes> accountSwipes = new LongSparseArray<>();
@ -1260,6 +1262,15 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
return heights.get(id, defaultHeight);
}
public void setPosition(long id, Pair<Integer, Integer> position) {
Log.i("Position=" + position);
positions.put(id, position);
}
public Pair<Integer, Integer> getPosition(long id) {
return positions.get(id);
}
@Override
public void setAttachments(long id, List<EntityAttachment> list) {
attachments.put(id, list);
@ -2181,6 +2192,19 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
outState.putLongArray("fair:heights:keys", hkeys);
outState.putIntArray("fair:heights:values", hvalues);
long[] pkeys = new long[positions.size()];
int[] xvalues = new int[positions.size()];
int[] yvalues = new int[positions.size()];
for (int i = 0; i < positions.size(); i++) {
pkeys[i] = positions.keyAt(i);
Pair<Integer, Integer> position = positions.valueAt(i);
xvalues[i] = position.first;
yvalues[i] = position.second;
}
outState.putLongArray("fair:pos:keys", pkeys);
outState.putIntArray("fair:posx:values", xvalues);
outState.putIntArray("fair:posy:values", yvalues);
if (rvMessage != null) {
Parcelable rv = rvMessage.getLayoutManager().onSaveInstanceState();
outState.putParcelable("fair:rv", rv);
@ -2221,6 +2245,13 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
for (int i = 0; i < hkeys.length; i++)
heights.put(hkeys[i], hvalues[i]);
long[] pkeys = savedInstanceState.getLongArray("fair:pos:keys");
int[] xvalues = savedInstanceState.getIntArray("fair:posx:values");
int[] yvalues = savedInstanceState.getIntArray("fair:posy:values");
for (int i = 0; i < pkeys.length; i++)
positions.put(pkeys[i], new Pair<Integer, Integer>(xvalues[i], yvalues[i]));
if (rvMessage != null) {
Parcelable rv = savedInstanceState.getBundle("fair:rv");
rvMessage.getLayoutManager().onRestoreInstanceState(rv);
@ -2340,6 +2371,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
values.get(key).remove(id);
sizes.remove(id);
heights.remove(id);
positions.remove(id);
attachments.remove(id);
}
updateExpanded();

Loading…
Cancel
Save