From 45f6ba553251a1920ce8688c20679b9504389e30 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Thu, 9 Jul 2020 10:51:24 +0800 Subject: Add an option to mute nsfw videos. Show preview before autoplaying videos in CommentAndPostRecyclerViewAdapter. --- .../Activity/LinkResolverActivity.java | 6 ++++- .../Activity/ViewVideoActivity.java | 7 +++++- .../Adapter/CommentAndPostRecyclerViewAdapter.java | 29 ++++++++++++++++++++-- .../Adapter/PostRecyclerViewAdapter.java | 24 +++++++++++++++--- .../Event/ChangeMuteNSFWVideoEvent.java | 9 +++++++ .../infinityforreddit/Fragment/PostFragment.java | 9 +++++++ .../Service/DownloadRedditVideoService.java | 2 -- .../Settings/VideoPreferenceFragment.java | 9 +++++++ .../Utils/SharedPreferencesUtils.java | 1 + 9 files changed, 87 insertions(+), 9 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeMuteNSFWVideoEvent.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 45c310c0..95e98f40 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java @@ -7,7 +7,6 @@ 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; @@ -30,6 +29,7 @@ public class LinkResolverActivity extends AppCompatActivity { public static final String EXTRA_MESSAGE_FULLNAME = "ENF"; public static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN"; + public static final String EXTRA_IS_NSFW = "EIN"; private static final String POST_PATTERN = "/r/\\w+/comments/\\w+/?\\w+/?"; private static final String COMMENT_PATTERN = "/(r|u|U|user)/\\w+/comments/\\w+/?\\w+/\\w+/?"; @@ -97,6 +97,7 @@ public class LinkResolverActivity extends AppCompatActivity { } else if (path.endsWith("mp4")) { Intent intent = new Intent(this, ViewVideoActivity.class); intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_DIRECT); + intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, getIntent().getBooleanExtra(EXTRA_IS_NSFW, false)); intent.setData(uri); startActivity(intent); } else { @@ -186,6 +187,7 @@ public class LinkResolverActivity extends AppCompatActivity { Intent intent = new Intent(this, ViewVideoActivity.class); intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, path.substring(1)); intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT); + intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, getIntent().getBooleanExtra(EXTRA_IS_NSFW, false)); startActivity(intent); } else { deepLinkError(uri); @@ -195,6 +197,7 @@ public class LinkResolverActivity extends AppCompatActivity { Intent intent = new Intent(this, ViewVideoActivity.class); intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, path.substring(7)); intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS); + intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, true); startActivity(intent); } else { deepLinkError(uri); @@ -220,6 +223,7 @@ public class LinkResolverActivity extends AppCompatActivity { 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.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, getIntent().getBooleanExtra(EXTRA_IS_NSFW, false)); intent.setData(Uri.parse(url)); startActivity(intent); } else { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java index 3db53108..d76d2c00 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java @@ -75,6 +75,7 @@ public class ViewVideoActivity extends AppCompatActivity { public static final String EXTRA_PROGRESS_SECONDS = "EPS"; public static final String EXTRA_VIDEO_TYPE = "EVT"; public static final String EXTRA_GFYCAT_ID = "EGI"; + public static final String EXTRA_IS_NSFW = "EIN"; public static final int VIDEO_TYPE_DIRECT = 3; public static final int VIDEO_TYPE_REDGIFS = 2; public static final int VIDEO_TYPE_GFYCAT = 1; @@ -107,6 +108,7 @@ public class ViewVideoActivity extends AppCompatActivity { private boolean isDownloading = false; private boolean isMute = false; private String postTitle; + private boolean isNSFW; private long resumePosition = -1; private int videoType; @@ -174,10 +176,12 @@ public class ViewVideoActivity extends AppCompatActivity { Intent intent = getIntent(); mVideoUri = intent.getData(); postTitle = intent.getStringExtra(EXTRA_POST_TITLE); + isNSFW = intent.getBooleanExtra(EXTRA_IS_NSFW, false); if (savedInstanceState == null) { resumePosition = intent.getLongExtra(EXTRA_PROGRESS_SECONDS, -1); } + if (postTitle != null) { setTitle(Html.fromHtml(String.format("%s", postTitle))); } else { @@ -264,7 +268,8 @@ public class ViewVideoActivity extends AppCompatActivity { player.setPlayWhenReady(true); wasPlaying = true; - boolean muteVideo = mSharedPreferences.getBoolean(SharedPreferencesUtils.MUTE_VIDEO, false); + boolean muteVideo = mSharedPreferences.getBoolean(SharedPreferencesUtils.MUTE_VIDEO, false) || + (mSharedPreferences.getBoolean(SharedPreferencesUtils.MUTE_NSFW_VIDEO, false) && isNSFW); if (savedInstanceState != null) { isMute = savedInstanceState.getBoolean(IS_MUTE_STATE); 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 3dea5729..96901e29 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -109,6 +109,7 @@ import ml.docilealligator.infinityforreddit.Utils.GlideImageGetter; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.Utils.Utils; import ml.docilealligator.infinityforreddit.VoteThing; +import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; import static ml.docilealligator.infinityforreddit.Activity.CommentActivity.WRITE_COMMENT_REQUEST_CODE; @@ -162,6 +163,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { if (helper != null) { if (helper.getVolume() != 0) { @@ -2178,6 +2189,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter cues) { } + + @Override + public void onRenderedFirstFrame() { + mGlide.clear(previewImageView); + previewImageView.setVisibility(View.GONE); + } }); } helper.initialize(container, playbackInfo); @@ -2364,6 +2386,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { if (helper != null) { if (helper.getVolume() != 0) { @@ -1984,6 +1994,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { + EventBus.getDefault().post(new ChangeMuteNSFWVideoEvent((Boolean) newValue)); + return true; + }); + } + if (muteAutoplayingVideosSwitchPreference != null) { muteAutoplayingVideosSwitchPreference.setOnPreferenceChangeListener((preference, newValue) -> { EventBus.getDefault().post(new ChangeMuteAutoplayingVideosEvent((Boolean) newValue)); 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 eca06f7b..eb6402c2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java @@ -129,4 +129,5 @@ public class SharedPreferencesUtils { public static final String MAIN_PAGE_TAB_POST_TYPE_USER = "5"; public static final String START_AUTOPLAY_VISIBLE_AREA_OFFSET_PORTRAIT = "start_autoplay_visible_area_offset_portrait"; public static final String START_AUTOPLAY_VISIBLE_AREA_OFFSET_LANDSCAPE = "start_autoplay_visible_area_offset_landscape"; + public static final String MUTE_NSFW_VIDEO = "mute_nsfw_video"; } -- cgit v1.2.3