Move manga info summary more/less button toggle

This commit is contained in:
arkon 2020-09-22 22:20:29 -04:00
parent 01ad405dd2
commit a9bed90d02
4 changed files with 117 additions and 96 deletions

View File

@ -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
}
/**

View File

@ -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>

View File

@ -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>

View File

@ -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-->