Minor cleanup
This commit is contained in:
parent
535abcbb8b
commit
d5cfbef42b
5 changed files with 28 additions and 36 deletions
|
@ -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<Int, Int> = emptyMap()
|
||||
var itemsPerCategory: Map<Int, Int> = 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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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) }
|
||||
|
|
|
@ -50,7 +50,7 @@ class TrackSheet(
|
|||
|
||||
override fun show() {
|
||||
super.show()
|
||||
controller.presenter.trackingRefresh()
|
||||
controller.presenter.refreshTrackers()
|
||||
sheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
|
||||
}
|
||||
|
||||
|
|
|
@ -1,16 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/track_recycler"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="4dp"
|
||||
android:clipToPadding="false"
|
||||
tools:listitem="@layout/track_item" />
|
||||
|
||||
</LinearLayout>
|
||||
|
|
Reference in a new issue