mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2024-12-22 08:40:03 +02:00
improvements
This commit is contained in:
parent
4584630883
commit
25ad71080e
5 changed files with 56 additions and 10 deletions
|
@ -41,7 +41,7 @@ public class MainApplication extends MultiDexApplication {
|
|||
|
||||
|
||||
private static MainApplication app;
|
||||
|
||||
private WebView webView;
|
||||
public static MainApplication getApp() {
|
||||
return app;
|
||||
}
|
||||
|
@ -52,10 +52,9 @@ public class MainApplication extends MultiDexApplication {
|
|||
app = this;
|
||||
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(MainApplication.this);
|
||||
try {
|
||||
new WebView(this);
|
||||
webView = new WebView(this);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
boolean dynamicColor = sharedpreferences.getBoolean(getString(R.string.SET_DYNAMICCOLOR), false);
|
||||
if (dynamicColor) {
|
||||
DynamicColors.applyToActivitiesIfAvailable(this);
|
||||
|
@ -63,6 +62,12 @@ public class MainApplication extends MultiDexApplication {
|
|||
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
|
||||
StrictMode.setVmPolicy(builder.build());
|
||||
Toasty.Config.getInstance().apply();
|
||||
if (webView != null) {
|
||||
try {
|
||||
webView.destroy();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -117,6 +117,7 @@ public class Status implements Serializable, Cloneable {
|
|||
public boolean isChecked = false;
|
||||
public String translationContent;
|
||||
public boolean translationShown;
|
||||
public boolean mathsShown = false;
|
||||
public boolean canLoadMedia = false;
|
||||
public transient boolean isFocused = false;
|
||||
public transient boolean setCursorToEnd = false;
|
||||
|
|
|
@ -327,7 +327,7 @@ public class Helper {
|
|||
public static final Pattern groupPattern = Pattern.compile("(![\\w_]+)");
|
||||
public static final Pattern mentionPattern = Pattern.compile("(@[\\w_.-]?[\\w]+)");
|
||||
public static final Pattern mentionLongPattern = Pattern.compile("(@[\\w_.-]+@[a-zA-Z0-9][a-zA-Z0-9.-]{1,61}[a-zA-Z0-9](?:\\.[a-zA-Z]{2,})+)");
|
||||
public static final Pattern mathsPattern = Pattern.compile("\\\\\\(");
|
||||
public static final Pattern mathsPattern = Pattern.compile("\\\\\\(|\\\\\\{|\\\\\\[");
|
||||
public static final Pattern twitterPattern = Pattern.compile("((@[\\w]+)@twitter\\.com)");
|
||||
public static final Pattern youtubePattern = Pattern.compile("(www\\.|m\\.)?(youtube\\.com|youtu\\.be|youtube-nocookie\\.com)/(((?!([\"'<])).)*)");
|
||||
public static final Pattern nitterPattern = Pattern.compile("(mobile\\.|www\\.)?twitter.com([\\w-/]+)");
|
||||
|
|
|
@ -644,6 +644,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
if (status.isMaths == null) {
|
||||
if (Helper.mathsPattern.matcher(status.content).find()) {
|
||||
holder.binding.actionButtonMaths.setVisibility(View.VISIBLE);
|
||||
status.isMaths = true;
|
||||
} else {
|
||||
holder.binding.actionButtonMaths.setVisibility(View.GONE);
|
||||
}
|
||||
|
@ -654,10 +655,17 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
holder.binding.actionButtonMaths.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
if (status.mathsShown) {
|
||||
holder.binding.statusContentMaths.setVisibility(View.VISIBLE);
|
||||
holder.binding.statusContent.setVisibility(View.GONE);
|
||||
} else {
|
||||
holder.binding.statusContentMaths.setVisibility(View.GONE);
|
||||
holder.binding.statusContent.setVisibility(View.VISIBLE);
|
||||
}
|
||||
holder.binding.actionButtonMaths.setOnClickListener(v -> {
|
||||
if (holder.binding.statusContentMaths.getVisibility() == View.VISIBLE) {
|
||||
holder.binding.statusContentMaths.setVisibility(View.GONE);
|
||||
holder.binding.statusContent.setVisibility(View.VISIBLE);
|
||||
|
||||
if (status.mathsShown) {
|
||||
status.mathsShown = false;
|
||||
} else {
|
||||
holder.binding.statusContentMaths.removeAllViews();
|
||||
MathJaxConfig mathJaxConfig = new MathJaxConfig();
|
||||
|
@ -669,12 +677,12 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
mathJaxConfig.setTextColor("dark");
|
||||
break;
|
||||
}
|
||||
status.mathsShown = true;
|
||||
MathJaxView mathview = new MathJaxView(context, mathJaxConfig);
|
||||
holder.binding.statusContentMaths.addView(mathview);
|
||||
mathview.setInputText(status.contentSpan.toString());
|
||||
holder.binding.statusContentMaths.setVisibility(View.VISIBLE);
|
||||
holder.binding.statusContent.setVisibility(View.GONE);
|
||||
}
|
||||
adapter.notifyItemChanged(holder.getBindingAdapterPosition());
|
||||
});
|
||||
holder.binding.actionButtonFavorite.setActiveImage(R.drawable.ic_round_star_24);
|
||||
holder.binding.actionButtonFavorite.setInactiveImage(R.drawable.ic_round_star_border_24);
|
||||
|
@ -1305,7 +1313,9 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
if (statusToDeal.content.trim().length() == 0) {
|
||||
holder.binding.mediaContainer.setVisibility(View.GONE);
|
||||
} else {
|
||||
holder.binding.statusContent.setVisibility(View.VISIBLE);
|
||||
if (!status.mathsShown) {
|
||||
holder.binding.statusContent.setVisibility(View.VISIBLE);
|
||||
}
|
||||
if (statusToDeal.card != null && statusToDeal.quote_id == null && (display_card || statusToDeal.isFocused)) {
|
||||
holder.binding.card.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
|
|
|
@ -9,13 +9,17 @@ import android.os.Handler;
|
|||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewConfiguration;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
|
||||
/**
|
||||
* Containerview for an WebView which renders LaTex using MathJax
|
||||
|
@ -148,6 +152,32 @@ public class MathJaxView extends FrameLayout {
|
|||
mWebView.setVerticalScrollBarEnabled(verticalScrollbarsEnabled);
|
||||
mWebView.setHorizontalScrollBarEnabled(horizontalScrollbarsEnabled);
|
||||
mWebView.setBackgroundColor(0);
|
||||
mWebView.getSettings().setLoadWithOverviewMode(true);
|
||||
float touchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
|
||||
final boolean[] scrollFlag = {true};
|
||||
AtomicReference<Float> downX = new AtomicReference<>((float) 0);
|
||||
AtomicReference<Float> downY = new AtomicReference<>((float) 0);
|
||||
mWebView.setOnTouchListener((View v, MotionEvent event) -> {
|
||||
if (!scrollFlag[0] && event.getY() < getHeight() / 2) {
|
||||
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
downX.set(event.getX());
|
||||
downY.set(event.getY());
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
if (Math.abs(event.getY() - downY.get()) < touchSlop && Math.abs(event.getX() - downX.get()) > touchSlop) {
|
||||
getParent().requestDisallowInterceptTouchEvent(true);
|
||||
scrollFlag[0] = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (event.getAction() == MotionEvent.ACTION_UP)
|
||||
scrollFlag[0] = false;
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue