mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2025-09-15 08:20:18 +03:00
Improve translate button preference (fix #667)
This commit is contained in:
parent
18e666649e
commit
80d7443edd
5 changed files with 47 additions and 18 deletions
|
@ -1132,6 +1132,19 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
||||||
}
|
}
|
||||||
String software = sharedpreferences.getString(PREF_USER_SOFTWARE, null);
|
String software = sharedpreferences.getString(PREF_USER_SOFTWARE, null);
|
||||||
|
|
||||||
|
if (sharedpreferences.getString(getString(R.string.SET_TRANSLATE_BUTTON) + currentUserID + currentInstance, null) == null) {
|
||||||
|
boolean oldTranslateButtonPrefValue =
|
||||||
|
sharedpreferences.getBoolean(getString(R.string.SET_DISPLAY_TRANSLATE) + currentUserID + currentInstance, false);
|
||||||
|
String[] translateButtonEntryValues = getResources().getStringArray(R.array.set_translate_button_entry_values);
|
||||||
|
String newTranslateButtonValue;
|
||||||
|
if (oldTranslateButtonPrefValue)
|
||||||
|
newTranslateButtonValue = translateButtonEntryValues[1];
|
||||||
|
else
|
||||||
|
newTranslateButtonValue = translateButtonEntryValues[2];
|
||||||
|
sharedpreferences.edit()
|
||||||
|
.putString(getString(R.string.SET_TRANSLATE_BUTTON) + currentUserID + currentInstance, newTranslateButtonValue)
|
||||||
|
.apply();
|
||||||
|
}
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
ActivityResultLauncher<String> permissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> {
|
ActivityResultLauncher<String> permissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> {
|
||||||
|
|
|
@ -579,7 +579,8 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||||
boolean fullAttachement = sharedpreferences.getBoolean(context.getString(R.string.SET_FULL_PREVIEW), false);
|
boolean fullAttachement = sharedpreferences.getBoolean(context.getString(R.string.SET_FULL_PREVIEW), false);
|
||||||
boolean expand_media = sharedpreferences.getBoolean(context.getString(R.string.SET_EXPAND_MEDIA), false);
|
boolean expand_media = sharedpreferences.getBoolean(context.getString(R.string.SET_EXPAND_MEDIA), false);
|
||||||
boolean displayBookmark = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_BOOKMARK) + MainActivity.currentUserID + MainActivity.currentInstance, true);
|
boolean displayBookmark = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_BOOKMARK) + MainActivity.currentUserID + MainActivity.currentInstance, true);
|
||||||
boolean displayTranslate = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_TRANSLATE) + MainActivity.currentUserID + MainActivity.currentInstance, false);
|
String translateButton = sharedpreferences.getString(context.getString(R.string.SET_TRANSLATE_BUTTON) + MainActivity.currentUserID + MainActivity.currentInstance, "auto");
|
||||||
|
String[] translateButtonEntryValues = context.getResources().getStringArray(R.array.set_translate_button_entry_values);
|
||||||
boolean displayCounters = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_COUNTER_FAV_BOOST), false);
|
boolean displayCounters = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_COUNTER_FAV_BOOST), false);
|
||||||
boolean removeLeftMargin = sharedpreferences.getBoolean(context.getString(R.string.SET_REMOVE_LEFT_MARGIN), false);
|
boolean removeLeftMargin = sharedpreferences.getBoolean(context.getString(R.string.SET_REMOVE_LEFT_MARGIN), false);
|
||||||
boolean extraFeatures = sharedpreferences.getBoolean(context.getString(R.string.SET_EXTAND_EXTRA_FEATURES) + MainActivity.currentUserID + MainActivity.currentInstance, false);
|
boolean extraFeatures = sharedpreferences.getBoolean(context.getString(R.string.SET_EXTAND_EXTRA_FEATURES) + MainActivity.currentUserID + MainActivity.currentInstance, false);
|
||||||
|
@ -1076,13 +1077,15 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||||
} else {
|
} else {
|
||||||
holder.binding.actionButtonBookmark.setVisibility(View.GONE);
|
holder.binding.actionButtonBookmark.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
if (displayTranslate) {
|
if (translateButton.equals(translateButtonEntryValues[0])) { // Show
|
||||||
if (statusToDeal.language != null && statusToDeal.language.trim().length() > 0 && statusToDeal.language.equalsIgnoreCase(MyTransL.getLocale())) {
|
holder.binding.actionButtonTranslate.setVisibility(View.VISIBLE);
|
||||||
|
} else if (translateButton.equals(translateButtonEntryValues[1])) { // Auto
|
||||||
|
if (statusToDeal.language != null && !statusToDeal.language.trim().isEmpty() && statusToDeal.language.equalsIgnoreCase(MyTransL.getLocale())) {
|
||||||
holder.binding.actionButtonTranslate.setVisibility(View.GONE);
|
holder.binding.actionButtonTranslate.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
holder.binding.actionButtonTranslate.setVisibility(View.VISIBLE);
|
holder.binding.actionButtonTranslate.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
} else {
|
} else if (translateButton.equals(translateButtonEntryValues[2])) { // Hide
|
||||||
holder.binding.actionButtonTranslate.setVisibility(View.GONE);
|
holder.binding.actionButtonTranslate.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
//--- ACTIONS ---
|
//--- ACTIONS ---
|
||||||
|
|
|
@ -88,10 +88,10 @@ public class FragmentTimelinesSettings extends PreferenceFragmentCompat implemen
|
||||||
boolean checked = sharedpreferences.getBoolean(getString(R.string.SET_DISPLAY_BOOKMARK) + MainActivity.currentUserID + MainActivity.currentInstance, true);
|
boolean checked = sharedpreferences.getBoolean(getString(R.string.SET_DISPLAY_BOOKMARK) + MainActivity.currentUserID + MainActivity.currentInstance, true);
|
||||||
SET_DISPLAY_BOOKMARK.setChecked(checked);
|
SET_DISPLAY_BOOKMARK.setChecked(checked);
|
||||||
}
|
}
|
||||||
SwitchPreferenceCompat SET_DISPLAY_TRANSLATE = findPreference(getString(R.string.SET_DISPLAY_TRANSLATE));
|
ListPreference SET_TRANSLATE_BUTTON = findPreference(getString(R.string.SET_TRANSLATE_BUTTON));
|
||||||
if (SET_DISPLAY_TRANSLATE != null) {
|
if (SET_TRANSLATE_BUTTON != null) {
|
||||||
boolean checked = sharedpreferences.getBoolean(getString(R.string.SET_DISPLAY_TRANSLATE) + MainActivity.currentUserID + MainActivity.currentInstance, false);
|
String value = sharedpreferences.getString(getString(R.string.SET_TRANSLATE_BUTTON) + MainActivity.currentUserID + MainActivity.currentInstance, null);
|
||||||
SET_DISPLAY_TRANSLATE.setChecked(checked);
|
SET_TRANSLATE_BUTTON.setValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
SwitchPreferenceCompat SET_DISPLAY_QUOTE = findPreference(getString(R.string.SET_DISPLAY_QUOTE));
|
SwitchPreferenceCompat SET_DISPLAY_QUOTE = findPreference(getString(R.string.SET_DISPLAY_QUOTE));
|
||||||
|
@ -125,10 +125,10 @@ public class FragmentTimelinesSettings extends PreferenceFragmentCompat implemen
|
||||||
editor.putBoolean(getString(R.string.SET_DISPLAY_BOOKMARK) + MainActivity.currentUserID + MainActivity.currentInstance, SET_DISPLAY_BOOKMARK.isChecked());
|
editor.putBoolean(getString(R.string.SET_DISPLAY_BOOKMARK) + MainActivity.currentUserID + MainActivity.currentInstance, SET_DISPLAY_BOOKMARK.isChecked());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (key.compareToIgnoreCase(getString(R.string.SET_DISPLAY_TRANSLATE)) == 0) {
|
if (key.compareToIgnoreCase(getString(R.string.SET_TRANSLATE_BUTTON)) == 0) {
|
||||||
SwitchPreferenceCompat SET_DISPLAY_TRANSLATE = findPreference(getString(R.string.SET_DISPLAY_TRANSLATE));
|
ListPreference SET_TRANSLATE_BUTTON = findPreference(getString(R.string.SET_TRANSLATE_BUTTON));
|
||||||
if (SET_DISPLAY_TRANSLATE != null) {
|
if (SET_TRANSLATE_BUTTON != null) {
|
||||||
editor.putBoolean(getString(R.string.SET_DISPLAY_TRANSLATE) + MainActivity.currentUserID + MainActivity.currentInstance, SET_DISPLAY_TRANSLATE.isChecked());
|
editor.putString(getString(R.string.SET_TRANSLATE_BUTTON) + MainActivity.currentUserID + MainActivity.currentInstance, SET_TRANSLATE_BUTTON.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (key.compareToIgnoreCase(getString(R.string.SET_DISPLAY_QUOTE)) == 0) {
|
if (key.compareToIgnoreCase(getString(R.string.SET_DISPLAY_QUOTE)) == 0) {
|
||||||
|
|
|
@ -772,6 +772,16 @@
|
||||||
<string name="no_account_in_list">No accounts found for this list!</string>
|
<string name="no_account_in_list">No accounts found for this list!</string>
|
||||||
<string name="scheduled">Scheduled</string>
|
<string name="scheduled">Scheduled</string>
|
||||||
|
|
||||||
|
<string-array name="set_translate_button_entries">
|
||||||
|
<item>Show</item>
|
||||||
|
<item>Auto (depending on post language)</item>
|
||||||
|
<item>Hide</item>
|
||||||
|
</string-array>
|
||||||
|
<string-array name="set_translate_button_entry_values" translatable="false">
|
||||||
|
<item>show</item>
|
||||||
|
<item>auto</item>
|
||||||
|
<item>hide</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string-array name="set_thread_message_value">
|
<string-array name="set_thread_message_value">
|
||||||
<item>Ask</item>
|
<item>Ask</item>
|
||||||
|
@ -1262,6 +1272,7 @@
|
||||||
<string name="SET_DISPLAY_REACTIONS" translatable="false">SET_DISPLAY_REACTIONS</string>
|
<string name="SET_DISPLAY_REACTIONS" translatable="false">SET_DISPLAY_REACTIONS</string>
|
||||||
|
|
||||||
<string name="SET_DISPLAY_TRANSLATE" translatable="false">SET_DISPLAY_TRANSLATE</string>
|
<string name="SET_DISPLAY_TRANSLATE" translatable="false">SET_DISPLAY_TRANSLATE</string>
|
||||||
|
<string name="SET_TRANSLATE_BUTTON" translatable="false">SET_TRANSLATE_BUTTON</string>
|
||||||
<string name="SET_POST_FORMAT" translatable="false">SET_POST_FORMAT</string>
|
<string name="SET_POST_FORMAT" translatable="false">SET_POST_FORMAT</string>
|
||||||
<string name="SET_COMPOSE_LOCAL_ONLY" translatable="false">SET_COMPOSE_LOCAL_ONLY</string>
|
<string name="SET_COMPOSE_LOCAL_ONLY" translatable="false">SET_COMPOSE_LOCAL_ONLY</string>
|
||||||
|
|
||||||
|
@ -1370,6 +1381,7 @@
|
||||||
<string name="poll_duration">Poll duration:</string>
|
<string name="poll_duration">Poll duration:</string>
|
||||||
<string name="set_display_bookmark_indication">Always display bookmark button</string>
|
<string name="set_display_bookmark_indication">Always display bookmark button</string>
|
||||||
<string name="set_display_translate_indication">Always display translate button</string>
|
<string name="set_display_translate_indication">Always display translate button</string>
|
||||||
|
<string name="set_translate_button">Translate button</string>
|
||||||
<string name="display">Display</string>
|
<string name="display">Display</string>
|
||||||
<string name="bottom_menu">Bottom menu</string>
|
<string name="bottom_menu">Bottom menu</string>
|
||||||
<string name="top_menu">Top bar menu</string>
|
<string name="top_menu">Top bar menu</string>
|
||||||
|
|
|
@ -142,12 +142,13 @@
|
||||||
app:key="@string/SET_PIXELFED_PRESENTATION"
|
app:key="@string/SET_PIXELFED_PRESENTATION"
|
||||||
app:singleLineTitle="false"
|
app:singleLineTitle="false"
|
||||||
app:title="@string/set_pixelfed_presentation" />
|
app:title="@string/set_pixelfed_presentation" />
|
||||||
<SwitchPreferenceCompat
|
<ListPreference
|
||||||
android:defaultValue="false"
|
android:entries="@array/set_translate_button_entries"
|
||||||
app:iconSpaceReserved="false"
|
android:entryValues="@array/set_translate_button_entry_values"
|
||||||
app:key="@string/SET_DISPLAY_TRANSLATE"
|
android:title="@string/set_translate_button"
|
||||||
app:singleLineTitle="false"
|
app:key="@string/SET_TRANSLATE_BUTTON"
|
||||||
app:title="@string/set_display_translate_indication" />
|
app:icon="@drawable/ic_baseline_translate_24"
|
||||||
|
app:useSimpleSummaryProvider="true" />
|
||||||
<SwitchPreferenceCompat
|
<SwitchPreferenceCompat
|
||||||
android:defaultValue="true"
|
android:defaultValue="true"
|
||||||
app:iconSpaceReserved="false"
|
app:iconSpaceReserved="false"
|
||||||
|
|
Loading…
Reference in a new issue