aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-01-05 02:57:32 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-01-05 02:57:32 +0000
commit35acef9f8de9614f9cd108aa6a443ce0ba2abae5 (patch)
treeef1ec95431940061e49660830bdb74ae57befeae /app/src/main/java
parenta143501f9f3571c9f6c28490e8e826ece3dfa205 (diff)
downloadinfinity-for-reddit-35acef9f8de9614f9cd108aa6a443ce0ba2abae5.tar
infinity-for-reddit-35acef9f8de9614f9cd108aa6a443ce0ba2abae5.tar.gz
infinity-for-reddit-35acef9f8de9614f9cd108aa6a443ce0ba2abae5.tar.bz2
infinity-for-reddit-35acef9f8de9614f9cd108aa6a443ce0ba2abae5.tar.lz
infinity-for-reddit-35acef9f8de9614f9cd108aa6a443ce0ba2abae5.tar.xz
infinity-for-reddit-35acef9f8de9614f9cd108aa6a443ce0ba2abae5.tar.zst
infinity-for-reddit-35acef9f8de9614f9cd108aa6a443ce0ba2abae5.zip
Mute videos by default is now available.
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java71
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java1
3 files changed, 75 insertions, 0 deletions
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 27d937ab..6a2a4fdc 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java
@@ -7,6 +7,7 @@ import android.animation.ValueAnimator;
import android.app.DownloadManager;
import android.content.Context;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.PorterDuff;
@@ -22,6 +23,7 @@ import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;
@@ -37,10 +39,12 @@ import com.github.pwittchen.swipe.library.rx2.Swipe;
import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.SimpleExoPlayer;
+import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.source.hls.HlsMediaSource;
import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelection;
+import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.trackselection.TrackSelector;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.upstream.DataSource;
@@ -49,9 +53,13 @@ import com.google.android.exoplayer2.util.Util;
import java.io.File;
+import javax.inject.Inject;
+
import butterknife.BindView;
import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
public class ViewVideoActivity extends AppCompatActivity {
@@ -59,10 +67,13 @@ public class ViewVideoActivity extends AppCompatActivity {
public static final String EXTRA_SUBREDDIT = "ES";
public static final String EXTRA_ID = "EI";
private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0;
+ private static final String IS_MUTE_STATE = "IMS";
@BindView(R.id.relative_layout_view_video_activity)
RelativeLayout relativeLayout;
@BindView(R.id.player_view_view_video_activity)
PlayerView videoPlayerView;
+ @BindView(R.id.mute_exo_playback_control_view)
+ ImageButton muteButton;
private Uri mVideoUri;
private SimpleExoPlayer player;
@@ -75,15 +86,22 @@ public class ViewVideoActivity extends AppCompatActivity {
private String videoFileName;
private boolean wasPlaying;
private boolean isDownloading = false;
+ private boolean isMute = false;
private float totalLengthY = 0.0f;
private float touchY = -1.0f;
+ @Inject
+ SharedPreferences mSharedPreferences;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getTheme().applyStyle(R.style.Theme_Default, true);
setContentView(R.layout.activity_view_video);
+
+ ((Infinity) getApplication()).getAppComponent().inject(this);
+
ButterKnife.bind(this);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
@@ -293,6 +311,53 @@ public class ViewVideoActivity extends AppCompatActivity {
player.setRepeatMode(Player.REPEAT_MODE_ALL);
player.setPlayWhenReady(true);
wasPlaying = true;
+
+ boolean muteVideo = mSharedPreferences.getBoolean(SharedPreferencesUtils.MUTE_VIDEO, false);
+
+ if (savedInstanceState != null) {
+ isMute = savedInstanceState.getBoolean(IS_MUTE_STATE);
+ if (isMute) {
+ player.setVolume(0f);
+ muteButton.setImageResource(R.drawable.ic_unmute_24dp);
+ } else {
+ player.setVolume(1f);
+ muteButton.setImageResource(R.drawable.ic_mute_24dp);
+ }
+ } else if (muteVideo) {
+ isMute = true;
+ player.setVolume(0f);
+ muteButton.setImageResource(R.drawable.ic_unmute_24dp);
+ } else {
+ muteButton.setImageResource(R.drawable.ic_mute_24dp);
+ }
+
+ player.addListener(new Player.EventListener() {
+ @Override
+ public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
+ if (!trackGroups.isEmpty()) {
+ for (int i = 0; i < trackGroups.length; i++) {
+ String mimeType = trackGroups.get(i).getFormat(0).sampleMimeType;
+ if (mimeType != null && mimeType.contains("audio")) {
+ muteButton.setVisibility(View.VISIBLE);
+ muteButton.setOnClickListener(view -> {
+ if (isMute) {
+ isMute = false;
+ player.setVolume(1f);
+ muteButton.setImageResource(R.drawable.ic_mute_24dp);
+ } else {
+ isMute = true;
+ player.setVolume(0f);
+ muteButton.setImageResource(R.drawable.ic_unmute_24dp);
+ }
+ });
+ break;
+ }
+ }
+ } else {
+ muteButton.setVisibility(View.GONE);
+ }
+ }
+ });
}
@Override
@@ -423,4 +488,10 @@ public class ViewVideoActivity extends AppCompatActivity {
super.onPause();
overridePendingTransition(0, 0);
}
+
+ @Override
+ protected void onSaveInstanceState(@NonNull Bundle outState) {
+ super.onSaveInstanceState(outState);
+ outState.putBoolean(IS_MUTE_STATE, isMute);
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
index df7141bb..b7fe4a79 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
@@ -32,6 +32,7 @@ import ml.docilealligator.infinityforreddit.Activity.ViewPostDetailActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewSidebarActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewUserDetailActivity;
+import ml.docilealligator.infinityforreddit.Activity.ViewVideoActivity;
import ml.docilealligator.infinityforreddit.Fragment.CommentsListingFragment;
import ml.docilealligator.infinityforreddit.Fragment.FlairBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Fragment.FollowedUsersListingFragment;
@@ -125,4 +126,6 @@ public interface AppComponent {
void inject(ViewMultiRedditDetailActivity viewMultiRedditDetailActivity);
void inject(ViewSidebarActivity viewSidebarActivity);
+
+ void inject(ViewVideoActivity viewVideoActivity);
}
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 ef6354aa..b0434d82 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
@@ -65,4 +65,5 @@ public class SharedPreferencesUtils {
public static final String SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL = "swipe_to_go_back_from_post_detail";
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";
}