diff --git a/app/src/main/java/app/fedilab/android/helper/Helper.java b/app/src/main/java/app/fedilab/android/helper/Helper.java index f6c35ba6..6ea6179a 100644 --- a/app/src/main/java/app/fedilab/android/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/helper/Helper.java @@ -327,7 +327,8 @@ 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 mathsComposePattern = 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-/]+)"); diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java index 7933713e..5c580ae6 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java @@ -28,6 +28,7 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; +import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Color; @@ -531,7 +532,9 @@ public class ComposeAdapter extends RecyclerView.Adapter 0) { + statusList.get(holder.getLayoutPosition()).cursorPosition = holder.binding.content.getSelectionStart(); + } //Copy/past int max_car = MastodonHelper.getInstanceMaxChars(context); if (currentLength > max_car) { @@ -694,6 +697,24 @@ public class ComposeAdapter extends RecyclerView.Adapter { + int cursorPosition = holder.binding.content.getSelectionStart(); + AlertDialog.Builder builder = new AlertDialog.Builder(context, Helper.dialogStyle()); + Resources res = context.getResources(); + String[] formatArr = res.getStringArray(R.array.SET_MATHS_FORMAT); + builder.setItems(formatArr, (dialogInterface, i) -> { + if (statusDraft.text == null) { + statusDraft.text = ""; + } + if (i == 0) { + statusDraft.text = new StringBuilder(statusDraft.text).insert(cursorPosition, "\\( \\)").toString(); + } else { + statusDraft.text = new StringBuilder(statusDraft.text).insert(cursorPosition, "\\[ \\]").toString(); + } + statusDraft.cursorPosition = cursorPosition + 3; + notifyItemChanged(position); + dialogInterface.dismiss(); + }); + builder.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); + builder.create().show(); + }); + } else { + holder.binding.buttonMathsComposer.setVisibility(View.GONE); + } holder.binding.buttonEmojiOne.setVisibility(View.VISIBLE); if (extraFeatures) { diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java index af9c1ddf..eeff36c4 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java @@ -674,9 +674,10 @@ public class StatusAdapter extends RecyclerView.Adapter mathJaxConfig.setTextColor("white"); break; case Configuration.UI_MODE_NIGHT_NO: - mathJaxConfig.setTextColor("dark"); + mathJaxConfig.setTextColor("black"); break; } + mathJaxConfig.setAutomaticLinebreaks(true); status.mathsShown = true; MathJaxView mathview = new MathJaxView(context, mathJaxConfig); holder.binding.statusContentMaths.addView(mathview); diff --git a/app/src/main/res/layout/drawer_status_compose.xml b/app/src/main/res/layout/drawer_status_compose.xml index 81e2173e..b191643b 100644 --- a/app/src/main/res/layout/drawer_status_compose.xml +++ b/app/src/main/res/layout/drawer_status_compose.xml @@ -32,6 +32,27 @@ android:clipToPadding="false" android:orientation="vertical"> + + + + + + + app:layout_constraintTop_toBottomOf="@+id/laTexView_container" /> + + Mastalab + + + Inline\nNotation that sits inline with other text\n + Display-mode\nNotation that sits on its own line\n + + text/plain text/html @@ -1483,6 +1489,7 @@ SET_UNLISTED_REPLIES SET_SELECTED_LANGUAGE SET_WATERMARK_TEXT + SET_MATHS_COMPOSER SET_PROXY_PASSWORD SET_PROXY_LOGIN SET_ACCOUNTS_PER_CALL @@ -2214,4 +2221,6 @@ Disable release notes When a new version is published, you will not be alerted inside the app. Formula + Write formula + Maths format \ No newline at end of file diff --git a/app/src/main/res/xml/pref_compose.xml b/app/src/main/res/xml/pref_compose.xml index 4f263dd5..250aa892 100644 --- a/app/src/main/res/xml/pref_compose.xml +++ b/app/src/main/res/xml/pref_compose.xml @@ -60,6 +60,12 @@ app:key="@string/SET_WATERMARK_TEXT" app:useSimpleSummaryProvider="true" /> + = Build.VERSION_CODES.KITKAT) { + mWebView.evaluateJavascript("document.body.style.color=\"" + color + "\";", null); + } + } + @SuppressLint({"SetJavaScriptEnabled", "AddJavascriptInterface"}) private void init(Context context, AttributeSet attrSet, MathJaxConfig config) { mWebView = new WebView(context); int gravity = Gravity.START; boolean verticalScrollbarsEnabled = false; - boolean horizontalScrollbarsEnabled = true; + boolean horizontalScrollbarsEnabled = false; String textColor = config != null ? config.getTextColor() : null; if (attrSet != null) { TypedArray attrs = context.obtainStyledAttributes(attrSet, R.styleable.MathJaxView); gravity = attrs.getInteger(R.styleable.MathJaxView_android_gravity, Gravity.START); verticalScrollbarsEnabled = attrs.getBoolean(R.styleable.MathJaxView_verticalScrollbarsEnabled, false); - horizontalScrollbarsEnabled = attrs.getBoolean(R.styleable.MathJaxView_horizontalScrollbarsEnabled, true); + horizontalScrollbarsEnabled = attrs.getBoolean(R.styleable.MathJaxView_horizontalScrollbarsEnabled, false); textColor = attrs.getString(R.styleable.MathJaxView_textColor); config = new MathJaxConfig(attrs); attrs.recycle(); @@ -153,31 +155,6 @@ public class MathJaxView extends FrameLayout { mWebView.setHorizontalScrollBarEnabled(horizontalScrollbarsEnabled); mWebView.setBackgroundColor(0); mWebView.getSettings().setLoadWithOverviewMode(true); - float touchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); - final boolean[] scrollFlag = {true}; - AtomicReference downX = new AtomicReference<>((float) 0); - AtomicReference 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; - }); } /**