aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java38
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/settings/DataSavingModePreferenceFragment.java14
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java1
3 files changed, 41 insertions, 12 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java
index 6a6b378c..b6627337 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java
@@ -44,7 +44,9 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
+import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlayerFactory;
+import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.SimpleExoPlayer;
@@ -62,6 +64,7 @@ import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
import com.google.android.exoplayer2.upstream.cache.CacheDataSourceFactory;
import com.google.android.exoplayer2.upstream.cache.SimpleCache;
+import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoListener;
import com.google.android.material.bottomappbar.BottomAppBar;
@@ -188,7 +191,7 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
private long resumePosition = -1;
private int videoType;
private boolean isDataSavingMode;
- private boolean isHd;
+ private int dataSavingModeDefaultResolution;
private Integer originalOrientation;
private int playbackSpeed = 100;
private boolean useBottomAppBar;
@@ -333,7 +336,7 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
} else if (dataSavingModeString.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ONLY_ON_CELLULAR_DATA)) {
isDataSavingMode = networkType == Utils.NETWORK_TYPE_CELLULAR;
}
- isHd = !isDataSavingMode;
+ dataSavingModeDefaultResolution = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.REDDIT_VIDEO_DEFAULT_RESOLUTION, "360"));
if (!mSharedPreferences.getBoolean(SharedPreferencesUtils.VIDEO_PLAYER_IGNORE_NAV_BAR, false)) {
if (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) {
@@ -417,6 +420,11 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory();
trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
+ if (videoType == VIDEO_TYPE_NORMAL && isDataSavingMode && dataSavingModeDefaultResolution > 0) {
+ trackSelector.setParameters(
+ trackSelector.buildUponParameters()
+ .setMaxVideoSize(dataSavingModeDefaultResolution, dataSavingModeDefaultResolution));
+ }
player = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
playerControlView.setPlayer(player);
@@ -610,12 +618,6 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
if (!trackGroups.isEmpty()) {
if (videoType == VIDEO_TYPE_NORMAL) {
- if (isDataSavingMode) {
- trackSelector.setParameters(
- trackSelector.buildUponParameters()
- .setMaxVideoSize(720, 720));
- }
-
hdButton.setVisibility(View.VISIBLE);
hdButton.setOnClickListener(view -> {
TrackSelectionDialogBuilder builder = new TrackSelectionDialogBuilder(ViewVideoActivity.this, getString(R.string.select_video_quality), trackSelector, 0);
@@ -653,6 +655,26 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
});
}
+ private int inferPrimaryTrackType(Format format) {
+ int trackType = MimeTypes.getTrackType(format.sampleMimeType);
+ if (trackType != C.TRACK_TYPE_UNKNOWN) {
+ return trackType;
+ }
+ if (MimeTypes.getVideoMediaMimeType(format.codecs) != null) {
+ return C.TRACK_TYPE_VIDEO;
+ }
+ if (MimeTypes.getAudioMediaMimeType(format.codecs) != null) {
+ return C.TRACK_TYPE_AUDIO;
+ }
+ if (format.width != Format.NO_VALUE || format.height != Format.NO_VALUE) {
+ return C.TRACK_TYPE_VIDEO;
+ }
+ if (format.channelCount != Format.NO_VALUE || format.sampleRate != Format.NO_VALUE) {
+ return C.TRACK_TYPE_AUDIO;
+ }
+ return C.TRACK_TYPE_UNKNOWN;
+ }
+
private void loadGfycatOrRedgifsVideo(Retrofit retrofit, String gfycatId, Bundle savedInstanceState, boolean needErrorHandling) {
progressBar.setVisibility(View.VISIBLE);
FetchGfycatOrRedgifsVideoLinks.fetchGfycatOrRedgifsVideoLinks(mExecutor, new Handler(), retrofit, gfycatId,
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/DataSavingModePreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/DataSavingModePreferenceFragment.java
index 00afbfb3..8ab39189 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/DataSavingModePreferenceFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/DataSavingModePreferenceFragment.java
@@ -1,16 +1,13 @@
package ml.docilealligator.infinityforreddit.settings;
-import android.content.Context;
import android.os.Bundle;
-import androidx.annotation.NonNull;
import androidx.preference.ListPreference;
import androidx.preference.SwitchPreference;
import org.greenrobot.eventbus.EventBus;
import ml.docilealligator.infinityforreddit.R;
-import ml.docilealligator.infinityforreddit.activities.SettingsActivity;
import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat;
import ml.docilealligator.infinityforreddit.events.ChangeDataSavingModeEvent;
import ml.docilealligator.infinityforreddit.events.ChangeDisableImagePreviewEvent;
@@ -30,7 +27,7 @@ public class DataSavingModePreferenceFragment extends CustomFontPreferenceFragme
ListPreference dataSavingModeListPreference = findPreference(SharedPreferencesUtils.DATA_SAVING_MODE);
SwitchPreference disableImagePreviewPreference = findPreference(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW);
SwitchPreference onlyDisablePreviewInVideoAndGifPostsPreference = findPreference(SharedPreferencesUtils.ONLY_DISABLE_PREVIEW_IN_VIDEO_AND_GIF_POSTS);
-
+ ListPreference redditVideoDefaultResolutionListPreference = findPreference(SharedPreferencesUtils.REDDIT_VIDEO_DEFAULT_RESOLUTION);
if (dataSavingModeListPreference != null) {
if (dataSavingModeListPreference.getValue().equals("0")) {
@@ -40,6 +37,9 @@ public class DataSavingModePreferenceFragment extends CustomFontPreferenceFragme
if (disableImagePreviewPreference != null) {
disableImagePreviewPreference.setVisible(false);
}
+ if (redditVideoDefaultResolutionListPreference != null) {
+ redditVideoDefaultResolutionListPreference.setVisible(false);
+ }
}
dataSavingModeListPreference.setOnPreferenceChangeListener((preference, newValue) -> {
EventBus.getDefault().post(new ChangeDataSavingModeEvent((String) newValue));
@@ -50,6 +50,9 @@ public class DataSavingModePreferenceFragment extends CustomFontPreferenceFragme
if (disableImagePreviewPreference != null) {
disableImagePreviewPreference.setVisible(false);
}
+ if (redditVideoDefaultResolutionListPreference != null) {
+ redditVideoDefaultResolutionListPreference.setVisible(false);
+ }
} else {
if (onlyDisablePreviewInVideoAndGifPostsPreference != null) {
onlyDisablePreviewInVideoAndGifPostsPreference.setVisible(true);
@@ -57,6 +60,9 @@ public class DataSavingModePreferenceFragment extends CustomFontPreferenceFragme
if (disableImagePreviewPreference != null) {
disableImagePreviewPreference.setVisible(true);
}
+ if (redditVideoDefaultResolutionListPreference != null) {
+ redditVideoDefaultResolutionListPreference.setVisible(true);
+ }
}
return true;
});
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 9417352d..37c0924b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java
@@ -209,6 +209,7 @@ public class SharedPreferencesUtils {
public static final String ALWAYS_SHOW_CHILD_COMMENT_COUNT = "always_show_child_comment_count";
public static final String HIDE_UPVOTE_RATIO = "hide_upvote_ratio";
public static final String POST_FEED_MAX_RESOLUTION = "post_feed_max_resolution";
+ public static final String REDDIT_VIDEO_DEFAULT_RESOLUTION = "reddit_video_default_resolution";
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";