From 28b51516e0bf836f889e51fbd67a97de1750cd6a Mon Sep 17 00:00:00 2001 From: Alexandre Macabies Date: Sun, 17 Jan 2021 19:55:14 +0100 Subject: [PATCH] add a setting to control showing the post label per default This defaults to the current behavior of always showing the caption, but this can be turned off for reduced browsing noise: I often don't care about meaningless captions on most accounts. Added the pref translation for French as I'm a native speaker. --- .../instagrabber/fragments/PostViewV2Fragment.java | 10 ++++++---- .../settings/SettingsPreferencesFragment.java | 12 ++++++++++++ .../java/awais/instagrabber/utils/Constants.java | 1 + .../awais/instagrabber/utils/SettingsHelper.java | 3 ++- app/src/main/res/values/strings.xml | 1 + 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java b/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java index da96177c..74c1e589 100644 --- a/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java @@ -242,6 +242,8 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment { if (feedModel.getItemType() == MediaItemType.MEDIA_TYPE_SLIDER) { sliderPosition = arguments.getInt(ARG_SLIDER_POSITION, 0); } + captionState = settingsHelper.getBoolean(Constants.SHOW_CAPTIONS) ? + BottomSheetBehavior.STATE_COLLAPSED : BottomSheetBehavior.STATE_HIDDEN; } @Nullable @@ -384,7 +386,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment { ViewGroup.LayoutParams.MATCH_PARENT)); binding.postImage.requestLayout(); if (bottomSheetBehavior != null) { - bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); + bottomSheetBehavior.setState(captionState); } return; } @@ -393,7 +395,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment { ViewGroup.LayoutParams.MATCH_PARENT)); binding.sliderParent.requestLayout(); if (bottomSheetBehavior != null) { - bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); + bottomSheetBehavior.setState(captionState); } return; } @@ -404,7 +406,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment { binding.videoPost.thumbnailParent.setLayoutParams(params); binding.videoPost.thumbnailParent.requestLayout(); if (bottomSheetBehavior != null) { - bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); + bottomSheetBehavior.setState(captionState); } } } @@ -846,7 +848,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment { public void onGlobalLayout() { binding.getRoot().getViewTreeObserver().removeOnGlobalLayoutListener(this); if (bottomSheetBehavior == null) return; - bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); + bottomSheetBehavior.setState(captionState); } }); } diff --git a/app/src/main/java/awais/instagrabber/fragments/settings/SettingsPreferencesFragment.java b/app/src/main/java/awais/instagrabber/fragments/settings/SettingsPreferencesFragment.java index 64c49ed9..97b1c426 100644 --- a/app/src/main/java/awais/instagrabber/fragments/settings/SettingsPreferencesFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/settings/SettingsPreferencesFragment.java @@ -52,6 +52,7 @@ public class SettingsPreferencesFragment extends BasePreferencesFragment { generalCategory.addPreference(getUpdateCheckPreference()); // generalCategory.addPreference(getAutoPlayVideosPreference()); generalCategory.addPreference(getAlwaysMuteVideosPreference()); + generalCategory.addPreference(getShowCaptionPreference()); // screen.addPreference(getDivider(context)); // final PreferenceCategory themeCategory = new PreferenceCategory(context); @@ -204,6 +205,17 @@ public class SettingsPreferencesFragment extends BasePreferencesFragment { return preference; } + private Preference getShowCaptionPreference() { + final Context context = getContext(); + if (context == null) return null; + final SwitchPreferenceCompat preference = new SwitchPreferenceCompat(context); + preference.setKey(Constants.SHOW_CAPTIONS); + preference.setDefaultValue(true); + preference.setTitle(R.string.post_viewer_show_captions); + preference.setIconSpaceReserved(false); + return preference; + } + private Preference getStorySortPreference() { final Context context = getContext(); if (context == null) return null; diff --git a/app/src/main/java/awais/instagrabber/utils/Constants.java b/app/src/main/java/awais/instagrabber/utils/Constants.java index 85125516..9bc5f5b1 100644 --- a/app/src/main/java/awais/instagrabber/utils/Constants.java +++ b/app/src/main/java/awais/instagrabber/utils/Constants.java @@ -17,6 +17,7 @@ public final class Constants { public static final String FOLDER_SAVE_TO = "saved_to"; public static final String AUTOPLAY_VIDEOS = "autoplay_videos"; public static final String MUTED_VIDEOS = "muted_videos"; + public static final String SHOW_CAPTIONS = "show_captions"; public static final String CUSTOM_DATE_TIME_FORMAT_ENABLED = "data_time_custom_enabled"; public static final String SWAP_DATE_TIME_FORMAT_ENABLED = "swap_date_time_enabled"; public static final String MARK_AS_SEEN = "mark_as_seen"; diff --git a/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java b/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java index fa99a91f..e390d0a6 100755 --- a/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java +++ b/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java @@ -37,6 +37,7 @@ import static awais.instagrabber.utils.Constants.PREF_SAVED_POSTS_LAYOUT; import static awais.instagrabber.utils.Constants.PREF_TAGGED_POSTS_LAYOUT; import static awais.instagrabber.utils.Constants.PREF_TOPIC_POSTS_LAYOUT; import static awais.instagrabber.utils.Constants.PREV_INSTALL_VERSION; +import static awais.instagrabber.utils.Constants.SHOW_CAPTIONS; import static awais.instagrabber.utils.Constants.SHOW_QUICK_ACCESS_DIALOG; import static awais.instagrabber.utils.Constants.SKIPPED_VERSION; import static awais.instagrabber.utils.Constants.STORY_SORT; @@ -126,7 +127,7 @@ public final class SettingsHelper { public @interface StringSettings {} @StringDef({DOWNLOAD_USER_FOLDER, FOLDER_SAVE_TO, AUTOPLAY_VIDEOS, SHOW_QUICK_ACCESS_DIALOG, MUTED_VIDEOS, - CUSTOM_DATE_TIME_FORMAT_ENABLED, MARK_AS_SEEN, DM_MARK_AS_SEEN, CHECK_ACTIVITY, + SHOW_CAPTIONS, CUSTOM_DATE_TIME_FORMAT_ENABLED, MARK_AS_SEEN, DM_MARK_AS_SEEN, CHECK_ACTIVITY, CHECK_UPDATES, SWAP_DATE_TIME_FORMAT_ENABLED}) public @interface BooleanSettings {} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d93c5948..24e36413 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -57,6 +57,7 @@ %s Following Autoplay videos Always mute videos + Always show post captions Select what to download Current Whole Album