From bb36cc79fdded7209a4848c85a37076d2cf7f064 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sat, 15 May 2021 13:41:20 +0800 Subject: New option: Swipe Vertically to Go Back From Media. --- .../activities/ViewImageOrGifActivity.java | 4 +++- .../activities/ViewImgurMediaActivity.java | 14 +++++++++----- .../activities/ViewRedditGalleryActivity.java | 14 +++++++++----- .../infinityforreddit/activities/ViewVideoActivity.java | 14 +++++++++----- .../infinityforreddit/utils/SharedPreferencesUtils.java | 1 + app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/gestures_and_buttons_preferences.xml | 5 +++++ 7 files changed, 37 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java index e82ea47a..3988d3c8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java @@ -135,7 +135,9 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa actionBar.setHomeAsUpIndicator(upArrow); actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.transparentActionBarAndExoPlayerControllerColor))); - Slidr.attach(this, new SlidrConfig.Builder().position(SlidrPosition.VERTICAL).distanceThreshold(0.125f).build()); + if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_VERTICALLY_TO_GO_BACK_FROM_MEDIA, true)) { + Slidr.attach(this, new SlidrConfig.Builder().position(SlidrPosition.VERTICAL).distanceThreshold(0.125f).build()); + } glide = Glide.with(this); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImgurMediaActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImgurMediaActivity.java index 10866770..c16cef7d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImgurMediaActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImgurMediaActivity.java @@ -133,11 +133,15 @@ public class ViewImgurMediaActivity extends AppCompatActivity implements SetAsWa images = savedInstanceState.getParcelableArrayList(IMGUR_IMAGES_STATE); } - haulerView.setOnDragDismissedListener(dragDirection -> { - int slide = dragDirection == DragDirection.UP ? R.anim.slide_out_up : R.anim.slide_out_down; - finish(); - overridePendingTransition(0, slide); - }); + if (sharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_VERTICALLY_TO_GO_BACK_FROM_MEDIA, true)) { + haulerView.setOnDragDismissedListener(dragDirection -> { + int slide = dragDirection == DragDirection.UP ? R.anim.slide_out_up : R.anim.slide_out_down; + finish(); + overridePendingTransition(0, slide); + }); + } else { + haulerView.setDragEnabled(false); + } if (images == null) { fetchImgurMedia(imgurId); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java index 6bcccfa3..267bd56b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java @@ -105,11 +105,15 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA } subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME); - haulerView.setOnDragDismissedListener(dragDirection -> { - int slide = dragDirection == DragDirection.UP ? R.anim.slide_out_up : R.anim.slide_out_down; - finish(); - overridePendingTransition(0, slide); - }); + if (sharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_VERTICALLY_TO_GO_BACK_FROM_MEDIA, true)) { + haulerView.setOnDragDismissedListener(dragDirection -> { + int slide = dragDirection == DragDirection.UP ? R.anim.slide_out_up : R.anim.slide_out_down; + finish(); + overridePendingTransition(0, slide); + }); + } else { + haulerView.setDragEnabled(false); + } setupViewPager(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java index 61a12366..7e44ba9f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java @@ -204,11 +204,15 @@ public class ViewVideoActivity extends AppCompatActivity { } } - haulerView.setOnDragDismissedListener(dragDirection -> { - int slide = dragDirection == DragDirection.UP ? R.anim.slide_out_up : R.anim.slide_out_down; - finish(); - overridePendingTransition(0, slide); - }); + if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_VERTICALLY_TO_GO_BACK_FROM_MEDIA, true)) { + haulerView.setOnDragDismissedListener(dragDirection -> { + int slide = dragDirection == DragDirection.UP ? R.anim.slide_out_up : R.anim.slide_out_down; + finish(); + overridePendingTransition(0, slide); + }); + } else { + haulerView.setDragEnabled(false); + } Intent intent = getIntent(); postTitle = intent.getStringExtra(EXTRA_POST_TITLE); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java index 3242c63c..011e40cf 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java @@ -87,6 +87,7 @@ public class SharedPreferencesUtils { public static final String NUMBER_OF_COLUMNS_IN_POST_FEED_PORTRAIT_GALLERY_LAYOUT = "number_of_columns_in_post_feed_portrait_gallery_layout"; public static final String NUMBER_OF_COLUMNS_IN_POST_FEED_LANDSCAPE_GALLERY_LAYOUT = "number_of_columns_in_post_feed_landscape_gallery_layout"; public static final String SWIPE_RIGHT_TO_GO_BACK = "swipe_to_go_back_from_post_detail"; + public static final String SWIPE_VERTICALLY_TO_GO_BACK_FROM_MEDIA = "swipe_vertically_to_go_back_from_media"; public static final String VOLUME_KEYS_NAVIGATE_COMMENTS = "volume_keys_navigate_comments"; public static final String VOLUME_KEYS_NAVIGATE_POSTS = "volume_keys_navigate_posts"; public static final String MUTE_VIDEO = "mute_video"; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6dd4979f..dc7d9493 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -398,6 +398,7 @@ Swap Tap and Long Press in Comments Swipe Right to Go Back Does Not Apply to All Pages + Swipe Vertically to Go Back From Media Lock Jump to Next Top-level Comment Button Lock Bottom Navigation Bar Swipe Up to Hide Jump to Next Top-level Comment Button diff --git a/app/src/main/res/xml/gestures_and_buttons_preferences.xml b/app/src/main/res/xml/gestures_and_buttons_preferences.xml index b5c30058..fd49d4c0 100644 --- a/app/src/main/res/xml/gestures_and_buttons_preferences.xml +++ b/app/src/main/res/xml/gestures_and_buttons_preferences.xml @@ -7,6 +7,11 @@ app:title="@string/settings_swipe_to_go_back_title" app:summary="@string/settings_swipe_to_go_back_summary" /> + +