From 1aebd3acedb1b8ba05f42f5b15943fd04caa2eae Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 9 Apr 2020 02:01:56 -0400 Subject: [PATCH] light Manga details refactoring --- .../tachiyomi/data/database/models/Manga.kt | 2 +- .../tachiyomi/ui/manga/MangaDetailsAdapter.kt | 58 ++++--------------- .../ui/manga/MangaDetailsController.kt | 7 ++- .../ui/manga/MangaDetailsPresenter.kt | 1 + .../tachiyomi/ui/manga/MangaHeaderHolder.kt | 11 +--- .../ui/recently_read/RemoveHistoryDialog.kt | 6 +- .../res/layout/manga_details_controller.xml | 2 +- 7 files changed, 19 insertions(+), 68 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt index 306b3e6376..e5e44b1ecd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt @@ -54,7 +54,7 @@ interface Manga : SManga { TYPE_MANHUA -> R.string.manhua TYPE_COMIC -> R.string.comic else -> R.string.manga - }) + }).toLowerCase(Locale.getDefault()) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsAdapter.kt index 9ef0928b28..128e25c1d3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsAdapter.kt @@ -111,58 +111,20 @@ class MangaDetailsAdapter( } private fun get100sRange(value: Float): String { - return when (value.toInt()) { - in 0..99 -> "0-99" - in 100..199 -> "100-199" - in 200..299 -> "200-299" - in 300..399 -> "300-399" - in 400..499 -> "400-499" - in 500..599 -> "500-599" - in 600..699 -> "600-699" - in 700..799 -> "700-799" - in 800..899 -> "800-899" - in 900..Int.MAX_VALUE -> "900+" - else -> "None" + val number = value.toInt() + return if (number < 100) "0-99" + else { + val hundred = number / 100 + "${hundred}00-${hundred}99" } } private fun get10sRange(value: Float): String { - return when (value.toInt()) { - in 0..9 -> "0-9" - in 10..19 -> "10-19" - in 20..29 -> "20-29" - in 30..39 -> "30-39" - in 40..49 -> "40-49" - in 50..59 -> "50-59" - in 60..69 -> "60-69" - in 70..79 -> "70-79" - in 80..89 -> "80-89" - in 80..89 -> "80-89" - in 90..99 -> "90-99" - in 100..109 -> "100-109" - in 110..119 -> "110-119" - in 120..129 -> "120-129" - in 130..139 -> "130-139" - in 140..149 -> "140-149" - in 150..159 -> "150-159" - in 160..169 -> "160-169" - in 170..179 -> "170-179" - in 180..189 -> "180-189" - in 190..199 -> "190-199" - in 190..199 -> "190-199" - in 200..209 -> "200-209" - in 210..219 -> "210-219" - in 220..229 -> "220-229" - in 230..239 -> "230-239" - in 240..249 -> "240-249" - in 250..259 -> "250-259" - in 260..269 -> "260-269" - in 270..279 -> "270-279" - in 280..289 -> "280-289" - in 290..299 -> "290-299" - in 290..299 -> "290-299" - in 300..Int.MAX_VALUE -> "300+" - else -> recyclerView.context.getString(R.string.unknown) + val number = value.toInt() + return if (number < 10) "0-9" + else { + val hundred = number / 10 + "${hundred}0-${hundred + 1}9" } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt index ed0671216d..b6fbbc3afd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt @@ -242,7 +242,7 @@ class MangaDetailsController : BaseController, } presenter.onCreate() - fast_scroller.translationX = if (showScroll) 0f else 22f.dpToPx + fast_scroller.translationX = if (showScroll) 0f else 25f.dpToPx recycler.addOnScrollListener(object : RecyclerView.OnScrollListener() { override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { super.onScrolled(recyclerView, dx, dy) @@ -275,7 +275,7 @@ class MangaDetailsController : BaseController, } else if (fPosition <= 0 && showScroll) { showScroll = false scrollAnim?.cancel() - scrollAnim = fast_scroller.animate().setDuration(100).translationX(22f.dpToPx) + scrollAnim = fast_scroller.animate().setDuration(100).translationX(25f.dpToPx) scrollAnim?.start() } } @@ -690,7 +690,8 @@ class MangaDetailsController : BaseController, presenter.getNextUnreadChapter() != null && !presenter.isLockedFromSearch menu.findItem(R.id.action_mark_all_as_unread).isVisible = !presenter.allUnread() && !presenter.isLockedFromSearch - menu.findItem(R.id.action_remove_downloads).isVisible = !presenter.isLockedFromSearch + menu.findItem(R.id.action_remove_downloads).isVisible = + presenter.hasDownloads() && !presenter.isLockedFromSearch menu.findItem(R.id.remove_non_bookmarked).isVisible = presenter.hasBookmark() && !presenter.isLockedFromSearch menu.findItem(R.id.action_mark_all_as_unread).isVisible = presenter.isTracked() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt index a2e43149fd..af6448a1d0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt @@ -321,6 +321,7 @@ class MangaDetailsPresenter( fun allUnread(): Boolean = chapters.none { it.read } fun hasBookmark(): Boolean = chapters.any { it.bookmark } + fun hasDownloads(): Boolean = chapters.any { it.isDownloaded } fun getUnreadChaptersSorted() = chapters.filter { !it.read && it.status == Download.NOT_DOWNLOADED }.distinctBy { it.name } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt index 5506ba440d..7cb6de8b40 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt @@ -28,7 +28,6 @@ import eu.kanade.tachiyomi.util.view.visible import eu.kanade.tachiyomi.util.view.visibleIf import kotlinx.android.synthetic.main.manga_details_controller.* import kotlinx.android.synthetic.main.manga_header_item.* -import java.util.Locale class MangaHeaderHolder( private val view: View, @@ -137,15 +136,7 @@ class MangaHeaderHolder( else expand() } manga_summary_label.text = itemView.context.getString( - R.string.about_this_, itemView.context.getString( - when { - manga.mangaType() == Manga.TYPE_MANHWA -> R.string.manhwa - manga.mangaType() == Manga.TYPE_MANHUA -> R.string.manhua - manga.mangaType() == Manga.TYPE_COMIC -> R.string.comic - manga.mangaType() == Manga.TYPE_WEBTOON -> R.string.webtoon - else -> R.string.manga - } - ).toLowerCase(Locale.getDefault()) + R.string.about_this_, manga.mangaType(itemView.context) ) with(favorite_button) { icon = ContextCompat.getDrawable( diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RemoveHistoryDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RemoveHistoryDialog.kt index 8ddc9d696c..2b9e51d20d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RemoveHistoryDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RemoveHistoryDialog.kt @@ -10,7 +10,6 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.History import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.ui.base.controller.DialogController -import java.util.Locale class RemoveHistoryDialog(bundle: Bundle? = null) : DialogController(bundle) where T : Controller, T : RemoveHistoryDialog.Listener { @@ -31,10 +30,7 @@ class RemoveHistoryDialog(bundle: Bundle? = null) : DialogController(bundle) return MaterialDialog(activity).title(R.string.remove) .message(R.string.this_will_remove_the_read_date_question).checkBoxPrompt( text = activity.getString( - R.string.reset_all_chapters_for_this_, - (manga?.mangaType(activity) ?: activity.getString(R.string.manga)).toLowerCase( - Locale.ROOT - ) + R.string.reset_all_chapters_for_this_, manga!!.mangaType(activity) ) ) {}.negativeButton(android.R.string.cancel).positiveButton(R.string.remove) { onPositive(it.isCheckPromptChecked()) diff --git a/app/src/main/res/layout/manga_details_controller.xml b/app/src/main/res/layout/manga_details_controller.xml index c16ee681a5..b0fedbde82 100644 --- a/app/src/main/res/layout/manga_details_controller.xml +++ b/app/src/main/res/layout/manga_details_controller.xml @@ -35,7 +35,7 @@ android:id="@+id/fast_scroller" android:textColor="?android:attr/textColorPrimary" app:iconColor="?android:attr/textColorPrimary" - android:layout_width="22dp" + android:layout_width="25dp" android:layout_height="0dp" android:elevation="10dp" android:layout_gravity="end"