From cbb310080eb468dc6789a7952f36cd2e1816e8b1 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Wed, 25 Mar 2020 17:49:25 +0100 Subject: Redesign ExternalPlayerFragment --- .../bottomsheet/ViewPagerBottomSheetBehavior.java | 4 +- .../fragment/ExternalPlayerFragment.java | 27 ++-- app/src/main/res/drawable/shadow.xml | 7 - .../main/res/layout/external_player_fragment.xml | 157 ++++++++++----------- core/src/main/res/values/dimens.xml | 2 +- 5 files changed, 97 insertions(+), 100 deletions(-) delete mode 100644 app/src/main/res/drawable/shadow.xml diff --git a/app/src/main/java/com/google/android/material/bottomsheet/ViewPagerBottomSheetBehavior.java b/app/src/main/java/com/google/android/material/bottomsheet/ViewPagerBottomSheetBehavior.java index 1e76b3bc1..1667006a5 100644 --- a/app/src/main/java/com/google/android/material/bottomsheet/ViewPagerBottomSheetBehavior.java +++ b/app/src/main/java/com/google/android/material/bottomsheet/ViewPagerBottomSheetBehavior.java @@ -34,7 +34,9 @@ public class ViewPagerBottomSheetBehavior extends BottomSheetBeh if (view instanceof ViewPager) { ViewPager viewPager = (ViewPager) view; View currentViewPagerChild = viewPager.getChildAt(viewPager.getCurrentItem()); - return findScrollingChild(currentViewPagerChild); + if (currentViewPagerChild != null) { + return findScrollingChild(currentViewPagerChild); + } } else if (view instanceof ViewGroup) { ViewGroup group = (ViewGroup) view; for (int i = 0, count = group.getChildCount(); i < count; i++) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java index 57193e08b..03b1d6f8f 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java @@ -40,7 +40,6 @@ import org.greenrobot.eventbus.ThreadMode; public class ExternalPlayerFragment extends Fragment { public static final String TAG = "ExternalPlayerFragment"; - private ViewGroup fragmentLayout; private ImageView imgvCover; private TextView txtvTitle; private ImageButton butPlay; @@ -56,16 +55,14 @@ public class ExternalPlayerFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View root = inflater.inflate(R.layout.external_player_fragment, - container, false); - fragmentLayout = root.findViewById(R.id.fragmentLayout); + View root = inflater.inflate(R.layout.external_player_fragment, container, false); imgvCover = root.findViewById(R.id.imgvCover); txtvTitle = root.findViewById(R.id.txtvTitle); butPlay = root.findViewById(R.id.butPlay); mFeedName = root.findViewById(R.id.txtvAuthor); mProgressBar = root.findViewById(R.id.episodeProgress); - fragmentLayout.setOnClickListener(v -> { + root.findViewById(R.id.fragmentLayout).setOnClickListener(v -> { Log.d(TAG, "layoutInfo was clicked"); if (controller != null && controller.getMedia() != null) { @@ -175,9 +172,7 @@ public class ExternalPlayerFragment extends Fragment { } private void playbackDone() { - if (fragmentLayout != null) { - fragmentLayout.setVisibility(View.GONE); - } + clearUi(); if (controller != null) { controller.release(); } @@ -214,10 +209,22 @@ public class ExternalPlayerFragment extends Fragment { .observeOn(AndroidSchedulers.mainThread()) .subscribe(media -> updateUi((Playable) media), error -> Log.e(TAG, Log.getStackTraceString(error)), - () -> fragmentLayout.setVisibility(View.GONE)); + this::clearUi); return true; } + private void clearUi() { + if (txtvTitle == null || mFeedName == null || mProgressBar == null || butPlay == null) { + return; + } + txtvTitle.setText(R.string.no_media_playing_label); + mFeedName.setText(""); + butPlay.setVisibility(View.GONE); + mProgressBar.setProgress(0); + Glide.with(getActivity()).clear(imgvCover); + ((MainActivity) getActivity()).getBottomSheet().setLocked(true); + } + private void updateUi(Playable media) { if (media != null) { txtvTitle.setText(media.getEpisodeTitle()); @@ -233,8 +240,6 @@ public class ExternalPlayerFragment extends Fragment { .fitCenter() .dontAnimate()) .into(imgvCover); - - fragmentLayout.setVisibility(View.VISIBLE); if (controller != null && controller.isPlayingVideoLocally()) { butPlay.setVisibility(View.GONE); ((MainActivity) getActivity()).getBottomSheet().setLocked(true); diff --git a/app/src/main/res/drawable/shadow.xml b/app/src/main/res/drawable/shadow.xml deleted file mode 100644 index fc5110e0b..000000000 --- a/app/src/main/res/drawable/shadow.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - diff --git a/app/src/main/res/layout/external_player_fragment.xml b/app/src/main/res/layout/external_player_fragment.xml index 3e2efe47e..651953b0e 100644 --- a/app/src/main/res/layout/external_player_fragment.xml +++ b/app/src/main/res/layout/external_player_fragment.xml @@ -1,87 +1,84 @@ - - - + android:background="?attr/selectableItemBackground" + android:orientation="vertical"> - + - + + + - - + + + + + + + + + + + + + - + diff --git a/core/src/main/res/values/dimens.xml b/core/src/main/res/values/dimens.xml index 5083eb749..cfb272ad9 100644 --- a/core/src/main/res/values/dimens.xml +++ b/core/src/main/res/values/dimens.xml @@ -3,7 +3,7 @@ 0dp 70dp - 56dp + 64dp 20dp 12sp 14sp -- cgit v1.2.3