From 1194209c82205df8b5c36d6f9cf3012a0d289386 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 24 Oct 2020 14:42:51 +0200 Subject: [PATCH] Fix #13 - #14 - #15 Settings for auto fullscreen/ disable auto playblack / pause videos in fullscreen with key back --- app/src/acad/res/values/strings.xml | 9 +++++ app/src/full/res/values/strings.xml | 10 +++++ .../fedilab/fedilabtube/PeertubeActivity.java | 39 ++++++++++++++----- .../fragment/SettingsFragment.java | 25 ++++++++++++ .../drawable/ic_baseline_open_in_full_24.xml | 10 +++++ .../drawable/ic_baseline_play_arrow_24.xml | 10 +++++ app/src/main/res/xml/main_preferences.xml | 12 ++++++ 7 files changed, 105 insertions(+), 10 deletions(-) create mode 100644 app/src/main/res/drawable/ic_baseline_open_in_full_24.xml create mode 100644 app/src/main/res/drawable/ic_baseline_play_arrow_24.xml diff --git a/app/src/acad/res/values/strings.xml b/app/src/acad/res/values/strings.xml index f09e53e..6dcf9fa 100644 --- a/app/src/acad/res/values/strings.xml +++ b/app/src/acad/res/values/strings.xml @@ -6,7 +6,16 @@ set_video_language_choice set_video_quality_choice set_video_cache_choice + set_autoplay_choice set_theme_choice + set_fullscreen_choice + + + Lecture automatique + Si activé, les vidéos seront lues automatiquement + + Plein écran + Ouvre automatiquement les vidéos en plein écran Supprimer tous les commentaires Etes-vous sûr de vouloir supprimer tous les commentaires de ce compte pour vos vidéos ? diff --git a/app/src/full/res/values/strings.xml b/app/src/full/res/values/strings.xml index 57af2e1..1e2c3fd 100644 --- a/app/src/full/res/values/strings.xml +++ b/app/src/full/res/values/strings.xml @@ -5,10 +5,20 @@ set_video_language_choice set_video_quality_choice set_video_cache_choice + set_autoplay_choice set_theme_choice + set_fullscreen_choice + + + Automatic playback + If enabled, videos will be played automatically + + Fullscreen + Automatically open videos in fullscreen Add a public reply + %d reply %d replies diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java index e87cd4c..4124919 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java @@ -146,7 +146,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd private VideoData.Video peertube; private int mode; private Map> playlists; - private boolean playInMinimized; + private boolean playInMinimized, autoPlay, autoFullscreen; private boolean onStopCalled; private List captions; private String max_id; @@ -221,6 +221,8 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd binding.writeCommentContainer.setVisibility(View.GONE); } playInMinimized = sharedpreferences.getBoolean(getString(R.string.set_video_minimize_choice), true); + autoPlay = sharedpreferences.getBoolean(getString(R.string.set_autoplay_choice), true); + autoFullscreen = sharedpreferences.getBoolean(getString(R.string.set_fullscreen_choice), false); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O || !getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) { playInMinimized = false; @@ -305,6 +307,10 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd playVideo(); } registBroadcastReceiver(); + if( autoFullscreen) { + openFullscreenDialog(); + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + } } @@ -394,17 +400,24 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd private void playVideo() { if (player != null) { - player.setPlayWhenReady(false); player.release(); player = ExoPlayerFactory.newSimpleInstance(PeertubeActivity.this); binding.mediaVideo.setPlayer(player); binding.loader.setVisibility(View.GONE); - player.setPlayWhenReady(true); + player.setPlayWhenReady(autoPlay); captions = null; } - fullscreen = FullScreenMediaController.fullscreen.OFF; - setFullscreen(FullScreenMediaController.fullscreen.OFF); - fullScreenMode = false; + if( autoFullscreen) { + fullscreen = FullScreenMediaController.fullscreen.ON; + setFullscreen(FullScreenMediaController.fullscreen.ON); + fullScreenMode = true; + openFullscreenDialog(); + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + } else { + fullscreen = FullScreenMediaController.fullscreen.OFF; + setFullscreen(FullScreenMediaController.fullscreen.OFF); + fullScreenMode = false; + } binding.peertubePlaylist.setVisibility(View.VISIBLE); binding.peertubeBookmark.setVisibility(View.GONE); @@ -655,7 +668,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd .createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getStreamingPlaylists().get(0).getPlaylistUrl())); player.prepare(hlsMediaSource); } - player.setPlayWhenReady(true); + player.setPlayWhenReady(autoPlay); } @@ -853,7 +866,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd super.onDestroy(); binding = null; if (player != null) { - player.setPlayWhenReady(false); player.release(); } unregisterReceiver(); @@ -965,7 +977,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd super.onResume(); onStopCalled = false; if (player != null && !player.isPlaying()) { - player.setPlayWhenReady(true); + player.setPlayWhenReady(autoPlay); } } @@ -1025,8 +1037,15 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd fullScreenDialog = new Dialog(this, android.R.style.Theme_Black_NoTitleBar_Fullscreen) { public void onBackPressed() { - if (fullScreenMode) { + if( player != null && player.isPlaying() && fullScreenMode) { + player.setPlayWhenReady(false); + return; + } + if( fullScreenMode) { closeFullscreenDialog(); + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + Handler handler = new Handler(); + handler.postDelayed(() -> setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR), 2000); } super.onBackPressed(); } diff --git a/app/src/main/java/app/fedilab/fedilabtube/fragment/SettingsFragment.java b/app/src/main/java/app/fedilab/fedilabtube/fragment/SettingsFragment.java index 4e71475..7940c7a 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/fragment/SettingsFragment.java +++ b/app/src/main/java/app/fedilab/fedilabtube/fragment/SettingsFragment.java @@ -137,6 +137,16 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared assert set_video_minimize_choice != null; editor.putBoolean(getString(R.string.set_video_minimize_choice), set_video_minimize_choice.isChecked()); } + if (key.compareTo(getString(R.string.set_autoplay_choice)) == 0) { + SwitchPreference set_autoplay_choice = findPreference(getString(R.string.set_autoplay_choice)); + assert set_autoplay_choice != null; + editor.putBoolean(getString(R.string.set_autoplay_choice), set_autoplay_choice.isChecked()); + } + if (key.compareTo(getString(R.string.set_fullscreen_choice)) == 0) { + SwitchPreference set_fullscreen_choice = findPreference(getString(R.string.set_fullscreen_choice)); + assert set_fullscreen_choice != null; + editor.putBoolean(getString(R.string.set_fullscreen_choice), set_fullscreen_choice.isChecked()); + } if (key.compareTo(getString(R.string.set_video_language_choice)) == 0) { MultiSelectListPreference set_video_language_choice = findPreference(getString(R.string.set_video_language_choice)); assert set_video_language_choice != null; @@ -208,12 +218,27 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared assert set_video_cache_choice != null; set_video_cache_choice.setValue(video_cache / 10); + //****** Minimized videos ******* boolean minimized = sharedpref.getBoolean(getString(R.string.set_video_minimize_choice), true); SwitchPreference set_video_minimize_choice = findPreference(getString(R.string.set_video_minimize_choice)); assert set_video_minimize_choice != null; set_video_minimize_choice.setChecked(minimized); + //****** Autoplay videos ******* + boolean autoplay = sharedpref.getBoolean(getString(R.string.set_autoplay_choice), true); + SwitchPreference set_autoplay_choice = findPreference(getString(R.string.set_autoplay_choice)); + assert set_autoplay_choice != null; + set_autoplay_choice.setChecked(autoplay); + + + //****** Fullscreen videos ******* + boolean fullscreen = sharedpref.getBoolean(getString(R.string.set_fullscreen_choice), false); + SwitchPreference set_fullscreen_choice = findPreference(getString(R.string.set_fullscreen_choice)); + assert set_fullscreen_choice != null; + set_fullscreen_choice.setChecked(fullscreen); + + //****** Language filter ********* LinkedHashMap languages = new LinkedHashMap<>(peertubeInformation.getLanguages()); List entriesLanguages = new ArrayList<>(); List valuesLanguages = new ArrayList<>(); diff --git a/app/src/main/res/drawable/ic_baseline_open_in_full_24.xml b/app/src/main/res/drawable/ic_baseline_open_in_full_24.xml new file mode 100644 index 0000000..e1da4fe --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_open_in_full_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_baseline_play_arrow_24.xml b/app/src/main/res/drawable/ic_baseline_play_arrow_24.xml new file mode 100644 index 0000000..13c137a --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_play_arrow_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/xml/main_preferences.xml b/app/src/main/res/xml/main_preferences.xml index 9ddd467..289294d 100644 --- a/app/src/main/res/xml/main_preferences.xml +++ b/app/src/main/res/xml/main_preferences.xml @@ -21,6 +21,18 @@ android:summary="@string/set_video_quality_description" android:title="@string/set_quality_mode" /> + + + +