Highlight LT text

This commit is contained in:
M66B 2022-10-20 22:17:39 +02:00
parent de9f3f3b18
commit 941dbd86a2
1 changed files with 21 additions and 3 deletions

View File

@ -633,6 +633,7 @@ public class FragmentCompose extends FragmentBase {
private Integer added = null; private Integer added = null;
private Integer removed = null; private Integer removed = null;
private Integer inserted = null; private Integer inserted = null;
private Pair<Integer, Integer> lt = null;
@Override @Override
public void beforeTextChanged(CharSequence text, int start, int count, int after) { public void beforeTextChanged(CharSequence text, int start, int count, int after) {
@ -803,7 +804,7 @@ public class FragmentCompose extends FragmentBase {
while (start > 0 && text.charAt(start - 1) != '\n') while (start > 0 && text.charAt(start - 1) != '\n')
start--; start--;
if (start < added) if (start < added)
onLanguageTool(start, added, true); lt = new Pair<>(start, added);
} }
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); Log.e(ex);
@ -854,6 +855,14 @@ public class FragmentCompose extends FragmentBase {
save = false; save = false;
} }
if (lt != null)
try {
onLanguageTool(lt.first, lt.second, true);
} finally {
lt = null;
}
if (lp != null) if (lp != null)
TextUtils.dumpSpans(text, lp, "---after>"); TextUtils.dumpSpans(text, lp, "---after>");
} }
@ -2590,10 +2599,16 @@ public class FragmentCompose extends FragmentBase {
new SimpleTask<List<LanguageTool.Suggestion>>() { new SimpleTask<List<LanguageTool.Suggestion>>() {
private Toast toast = null; private Toast toast = null;
private BackgroundColorSpan highlightSpan = null;
@Override @Override
protected void onPreExecute(Bundle args) { protected void onPreExecute(Bundle args) {
if (!silent) { if (silent) {
int textColorHighlight = Helper.resolveColor(getContext(), android.R.attr.textColorHighlight);
highlightSpan = new BackgroundColorSpan(textColorHighlight);
etBody.getText().setSpan(highlightSpan, start, end,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_COMPOSING);
} else {
toast = ToastEx.makeText(getContext(), R.string.title_suggestions_check, Toast.LENGTH_LONG); toast = ToastEx.makeText(getContext(), R.string.title_suggestions_check, Toast.LENGTH_LONG);
toast.show(); toast.show();
setBusy(true); setBusy(true);
@ -2602,7 +2617,10 @@ public class FragmentCompose extends FragmentBase {
@Override @Override
protected void onPostExecute(Bundle args) { protected void onPostExecute(Bundle args) {
if (!silent) { if (silent) {
if (highlightSpan != null)
etBody.getText().removeSpan(highlightSpan);
} else {
if (toast != null) if (toast != null)
toast.cancel(); toast.cancel();
setBusy(false); setBusy(false);