aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
Diffstat (limited to '')
-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
-rw-r--r--app/src/main/res/drawable-night/ic_mute_preferences_24dp.xml9
-rw-r--r--app/src/main/res/drawable/ic_mute_24dp.xml9
-rw-r--r--app/src/main/res/drawable/ic_mute_preferences_24dp.xml9
-rw-r--r--app/src/main/res/drawable/ic_unmute_24dp.xml9
-rw-r--r--app/src/main/res/layout/exo_playback_control_view.xml11
-rw-r--r--app/src/main/res/values/strings.xml1
-rw-r--r--app/src/main/res/xml/main_preferences.xml6
10 files changed, 126 insertions, 3 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";
}
diff --git a/app/src/main/res/drawable-night/ic_mute_preferences_24dp.xml b/app/src/main/res/drawable-night/ic_mute_preferences_24dp.xml
new file mode 100644
index 00000000..ff764c78
--- /dev/null
+++ b/app/src/main/res/drawable-night/ic_mute_preferences_24dp.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:fillColor="#FFFFFFFF"
+ android:pathData="M4.34,2.93L2.93,4.34 7.29,8.7 7,9L3,9v6h4l5,5v-6.59l4.18,4.18c-0.65,0.49 -1.38,0.88 -2.18,1.11v2.06c1.34,-0.3 2.57,-0.92 3.61,-1.75l2.05,2.05 1.41,-1.41L4.34,2.93zM10,15.17L7.83,13L5,13v-2h2.83l0.88,-0.88L10,11.41v3.76zM19,12c0,0.82 -0.15,1.61 -0.41,2.34l1.53,1.53c0.56,-1.17 0.88,-2.48 0.88,-3.87 0,-4.28 -2.99,-7.86 -7,-8.77v2.06c2.89,0.86 5,3.54 5,6.71zM12,4l-1.88,1.88L12,7.76zM16.5,12c0,-1.77 -1.02,-3.29 -2.5,-4.03v1.79l2.48,2.48c0.01,-0.08 0.02,-0.16 0.02,-0.24z"/>
+</vector>
diff --git a/app/src/main/res/drawable/ic_mute_24dp.xml b/app/src/main/res/drawable/ic_mute_24dp.xml
new file mode 100644
index 00000000..ff764c78
--- /dev/null
+++ b/app/src/main/res/drawable/ic_mute_24dp.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:fillColor="#FFFFFFFF"
+ android:pathData="M4.34,2.93L2.93,4.34 7.29,8.7 7,9L3,9v6h4l5,5v-6.59l4.18,4.18c-0.65,0.49 -1.38,0.88 -2.18,1.11v2.06c1.34,-0.3 2.57,-0.92 3.61,-1.75l2.05,2.05 1.41,-1.41L4.34,2.93zM10,15.17L7.83,13L5,13v-2h2.83l0.88,-0.88L10,11.41v3.76zM19,12c0,0.82 -0.15,1.61 -0.41,2.34l1.53,1.53c0.56,-1.17 0.88,-2.48 0.88,-3.87 0,-4.28 -2.99,-7.86 -7,-8.77v2.06c2.89,0.86 5,3.54 5,6.71zM12,4l-1.88,1.88L12,7.76zM16.5,12c0,-1.77 -1.02,-3.29 -2.5,-4.03v1.79l2.48,2.48c0.01,-0.08 0.02,-0.16 0.02,-0.24z"/>
+</vector>
diff --git a/app/src/main/res/drawable/ic_mute_preferences_24dp.xml b/app/src/main/res/drawable/ic_mute_preferences_24dp.xml
new file mode 100644
index 00000000..c206c848
--- /dev/null
+++ b/app/src/main/res/drawable/ic_mute_preferences_24dp.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M4.34,2.93L2.93,4.34 7.29,8.7 7,9L3,9v6h4l5,5v-6.59l4.18,4.18c-0.65,0.49 -1.38,0.88 -2.18,1.11v2.06c1.34,-0.3 2.57,-0.92 3.61,-1.75l2.05,2.05 1.41,-1.41L4.34,2.93zM10,15.17L7.83,13L5,13v-2h2.83l0.88,-0.88L10,11.41v3.76zM19,12c0,0.82 -0.15,1.61 -0.41,2.34l1.53,1.53c0.56,-1.17 0.88,-2.48 0.88,-3.87 0,-4.28 -2.99,-7.86 -7,-8.77v2.06c2.89,0.86 5,3.54 5,6.71zM12,4l-1.88,1.88L12,7.76zM16.5,12c0,-1.77 -1.02,-3.29 -2.5,-4.03v1.79l2.48,2.48c0.01,-0.08 0.02,-0.16 0.02,-0.24z"/>
+</vector>
diff --git a/app/src/main/res/drawable/ic_unmute_24dp.xml b/app/src/main/res/drawable/ic_unmute_24dp.xml
new file mode 100644
index 00000000..d2c9bb24
--- /dev/null
+++ b/app/src/main/res/drawable/ic_unmute_24dp.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:fillColor="#FFFFFFFF"
+ android:pathData="M3,9v6h4l5,5L12,4L7,9L3,9zM10,8.83v6.34L7.83,13L5,13v-2h2.83L10,8.83zM16.5,12c0,-1.77 -1.02,-3.29 -2.5,-4.03v8.05c1.48,-0.73 2.5,-2.25 2.5,-4.02zM14,3.23v2.06c2.89,0.86 5,3.54 5,6.71s-2.11,5.85 -5,6.71v2.06c4.01,-0.91 7,-4.49 7,-8.77 0,-4.28 -2.99,-7.86 -7,-8.77z"/>
+</vector>
diff --git a/app/src/main/res/layout/exo_playback_control_view.xml b/app/src/main/res/layout/exo_playback_control_view.xml
index ed305e41..d76c46fc 100644
--- a/app/src/main/res/layout/exo_playback_control_view.xml
+++ b/app/src/main/res/layout/exo_playback_control_view.xml
@@ -18,16 +18,21 @@
android:orientation="horizontal">
<ImageButton android:id="@id/exo_rew"
- style="@style/ExoMediaButton.Rewind"/>
+ style="@style/ExoMediaButton.Rewind" />
<ImageButton android:id="@id/exo_play"
style="@style/ExoMediaButton.Play"/>
<ImageButton android:id="@id/exo_pause"
- style="@style/ExoMediaButton.Pause"/>
+ style="@style/ExoMediaButton.Pause" />
<ImageButton android:id="@id/exo_ffwd"
- style="@style/ExoMediaButton.FastForward"/>
+ style="@style/ExoMediaButton.FastForward" />
+
+ <ImageButton
+ android:id="@+id/mute_exo_playback_control_view"
+ style="@style/ExoMediaButton"
+ android:visibility="gone" />
</LinearLayout>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 64cbedf9..dc6bcf92 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -298,6 +298,7 @@
<string name="settings_vote_buttons_on_the_right_title">Vote Buttons on the Right</string>
<string name="settings_volume_keys_navigate_comments_title">Use Volume Keys to Navigate Comments in Posts</string>
<string name="settings_volume_keys_navigate_posts_title">Use Volume Keys to Navigate Posts</string>
+ <string name="settings_mute_video_title">Mute Video</string>
<string name="settings_show_elapsed_time">Show Elapsed Time in Posts and Comments</string>
<string name="swipe_to_go_back_from_post_detail">Swipe Right to Go Back From Comments</string>
<string name="settings_lazy_mode_interval_title">Lazy Mode Interval</string>
diff --git a/app/src/main/res/xml/main_preferences.xml b/app/src/main/res/xml/main_preferences.xml
index 02c0f750..561222cd 100644
--- a/app/src/main/res/xml/main_preferences.xml
+++ b/app/src/main/res/xml/main_preferences.xml
@@ -56,6 +56,12 @@
app:key="volume_keys_navigate_posts"
app:title="@string/settings_volume_keys_navigate_posts_title" />
+ <SwitchPreference
+ app:defaultValue="false"
+ app:key="mute_video"
+ android:icon="@drawable/ic_mute_preferences_24dp"
+ app:title="@string/settings_mute_video_title" />
+
<Preference
app:title="@string/settings_font_size_title"
app:icon="@drawable/ic_font_size_24dp"