LT description popup

pull/214/head
M66B 12 months ago
parent 98978dc562
commit ac2f4ac6a8

@ -77,6 +77,10 @@ public class EditTextCompose extends FixedEditText {
private int colorBlockquote;
private int quoteGap;
private int quoteStripe;
private boolean lt_description;
private int lastStart = -1;
private int lastEnd = -1;
public EditTextCompose(Context context) {
super(context);
@ -96,12 +100,13 @@ public class EditTextCompose extends FixedEditText {
void init(Context context) {
Helper.setKeyboardIncognitoMode(this, context);
colorPrimary = Helper.resolveColor(context, androidx.appcompat.R.attr.colorPrimary);
colorBlockquote = Helper.resolveColor(context, R.attr.colorBlockquote, colorPrimary);
quoteGap = context.getResources().getDimensionPixelSize(R.dimen.quote_gap_size);
quoteStripe = context.getResources().getDimensionPixelSize(R.dimen.quote_stripe_width);
this.colorPrimary = Helper.resolveColor(context, androidx.appcompat.R.attr.colorPrimary);
this.colorBlockquote = Helper.resolveColor(context, R.attr.colorBlockquote, colorPrimary);
this.quoteGap = context.getResources().getDimensionPixelSize(R.dimen.quote_gap_size);
this.quoteStripe = context.getResources().getDimensionPixelSize(R.dimen.quote_stripe_width);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
this.lt_description = prefs.getBoolean("lt_description", false);
boolean undo_manager = prefs.getBoolean("undo_manager", false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
@ -114,8 +119,6 @@ public class EditTextCompose extends FixedEditText {
order++, context.getString(R.string.title_insert_brackets));
menu.add(Menu.CATEGORY_SECONDARY, R.string.title_insert_quotes,
order++, context.getString(R.string.title_insert_quotes));
menu.add(Menu.CATEGORY_SECONDARY, R.string.title_setup_help,
order++, context.getString(R.string.title_setup_help));
menu.add(Menu.CATEGORY_SECONDARY, R.string.title_lt_add,
order++, context.getString(R.string.title_lt_add));
menu.add(Menu.CATEGORY_SECONDARY, R.string.title_lt_delete,
@ -144,7 +147,6 @@ public class EditTextCompose extends FixedEditText {
edit.subSequence(start, end).toString().indexOf(' ') < 0);
menu.findItem(R.string.title_insert_brackets).setVisible(selection);
menu.findItem(R.string.title_insert_quotes).setVisible(selection);
menu.findItem(R.string.title_setup_help).setVisible(hasSuggestions);
menu.findItem(R.string.title_lt_add).setVisible(dictionary);
menu.findItem(R.string.title_lt_delete).setVisible(dictionary);
return false;
@ -158,13 +160,6 @@ public class EditTextCompose extends FixedEditText {
return surround("(", ")");
else if (id == R.string.title_insert_quotes)
return surround("\"", "\"");
else if (id == R.string.title_setup_help) {
if (showSuggestion()) {
mode.finish();
return true;
}
} else if (id == R.string.title_lt_add)
return modifyDictionary(true);
else if (id == R.string.title_lt_delete)
return modifyDictionary(false);
}
@ -240,21 +235,6 @@ public class EditTextCompose extends FixedEditText {
return true;
}
private boolean showSuggestion() {
Editable edit = getText();
if (edit == null)
return false;
int start = getSelectionStart();
int end = getSelectionEnd();
if (end <= start)
return false;
SuggestionSpanEx[] suggestions = edit.getSpans(start, end, SuggestionSpanEx.class);
if (suggestions == null || suggestions.length == 0)
return false;
ToastEx.makeText(getContext(), suggestions[0].getDescription(), Toast.LENGTH_LONG).show();
return true;
}
});
setCustomInsertionActionModeCallback(new ActionMode.Callback() {
@ -477,6 +457,20 @@ public class EditTextCompose extends FixedEditText {
super.onSelectionChanged(selStart, selEnd);
if (selectionListener != null)
selectionListener.onSelected(hasSelection());
if (selStart != lastStart && selEnd != lastEnd) {
lastStart = selStart;
lastEnd = selEnd;
Editable edit = getText();
if (lastStart >= 0 && edit != null && lt_description) {
SuggestionSpanEx[] suggestions = getText().getSpans(selStart, selEnd, SuggestionSpanEx.class);
if (suggestions != null && suggestions.length > 0) {
String description = suggestions[0].getDescription();
if (!TextUtils.isEmpty(description))
ToastEx.makeText(getContext(), description, Toast.LENGTH_LONG).show();
}
}
}
}
@Override

@ -148,6 +148,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private SwitchCompat swLanguageToolAuto;
private SwitchCompat swLanguageToolPicky;
private SwitchCompat swLanguageToolHighlight;
private SwitchCompat swLanguageToolDescription;
private EditText etLanguageTool;
private EditText etLanguageToolUser;
private TextInputLayout tilLanguageToolKey;
@ -287,7 +288,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
"classification", "class_min_probability", "class_min_difference",
"show_filtered",
"language",
"lt_enabled", "lt_sentence", "lt_auto", "lt_picky", "lt_highlight", "lt_uri", "lt_user", "lt_key",
"lt_enabled", "lt_sentence", "lt_auto", "lt_picky", "lt_highlight", "lt_description", "lt_uri", "lt_user", "lt_key",
"deepl_enabled",
"vt_enabled", "vt_apikey",
"send_enabled", "send_host", "send_dlimit", "send_tlimit",
@ -405,6 +406,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swLanguageToolAuto = view.findViewById(R.id.swLanguageToolAuto);
swLanguageToolPicky = view.findViewById(R.id.swLanguageToolPicky);
swLanguageToolHighlight = view.findViewById(R.id.swLanguageToolHighlight);
swLanguageToolDescription = view.findViewById(R.id.swLanguageToolDescription);
etLanguageTool = view.findViewById(R.id.etLanguageTool);
etLanguageToolUser = view.findViewById(R.id.etLanguageToolUser);
tilLanguageToolKey = view.findViewById(R.id.tilLanguageToolKey);
@ -866,6 +868,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swLanguageToolAuto.setEnabled(checked);
swLanguageToolPicky.setEnabled(checked);
swLanguageToolHighlight.setEnabled(checked);
swLanguageToolDescription.setEnabled(checked);
}
});
@ -905,6 +908,13 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
}
});
swLanguageToolDescription.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("lt_description", checked).apply();
}
});
etLanguageTool.setHint(LanguageTool.LT_URI);
etLanguageTool.addTextChangedListener(new TextWatcher() {
@Override
@ -2574,6 +2584,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swLanguageToolPicky.setEnabled(swLanguageTool.isChecked());
swLanguageToolHighlight.setChecked(prefs.getBoolean("lt_highlight", !BuildConfig.PLAY_STORE_RELEASE));
swLanguageToolHighlight.setEnabled(swLanguageTool.isChecked());
swLanguageToolDescription.setChecked(prefs.getBoolean("lt_description", false));
swLanguageToolDescription.setEnabled(swLanguageTool.isChecked());
etLanguageTool.setText(prefs.getString("lt_uri", null));
etLanguageToolUser.setText(prefs.getString("lt_user", null));
tilLanguageToolKey.getEditText().setText(prefs.getString("lt_key", null));

@ -696,6 +696,18 @@
app:layout_constraintTop_toBottomOf="@id/swLanguageToolPicky"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swLanguageToolDescription"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_lt_description"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swLanguageToolHighlight"
app:switchPadding="12dp" />
<EditText
android:id="@+id/etLanguageTool"
android:layout_width="0dp"
@ -706,7 +718,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swLanguageToolHighlight" />
app:layout_constraintTop_toBottomOf="@id/swLanguageToolDescription" />
<EditText
android:id="@+id/etLanguageToolUser"

@ -827,6 +827,7 @@
<string name="title_advanced_lt_sentence">Check every sentence</string>
<string name="title_advanced_lt_auto">Check paragraph after a new line</string>
<string name="title_advanced_lt_highlight">Highlight the text being checked</string>
<string name="title_advanced_lt_description">Show popup with problem description</string>
<string name="title_advanced_lt_user">Username (optional)</string>
<string name="title_advanced_lt_key">API key (optional)</string>
<string name="title_advanced_deepl">DeepL integration</string>

Loading…
Cancel
Save