More manga info header tweaks

This commit is contained in:
arkon 2020-06-20 11:41:20 -04:00
parent ce22b2c29a
commit 52e846f3b6
5 changed files with 218 additions and 161 deletions

View File

@ -515,6 +515,9 @@ class MangaInfoChaptersController(private val fromSource: Boolean = false) :
fetchChaptersFromSource() fetchChaptersFromSource()
} }
val header = headerAdapter ?: return
header.setNumChapters(chapters.size)
val adapter = chaptersAdapter ?: return val adapter = chaptersAdapter ?: return
adapter.updateDataSet(chapters) adapter.updateDataSet(chapters)

View File

@ -41,6 +41,7 @@ class MangaInfoHeaderAdapter(
private var manga: Manga? = null private var manga: Manga? = null
private var source: Source? = null private var source: Source? = null
private var numChapters: Int? = null
private val scope = CoroutineScope(Job() + Dispatchers.Main) private val scope = CoroutineScope(Job() + Dispatchers.Main)
private lateinit var binding: MangaInfoHeaderBinding private lateinit var binding: MangaInfoHeaderBinding
@ -71,6 +72,12 @@ class MangaInfoHeaderAdapter(
notifyDataSetChanged() notifyDataSetChanged()
} }
fun setNumChapters(numChapters: Int) {
this.numChapters = numChapters
notifyDataSetChanged()
}
inner class HeaderViewHolder(private val view: View) : RecyclerView.ViewHolder(view) { inner class HeaderViewHolder(private val view: View) : RecyclerView.ViewHolder(view) {
fun bind() { fun bind() {
if (manga == null) { if (manga == null) {
@ -155,6 +162,7 @@ class MangaInfoHeaderAdapter(
.launchIn(scope) .launchIn(scope)
setMangaInfo(manga!!, source) setMangaInfo(manga!!, source)
setChapterInfo()
} }
/** /**
@ -316,5 +324,14 @@ class MangaInfoHeaderAdapter(
isChecked = isFavorite isChecked = isFavorite
} }
} }
private fun setChapterInfo() {
// Chapters heading
binding.chaptersLabel.text = if (numChapters == null) {
view.context.getString(R.string.chapters)
} else {
view.context.resources.getQuantityString(R.plurals.manga_num_chapters, numChapters!!, numChapters)
}
}
} }
} }

View File

@ -1,11 +1,16 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".ui.browse.source.browse.BrowseSourceController"> tools:context=".ui.browse.source.browse.BrowseSourceController">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView <ImageView
android:id="@+id/manga_cover" android:id="@+id/manga_cover"
android:layout_width="0dp" android:layout_width="0dp"
@ -13,27 +18,20 @@
android:layout_margin="16dp" android:layout_margin="16dp"
android:background="@drawable/rounded_rectangle" android:background="@drawable/rounded_rectangle"
android:contentDescription="@string/description_cover" android:contentDescription="@string/description_cover"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="h,3:2" app:layout_constraintDimensionRatio="h,3:2"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" app:layout_constraintWidth_max="250dp"
tools:src="@mipmap/ic_launcher" /> tools:src="@mipmap/ic_launcher" />
<androidx.core.widget.NestedScrollView <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/info_scrollview"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent" android:padding="16dp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/manga_cover" app:layout_constraintStart_toEndOf="@+id/manga_cover"
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<TextView <TextView
android:id="@+id/manga_full_title" android:id="@+id/manga_full_title"
style="@style/TextAppearance.Medium.Title" style="@style/TextAppearance.Medium.Title"
@ -85,16 +83,19 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/manga_status" /> app:layout_constraintTop_toBottomOf="@+id/manga_status" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout <LinearLayout
android:id="@+id/actions_bar" android:id="@+id/actions_bar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingStart="16dp"
android:paddingTop="8dp" android:paddingTop="8dp"
android:paddingBottom="8dp" android:paddingEnd="16dp"
app:layout_constraintEnd_toEndOf="parent" android:paddingBottom="8dp">
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/manga_source">
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/btn_favorite" android:id="@+id/btn_favorite"
@ -144,27 +145,24 @@
style="@style/TextAppearance.Regular.SubHeading" style="@style/TextAppearance.Regular.SubHeading"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="8dp" android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:text="@string/manga_info_about_label" android:text="@string/manga_info_about_label"
android:textIsSelectable="false" android:textIsSelectable="false" />
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/actions_bar" />
<TextView <TextView
android:id="@+id/manga_summary" android:id="@+id/manga_summary"
style="@style/TextAppearance.Regular.Body1.Secondary" style="@style/TextAppearance.Regular.Body1.Secondary"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:clickable="true" android:clickable="true"
android:ellipsize="end" android:ellipsize="end"
android:focusable="true" android:focusable="true"
android:maxLines="3" android:maxLines="3"
android:textIsSelectable="false" android:textIsSelectable="false"
app:layout_constraintBottom_toTopOf="@id/manga_genres_tags_wrapper"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/manga_summary_label"
tools:text="Summary" /> tools:text="Summary" />
<FrameLayout <FrameLayout
@ -182,6 +180,8 @@
android:id="@+id/manga_genres_tags_full_chips" android:id="@+id/manga_genres_tags_full_chips"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:visibility="gone" android:visibility="gone"
app:chipSpacingHorizontal="4dp" /> app:chipSpacingHorizontal="4dp" />
@ -195,6 +195,8 @@
android:id="@+id/manga_genres_tags_compact_chips" android:id="@+id/manga_genres_tags_compact_chips"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingStart="16dp"
android:paddingEnd="16dp"
app:chipSpacingHorizontal="4dp" app:chipSpacingHorizontal="4dp"
app:singleLine="true" /> app:singleLine="true" />
@ -207,14 +209,30 @@
style="@style/Theme.Widget.Button" style="@style/Theme.Widget.Button"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="@string/manga_info_expand" android:text="@string/manga_info_expand"
android:textSize="12sp" android:textSize="12sp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/manga_genres_tags_wrapper" /> app:layout_constraintTop_toBottomOf="@id/manga_genres_tags_wrapper" />
</androidx.constraintlayout.widget.ConstraintLayout> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:paddingTop="16dp"
android:paddingBottom="8dp">
</androidx.core.widget.NestedScrollView> <TextView
android:id="@+id/chapters_label"
style="@style/TextAppearance.Regular.SubHeading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/chapters"
android:textIsSelectable="false" />
</androidx.constraintlayout.widget.ConstraintLayout> </RelativeLayout>
</LinearLayout>

View File

@ -5,7 +5,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:paddingBottom="8dp"
tools:context=".ui.browse.source.browse.BrowseSourceController"> tools:context=".ui.browse.source.browse.BrowseSourceController">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
@ -40,7 +39,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
app:layout_constraintGuide_percent="0.38" /> app:layout_constraintGuide_percent="0.33" />
<ImageView <ImageView
android:id="@+id/manga_cover" android:id="@+id/manga_cover"
@ -88,7 +87,6 @@
style="@style/TextAppearance.Regular.Body1.Secondary" style="@style/TextAppearance.Regular.Body1.Secondary"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textIsSelectable="false" android:textIsSelectable="false"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
@ -130,9 +128,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingStart="16dp" android:paddingStart="16dp"
android:paddingTop="8dp"
android:paddingEnd="16dp" android:paddingEnd="16dp"
android:paddingBottom="8dp"
app:layout_constraintTop_toBottomOf="@+id/manga_info"> app:layout_constraintTop_toBottomOf="@+id/manga_info">
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
@ -251,4 +247,22 @@
android:text="@string/manga_info_expand" android:text="@string/manga_info_expand"
android:textSize="12sp" /> android:textSize="12sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:paddingTop="16dp"
android:paddingBottom="8dp">
<TextView
android:id="@+id/chapters_label"
style="@style/TextAppearance.Regular.SubHeading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/chapters"
android:textIsSelectable="false" />
</RelativeLayout>
</LinearLayout> </LinearLayout>

View File

@ -463,6 +463,11 @@
<string name="manga_info_about_label">About</string> <string name="manga_info_about_label">About</string>
<string name="manga_info_expand">Show more info</string> <string name="manga_info_expand">Show more info</string>
<string name="manga_info_collapse">Show less info</string> <string name="manga_info_collapse">Show less info</string>
<plurals name="manga_num_chapters">
<item quantity="zero">No chapters</item>
<item quantity="one">1 chapter</item>
<item quantity="other">%1$s chapters</item>
</plurals>
<string name="delete_downloads_for_manga">Delete downloaded chapters?</string> <string name="delete_downloads_for_manga">Delete downloaded chapters?</string>
<string name="copied_to_clipboard">Copied to clipboard:\n%1$s</string> <string name="copied_to_clipboard">Copied to clipboard:\n%1$s</string>
<string name="source_not_installed">Source not installed: %1$s</string> <string name="source_not_installed">Source not installed: %1$s</string>