diff options
author | H. Lehmann <ByteHamster@users.noreply.github.com> | 2020-07-19 16:53:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-19 16:53:47 +0200 |
commit | 84a8eaaee0bf110b371043a5f5187d7f601f4b5f (patch) | |
tree | 324e92fad936c21dcc03b0af5730dc595cb74f4e /app/src | |
parent | abece8a3407508dd7ec168ad3365b94a7db23ea7 (diff) | |
parent | e53db91ee38173be33fb2273070ec2f76d05763a (diff) | |
download | AntennaPod-84a8eaaee0bf110b371043a5f5187d7f601f4b5f.zip |
Merge pull request #4292 from tonytamsf/landscape-1
FIX: In landscape mode, the album art overwhelms the playback screen #4009
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java | 58 | ||||
-rw-r--r-- | app/src/main/res/layout/cover_fragment.xml | 69 |
2 files changed, 90 insertions, 37 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java index 7593188b7..4e8cfbf86 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java @@ -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) { @@ -160,6 +171,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(); diff --git a/app/src/main/res/layout/cover_fragment.xml b/app/src/main/res/layout/cover_fragment.xml index 28321e760..443f19835 100644 --- a/app/src/main/res/layout/cover_fragment.xml +++ b/app/src/main/res/layout/cover_fragment.xml @@ -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> |