LT description popup

This commit is contained in:
M66B
2023-09-13 16:22:12 +02:00
parent 98978dc562
commit ac2f4ac6a8
4 changed files with 50 additions and 31 deletions

View File

@@ -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

View File

@@ -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));