Merge pull request #4292 from tonytamsf/landscape-1

FIX:  In landscape mode, the album art overwhelms the playback screen #4009
This commit is contained in:
H. Lehmann 2020-07-19 16:53:47 +02:00 committed by GitHub
commit 84a8eaaee0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 90 additions and 37 deletions

View File

@ -1,16 +1,23 @@
package de.danoeh.antennapod.fragment;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.FitCenter;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
@ -60,6 +67,11 @@ public class CoverFragment extends Fragment {
return root;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
configureForOrientation(getResources().getConfiguration());
}
private void loadMediaInfo() {
if (disposable != null) {
disposable.dispose();
@ -71,13 +83,12 @@ public class CoverFragment extends Fragment {
} else {
emitter.onComplete();
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(media -> {
this.media = media;
displayMediaInfo(media);
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
}).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(media -> {
this.media = media;
displayMediaInfo(media);
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
}
private void displayMediaInfo(@NonNull Playable media) {
@ -159,6 +170,39 @@ public class CoverFragment extends Fragment {
}
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
configureForOrientation(newConfig);
}
public float convertDpToPixel(float dp) {
Context context = this.getActivity().getApplicationContext();
return dp * ((float) context.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}
private void configureForOrientation(Configuration newConfig) {
LinearLayout mainContainer = getView().findViewById(R.id.cover_fragment);
ViewGroup.LayoutParams params = imgvCover.getLayoutParams();
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
mainContainer.setOrientation(LinearLayout.VERTICAL);
if (newConfig.screenWidthDp > 0) {
params.width = (int) (convertDpToPixel(newConfig.screenWidthDp) * .80);
params.height = params.width;
imgvCover.setLayoutParams(params);
}
} else {
mainContainer.setOrientation(LinearLayout.HORIZONTAL);
if (newConfig.screenHeightDp > 0) {
params.height = (int) (convertDpToPixel(newConfig.screenHeightDp) * .40);
params.width = params.height;
imgvCover.setLayoutParams(params);
}
}
}
@Override
public void onDestroyView() {
super.onDestroyView();

View File

@ -1,49 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:squareImageView="http://schemas.android.com/apk/de.danoeh.antennapod"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:orientation="horizontal"
android:id="@+id/cover_fragment"
android:padding="8dp"
android:gravity="center">
<de.danoeh.antennapod.view.SquareImageView
android:id="@+id/imgvCover"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scaleType="fitCenter"
android:layout_marginLeft="32dp"
android:layout_marginRight="32dp"
android:transitionName="coverTransition"
tools:src="@android:drawable/sym_def_app_icon"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:layout_marginLeft="64dp"
android:layout_marginRight="64dp"
android:layout_weight="0"
android:foreground="?attr/selectableItemBackgroundBorderless"
android:importantForAccessibility="no"
squareImageView:direction="minimum" />
android:scaleType="fitCenter"
squareImageView:direction="height"
tools:src="@android:drawable/sym_def_app_icon" />
<TextView
android:id="@+id/txtvPodcastTitle"
<LinearLayout
android:id="@+id/cover_fragment_text_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center"
android:maxLines="2"
android:orientation="vertical"
android:layout_marginTop="16dp"
android:textColor="?android:attr/textColorSecondary"
android:textIsSelectable="true"
tools:text="Podcast" />
android:layout_marginBottom="8dp">
<TextView
android:id="@+id/txtvEpisodeTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center"
android:maxLines="2"
android:textColor="?android:attr/textColorPrimary"
android:textIsSelectable="true"
android:layout_marginBottom="8dp"
tools:text="Episode" />
<TextView
android:id="@+id/txtvPodcastTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center"
android:maxLines="2"
android:textColor="?android:attr/textColorSecondary"
android:textIsSelectable="true"
tools:text="Podcast" />
<TextView
android:id="@+id/txtvEpisodeTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center"
android:maxLines="2"
android:textColor="?android:attr/textColorPrimary"
android:textIsSelectable="true"
tools:text="Episode" />
</LinearLayout>
</LinearLayout>