Fix #13 - #14 - #15 Settings for auto fullscreen/ disable auto playblack / pause videos in fullscreen with key back

This commit is contained in:
Thomas 2020-10-24 14:42:51 +02:00
parent f31b6e9ac8
commit 1194209c82
7 changed files with 105 additions and 10 deletions

View File

@ -6,7 +6,16 @@
<string name="set_video_language_choice" translatable="false">set_video_language_choice</string>
<string name="set_video_quality_choice" translatable="false">set_video_quality_choice</string>
<string name="set_video_cache_choice" translatable="false">set_video_cache_choice</string>
<string name="set_autoplay_choice" translatable="false">set_autoplay_choice</string>
<string name="set_theme_choice" translatable="false">set_theme_choice</string>
<string name="set_fullscreen_choice" translatable="false">set_fullscreen_choice</string>
<string name="set_autoplay">Lecture automatique</string>
<string name="set_autoplay_description">Si activé, les vidéos seront lues automatiquement</string>
<string name="set_fullscreen">Plein écran</string>
<string name="set_fullscreen_description">Ouvre automatiquement les vidéos en plein écran</string>
<string name="delete_account_comment">Supprimer tous les commentaires</string>
<string name="delete_account_comment_confirm">Etes-vous sûr de vouloir supprimer tous les commentaires de ce compte pour vos vidéos ?</string>

View File

@ -5,10 +5,20 @@
<string name="set_video_language_choice" translatable="false">set_video_language_choice</string>
<string name="set_video_quality_choice" translatable="false">set_video_quality_choice</string>
<string name="set_video_cache_choice" translatable="false">set_video_cache_choice</string>
<string name="set_autoplay_choice" translatable="false">set_autoplay_choice</string>
<string name="set_theme_choice" translatable="false">set_theme_choice</string>
<string name="set_fullscreen_choice" translatable="false">set_fullscreen_choice</string>
<string name="set_autoplay">Automatic playback</string>
<string name="set_autoplay_description">If enabled, videos will be played automatically</string>
<string name="set_fullscreen">Fullscreen</string>
<string name="set_fullscreen_description">Automatically open videos in fullscreen</string>
<string name="add_public_reply">Add a public reply</string>
<plurals name="number_of_replies">
<item quantity="one">%d reply</item>
<item quantity="other">%d replies</item>

View File

@ -146,7 +146,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
private VideoData.Video peertube;
private int mode;
private Map<String, List<PlaylistExist>> playlists;
private boolean playInMinimized;
private boolean playInMinimized, autoPlay, autoFullscreen;
private boolean onStopCalled;
private List<Caption> 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;
}
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();
}

View File

@ -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<String, String> languages = new LinkedHashMap<>(peertubeInformation.getLanguages());
List<CharSequence> entriesLanguages = new ArrayList<>();
List<CharSequence> valuesLanguages = new ArrayList<>();

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M21,11l0,-8l-8,0l3.29,3.29l-10,10l-3.29,-3.29l0,8l8,0l-3.29,-3.29l10,-10z"/>
</vector>

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M8,5v14l11,-7z"/>
</vector>

View File

@ -21,6 +21,18 @@
android:summary="@string/set_video_quality_description"
android:title="@string/set_quality_mode" />
<androidx.preference.SwitchPreference
android:icon="@drawable/ic_baseline_play_arrow_24"
android:key="@string/set_autoplay_choice"
android:summary="@string/set_autoplay_description"
android:title="@string/set_autoplay" />
<androidx.preference.SwitchPreference
android:icon="@drawable/ic_baseline_open_in_full_24"
android:key="@string/set_fullscreen_choice"
android:summary="@string/set_fullscreen_description"
android:title="@string/set_fullscreen" />
<androidx.preference.SeekBarPreference
android:icon="@drawable/ic_baseline_storage_24"
android:defaultValue="10"