Skip to content

Commit

Permalink
Add back "always show alt text" and "back button enables alt text"
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-anders committed Apr 9, 2022
1 parent 2797f6b commit 54e42a4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/de/tap/easy_xkcd/utils/PrefHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -261,6 +262,10 @@ public boolean altBackButton() {
return prefs.getStringSet(ALT_OPTIONS, new HashSet<String>()).contains(ALT_BACK);
}

public boolean alwaysShowAltText() {
return prefs.getStringSet(ALT_OPTIONS, new HashSet<String>()).contains(ALT_ALWAYS_SHOW);
}

public boolean showAltTip() {
return sharedPrefs.getBoolean(ALT_TIP, true);
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/pager_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" >
Expand Down

0 comments on commit 54e42a4

Please sign in to comment.