From 08412d61089ebe5281392be311da2dfc5310f45b Mon Sep 17 00:00:00 2001 From: Avently <7953703+avently@users.noreply.github.com> Date: Tue, 14 Jul 2020 21:52:55 +0300 Subject: [PATCH] Mini player slide to botom fix, buttons size fix --- .../fragments/detail/VideoDetailFragment.java | 16 ++++++---- .../newpipe/player/VideoPlayerImpl.java | 32 +++++++++---------- .../activity_main_player.xml | 6 ++-- .../main/res/layout/activity_main_player.xml | 1 + 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 7586ca241..9cc4357d7 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -2245,14 +2245,16 @@ public class VideoDetailFragment private void setOverlayLook(final AppBarLayout appBar, final AppBarLayout.Behavior behavior, final float slideOffset) { - if (behavior != null) { - overlay.setAlpha(Math.min(MAX_OVERLAY_ALPHA, 1 - slideOffset)); - - // These numbers are not special. They just do a cool transition - behavior.setTopAndBottomOffset( - (int) (-thumbnailImageView.getHeight() * 2 * (1 - slideOffset) / 3)); - appBar.requestLayout(); + // SlideOffset < 0 when mini player is about to close via swipe. + // Stop animation in this case + if (behavior == null || slideOffset < 0) { + return; } + overlay.setAlpha(Math.min(MAX_OVERLAY_ALPHA, 1 - slideOffset)); + // These numbers are not special. They just do a cool transition + behavior.setTopAndBottomOffset( + (int) (-thumbnailImageView.getHeight() * 2 * (1 - slideOffset) / 3)); + appBar.requestLayout(); } private void setOverlayElementsClickable(final boolean enable) { diff --git a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java index 8aa7120d7..ec01ef11e 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java @@ -106,7 +106,7 @@ import java.util.List; import static android.content.Context.WINDOW_SERVICE; import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; -import static org.schabi.newpipe.player.BackgroundPlayer.ACTION_CLOSE; +import static org.schabi.newpipe.player.MainPlayer.ACTION_CLOSE; import static org.schabi.newpipe.player.MainPlayer.ACTION_FAST_FORWARD; import static org.schabi.newpipe.player.MainPlayer.ACTION_FAST_REWIND; import static org.schabi.newpipe.player.MainPlayer.ACTION_OPEN_CONTROLS; @@ -376,12 +376,7 @@ public class VideoPlayerImpl extends VideoPlayer moreOptionsButton.setImageDrawable(service.getResources().getDrawable( R.drawable.ic_expand_more_white_24dp)); shareButton.setVisibility(View.VISIBLE); - final boolean supportedByKore = playQueue != null - && playQueue.getItem() != null - && KoreUtil.isServiceSupportedByKore(playQueue.getItem().getServiceId()); - final boolean kodiEnabled = defaultPreferences.getBoolean( - service.getString(R.string.show_play_with_kodi_key), false); - playWithKodi.setVisibility(kodiEnabled && supportedByKore ? View.VISIBLE : View.GONE); + showHideKodiButton(); openInBrowser.setVisibility(View.VISIBLE); muteButton.setVisibility(View.VISIBLE); playerCloseButton.setVisibility(isFullscreen ? View.GONE : View.VISIBLE); @@ -418,11 +413,8 @@ public class VideoPlayerImpl extends VideoPlayer buttonsPadding, buttonsPadding, buttonsPadding, buttonsPadding); getPlaybackSpeedTextView().setPadding( buttonsPadding, buttonsPadding, buttonsPadding, buttonsPadding); - getQualityTextView().setPadding( - buttonsPadding, buttonsPadding, buttonsPadding, buttonsPadding); getCaptionTextView().setPadding( buttonsPadding, buttonsPadding, buttonsPadding, buttonsPadding); - getQualityTextView().setMinimumWidth(0); getPlaybackSpeedTextView().setMinimumWidth(0); } else if (videoPlayerSelected()) { final int buttonsMinWidth = service.getResources() @@ -440,7 +432,6 @@ public class VideoPlayerImpl extends VideoPlayer buttonsPadding, buttonsPadding, buttonsPadding, buttonsPadding); getPlaybackSpeedTextView().setPadding( buttonsPadding, buttonsPadding, buttonsPadding, buttonsPadding); - getQualityTextView().setMinimumWidth(buttonsMinWidth); getPlaybackSpeedTextView().setMinimumWidth(buttonsMinWidth); getCaptionTextView().setPadding( buttonsPadding, buttonsPadding, buttonsPadding, buttonsPadding); @@ -615,12 +606,7 @@ public class VideoPlayerImpl extends VideoPlayer protected void onMetadataChanged(@NonNull final MediaSourceTag tag) { super.onMetadataChanged(tag); - // show kodi button if it supports the current service and it is enabled in settings - final boolean showKodiButton = - KoreUtil.isServiceSupportedByKore(tag.getMetadata().getServiceId()) - && PreferenceManager.getDefaultSharedPreferences(context) - .getBoolean(context.getString(R.string.show_play_with_kodi_key), false); - playWithKodi.setVisibility(showKodiButton ? View.VISIBLE : View.GONE); + showHideKodiButton(); titleTextView.setText(tag.getMetadata().getName()); channelTextView.setText(tag.getMetadata().getUploaderName()); @@ -920,6 +906,18 @@ public class VideoPlayerImpl extends VideoPlayer getCurrentMetadata().getMetadata().getOriginalUrl()); } + private void showHideKodiButton() { + final boolean kodiEnabled = defaultPreferences.getBoolean( + service.getString(R.string.show_play_with_kodi_key), false); + // show kodi button if it supports the current service and it is enabled in settings + final boolean showKodiButton = playQueue != null && playQueue.getItem() != null + && KoreUtil.isServiceSupportedByKore(playQueue.getItem().getServiceId()) + && PreferenceManager.getDefaultSharedPreferences(context) + .getBoolean(context.getString(R.string.show_play_with_kodi_key), false); + playWithKodi.setVisibility(videoPlayerSelected() && kodiEnabled && showKodiButton + ? View.VISIBLE : View.GONE); + } + private static void showInstallKoreDialog(final Context context) { final AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setMessage(R.string.kore_not_found) diff --git a/app/src/main/res/layout-large-land/activity_main_player.xml b/app/src/main/res/layout-large-land/activity_main_player.xml index 1a4e6b4e4..26a2ebc8b 100644 --- a/app/src/main/res/layout-large-land/activity_main_player.xml +++ b/app/src/main/res/layout-large-land/activity_main_player.xml @@ -218,10 +218,10 @@