diff options
author | Thomas <tschneider.ac@gmail.com> | 2022-12-12 12:18:19 +0100 |
---|---|---|
committer | Thomas <tschneider.ac@gmail.com> | 2022-12-12 12:18:19 +0100 |
commit | 5a0eff4ae838660ab853290b9b0c10973ffc365e (patch) | |
tree | a3348b995c93eca1e586db9875294361025b6dab | |
parent | 1b643bcb1d1ed0875fc9ed8b40e6f9a334c81714 (diff) |
Fix issue #623 - Allow to display the translate button at the bottom.
-rw-r--r-- | app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java | 91 | ||||
-rw-r--r-- | app/src/main/res/layout/drawer_status.xml | 22 | ||||
-rw-r--r-- | app/src/main/res/values/strings.xml | 2 | ||||
-rw-r--r-- | app/src/main/res/xml/pref_timelines.xml | 7 |
4 files changed, 85 insertions, 37 deletions
diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java index 9cf4478a0..446dce139 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java @@ -395,6 +395,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> boolean confirmBoost = sharedpreferences.getBoolean(context.getString(R.string.SET_NOTIF_VALIDATION), true); boolean fullAttachement = sharedpreferences.getBoolean(context.getString(R.string.SET_FULL_PREVIEW), false); boolean displayBookmark = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_BOOKMARK), true); + boolean displayTranslate = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_TRANSLATE), false); boolean displayCounters = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_COUNTER_FAV_BOOST), false); String loadMediaType = sharedpreferences.getString(context.getString(R.string.SET_LOAD_MEDIA_TYPE), "ALWAYS"); @@ -628,6 +629,11 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> } else { holder.binding.actionButtonBookmark.setVisibility(View.GONE); } + if (displayTranslate) { + holder.binding.actionButtonTranslate.setVisibility(View.VISIBLE); + } else { + holder.binding.actionButtonTranslate.setVisibility(View.GONE); + } //--- ACTIONS --- holder.binding.actionButtonBookmark.setChecked(statusToDeal.bookmarked); //---> BOOKMARK/UNBOOKMARK @@ -635,6 +641,9 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> CrossActionHelper.doCrossAction(context, CrossActionHelper.TypeOfCrossAction.BOOKMARK_ACTION, null, statusToDeal); return true; }); + holder.binding.actionButtonTranslate.setOnClickListener(v -> { + translate(context, statusToDeal, holder, adapter); + }); holder.binding.actionButtonBookmark.setOnClickListener(v -> { if (remote) { Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show(); @@ -887,6 +896,11 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> holder.binding.actionButtonReply.getLayoutParams().width = (int) (normalSize * scaleIcon); holder.binding.actionButtonReply.getLayoutParams().height = (int) (normalSize * scaleIcon); holder.binding.actionButtonReply.requestLayout(); + + holder.binding.actionButtonTranslate.getLayoutParams().width = (int) (normalSize * scaleIcon); + holder.binding.actionButtonTranslate.getLayoutParams().height = (int) (normalSize * scaleIcon); + holder.binding.actionButtonTranslate.requestLayout(); + holder.binding.actionButtonBoost.setImageSize((int) (normalSize * scaleIcon)); holder.binding.actionButtonFavorite.setImageSize((int) (normalSize * scaleIcon)); holder.binding.actionButtonBookmark.setImageSize((int) (normalSize * scaleIcon)); @@ -1676,41 +1690,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> })); builderInner.show(); } else if (itemId == R.id.action_translate) { - MyTransL.translatorEngine et = MyTransL.translatorEngine.LIBRETRANSLATE; - final MyTransL myTransL = MyTransL.getInstance(et); - myTransL.setObfuscation(true); - Params params = new Params(); - params.setSplit_sentences(false); - params.setFormat(Params.fType.TEXT); - params.setSource_lang("auto"); - myTransL.setLibretranslateDomain("translate.fedilab.app"); - String statusToTranslate; - String translate = sharedpreferences.getString(context.getString(R.string.SET_LIVE_TRANSLATE), MyTransL.getLocale()); - if (translate != null && translate.equalsIgnoreCase("default")) { - translate = MyTransL.getLocale(); - } - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - statusToTranslate = Html.fromHtml(statusToDeal.content, Html.FROM_HTML_MODE_LEGACY).toString(); - else - statusToTranslate = Html.fromHtml(statusToDeal.content).toString(); - myTransL.translate(statusToTranslate, translate, params, new Results() { - @Override - public void onSuccess(Translate translate) { - if (translate.getTranslatedContent() != null) { - statusToDeal.translationShown = true; - statusToDeal.translationContent = translate.getTranslatedContent(); - adapter.notifyItemChanged(holder.getBindingAdapterPosition()); - } else { - Toasty.error(context, context.getString(R.string.toast_error_translate), Toast.LENGTH_LONG).show(); - } - } - - @Override - public void onFail(HttpsConnectionException httpsConnectionException) { - - } - }); + translate(context, statusToDeal, holder, adapter); return true; } else if (itemId == R.id.action_report) { Intent intent = new Intent(context, ReportActivity.class); @@ -1918,6 +1898,46 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> } + private static void translate(Context context, Status statusToDeal, + StatusViewHolder holder, + RecyclerView.Adapter<RecyclerView.ViewHolder> adapter) { + MyTransL.translatorEngine et = MyTransL.translatorEngine.LIBRETRANSLATE; + final MyTransL myTransL = MyTransL.getInstance(et); + myTransL.setObfuscation(true); + Params params = new Params(); + params.setSplit_sentences(false); + params.setFormat(Params.fType.TEXT); + params.setSource_lang("auto"); + myTransL.setLibretranslateDomain("translate.fedilab.app"); + String statusToTranslate; + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); + String translate = sharedpreferences.getString(context.getString(R.string.SET_LIVE_TRANSLATE), MyTransL.getLocale()); + if (translate != null && translate.equalsIgnoreCase("default")) { + translate = MyTransL.getLocale(); + } + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + statusToTranslate = Html.fromHtml(statusToDeal.content, Html.FROM_HTML_MODE_LEGACY).toString(); + else + statusToTranslate = Html.fromHtml(statusToDeal.content).toString(); + myTransL.translate(statusToTranslate, translate, params, new Results() { + @Override + public void onSuccess(Translate translate) { + if (translate.getTranslatedContent() != null) { + statusToDeal.translationShown = true; + statusToDeal.translationContent = translate.getTranslatedContent(); + adapter.notifyItemChanged(holder.getBindingAdapterPosition()); + } else { + Toasty.error(context, context.getString(R.string.toast_error_translate), Toast.LENGTH_LONG).show(); + } + } + + @Override + public void onFail(HttpsConnectionException httpsConnectionException) { + + } + }); + } private static void loadAndAddAttachment(Context context, LayoutMediaBinding layoutMediaBinding, StatusViewHolder holder, @@ -2207,6 +2227,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> Helper.changeDrawableColor(context, R.drawable.ic_person, theme_icons_color); Helper.changeDrawableColor(context, R.drawable.ic_bot, theme_icons_color); Helper.changeDrawableColor(context, R.drawable.ic_round_reply_24, theme_icons_color); + Helper.changeDrawableColor(context, holder.binding.actionButtonTranslate, theme_icons_color); holder.binding.actionButtonFavorite.setInActiveImageTintColor(theme_icons_color); holder.binding.actionButtonBookmark.setInActiveImageTintColor(theme_icons_color); holder.binding.actionButtonBoost.setInActiveImageTintColor(theme_icons_color); diff --git a/app/src/main/res/layout/drawer_status.xml b/app/src/main/res/layout/drawer_status.xml index 23a237402..9f7466425 100644 --- a/app/src/main/res/layout/drawer_status.xml +++ b/app/src/main/res/layout/drawer_status.xml @@ -659,7 +659,7 @@ <com.varunest.sparkbutton.SparkButton android:id="@+id/action_button_bookmark" app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toStartOf="@+id/status_add_custom_emoji" + app:layout_constraintEnd_toStartOf="@+id/action_button_translate" app:layout_constraintStart_toEndOf="@+id/action_button_favorite" app:layout_constraintTop_toTopOf="parent" android:layout_width="48dp" @@ -676,11 +676,29 @@ <androidx.appcompat.widget.AppCompatImageButton + android:id="@+id/action_button_translate" + style="@style/Widget.Material3.Button.IconButton" + android:layout_width="48dp" + android:layout_height="48dp" + android:layout_gravity="center" + android:adjustViewBounds="true" + android:clickable="true" + android:contentDescription="@string/translate" + android:focusable="true" + android:src="@drawable/ic_baseline_translate_24" + android:visibility="gone" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toStartOf="@+id/status_add_custom_emoji" + app:layout_constraintStart_toEndOf="@+id/action_button_bookmark" + app:layout_constraintTop_toTopOf="parent" + tools:visibility="visible" /> + + <androidx.appcompat.widget.AppCompatImageButton android:id="@+id/status_add_custom_emoji" style="@style/Widget.Material3.Button.IconButton" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@+id/status_emoji" - app:layout_constraintStart_toEndOf="@+id/action_button_bookmark" + app:layout_constraintStart_toEndOf="@+id/action_button_translate" app:layout_constraintTop_toTopOf="parent" android:layout_width="48dp" android:layout_height="48dp" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index de2d5e379..b38a02223 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1356,6 +1356,7 @@ <string name="SET_FILTER_REGEX_PUBLIC" translatable="false">SET_FILTER_REGEX_PUBLIC</string> <string name="SET_NOTIF_VALIDATION" translatable="false">SET_NOTIF_VALIDATION</string> <string name="SET_DISPLAY_BOOKMARK" translatable="false">SET_DISPLAY_BOOKMARK</string> + <string name="SET_DISPLAY_TRANSLATE" translatable="false">SET_DISPLAY_TRANSLATE</string> <string name="SET_NOTIF_VALIDATION_FAV" translatable="false">SET_NOTIF_VALIDATION_FAV</string> <string name="SET_DISPLAY_COUNTER_FAV_BOOST" translatable="false">SET_DISPLAY_COUNTER_FAV_BOOST</string> <string name="SET_INNER_MARKER" translatable="false">SET_INNER_MARKER</string> @@ -1423,6 +1424,7 @@ <string name="poll_type">Poll type:</string> <string name="poll_duration">Poll duration:</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="display">Display</string> <string name="bottom_menu">Bottom menu</string> <string name="top_menu">Top bar menu</string> diff --git a/app/src/main/res/xml/pref_timelines.xml b/app/src/main/res/xml/pref_timelines.xml index 04f2a8b8a..4afdb7d7b 100644 --- a/app/src/main/res/xml/pref_timelines.xml +++ b/app/src/main/res/xml/pref_timelines.xml @@ -43,6 +43,13 @@ app:title="@string/set_display_bookmark_indication" /> <SwitchPreferenceCompat + android:defaultValue="false" + app:iconSpaceReserved="false" + app:key="@string/SET_DISPLAY_TRANSLATE" + app:singleLineTitle="false" + app:title="@string/set_display_translate_indication" /> + + <SwitchPreferenceCompat app:defaultValue="true" app:iconSpaceReserved="false" app:key="@string/SET_AGGREGATE_NOTIFICATION" |