From a9bed90d028bc93bfae49edd10e7ede71decd6a7 Mon Sep 17 00:00:00 2001 From: arkon <eugcheung94@gmail.com> Date: Tue, 22 Sep 2020 22:20:29 -0400 Subject: [PATCH] Move manga info summary more/less button toggle --- .../ui/manga/info/MangaInfoHeaderAdapter.kt | 57 +++----- .../res/drawable/manga_info_more_gradient.xml | 13 ++ app/src/main/res/layout/manga_info_header.xml | 126 ++++++++++-------- app/src/main/res/values/styles.xml | 17 +++ 4 files changed, 117 insertions(+), 96 deletions(-) create mode 100644 app/src/main/res/drawable/manga_info_more_gradient.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoHeaderAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoHeaderAdapter.kt index 88b1eeca25..0c3f82be06 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoHeaderAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoHeaderAdapter.kt @@ -1,7 +1,5 @@ package eu.kanade.tachiyomi.ui.manga.info -import android.content.Context -import android.text.TextUtils import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -302,21 +300,23 @@ class MangaInfoHeaderAdapter( controller::performSearch ) } else { - binding.mangaGenresTagsWrapper.isVisible = false + binding.mangaGenresTagsCompactChips.isVisible = false + binding.mangaGenresTagsFullChips.isVisible = false } // Handle showing more or less info merge( binding.mangaSummarySection.clicks(), binding.mangaSummaryText.clicks(), - binding.mangaInfoToggle.clicks() + binding.mangaInfoToggleMore.clicks(), + binding.mangaInfoToggleLess.clicks() ) - .onEach { toggleMangaInfo(view.context) } + .onEach { toggleMangaInfo() } .launchIn(scope) // Expand manga info if navigated from source listing if (initialLoad && fromSource) { - toggleMangaInfo(view.context) + toggleMangaInfo() initialLoad = false } } @@ -326,44 +326,21 @@ class MangaInfoHeaderAdapter( binding.mangaSummarySection.isVisible = visible } - private fun toggleMangaInfo(context: Context) { - val isExpanded = - binding.mangaInfoToggle.contentDescription == context.getString(R.string.manga_info_collapse) + private fun toggleMangaInfo() { + val isCurrentlyExpanded = binding.mangaSummaryText.maxLines != 2 - with(binding.mangaInfoToggle) { - contentDescription = if (isExpanded) { - context.getString(R.string.manga_info_expand) - } else { - context.getString(R.string.manga_info_collapse) - } + binding.mangaInfoToggleMoreScrim.isVisible = isCurrentlyExpanded + binding.mangaInfoToggleMore.isVisible = isCurrentlyExpanded + binding.mangaInfoToggleLess.isVisible = !isCurrentlyExpanded - setImageDrawable( - if (isExpanded) { - context.getDrawable(R.drawable.ic_baseline_expand_more_24dp) - } else { - context.getDrawable(R.drawable.ic_baseline_expand_less_24dp) - } - ) + binding.mangaSummaryText.maxLines = if (isCurrentlyExpanded) { + 2 + } else { + Int.MAX_VALUE } - with(binding.mangaSummaryText) { - maxLines = - if (isExpanded) { - 2 - } else { - Int.MAX_VALUE - } - - ellipsize = - if (isExpanded) { - TextUtils.TruncateAt.END - } else { - null - } - } - - binding.mangaGenresTagsCompact.isVisible = isExpanded - binding.mangaGenresTagsFullChips.isVisible = !isExpanded + binding.mangaGenresTagsCompact.isVisible = isCurrentlyExpanded + binding.mangaGenresTagsFullChips.isVisible = !isCurrentlyExpanded } /** diff --git a/app/src/main/res/drawable/manga_info_more_gradient.xml b/app/src/main/res/drawable/manga_info_more_gradient.xml new file mode 100644 index 0000000000..f3a077d041 --- /dev/null +++ b/app/src/main/res/drawable/manga_info_more_gradient.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8"?> +<shape xmlns:android="http://schemas.android.com/apk/res/android" + android:shape="rectangle"> + + <gradient + android:angle="180" + android:centerColor="#ff000000" + android:endColor="#00000000" + android:startColor="#ff000000" /> + + <corners android:radius="0dp" /> + +</shape> diff --git a/app/src/main/res/layout/manga_info_header.xml b/app/src/main/res/layout/manga_info_header.xml index 80ceb2b4e7..48adc6a867 100644 --- a/app/src/main/res/layout/manga_info_header.xml +++ b/app/src/main/res/layout/manga_info_header.xml @@ -38,7 +38,7 @@ android:paddingStart="16dp" android:paddingTop="64dp" android:paddingEnd="16dp" - android:paddingBottom="16dp" + android:paddingBottom="8dp" app:layout_constraintTop_toTopOf="parent"> <eu.kanade.tachiyomi.ui.manga.info.MangaCoverImageView @@ -178,34 +178,12 @@ </androidx.constraintlayout.widget.ConstraintLayout> - <LinearLayout + <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/manga_summary_section" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" - android:background="?attr/selectableItemBackground" - android:orientation="vertical"> - - <androidx.constraintlayout.widget.ConstraintLayout - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:paddingStart="16dp" - android:paddingEnd="16dp"> - - <ImageButton - android:id="@+id/manga_info_toggle" - android:layout_width="32dp" - android:layout_height="32dp" - android:layout_alignParentEnd="true" - android:background="?selectableItemBackgroundBorderless" - android:contentDescription="@string/manga_info_expand" - app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintTop_toTopOf="parent" - app:srcCompat="@drawable/ic_baseline_expand_more_24dp" - app:tint="?attr/colorOnPrimary" /> - - </androidx.constraintlayout.widget.ConstraintLayout> + android:background="?attr/selectableItemBackground"> <TextView android:id="@+id/manga_summary_text" @@ -215,49 +193,85 @@ android:layout_marginStart="16dp" android:layout_marginEnd="16dp" android:clickable="true" - android:ellipsize="end" android:focusable="true" android:maxLines="2" android:textIsSelectable="false" - tools:text="Summary" /> + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + tools:text="Collapsed summary content Collapsed summary content Collapsed summary content Collapsed summary content Collapsed summary content Collapsed summary content" /> - <FrameLayout - android:id="@+id/manga_genres_tags_wrapper" + <View + android:id="@+id/manga_info_toggle_more_scrim" + android:layout_width="20dp" + android:layout_height="0dp" + android:background="@drawable/manga_info_more_gradient" + android:backgroundTint="?android:attr/colorBackground" + app:layout_constraintBottom_toBottomOf="@+id/manga_summary_text" + app:layout_constraintEnd_toStartOf="@id/manga_info_toggle_more" + app:layout_constraintTop_toTopOf="@+id/manga_info_toggle_more" /> + + <com.google.android.material.button.MaterialButton + android:id="@+id/manga_info_toggle_more" + style="@style/Theme.Widget.Button.TextButton" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:paddingStart="8dp" + android:paddingEnd="16dp" + android:text="@string/manga_info_expand" + android:textAlignment="viewEnd" + app:layout_constraintBottom_toBottomOf="@+id/manga_summary_text" + app:layout_constraintEnd_toEndOf="parent" /> + + <com.google.android.material.button.MaterialButton + android:id="@+id/manga_info_toggle_less" + style="@style/Theme.Widget.Button.TextButton" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:paddingStart="8dp" + android:paddingEnd="16dp" + android:text="@string/manga_info_collapse" + android:textAlignment="viewEnd" + android:visibility="gone" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toBottomOf="@+id/manga_summary_text" /> + + <HorizontalScrollView + android:id="@+id/manga_genres_tags_compact" android:layout_width="match_parent" - android:layout_height="wrap_content"> + android:layout_height="wrap_content" + android:requiresFadingEdge="horizontal" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/manga_summary_text"> <com.google.android.material.chip.ChipGroup - android:id="@+id/manga_genres_tags_full_chips" - android:layout_width="match_parent" + android:id="@+id/manga_genres_tags_compact_chips" + android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginStart="16dp" - android:layout_marginEnd="16dp" + android:paddingStart="16dp" android:paddingTop="8dp" + android:paddingEnd="16dp" android:paddingBottom="8dp" - android:visibility="gone" - app:chipSpacingHorizontal="4dp" /> + app:chipSpacingHorizontal="4dp" + app:singleLine="true" /> - <HorizontalScrollView - android:id="@+id/manga_genres_tags_compact" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:requiresFadingEdge="horizontal"> + </HorizontalScrollView> - <com.google.android.material.chip.ChipGroup - android:id="@+id/manga_genres_tags_compact_chips" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:paddingStart="16dp" - android:paddingTop="8dp" - android:paddingEnd="16dp" - android:paddingBottom="8dp" - app:chipSpacingHorizontal="4dp" - app:singleLine="true" /> + <com.google.android.material.chip.ChipGroup + android:id="@+id/manga_genres_tags_full_chips" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginStart="16dp" + android:layout_marginEnd="16dp" + android:paddingTop="8dp" + android:paddingBottom="8dp" + android:visibility="gone" + app:chipSpacingHorizontal="4dp" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/manga_info_toggle_less" /> - </HorizontalScrollView> - - </FrameLayout> - - </LinearLayout> + </androidx.constraintlayout.widget.ConstraintLayout> </LinearLayout> diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 51874a7af8..95c642f035 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -265,6 +265,23 @@ <item name="backgroundTint">@color/outlined_button_bg</item> </style> + <style name="Theme.Widget.Button.TextButton" parent="Widget.MaterialComponents.Button.TextButton"> + <item name="android:letterSpacing">0.0</item> + <item name="android:textColor">?attr/colorAccent</item> + <item name="android:textAllCaps">false</item> + + <item name="android:minHeight">0dp</item> + <item name="android:minWidth">0dp</item> + <item name="android:paddingTop">0dp</item> + <item name="android:paddingBottom">0dp</item> + <item name="android:insetTop">0dp</item> + <item name="android:insetBottom">0dp</item> + + <item name="android:background">?android:attr/colorBackground</item> + <item name="backgroundTint">@null</item> + <item name="rippleColor">@null</item> + </style> + <!--=================--> <!--Widgets.TabLayout-->