Fix some crashes

This commit is contained in:
Thomas 2023-01-31 15:00:40 +01:00
parent c37d8ab34f
commit f8b0ed7f18
2 changed files with 22 additions and 28 deletions

View file

@ -2434,28 +2434,19 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
@Override
public List<Attachment> getPreloadItems(int position) {
List<Attachment> attachments = new ArrayList<>();
if (position == 0 && statusList.size() > 0) {
for (Status status : statusList.subList(0, 1)) {
int max_size = statusList.size();
int siblings = 3;
int from = Math.max((position - siblings), 0);
if (from > max_size - 1) {
from = max_size - 1;
}
int to = Math.min(position + siblings, max_size - 1);
for (Status status : statusList.subList(from, to)) {
Status statusToDeal = status.reblog != null ? status.reblog : status;
if (statusToDeal.media_attachments != null && statusToDeal.media_attachments.size() > 0) {
attachments.addAll(statusToDeal.media_attachments);
}
}
} else if (position > 0 && position < (statusList.size() - 1)) {
for (Status status : statusList.subList(position - 1, position + 1)) {
Status statusToDeal = status.reblog != null ? status.reblog : status;
if (statusToDeal.media_attachments != null && statusToDeal.media_attachments.size() > 0) {
attachments.addAll(statusToDeal.media_attachments);
}
}
} else {
for (Status status : statusList.subList(position, position)) {
Status statusToDeal = status.reblog != null ? status.reblog : status;
if (statusToDeal.media_attachments != null && statusToDeal.media_attachments.size() > 0) {
attachments.addAll(statusToDeal.media_attachments);
}
}
}
return attachments;
}

View file

@ -1,8 +1,9 @@
package de.timfreiheit.mathjax.android;
import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.app.Application;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build;
@ -91,7 +92,7 @@ public class MathJaxView extends FrameLayout {
}
}
public static String getProcessName(Context context) {
/* public static String getProcessName(Context context) {
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) {
if (processInfo.pid == android.os.Process.myPid()) {
@ -100,10 +101,16 @@ public class MathJaxView extends FrameLayout {
}
return null;
}
}*/
@SuppressLint({"SetJavaScriptEnabled", "AddJavascriptInterface"})
private void init(Context context, AttributeSet attrSet, MathJaxConfig config) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
String process = Application.getProcessName();
if (!context.getPackageName().equals(process))
WebView.setDataDirectorySuffix(process);
}
mWebView = new WebView(context);
int gravity = Gravity.START;
@ -170,11 +177,7 @@ public class MathJaxView extends FrameLayout {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
WebView.setWebContentsDebuggingEnabled(true);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
String process = getProcessName(context);
if (!context.getPackageName().equals(process))
WebView.setDataDirectorySuffix(process);
}
}
/**