diff options
Diffstat (limited to '')
6 files changed, 70 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"; diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 55b887bd..79229db3 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -643,4 +643,24 @@ <item>2</item> </string-array> + <string-array name="settings_reddit_video_default_resolution"> + <item>Auto</item> + <item>1080p</item> + <item>720p</item> + <item>480p</item> + <item>360p</item> + <item>240p</item> + <item>144p</item> + </string-array> + + <string-array name="settings_reddit_video_default_resolution_values"> + <item>0</item> + <item>1080</item> + <item>720</item> + <item>480</item> + <item>360</item> + <item>240</item> + <item>144</item> + </string-array> + </resources> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1293fe57..bb420e07 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -640,6 +640,7 @@ <string name="settings_miscellaneous_dangerous_group_title">Dangerous</string> <string name="settings_post_feed_max_resolution_warning_title">Increase the value to show previews in higher resolution, but the app may crash unexpectedly.</string> <string name="settings_post_feed_max_resolution_title">Post Feed Preview Max Resolution (Width * Height)</string> + <string name="settings_reddit_video_default_resolution">Reddit Video Default Resolution</string> <string name="no_link_available">Cannot get the link</string> diff --git a/app/src/main/res/xml/data_saving_mode_preferences.xml b/app/src/main/res/xml/data_saving_mode_preferences.xml index 4c348335..1aad1008 100644 --- a/app/src/main/res/xml/data_saving_mode_preferences.xml +++ b/app/src/main/res/xml/data_saving_mode_preferences.xml @@ -25,4 +25,12 @@ app:key="only_disable_preview_in_video_and_gif_posts" android:title="@string/settings_only_disable_preview_in_video_and_gif_posts_title" /> + <ml.docilealligator.infinityforreddit.customviews.CustomFontListPreference + app:defaultValue="360" + app:key="reddit_video_default_resolution" + android:title="@string/settings_reddit_video_default_resolution" + app:entries="@array/settings_reddit_video_default_resolution" + app:entryValues="@array/settings_reddit_video_default_resolution_values" + app:useSimpleSummaryProvider="true" /> + </PreferenceScreen>
\ No newline at end of file |