New option: Remeber Muting Option in Post Feed.

This commit is contained in:
Alex Ning 2021-07-20 09:01:57 +08:00
parent 7bef0f28ca
commit f68e4aad09
7 changed files with 77 additions and 2 deletions

View File

@ -709,7 +709,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
} else {
((PostVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1);
}
((PostVideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (post.isNSFW() && mMuteNSFWVideo) ? 0f : 1f);
if (mFragment.getMasterMutingOption() == null) {
((PostVideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (post.isNSFW() && mMuteNSFWVideo) ? 0f : 1f);
} else {
((PostVideoAutoplayViewHolder) holder).setVolume(mFragment.getMasterMutingOption() ? 0f : 1f);
}
if (post.isGfycat() || post.isRedgifs() && !post.isLoadGfyOrRedgifsVideoSuccess()) {
((PostVideoAutoplayViewHolder) holder).fetchGfycatOrRedgifsVideoLinks = new FetchGfycatOrRedgifsVideoLinks(new FetchGfycatOrRedgifsVideoLinks.FetchGfycatOrRedgifsVideoLinksListener() {
@ -833,7 +837,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
} else {
((PostCard2VideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1);
}
((PostCard2VideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (post.isNSFW() && mMuteNSFWVideo) ? 0f : 1f);
if (mFragment.getMasterMutingOption() == null) {
((PostCard2VideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (post.isNSFW() && mMuteNSFWVideo) ? 0f : 1f);
} else {
((PostCard2VideoAutoplayViewHolder) holder).setVolume(mFragment.getMasterMutingOption() ? 0f : 1f);
}
if (post.isGfycat() || post.isRedgifs() && !post.isLoadGfyOrRedgifsVideoSuccess()) {
((PostCard2VideoAutoplayViewHolder) holder).fetchGfycatOrRedgifsVideoLinks = new FetchGfycatOrRedgifsVideoLinks(new FetchGfycatOrRedgifsVideoLinks.FetchGfycatOrRedgifsVideoLinksListener() {
@ -2764,10 +2772,12 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_mute_white_rounded_18dp));
helper.setVolume(0f);
volume = 0f;
mFragment.videoAutoplayChangeMutingOption(true);
} else {
muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_unmute_white_rounded_18dp));
helper.setVolume(1f);
volume = 1f;
mFragment.videoAutoplayChangeMutingOption(false);
}
}
});
@ -2851,6 +2861,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
for (int i = 0; i < trackGroups.length; i++) {
String mimeType = trackGroups.get(i).getFormat(0).sampleMimeType;
if (mimeType != null && mimeType.contains("audio")) {
if (mFragment.getMasterMutingOption() != null) {
volume = mFragment.getMasterMutingOption() ? 0f : 1f;
}
helper.setVolume(volume);
muteButton.setVisibility(View.VISIBLE);
if (volume != 0f) {
@ -3978,10 +3991,12 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_mute_white_rounded_18dp));
helper.setVolume(0f);
volume = 0f;
mFragment.videoAutoplayChangeMutingOption(true);
} else {
muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_unmute_white_rounded_18dp));
helper.setVolume(1f);
volume = 1f;
mFragment.videoAutoplayChangeMutingOption(false);
}
}
});
@ -4065,6 +4080,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
for (int i = 0; i < trackGroups.length; i++) {
String mimeType = trackGroups.get(i).getFormat(0).sampleMimeType;
if (mimeType != null && mimeType.contains("audio")) {
if (mFragment.getMasterMutingOption() != null) {
volume = mFragment.getMasterMutingOption() ? 0f : 1f;
}
helper.setVolume(volume);
muteButton.setVisibility(View.VISIBLE);
if (volume != 0f) {
@ -4103,6 +4121,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
@Override
public void play() {
if (helper != null && mediaUri != null) {
if (mFragment.getMasterMutingOption() != null) {
helper.setVolume(mFragment.getMasterMutingOption() ? 0f : 1f);
}
helper.play();
}
}

View File

@ -0,0 +1,9 @@
package ml.docilealligator.infinityforreddit.events;
public class ChangeRememberMutingOptionInPostFeedEvent {
public boolean rememberMutingOptionInPostFeedEvent;
public ChangeRememberMutingOptionInPostFeedEvent(boolean rememberMutingOptionInPostFeedEvent) {
this.rememberMutingOptionInPostFeedEvent = rememberMutingOptionInPostFeedEvent;
}
}

View File

@ -29,6 +29,7 @@ import android.widget.Toast;
import androidx.annotation.DimenRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.res.ResourcesCompat;
import androidx.fragment.app.Fragment;
@ -97,6 +98,7 @@ import ml.docilealligator.infinityforreddit.events.ChangeNSFWBlurEvent;
import ml.docilealligator.infinityforreddit.events.ChangeNetworkStatusEvent;
import ml.docilealligator.infinityforreddit.events.ChangeOnlyDisablePreviewInVideoAndGifPostsEvent;
import ml.docilealligator.infinityforreddit.events.ChangePostLayoutEvent;
import ml.docilealligator.infinityforreddit.events.ChangeRememberMutingOptionInPostFeedEvent;
import ml.docilealligator.infinityforreddit.events.ChangeSavePostFeedScrolledPositionEvent;
import ml.docilealligator.infinityforreddit.events.ChangeShowAbsoluteNumberOfVotesEvent;
import ml.docilealligator.infinityforreddit.events.ChangeShowElapsedTimeEvent;
@ -211,6 +213,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
private boolean hasPost = false;
private boolean isShown = false;
private boolean savePostFeedScrolledPosition;
private boolean rememberMutingOptionInPostFeed;
private Boolean masterMutingOption;
private PostRecyclerViewAdapter mAdapter;
private RecyclerView.SmoothScroller smoothScroller;
private Window window;
@ -417,6 +421,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
int defaultPostLayout = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY, "0"));
savePostFeedScrolledPosition = mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_FRONT_PAGE_SCROLLED_POSITION, false);
rememberMutingOptionInPostFeed = mSharedPreferences.getBoolean(SharedPreferencesUtils.REMEMBER_MUTING_OPTION_IN_POST_FEED, false);
Locale locale = getResources().getConfiguration().locale;
int usage;
@ -1550,6 +1555,17 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
}
@Nullable
public Boolean getMasterMutingOption() {
return masterMutingOption;
}
public void videoAutoplayChangeMutingOption(boolean isMute) {
if (rememberMutingOptionInPostFeed) {
masterMutingOption = isMute;
}
}
@Subscribe
public void onPostUpdateEvent(PostUpdateEventToPostList event) {
PagedList<Post> posts = mAdapter.getCurrentList();
@ -1878,6 +1894,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
}
@Subscribe
public void onChangeRememberMutingOptionInPostFeedEvent(ChangeRememberMutingOptionInPostFeedEvent event) {
rememberMutingOptionInPostFeed = event.rememberMutingOptionInPostFeedEvent;
if (!event.rememberMutingOptionInPostFeedEvent) {
masterMutingOption = null;
}
}
private void refreshAdapter() {
int previousPosition = -1;
if (mLinearLayoutManager != null) {

View File

@ -22,6 +22,7 @@ import javax.inject.Named;
import ml.docilealligator.infinityforreddit.events.ChangeAutoplayNsfwVideosEvent;
import ml.docilealligator.infinityforreddit.events.ChangeMuteAutoplayingVideosEvent;
import ml.docilealligator.infinityforreddit.events.ChangeMuteNSFWVideoEvent;
import ml.docilealligator.infinityforreddit.events.ChangeRememberMutingOptionInPostFeedEvent;
import ml.docilealligator.infinityforreddit.events.ChangeStartAutoplayVisibleAreaOffsetEvent;
import ml.docilealligator.infinityforreddit.events.ChangeVideoAutoplayEvent;
import ml.docilealligator.infinityforreddit.Infinity;
@ -43,6 +44,7 @@ public class VideoPreferenceFragment extends PreferenceFragmentCompat {
ListPreference videoAutoplayListPreference = findPreference(SharedPreferencesUtils.VIDEO_AUTOPLAY);
SwitchPreference muteAutoplayingVideosSwitchPreference = findPreference(SharedPreferencesUtils.MUTE_AUTOPLAYING_VIDEOS);
SwitchPreference rememberMutingOptionInPostFeedSwitchPreference = findPreference(SharedPreferencesUtils.REMEMBER_MUTING_OPTION_IN_POST_FEED);
SwitchPreference muteNSFWVideosSwitchPreference = findPreference(SharedPreferencesUtils.MUTE_NSFW_VIDEO);
SwitchPreference autoplayNsfwVideosSwitchPreference = findPreference(SharedPreferencesUtils.AUTOPLAY_NSFW_VIDEOS);
SeekBarPreference startAutoplayVisibleAreaOffsetPortrait = findPreference(SharedPreferencesUtils.START_AUTOPLAY_VISIBLE_AREA_OFFSET_PORTRAIT);
@ -74,6 +76,13 @@ public class VideoPreferenceFragment extends PreferenceFragmentCompat {
});
}
if (rememberMutingOptionInPostFeedSwitchPreference != null) {
rememberMutingOptionInPostFeedSwitchPreference.setOnPreferenceChangeListener((preference, newValue) -> {
EventBus.getDefault().post(new ChangeRememberMutingOptionInPostFeedEvent((Boolean) newValue));
return true;
});
}
int orientation = getResources().getConfiguration().orientation;
if (startAutoplayVisibleAreaOffsetPortrait != null) {

View File

@ -183,6 +183,7 @@ public class SharedPreferencesUtils {
public static final String ENABLE_MATERIAL_YOU = "enable_material_you";
public static final String APPLY_MATERIAL_YOU = "apply_material_you";
public static final String VIDEO_PLAYER_AUTOMATIC_LANDSCAPE_ORIENTATION = "video_player_automatic_landscape_orientation";
public static final String REMEMBER_MUTING_OPTION_IN_POST_FEED = "remember_muting_option_in_post_feed";
public static final String DEFAULT_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit_preferences";
public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs";

View File

@ -586,6 +586,7 @@
<string name="settings_disable_nsfw_forever_title">Disable NSFW Forever</string>
<string name="settings_show_only_one_comment_level_indicator">Show Only One Comment Level Indicator</string>
<string name="settings_video_player_automatic_landscape_orientation">Switch to Landscape Orientation in Video Player Automatically</string>
<string name="settings_remember_muting_option_in_post_feed">Remember Muting Option in Post Feed</string>
<string name="no_link_available">Cannot get the link</string>

View File

@ -19,6 +19,11 @@
app:key="automatically_try_redgifs"
app:title="@string/settings_automatically_try_redgifs_title" />
<SwitchPreference
app:defaultValue="false"
app:key="remember_mute_status_in_post_feed"
app:title="@string/settings_automatically_try_redgifs_title" />
<SwitchPreference
app:defaultValue="false"
app:key="video_player_ignore_nav_bar"
@ -47,6 +52,11 @@
app:icon="@drawable/ic_mute_preferences_24dp"
app:title="@string/settings_mute_autoplaying_videos_title" />
<SwitchPreference
app:defaultValue="false"
app:key="remember_muting_option_in_post_feed"
app:title="@string/settings_remember_muting_option_in_post_feed" />
<SwitchPreference
app:defaultValue="true"
app:key="autoplay_nsfw_videos"