Redesign ExternalPlayerFragment

This commit is contained in:
ByteHamster 2020-03-25 17:49:25 +01:00
parent 0a7d054aad
commit cbb310080e
5 changed files with 99 additions and 102 deletions

View File

@ -34,7 +34,9 @@ public class ViewPagerBottomSheetBehavior<V extends View> extends BottomSheetBeh
if (view instanceof ViewPager) { if (view instanceof ViewPager) {
ViewPager viewPager = (ViewPager) view; ViewPager viewPager = (ViewPager) view;
View currentViewPagerChild = viewPager.getChildAt(viewPager.getCurrentItem()); View currentViewPagerChild = viewPager.getChildAt(viewPager.getCurrentItem());
if (currentViewPagerChild != null) {
return findScrollingChild(currentViewPagerChild); return findScrollingChild(currentViewPagerChild);
}
} else if (view instanceof ViewGroup) { } else if (view instanceof ViewGroup) {
ViewGroup group = (ViewGroup) view; ViewGroup group = (ViewGroup) view;
for (int i = 0, count = group.getChildCount(); i < count; i++) { for (int i = 0, count = group.getChildCount(); i < count; i++) {

View File

@ -40,7 +40,6 @@ import org.greenrobot.eventbus.ThreadMode;
public class ExternalPlayerFragment extends Fragment { public class ExternalPlayerFragment extends Fragment {
public static final String TAG = "ExternalPlayerFragment"; public static final String TAG = "ExternalPlayerFragment";
private ViewGroup fragmentLayout;
private ImageView imgvCover; private ImageView imgvCover;
private TextView txtvTitle; private TextView txtvTitle;
private ImageButton butPlay; private ImageButton butPlay;
@ -56,16 +55,14 @@ public class ExternalPlayerFragment extends Fragment {
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.external_player_fragment, View root = inflater.inflate(R.layout.external_player_fragment, container, false);
container, false);
fragmentLayout = root.findViewById(R.id.fragmentLayout);
imgvCover = root.findViewById(R.id.imgvCover); imgvCover = root.findViewById(R.id.imgvCover);
txtvTitle = root.findViewById(R.id.txtvTitle); txtvTitle = root.findViewById(R.id.txtvTitle);
butPlay = root.findViewById(R.id.butPlay); butPlay = root.findViewById(R.id.butPlay);
mFeedName = root.findViewById(R.id.txtvAuthor); mFeedName = root.findViewById(R.id.txtvAuthor);
mProgressBar = root.findViewById(R.id.episodeProgress); mProgressBar = root.findViewById(R.id.episodeProgress);
fragmentLayout.setOnClickListener(v -> { root.findViewById(R.id.fragmentLayout).setOnClickListener(v -> {
Log.d(TAG, "layoutInfo was clicked"); Log.d(TAG, "layoutInfo was clicked");
if (controller != null && controller.getMedia() != null) { if (controller != null && controller.getMedia() != null) {
@ -175,9 +172,7 @@ public class ExternalPlayerFragment extends Fragment {
} }
private void playbackDone() { private void playbackDone() {
if (fragmentLayout != null) { clearUi();
fragmentLayout.setVisibility(View.GONE);
}
if (controller != null) { if (controller != null) {
controller.release(); controller.release();
} }
@ -214,10 +209,22 @@ public class ExternalPlayerFragment extends Fragment {
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(media -> updateUi((Playable) media), .subscribe(media -> updateUi((Playable) media),
error -> Log.e(TAG, Log.getStackTraceString(error)), error -> Log.e(TAG, Log.getStackTraceString(error)),
() -> fragmentLayout.setVisibility(View.GONE)); this::clearUi);
return true; 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) { private void updateUi(Playable media) {
if (media != null) { if (media != null) {
txtvTitle.setText(media.getEpisodeTitle()); txtvTitle.setText(media.getEpisodeTitle());
@ -233,8 +240,6 @@ public class ExternalPlayerFragment extends Fragment {
.fitCenter() .fitCenter()
.dontAnimate()) .dontAnimate())
.into(imgvCover); .into(imgvCover);
fragmentLayout.setVisibility(View.VISIBLE);
if (controller != null && controller.isPlayingVideoLocally()) { if (controller != null && controller.isPlayingVideoLocally()) {
butPlay.setVisibility(View.GONE); butPlay.setVisibility(View.GONE);
((MainActivity) getActivity()).getBottomSheet().setLocked(true); ((MainActivity) getActivity()).getBottomSheet().setLocked(true);

View File

@ -1,7 +0,0 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="@android:color/transparent"
android:endColor="#40000000"
android:angle="90" />
</shape>

View File

@ -1,66 +1,48 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/fragmentLayout" android:id="@+id/fragmentLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/external_player_height" android:layout_height="@dimen/external_player_height"
android:visibility="gone" android:background="?attr/selectableItemBackground"
android:background="?attr/selectableItemBackground"> android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?android:attr/dividerHorizontal" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center_vertical"
android:layout_weight="1">
<ImageView <ImageView
android:id="@+id/imgvCover" android:id="@+id/imgvCover"
android:contentDescription="@string/cover_label" android:contentDescription="@string/cover_label"
android:layout_width="@dimen/external_player_height" android:layout_width="wrap_content"
android:layout_height="@dimen/external_player_height" android:layout_height="match_parent"
android:adjustViewBounds="true" android:adjustViewBounds="true"
android:cropToPadding="true" android:cropToPadding="true"
android:scaleType="centerCrop" android:scaleType="centerCrop"
tools:src="@drawable/ic_drag_vertical_white_48dp" tools:src="@tools:sample/avatars"/>
tools:background="@android:color/holo_green_dark"
android:transitionName="coverTransition"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<ProgressBar
android:id="@+id/episodeProgress"
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_toRightOf="@id/imgvCover"
android:layout_toEndOf="@id/imgvCover"
android:layout_alignParentTop="true"
style="?attr/progressBarTheme"
android:indeterminate="false"
tools:progress="100"/>
<ImageButton <LinearLayout
android:id="@+id/butPlay" android:layout_width="0dp"
android:layout_width="52dp" android:layout_height="wrap_content"
android:layout_height="52dp" android:layout_weight="1"
android:layout_alignParentRight="true" android:orientation="vertical"
android:layout_alignParentEnd="true" android:layout_marginLeft="16dp"
android:layout_below="@id/episodeProgress" android:layout_marginStart="16dp">
android:layout_centerVertical="true"
android:contentDescription="@string/pause_label"
android:background="?attr/selectableItemBackground"
app:srcCompat="?attr/av_play"
android:scaleType="fitCenter"
android:padding="8dp"
tools:src="@drawable/ic_play_arrow_white_36dp"/>
<TextView <TextView
android:id="@+id/txtvTitle" android:id="@+id/txtvTitle"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="26dp"
android:layout_toRightOf="@id/imgvCover"
android:layout_toEndOf="@id/imgvCover"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_toLeftOf="@id/butPlay"
android:layout_toStartOf="@id/butPlay"
style="@style/Base.TextAppearance.AppCompat.Body1" style="@style/Base.TextAppearance.AppCompat.Body1"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"
@ -70,18 +52,33 @@
android:id="@+id/txtvAuthor" android:id="@+id/txtvAuthor"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/episodeProgress"
android:layout_marginTop="26dp"
android:layout_toRightOf="@id/imgvCover"
android:layout_toEndOf="@id/imgvCover"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_toLeftOf="@id/butPlay"
android:layout_toStartOf="@id/butPlay"
style="@style/TextAppearance.AppCompat.Body1" style="@style/TextAppearance.AppCompat.Body1"
android:textColor="?android:attr/textColorSecondary" android:textColor="?android:attr/textColorSecondary"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"
tools:text="Episode author that is too long and will cause the text to wrap"/> tools:text="Episode author that is too long and will cause the text to wrap"/>
</LinearLayout>
</RelativeLayout>
<ImageButton
android:id="@+id/butPlay"
android:layout_width="52dp"
android:layout_height="match_parent"
android:contentDescription="@string/pause_label"
android:background="?attr/selectableItemBackground"
app:srcCompat="?attr/av_play"
android:scaleType="fitCenter"
android:padding="8dp"
tools:src="@drawable/ic_play_arrow_white_36dp"/>
</LinearLayout>
<ProgressBar
android:id="@+id/episodeProgress"
android:layout_width="match_parent"
android:layout_height="4dp"
style="?attr/progressBarTheme"
android:indeterminate="false"
tools:progress="100"/>
</LinearLayout>

View File

@ -3,7 +3,7 @@
<dimen name="widget_margin">0dp</dimen> <dimen name="widget_margin">0dp</dimen>
<dimen name="thumbnail_length">70dp</dimen> <dimen name="thumbnail_length">70dp</dimen>
<dimen name="external_player_height">56dp</dimen> <dimen name="external_player_height">64dp</dimen>
<dimen name="enc_icons_size">20dp</dimen> <dimen name="enc_icons_size">20dp</dimen>
<dimen name="text_size_micro">12sp</dimen> <dimen name="text_size_micro">12sp</dimen>
<dimen name="text_size_small">14sp</dimen> <dimen name="text_size_small">14sp</dimen>