Optimizations and fixes of rare situations

- popup after orientation change had incorrect allowed bounds for swiping
- popup could cause a crash after many quick switches to main player and back
- better method of setting fullscreen/non-fullscreen layout using thumbnail view. Also fixed thumbnail height in fullscreen layout
- global settings observer didn't work when a user closed a service manually via notification because it checked for service existing
- app will now exits from fullscreen mode when the user switches players
- playQueuePanel has visibility "gone" by default (not "invisible") because "invisible" can cause problems
This commit is contained in:
Avently 2019-12-31 05:07:07 +03:00
parent c45514b989
commit fc9b63298c
5 changed files with 22 additions and 21 deletions

View file

@ -1040,6 +1040,9 @@ public class VideoDetailFragment
boolean useExternalAudioPlayer = PreferenceManager.getDefaultSharedPreferences(activity)
.getBoolean(activity.getString(R.string.use_external_audio_player_key), false);
// If a user watched video inside fullscreen mode and than chose another player return to non-fullscreen mode
if (player != null && player.isInFullscreen()) player.toggleFullscreen();
if (!useExternalAudioPlayer && android.os.Build.VERSION.SDK_INT >= 16) {
openNormalBackgroundPlayer(append);
} else {
@ -1056,6 +1059,9 @@ public class VideoDetailFragment
// See UI changes while remote playQueue changes
if (!bounded) startService(false);
// If a user watched video inside fullscreen mode and than chose another player return to non-fullscreen mode
if (player != null && player.isInFullscreen()) player.toggleFullscreen();
PlayQueue queue = setupPlayQueueForIntent(append);
if (append) {
NavigationHelper.enqueueOnPopupPlayer(activity, queue, false);
@ -1181,17 +1187,7 @@ public class VideoDetailFragment
// Check if viewHolder already contains a child
if (player.getRootView() != viewHolder) removeVideoPlayerView();
final int newHeight;
if (player.isInFullscreen())
newHeight = activity.getWindow().getDecorView().getHeight();
else
newHeight = FrameLayout.LayoutParams.MATCH_PARENT;
if (viewHolder.getLayoutParams().height != newHeight) {
viewHolder.getLayoutParams().height = newHeight;
viewHolder.requestLayout();
}
setHeightThumbnail();
// Prevent from re-adding a view multiple times
if (player.getRootView().getParent() == null) viewHolder.addView(player.getRootView());
@ -1242,9 +1238,15 @@ public class VideoDetailFragment
private void setHeightThumbnail() {
final DisplayMetrics metrics = getResources().getDisplayMetrics();
boolean isPortrait = metrics.heightPixels > metrics.widthPixels;
int height = isPortrait
int height;
if (player != null && player.isInFullscreen())
height = activity.getWindow().getDecorView().getHeight();
else
height = isPortrait
? (int) (metrics.widthPixels / (16.0f / 9.0f))
: (int) (metrics.heightPixels / 2f);
: (int) (metrics.heightPixels / 2f);;
thumbnailImageView.setLayoutParams(
new FrameLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, height));
thumbnailImageView.setMinimumHeight(height);
@ -1334,8 +1336,6 @@ public class VideoDetailFragment
@Override
public void onSettingsChanged() {
if (player == null) return;
if(!globalScreenOrientationLocked())
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
}

View file

@ -1329,7 +1329,7 @@ public class VideoPlayerImpl extends VideoPlayer
public void updatePopupSize(int width, int height) {
if (DEBUG) Log.d(TAG, "updatePopupSize() called with: width = [" + width + "], height = [" + height + "]");
if (popupLayoutParams == null || windowManager == null || !popupPlayerSelected() || getRootView().getParent() == null)
if (popupLayoutParams == null || windowManager == null || getParentActivity() != null || getRootView().getParent() == null)
return;
width = (int) (width > maximumWidth ? maximumWidth : width < minimumWidth ? minimumWidth : width);
@ -1347,7 +1347,7 @@ public class VideoPlayerImpl extends VideoPlayer
}
private void updateWindowFlags(final int flags) {
if (popupLayoutParams == null || windowManager == null || !popupPlayerSelected() || getRootView().getParent() == null)
if (popupLayoutParams == null || windowManager == null || getParentActivity() != null || getRootView().getParent() == null)
return;
popupLayoutParams.flags = flags;

View file

@ -299,7 +299,8 @@ public class PlayerGestureListener extends GestureDetector.SimpleOnGestureListen
private boolean onDownInPopup(MotionEvent e) {
// Fix popup position when the user touch it, it may have the wrong one
// because the soft input is visible (the draggable area is currently resized).
playerImpl.checkPopupPositionBounds(playerImpl.getCloseOverlayView().getWidth(), playerImpl.getCloseOverlayView().getHeight());
playerImpl.updateScreenSize();
playerImpl.checkPopupPositionBounds();
initialPopupX = playerImpl.getPopupLayoutParams().x;
initialPopupY = playerImpl.getPopupLayoutParams().y;

View file

@ -53,7 +53,7 @@
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_height="match_parent"
android:visibility="invisible"
android:visibility="gone"
android:background="?attr/queue_background_color"
tools:visibility="visible">

View file

@ -51,7 +51,7 @@
android:id="@+id/playQueuePanel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible"
android:visibility="gone"
android:background="?attr/queue_background_color"
tools:visibility="visible">