some fixes

This commit is contained in:
Thomas 2020-09-19 16:50:20 +02:00
parent f7f85a9dbb
commit 4d6cb47e6c
2 changed files with 78 additions and 34 deletions

View File

@ -40,7 +40,7 @@
android:name=".PeertubeActivity" android:name=".PeertubeActivity"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation" android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
android:label="@string/app_name" android:label="@string/app_name"
android:resizeableActivity="true" android:launchMode="singleTask"
android:supportsPictureInPicture="true" android:supportsPictureInPicture="true"
tools:targetApi="n" /> tools:targetApi="n" />
<activity <activity

View File

@ -148,13 +148,8 @@ public class PeertubeActivity extends AppCompatActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
fullscreen = FullScreenMediaController.fullscreen.OFF;
fullScreenMode = false;
playlistForVideo = new ArrayList<>();
setContentView(R.layout.activity_peertube); setContentView(R.layout.activity_peertube);
loader = findViewById(R.id.loader);
peertube_view_count = findViewById(R.id.peertube_view_count); peertube_view_count = findViewById(R.id.peertube_view_count);
peertube_bookmark = findViewById(R.id.peertube_bookmark); peertube_bookmark = findViewById(R.id.peertube_bookmark);
peertube_like_count = findViewById(R.id.peertube_like_count); peertube_like_count = findViewById(R.id.peertube_like_count);
@ -164,22 +159,23 @@ public class PeertubeActivity extends AppCompatActivity {
peertube_description = findViewById(R.id.peertube_description); peertube_description = findViewById(R.id.peertube_description);
peertube_title = findViewById(R.id.peertube_title); peertube_title = findViewById(R.id.peertube_title);
peertube_information_container = findViewById(R.id.peertube_information_container); peertube_information_container = findViewById(R.id.peertube_information_container);
CustomWebview webview_video = findViewById(R.id.webview_video);
playerView = findViewById(R.id.media_video);
write_comment_container = findViewById(R.id.write_comment_container);
ImageView my_pp = findViewById(R.id.my_pp);
add_comment_read = findViewById(R.id.add_comment_read); add_comment_read = findViewById(R.id.add_comment_read);
add_comment_write = findViewById(R.id.add_comment_write); add_comment_write = findViewById(R.id.add_comment_write);
peertube_playlist = findViewById(R.id.peertube_playlist); peertube_playlist = findViewById(R.id.peertube_playlist);
send = findViewById(R.id.send); send = findViewById(R.id.send);
CustomWebview webview_video = findViewById(R.id.webview_video);
playerView = findViewById(R.id.media_video);
write_comment_container = findViewById(R.id.write_comment_container);
loader = findViewById(R.id.loader);
ImageView my_pp = findViewById(R.id.my_pp);
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = Helper.getLiveInstance(PeertubeActivity.this);
Account account = new AccountDAO(PeertubeActivity.this, db).getUniqAccount(userId, instance);
Helper.loadGiF(PeertubeActivity.this, account, my_pp);
playInMinimized = sharedpreferences.getBoolean(getString(R.string.set_video_minimize_choice), true);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N
&& !getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) {
playInMinimized = false;
}
peertube_playlist.setVisibility(View.VISIBLE);
peertube_bookmark.setVisibility(View.GONE);
if (Helper.isTablet(PeertubeActivity.this)) { if (Helper.isTablet(PeertubeActivity.this)) {
RelativeLayout video_container = findViewById(R.id.video_container); RelativeLayout video_container = findViewById(R.id.video_container);
@ -191,28 +187,33 @@ public class PeertubeActivity extends AppCompatActivity {
video_container.setLayoutParams(param); video_container.setLayoutParams(param);
} }
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); if (getSupportActionBar() != null)
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
String instance = Helper.getLiveInstance(PeertubeActivity.this);
Account account = new AccountDAO(PeertubeActivity.this, db).getUniqAccount(userId, instance); mode = sharedpreferences.getInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_NORMAL);
Helper.loadGiF(PeertubeActivity.this, account, my_pp);
playlistForVideo = new ArrayList<>();
playlistsViewModel = new ViewModelProvider(PeertubeActivity.this).get(PlaylistsVM.class);
if (Helper.isLoggedIn(PeertubeActivity.this)) {
playlistsViewModel.manage(GET_PLAYLIST, null, null, null).observe(PeertubeActivity.this, apiResponse -> manageVIewPlaylists(GET_PLAYLIST, apiResponse));
}
Bundle b = getIntent().getExtras(); Bundle b = getIntent().getExtras();
if (b != null) { if (b != null) {
peertubeInstance = b.getString("peertube_instance", Helper.getLiveInstance(PeertubeActivity.this)); peertubeInstance = b.getString("peertube_instance", Helper.getLiveInstance(PeertubeActivity.this));
videoId = b.getString("video_id", null); videoId = b.getString("video_id", null);
} }
if (getSupportActionBar() != null) playInMinimized = sharedpreferences.getBoolean(getString(R.string.set_video_minimize_choice), true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N
&& !getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) {
playInMinimized = false;
}
mode = sharedpreferences.getInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_NORMAL);
if (mode != Helper.VIDEO_MODE_WEBVIEW && mode != Helper.VIDEO_MODE_NORMAL) if (mode != Helper.VIDEO_MODE_WEBVIEW && mode != Helper.VIDEO_MODE_NORMAL)
mode = Helper.VIDEO_MODE_NORMAL; mode = Helper.VIDEO_MODE_NORMAL;
if (mode == Helper.VIDEO_MODE_WEBVIEW) { if (mode == Helper.VIDEO_MODE_WEBVIEW) {
webview_video.setVisibility(View.VISIBLE); webview_video.setVisibility(View.VISIBLE);
playerView.setVisibility(View.GONE); playerView.setVisibility(View.GONE);
webview_video = Helper.initializeWebview(PeertubeActivity.this, R.id.webview_video, null); webview_video = Helper.initializeWebview(PeertubeActivity.this, R.id.webview_video, null);
FrameLayout webview_container = findViewById(R.id.main_media_frame); FrameLayout webview_container = findViewById(R.id.main_media_frame);
final ViewGroup videoLayout = findViewById(R.id.videoLayout); final ViewGroup videoLayout = findViewById(R.id.videoLayout);
@ -251,17 +252,43 @@ public class PeertubeActivity extends AppCompatActivity {
loader.setVisibility(View.VISIBLE); loader.setVisibility(View.VISIBLE);
} }
if (mode != Helper.VIDEO_MODE_WEBVIEW) { if (mode != Helper.VIDEO_MODE_WEBVIEW) {
playerView.setControllerShowTimeoutMs(1000); playerView.setControllerShowTimeoutMs(1000);
playerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT); playerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT);
initFullscreenDialog(); initFullscreenDialog();
initFullscreenButton(); initFullscreenButton();
} }
playlistsViewModel = new ViewModelProvider(PeertubeActivity.this).get(PlaylistsVM.class); playVideo();
if (Helper.isLoggedIn(PeertubeActivity.this)) { }
playlistsViewModel.manage(GET_PLAYLIST, null, null, null).observe(PeertubeActivity.this, apiResponse -> manageVIewPlaylists(GET_PLAYLIST, apiResponse));
@Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Bundle b = intent.getExtras();
if (b != null) {
peertubeInstance = b.getString("peertube_instance", Helper.getLiveInstance(PeertubeActivity.this));
videoId = b.getString("video_id", null);
playVideo();
} }
}
private void playVideo() {
if (player != null) {
player.setPlayWhenReady(false);
player.release();
player = ExoPlayerFactory.newSimpleInstance(PeertubeActivity.this);
playerView.setPlayer(player);
loader.setVisibility(View.GONE);
player.setPlayWhenReady(true);
}
fullscreen = FullScreenMediaController.fullscreen.OFF;
setFullscreen(FullScreenMediaController.fullscreen.OFF);
fullScreenMode = false;
peertube_playlist.setVisibility(View.VISIBLE);
peertube_bookmark.setVisibility(View.GONE);
FeedsVM feedsViewModel = new ViewModelProvider(PeertubeActivity.this).get(FeedsVM.class); FeedsVM feedsViewModel = new ViewModelProvider(PeertubeActivity.this).get(FeedsVM.class);
feedsViewModel.getVideo(peertubeInstance, videoId).observe(PeertubeActivity.this, this::manageVIewVideo); feedsViewModel.getVideo(peertubeInstance, videoId).observe(PeertubeActivity.this, this::manageVIewVideo);
@ -380,6 +407,7 @@ public class PeertubeActivity extends AppCompatActivity {
return; return;
} }
peertube = apiResponse.getPeertubes().get(0); peertube = apiResponse.getPeertubes().get(0);
//TODO: currently streaming service gives the wrong values for duration //TODO: currently streaming service gives the wrong values for duration
playlistsViewModel.manage(GET_PLAYLIST_FOR_VIDEO, null, peertube.getId(), null).observe(PeertubeActivity.this, apiResponse2 -> manageVIewPlaylists(GET_PLAYLIST_FOR_VIDEO, apiResponse2)); playlistsViewModel.manage(GET_PLAYLIST_FOR_VIDEO, null, peertube.getId(), null).observe(PeertubeActivity.this, apiResponse2 -> manageVIewPlaylists(GET_PLAYLIST_FOR_VIDEO, apiResponse2));
@ -461,7 +489,7 @@ public class PeertubeActivity extends AppCompatActivity {
item1.setTitle("" + playlist.getDisplayName()); item1.setTitle("" + playlist.getDisplayName());
playlistsViewModel.manage(PlaylistsVM.action.ADD_VIDEOS, playlist, peertube.getId(), null).observe(PeertubeActivity.this, apiResponse3 -> manageVIewPlaylists(PlaylistsVM.action.ADD_VIDEOS, apiResponse3)); playlistsViewModel.manage(PlaylistsVM.action.ADD_VIDEOS, playlist, peertube.getId(), null).observe(PeertubeActivity.this, apiResponse3 -> manageVIewPlaylists(PlaylistsVM.action.ADD_VIDEOS, apiResponse3));
PlaylistElement playlistElement = new PlaylistElement(); PlaylistElement playlistElement = new PlaylistElement();
playlistElement.setPlaylistElementId(finalElementId); playlistElement.setPlaylistElementId(null);
playlistElement.setPlaylistId(playlist.getId()); playlistElement.setPlaylistId(playlist.getId());
playlistForVideo.add(playlistElement); playlistForVideo.add(playlistElement);
} }
@ -700,11 +728,26 @@ public class PeertubeActivity extends AppCompatActivity {
@RequiresApi(api = Build.VERSION_CODES.N) @RequiresApi(api = Build.VERSION_CODES.N)
@Override @Override
public void onUserLeaveHint() { public void onUserLeaveHint() {
if (playInMinimized) { enterVideoMode();
}
private void enterVideoMode() {
if (playInMinimized && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
enterPictureInPictureMode(); enterPictureInPictureMode();
} }
} }
@Override
public void onBackPressed() {
if (playInMinimized) {
enterVideoMode();
} else {
super.onBackPressed();
}
}
@Override @Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) { public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) {
if (isInPictureInPictureMode) { if (isInPictureInPictureMode) {
@ -778,6 +821,7 @@ public class PeertubeActivity extends AppCompatActivity {
builderSingle.show(); builderSingle.show();
} }
@SuppressWarnings({"unused", "RedundantSuppression"})
public void manageVIewPostActions(PeertubeAPI.StatusAction statusAction, APIResponse apiResponse) { public void manageVIewPostActions(PeertubeAPI.StatusAction statusAction, APIResponse apiResponse) {