From d5cfbef42bde2a785b9c3033dc2a769ac1a7c37f Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 31 Jan 2021 10:23:33 -0500 Subject: [PATCH] Minor cleanup --- .../tachiyomi/ui/library/LibraryAdapter.kt | 5 ++-- .../tachiyomi/ui/library/LibraryController.kt | 26 +++++++++---------- .../tachiyomi/ui/manga/MangaPresenter.kt | 14 +++++----- .../tachiyomi/ui/manga/track/TrackSheet.kt | 2 +- app/src/main/res/layout/track_controller.xml | 17 ++++-------- 5 files changed, 28 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryAdapter.kt index 7b594cf1b3..e26fd80fbd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryAdapter.kt @@ -6,7 +6,6 @@ import android.view.ViewGroup import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.databinding.LibraryCategoryBinding -import eu.kanade.tachiyomi.util.view.inflate import eu.kanade.tachiyomi.widget.RecyclerViewPagerAdapter import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -36,7 +35,7 @@ class LibraryAdapter( /** * The number of manga in each category. */ - var mangaCountPerCategory: Map = emptyMap() + var itemsPerCategory: Map = emptyMap() set(value) { if (field !== value) { field = value @@ -97,7 +96,7 @@ class LibraryAdapter( */ override fun getPageTitle(position: Int): CharSequence { if (preferences.categoryNumberOfItems().get()) { - return categories[position].let { "${it.name} (${mangaCountPerCategory[it.id]})" } + return categories[position].let { "${it.name} (${itemsPerCategory[it.id]})" } } return categories[position].name } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 0d3d382c2b..c976c76bc8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -144,27 +144,27 @@ class LibraryController( } private fun updateTitle() { - val categoryTabs = preferences.categoryTabs().get() + val showCategoryTabs = preferences.categoryTabs().get() val currentCategory = adapter?.categories?.getOrNull(binding.libraryPager.currentItem) - if (categoryTabs) { - currentTitle = resources?.getString(R.string.label_library) + var title = if (showCategoryTabs) { + resources?.getString(R.string.label_library) } else { - currentCategory?.let { - currentTitle = it.name - } + currentCategory?.name } if (preferences.categoryNumberOfItems().get() && libraryMangaRelay.hasValue()) { libraryMangaRelay.value.mangas.let { mangaMap -> - if (!categoryTabs) { - currentTitle += " (${mangaMap[currentCategory?.id]?.size ?: 0})" + if (!showCategoryTabs) { + title += " (${mangaMap[currentCategory?.id]?.size ?: 0})" } else if (adapter?.categories?.size == 1) { - // special case for if there are no categories - currentTitle += " (${mangaMap[0]?.size ?: 0})" + // Only "Default" category + title += " (${mangaMap[0]?.size ?: 0})" } } } + + currentTitle = title } override fun createPresenter(): LibraryPresenter { @@ -289,9 +289,9 @@ class LibraryController( // Set the categories adapter.categories = categories - adapter.mangaCountPerCategory = adapter.categories.map { - Pair(it.id ?: -1, mangaMap[it.id]?.size ?: 0) - }.toMap() + adapter.itemsPerCategory = adapter.categories + .map { (it.id ?: -1) to (mangaMap[it.id]?.size ?: 0) } + .toMap() // Restore active category. binding.libraryPager.setCurrentItem(activeCat, false) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt index ea36087f54..2cd45e8e74 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt @@ -99,8 +99,8 @@ class MangaPresenter( private val loggedServices by lazy { trackManager.services.filter { it.isLogged } } private var trackSubscription: Subscription? = null - private var searchJob: Job? = null - private var refreshJob: Job? = null + private var searchTrackerJob: Job? = null + private var refreshTrackersJob: Job? = null override fun onCreate(savedState: Bundle?) { super.onCreate(savedState) @@ -680,9 +680,9 @@ class MangaPresenter( .subscribeLatestCache(MangaController::onNextTrackers) } - fun trackingRefresh() { - refreshJob?.cancel() - refreshJob = launchIO { + fun refreshTrackers() { + refreshTrackersJob?.cancel() + refreshTrackersJob = launchIO { supervisorScope { try { trackList @@ -704,8 +704,8 @@ class MangaPresenter( } fun trackingSearch(query: String, service: TrackService) { - searchJob?.cancel() - searchJob = launchIO { + searchTrackerJob?.cancel() + searchTrackerJob = launchIO { try { val results = service.search(query) withUIContext { view?.onTrackingSearchResults(results) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSheet.kt index 1355e919cf..cd5c24778e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSheet.kt @@ -50,7 +50,7 @@ class TrackSheet( override fun show() { super.show() - controller.presenter.trackingRefresh() + controller.presenter.refreshTrackers() sheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED } diff --git a/app/src/main/res/layout/track_controller.xml b/app/src/main/res/layout/track_controller.xml index 07c707a77e..05495af73d 100644 --- a/app/src/main/res/layout/track_controller.xml +++ b/app/src/main/res/layout/track_controller.xml @@ -1,16 +1,9 @@ - - - - - + android:layout_marginTop="4dp" + android:clipToPadding="false" + tools:listitem="@layout/track_item" />