diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-06-04 14:33:24 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-06-04 14:33:24 +0000 |
commit | c37cc1bed372c7d6b632bedafbb283d08ed6c0bc (patch) | |
tree | 37251d28fd3595474914d641fea44f2f9dcad01d /app/src/main/java/ml/docilealligator/infinityforreddit | |
parent | e5d9f93e96a0876676a75e31ebea29e4071c580a (diff) | |
download | infinity-for-reddit-c37cc1bed372c7d6b632bedafbb283d08ed6c0bc.tar infinity-for-reddit-c37cc1bed372c7d6b632bedafbb283d08ed6c0bc.tar.gz infinity-for-reddit-c37cc1bed372c7d6b632bedafbb283d08ed6c0bc.tar.bz2 infinity-for-reddit-c37cc1bed372c7d6b632bedafbb283d08ed6c0bc.tar.lz infinity-for-reddit-c37cc1bed372c7d6b632bedafbb283d08ed6c0bc.tar.xz infinity-for-reddit-c37cc1bed372c7d6b632bedafbb283d08ed6c0bc.tar.zst infinity-for-reddit-c37cc1bed372c7d6b632bedafbb283d08ed6c0bc.zip |
Add an option to disable autoplaying nsfw videos. Support imgur gifv videos.
Diffstat (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit')
8 files changed, 84 insertions, 12 deletions
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<Recy private boolean mShowCommentDivider; private boolean mShowAbsoluteNumberOfVotes; private boolean mAutoplay = false; + private boolean mAutoplayNsfwVideos; private CommentRecyclerViewAdapterCallback mCommentRecyclerViewAdapterCallback; private boolean isInitiallyLoading; private boolean isInitiallyLoadingFailed; @@ -317,6 +318,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy } else if (autoplayString.equals(SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_ON_WIFI)) { mAutoplay = Utils.isConnectedToWifi(activity); } + mAutoplayNsfwVideos = mSharedPreferences.getBoolean(SharedPreferencesUtils.AUTOPLAY_NSFW_VIDEOS, true); mCommentRecyclerViewAdapterCallback = commentRecyclerViewAdapterCallback; isInitiallyLoading = true; @@ -382,12 +384,18 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy switch (mPost.getPostType()) { case Post.VIDEO_TYPE: if (mAutoplay) { + if (!mAutoplayNsfwVideos && mPost.isNSFW()) { + return VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW; + } return VIEW_TYPE_POST_DETAIL_VIDEO_AUTOPLAY; } else { return VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW; } case Post.GIF_TYPE: if (mAutoplay) { + if (!mAutoplayNsfwVideos && mPost.isNSFW()) { + return VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW; + } return VIEW_TYPE_POST_DETAIL_IMAGE_AND_GIF_AUTOPLAY; } else { return VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java index e335bfa0..a193b56f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -162,6 +162,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView private boolean mShowDividerInCompactLayout; private boolean mShowAbsoluteNumberOfVotes; private boolean mAutoplay = false; + private boolean mAutoplayNsfwVideos; private Drawable mCommentIcon; private NetworkState networkState; private ExoCreator mExoCreator; @@ -194,6 +195,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView } else if (autoplayString.equals(SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_ON_WIFI)) { mAutoplay = Utils.isConnectedToWifi(activity); } + mAutoplayNsfwVideos = sharedPreferences.getBoolean(SharedPreferencesUtils.AUTOPLAY_NSFW_VIDEOS, true); mPostLayout = postLayout; mColorPrimaryLightTheme = customThemeWrapper.getColorPrimaryLightTheme(); @@ -260,11 +262,17 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView switch (post.getPostType()) { case Post.VIDEO_TYPE: if (mAutoplay) { + if (!mAutoplayNsfwVideos && post.isNSFW()) { + return VIEW_TYPE_POST_CARD_VIDEO_AND_GIF_PREVIEW_TYPE; + } return VIEW_TYPE_POST_CARD_VIDEO_TYPE_AUTOPLAY; } return VIEW_TYPE_POST_CARD_VIDEO_AND_GIF_PREVIEW_TYPE; case Post.GIF_TYPE: if (mAutoplay) { + if (!mAutoplayNsfwVideos && post.isNSFW()) { + return VIEW_TYPE_POST_CARD_VIDEO_AND_GIF_PREVIEW_TYPE; + } return VIEW_TYPE_POST_CARD_IMAGE_AND_GIF_AUTOPLAY_TYPE; } return VIEW_TYPE_POST_CARD_VIDEO_AND_GIF_PREVIEW_TYPE; @@ -1309,6 +1317,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView return mAutoplay; } + public void setAutoplayNsfwVideos(boolean autoplayNsfwVideos) { + mAutoplayNsfwVideos = autoplayNsfwVideos; + } + @Override public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { super.onViewRecycled(holder); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeAutoplayNsfwVideosEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeAutoplayNsfwVideosEvent.java new file mode 100644 index 00000000..47af8163 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeAutoplayNsfwVideosEvent.java @@ -0,0 +1,9 @@ +package ml.docilealligator.infinityforreddit.Event; + +public class ChangeAutoplayNsfwVideosEvent { + public boolean autoplayNsfwVideos; + + public ChangeAutoplayNsfwVideosEvent(boolean autoplayNsfwVideos) { + this.autoplayNsfwVideos = autoplayNsfwVideos; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java index 53dd904b..d9c0368b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java @@ -57,6 +57,7 @@ import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity import ml.docilealligator.infinityforreddit.Adapter.PostRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.CustomView.CustomToroContainer; +import ml.docilealligator.infinityforreddit.Event.ChangeAutoplayNsfwVideosEvent; import ml.docilealligator.infinityforreddit.Event.ChangeDefaultPostLayoutEvent; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent; import ml.docilealligator.infinityforreddit.Event.ChangePostLayoutEvent; @@ -884,6 +885,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } @Subscribe + public void onChangeAutoplayNsfwVideosEvent(ChangeAutoplayNsfwVideosEvent changeAutoplayNsfwVideosEvent) { + if (mAdapter != null) { + mAdapter.setAutoplayNsfwVideos(changeAutoplayNsfwVideosEvent.autoplayNsfwVideos); + refresh(); + } + } + + @Subscribe public void onChangeWifiStatusEvent(ChangeWifiStatusEvent changeWifiStatusEvent) { if (mAdapter != null) { String autoplay = mSharedPreferences.getString(SharedPreferencesUtils.VIDEO_AUTOPLAY, SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_NEVER); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AutoplayPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AutoplayPreferenceFragment.java new file mode 100644 index 00000000..91bd52d7 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AutoplayPreferenceFragment.java @@ -0,0 +1,37 @@ +package ml.docilealligator.infinityforreddit.Settings; + +import android.os.Bundle; + +import androidx.preference.ListPreference; +import androidx.preference.PreferenceFragmentCompat; +import androidx.preference.SwitchPreference; + +import org.greenrobot.eventbus.EventBus; + +import ml.docilealligator.infinityforreddit.Event.ChangeAutoplayNsfwVideosEvent; +import ml.docilealligator.infinityforreddit.Event.ChangeVideoAutoplayEvent; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; + +public class AutoplayPreferenceFragment extends PreferenceFragmentCompat { + + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + setPreferencesFromResource(R.xml.autoplay_preferences, rootKey); + + ListPreference videoAutoplayListPreference = findPreference(SharedPreferencesUtils.VIDEO_AUTOPLAY); + SwitchPreference autoplayNsfwVideosSwitchPreference = findPreference(SharedPreferencesUtils.AUTOPLAY_NSFW_VIDEOS); + + if (videoAutoplayListPreference != null && autoplayNsfwVideosSwitchPreference != null) { + videoAutoplayListPreference.setOnPreferenceChangeListener((preference, newValue) -> { + 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"; |