From 54e42a4fd5b6b706ba248bbd8322931e1d94e4a9 Mon Sep 17 00:00:00 2001 From: Tom Praschan <13141438+tom-anders@users.noreply.github.com> Date: Sat, 9 Apr 2022 15:09:09 +0200 Subject: [PATCH] Add back "always show alt text" and "back button enables alt text" --- .../comicBrowsing/ComicBrowserBaseFragment.kt | 23 ++++++++++++++++++- .../comicBrowsing/FavoritesFragment.kt | 1 - .../de/tap/easy_xkcd/utils/PrefHelper.java | 5 ++++ app/src/main/res/layout/pager_item.xml | 3 ++- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/de/tap/easy_xkcd/comicBrowsing/ComicBrowserBaseFragment.kt b/app/src/main/java/de/tap/easy_xkcd/comicBrowsing/ComicBrowserBaseFragment.kt index bc9954f3..2f514957 100644 --- a/app/src/main/java/de/tap/easy_xkcd/comicBrowsing/ComicBrowserBaseFragment.kt +++ b/app/src/main/java/de/tap/easy_xkcd/comicBrowsing/ComicBrowserBaseFragment.kt @@ -11,6 +11,7 @@ import android.text.Html import android.transition.TransitionInflater import android.view.* import android.widget.* +import androidx.activity.addCallback import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity import androidx.browser.customtabs.CustomTabsIntent @@ -100,6 +101,18 @@ abstract class ComicBrowserBaseFragment : Fragment() { } + activity?.onBackPressedDispatcher + ?.addCallback { + if (prefHelper.altBackButton()) { + showAltText() + } else { + if (isEnabled) { + isEnabled = false + activity?.onBackPressed() + } + } + } + return binding.root } @@ -161,7 +174,7 @@ abstract class ComicBrowserBaseFragment : Fragment() { } fun altOrFullscreen(singleTap: Boolean) { - if (singleTap xor prefHelper.altLongTap()) { + if ((singleTap xor prefHelper.altLongTap()) && !prefHelper.alwaysShowAltText()) { if (prefHelper.altVibration()) { (activity?.getSystemService(Context.VIBRATOR_SERVICE) as? Vibrator?)?.vibrate(10) } @@ -208,6 +221,11 @@ abstract class ComicBrowserBaseFragment : Fragment() { holder.image.setOnDoubleTapListener(it) holder.image.setOnLongClickListener(it) } + + if (prefHelper.alwaysShowAltText()) { + holder.altText.text = comic.altText + holder.altText.visibility = View.VISIBLE + } } super.onBindViewHolder(holder, position) @@ -240,6 +258,9 @@ abstract class ComicBrowserBaseFragment : Fragment() { override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { MenuCompat.setGroupDividerEnabled(menu, true) + + menu.findItem(R.id.action_alt)?.isVisible = prefHelper.showAltTip() && !prefHelper.alwaysShowAltText() + super.onCreateOptionsMenu(menu, inflater) } diff --git a/app/src/main/java/de/tap/easy_xkcd/comicBrowsing/FavoritesFragment.kt b/app/src/main/java/de/tap/easy_xkcd/comicBrowsing/FavoritesFragment.kt index 8f687eeb..96bd7160 100644 --- a/app/src/main/java/de/tap/easy_xkcd/comicBrowsing/FavoritesFragment.kt +++ b/app/src/main/java/de/tap/easy_xkcd/comicBrowsing/FavoritesFragment.kt @@ -117,7 +117,6 @@ class FavoritesFragment : ComicBrowserBaseFragment() { override fun onPrepareOptionsMenu(menu: Menu) { menu.findItem(R.id.action_favorite)?.setIcon(R.drawable.ic_favorite_on_24dp) - menu.findItem(R.id.action_alt)?.isVisible = prefHelper.showAltTip() super.onPrepareOptionsMenu(menu) } diff --git a/app/src/main/java/de/tap/easy_xkcd/utils/PrefHelper.java b/app/src/main/java/de/tap/easy_xkcd/utils/PrefHelper.java index 82c4a8bf..029edd67 100644 --- a/app/src/main/java/de/tap/easy_xkcd/utils/PrefHelper.java +++ b/app/src/main/java/de/tap/easy_xkcd/utils/PrefHelper.java @@ -65,6 +65,7 @@ public class PrefHelper { private static final String LAST_COMIC = "Last Comic"; private static final String ALT_VIBRATION = "pref_alt"; private static final String ALT_BACK = "pref_alt_back"; + private static final String ALT_ALWAYS_SHOW = "pref_show_alt"; private static final String ALT_TIP = "alt_tip"; private static final String WHAT_IF_TIP = "whatif_tip"; private static final String RANDOM_TIP = "random_tip"; @@ -261,6 +262,10 @@ public boolean altBackButton() { return prefs.getStringSet(ALT_OPTIONS, new HashSet()).contains(ALT_BACK); } + public boolean alwaysShowAltText() { + return prefs.getStringSet(ALT_OPTIONS, new HashSet()).contains(ALT_ALWAYS_SHOW); + } + public boolean showAltTip() { return sharedPrefs.getBoolean(ALT_TIP, true); } diff --git a/app/src/main/res/layout/pager_item.xml b/app/src/main/res/layout/pager_item.xml index fa3108ee..14ba8730 100644 --- a/app/src/main/res/layout/pager_item.xml +++ b/app/src/main/res/layout/pager_item.xml @@ -37,7 +37,8 @@ android:layout_alignParentBottom="true" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/activity_horizontal_margin" - android:layout_marginRight="@dimen/text_alt_margin_right" + android:layout_marginRight="@dimen/activity_horizontal_margin" + android:layout_marginBottom="30dp" android:layout_width="match_parent" android:textSize="@dimen/text_body1" android:visibility="gone" >