Fix crashes when replying

This commit is contained in:
Thomas 2023-02-02 14:03:13 +01:00
parent ddbd3f8684
commit 0ca53b75d2
3 changed files with 18 additions and 14 deletions

View file

@ -29,6 +29,7 @@ import java.util.Date;
import java.util.List; import java.util.List;
import app.fedilab.android.mastodon.helper.SpannableHelper; import app.fedilab.android.mastodon.helper.SpannableHelper;
import de.timfreiheit.mathjax.android.MathJaxView;
public class Status implements Serializable, Cloneable { public class Status implements Serializable, Cloneable {
@ -128,6 +129,7 @@ public class Status implements Serializable, Cloneable {
public transient Spannable contentSpan; public transient Spannable contentSpan;
public transient Spannable contentSpoilerSpan; public transient Spannable contentSpoilerSpan;
public transient Spannable contentTranslateSpan; public transient Spannable contentTranslateSpan;
public transient MathJaxView mathJaxView;
@Override @Override
public boolean equals(@Nullable Object obj) { public boolean equals(@Nullable Object obj) {

View file

@ -20,6 +20,7 @@ import static app.fedilab.android.BaseMainActivity.currentAccount;
import static app.fedilab.android.BaseMainActivity.emojis; import static app.fedilab.android.BaseMainActivity.emojis;
import static app.fedilab.android.BaseMainActivity.instanceInfo; import static app.fedilab.android.BaseMainActivity.instanceInfo;
import static app.fedilab.android.mastodon.activities.ComposeActivity.MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE; import static app.fedilab.android.mastodon.activities.ComposeActivity.MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE;
import static de.timfreiheit.mathjax.android.MathJaxConfig.Input.TeX;
import android.Manifest; import android.Manifest;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
@ -127,6 +128,8 @@ import app.fedilab.android.mastodon.helper.ThemeHelper;
import app.fedilab.android.mastodon.imageeditor.EditImageActivity; import app.fedilab.android.mastodon.imageeditor.EditImageActivity;
import app.fedilab.android.mastodon.viewmodel.mastodon.AccountsVM; import app.fedilab.android.mastodon.viewmodel.mastodon.AccountsVM;
import app.fedilab.android.mastodon.viewmodel.mastodon.SearchVM; import app.fedilab.android.mastodon.viewmodel.mastodon.SearchVM;
import de.timfreiheit.mathjax.android.MathJaxConfig;
import de.timfreiheit.mathjax.android.MathJaxView;
import es.dmoral.toasty.Toasty; import es.dmoral.toasty.Toasty;
@ -702,19 +705,26 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
} }
Matcher mathsPatterns = Helper.mathsComposePattern.matcher((s.toString())); Matcher mathsPatterns = Helper.mathsComposePattern.matcher((s.toString()));
if (mathsPatterns.find()) { if (mathsPatterns.find()) {
if (holder.binding.laTexViewContainer.getVisibility() != View.VISIBLE) { if (holder.binding.laTexViewContainer.getChildCount() == 0) {
holder.binding.laTexViewContainer.setVisibility(View.VISIBLE); MathJaxConfig mathJaxConfig = new MathJaxConfig();
mathJaxConfig.setAutomaticLinebreaks(true);
mathJaxConfig.setInput(TeX);
switch (context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) { switch (context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) {
case Configuration.UI_MODE_NIGHT_YES: case Configuration.UI_MODE_NIGHT_YES:
holder.binding.laTexView.setTextColor("white"); mathJaxConfig.setTextColor("white");
break; break;
case Configuration.UI_MODE_NIGHT_NO: case Configuration.UI_MODE_NIGHT_NO:
holder.binding.laTexView.setTextColor("black"); mathJaxConfig.setTextColor("black");
break; break;
} }
statusList.get(holder.getBindingAdapterPosition()).mathJaxView = new MathJaxView(context, mathJaxConfig);
holder.binding.laTexViewContainer.addView(statusList.get(holder.getBindingAdapterPosition()).mathJaxView);
holder.binding.laTexViewContainer.setVisibility(View.VISIBLE);
} }
holder.binding.laTexView.setInputText(s.toString()); if (statusList.get(holder.getBindingAdapterPosition()).mathJaxView != null) {
statusList.get(holder.getBindingAdapterPosition()).mathJaxView.setInputText(s.toString());
}
} else { } else {
holder.binding.laTexViewContainer.setVisibility(View.GONE); holder.binding.laTexViewContainer.setVisibility(View.GONE);
} }

View file

@ -41,14 +41,6 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintTop_toTopOf="parent">
<de.timfreiheit.mathjax.android.MathJaxView
android:id="@+id/laTexView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:automaticLinebreaks="true"
app:input="TeX"
app:output="SVG" />
</androidx.core.widget.NestedScrollView> </androidx.core.widget.NestedScrollView>