From c37cc1bed372c7d6b632bedafbb283d08ed6c0bc Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Thu, 4 Jun 2020 22:33:24 +0800 Subject: Add an option to disable autoplaying nsfw videos. Support imgur gifv videos. --- .../Activity/LinkResolverActivity.java | 8 +++++ .../Adapter/CommentAndPostRecyclerViewAdapter.java | 8 +++++ .../Adapter/PostRecyclerViewAdapter.java | 12 +++++++ .../Event/ChangeAutoplayNsfwVideosEvent.java | 9 ++++++ .../infinityforreddit/Fragment/PostFragment.java | 9 ++++++ .../Settings/AutoplayPreferenceFragment.java | 37 ++++++++++++++++++++++ .../Settings/MainPreferenceFragment.java | 12 ------- .../Utils/SharedPreferencesUtils.java | 1 + 8 files changed, 84 insertions(+), 12 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeAutoplayNsfwVideosEvent.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AutoplayPreferenceFragment.java (limited to 'app/src/main/java/ml') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java index f987a2a3..0b7cf47f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java @@ -7,6 +7,7 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.net.Uri; import android.os.Bundle; +import android.util.Log; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; @@ -213,6 +214,13 @@ public class LinkResolverActivity extends AppCompatActivity { intent.putExtra(ViewImgurMediaActivity.EXTRA_IMGUR_TYPE, ViewImgurMediaActivity.IMGUR_TYPE_IMAGE); intent.putExtra(ViewImgurMediaActivity.EXTRA_IMGUR_ID, path.substring(1)); startActivity(intent); + } else if (path.endsWith("gifv")) { + String url = uri.toString(); + url = url.substring(0, url.length() - 5) + ".mp4"; + Intent intent = new Intent(this, ViewVideoActivity.class); + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_DIRECT); + intent.setData(Uri.parse(url)); + startActivity(intent); } else { deepLinkError(uri); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java index 4f638d8b..6bb80f1a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -154,6 +154,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { + EventBus.getDefault().post(new ChangeVideoAutoplayEvent((String) newValue)); + return true; + }); + + autoplayNsfwVideosSwitchPreference.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new ChangeAutoplayNsfwVideosEvent((Boolean) newValue)); + return true; + }); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java index f0b61023..aa1b77d0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java @@ -7,7 +7,6 @@ import android.content.SharedPreferences; import android.os.Bundle; import androidx.annotation.NonNull; -import androidx.preference.ListPreference; import androidx.preference.PreferenceFragmentCompat; import androidx.preference.SwitchPreference; @@ -19,15 +18,11 @@ import javax.inject.Named; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent; -import ml.docilealligator.infinityforreddit.Event.ChangeVideoAutoplayEvent; import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; -/** - * A simple {@link PreferenceFragmentCompat} subclass. - */ public class MainPreferenceFragment extends PreferenceFragmentCompat { @Inject @@ -40,18 +35,11 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat { setPreferencesFromResource(R.xml.main_preferences, rootKey); ((Infinity) activity.getApplication()).getAppComponent().inject(this); - ListPreference videoAutoplaySwitch = findPreference(SharedPreferencesUtils.VIDEO_AUTOPLAY); SwitchPreference confirmToExitSwitch = findPreference(SharedPreferencesUtils.CONFIRM_TO_EXIT); SwitchPreference nsfwSwitch = findPreference(SharedPreferencesUtils.NSFW_KEY); SwitchPreference blurNSFWSwitch = findPreference(SharedPreferencesUtils.BLUR_NSFW_KEY); SwitchPreference blurSpoilerSwitch = findPreference(SharedPreferencesUtils.BLUR_SPOILER_KEY); - if (videoAutoplaySwitch != null) { - videoAutoplaySwitch.setOnPreferenceChangeListener((preference, newValue) -> { - EventBus.getDefault().post(new ChangeVideoAutoplayEvent((String) newValue)); - return true; - }); - } if (confirmToExitSwitch != null) { confirmToExitSwitch.setOnPreferenceChangeListener((preference, newValue) -> { EventBus.getDefault().post(new RecreateActivityEvent()); 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 7b12ef6c..a51c9e0b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java @@ -80,6 +80,7 @@ public class SharedPreferencesUtils { public static final String VIDEO_AUTOPLAY_VALUE_ALWAYS_ON = "2"; public static final String VIDEO_AUTOPLAY_VALUE_ON_WIFI = "1"; public static final String VIDEO_AUTOPLAY_VALUE_NEVER = "0"; + public static final String AUTOPLAY_NSFW_VIDEOS = "autoplay_nsfw_videos"; public static final String LOCK_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON = "lock_jump_to_next_top_level_comment_button"; public static final String SWAP_TAP_AND_LONG_COMMENTS = "swap_tap_and_long_in_comments"; public static final String SWIPE_UP_TO_HIDE_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON = "swipe_up_to_hide_jump_to_next_top_level_comments_button"; -- cgit v1.2.3