Minor cleanup
This commit is contained in:
parent
535abcbb8b
commit
d5cfbef42b
@ -6,7 +6,6 @@ import android.view.ViewGroup
|
|||||||
import eu.kanade.tachiyomi.data.database.models.Category
|
import eu.kanade.tachiyomi.data.database.models.Category
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.databinding.LibraryCategoryBinding
|
import eu.kanade.tachiyomi.databinding.LibraryCategoryBinding
|
||||||
import eu.kanade.tachiyomi.util.view.inflate
|
|
||||||
import eu.kanade.tachiyomi.widget.RecyclerViewPagerAdapter
|
import eu.kanade.tachiyomi.widget.RecyclerViewPagerAdapter
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
@ -36,7 +35,7 @@ class LibraryAdapter(
|
|||||||
/**
|
/**
|
||||||
* The number of manga in each category.
|
* The number of manga in each category.
|
||||||
*/
|
*/
|
||||||
var mangaCountPerCategory: Map<Int, Int> = emptyMap()
|
var itemsPerCategory: Map<Int, Int> = emptyMap()
|
||||||
set(value) {
|
set(value) {
|
||||||
if (field !== value) {
|
if (field !== value) {
|
||||||
field = value
|
field = value
|
||||||
@ -97,7 +96,7 @@ class LibraryAdapter(
|
|||||||
*/
|
*/
|
||||||
override fun getPageTitle(position: Int): CharSequence {
|
override fun getPageTitle(position: Int): CharSequence {
|
||||||
if (preferences.categoryNumberOfItems().get()) {
|
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
|
return categories[position].name
|
||||||
}
|
}
|
||||||
|
@ -144,27 +144,27 @@ class LibraryController(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updateTitle() {
|
private fun updateTitle() {
|
||||||
val categoryTabs = preferences.categoryTabs().get()
|
val showCategoryTabs = preferences.categoryTabs().get()
|
||||||
val currentCategory = adapter?.categories?.getOrNull(binding.libraryPager.currentItem)
|
val currentCategory = adapter?.categories?.getOrNull(binding.libraryPager.currentItem)
|
||||||
|
|
||||||
if (categoryTabs) {
|
var title = if (showCategoryTabs) {
|
||||||
currentTitle = resources?.getString(R.string.label_library)
|
resources?.getString(R.string.label_library)
|
||||||
} else {
|
} else {
|
||||||
currentCategory?.let {
|
currentCategory?.name
|
||||||
currentTitle = it.name
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preferences.categoryNumberOfItems().get() && libraryMangaRelay.hasValue()) {
|
if (preferences.categoryNumberOfItems().get() && libraryMangaRelay.hasValue()) {
|
||||||
libraryMangaRelay.value.mangas.let { mangaMap ->
|
libraryMangaRelay.value.mangas.let { mangaMap ->
|
||||||
if (!categoryTabs) {
|
if (!showCategoryTabs) {
|
||||||
currentTitle += " (${mangaMap[currentCategory?.id]?.size ?: 0})"
|
title += " (${mangaMap[currentCategory?.id]?.size ?: 0})"
|
||||||
} else if (adapter?.categories?.size == 1) {
|
} else if (adapter?.categories?.size == 1) {
|
||||||
// special case for if there are no categories
|
// Only "Default" category
|
||||||
currentTitle += " (${mangaMap[0]?.size ?: 0})"
|
title += " (${mangaMap[0]?.size ?: 0})"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentTitle = title
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createPresenter(): LibraryPresenter {
|
override fun createPresenter(): LibraryPresenter {
|
||||||
@ -289,9 +289,9 @@ class LibraryController(
|
|||||||
|
|
||||||
// Set the categories
|
// Set the categories
|
||||||
adapter.categories = categories
|
adapter.categories = categories
|
||||||
adapter.mangaCountPerCategory = adapter.categories.map {
|
adapter.itemsPerCategory = adapter.categories
|
||||||
Pair(it.id ?: -1, mangaMap[it.id]?.size ?: 0)
|
.map { (it.id ?: -1) to (mangaMap[it.id]?.size ?: 0) }
|
||||||
}.toMap()
|
.toMap()
|
||||||
|
|
||||||
// Restore active category.
|
// Restore active category.
|
||||||
binding.libraryPager.setCurrentItem(activeCat, false)
|
binding.libraryPager.setCurrentItem(activeCat, false)
|
||||||
|
@ -99,8 +99,8 @@ class MangaPresenter(
|
|||||||
private val loggedServices by lazy { trackManager.services.filter { it.isLogged } }
|
private val loggedServices by lazy { trackManager.services.filter { it.isLogged } }
|
||||||
|
|
||||||
private var trackSubscription: Subscription? = null
|
private var trackSubscription: Subscription? = null
|
||||||
private var searchJob: Job? = null
|
private var searchTrackerJob: Job? = null
|
||||||
private var refreshJob: Job? = null
|
private var refreshTrackersJob: Job? = null
|
||||||
|
|
||||||
override fun onCreate(savedState: Bundle?) {
|
override fun onCreate(savedState: Bundle?) {
|
||||||
super.onCreate(savedState)
|
super.onCreate(savedState)
|
||||||
@ -680,9 +680,9 @@ class MangaPresenter(
|
|||||||
.subscribeLatestCache(MangaController::onNextTrackers)
|
.subscribeLatestCache(MangaController::onNextTrackers)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun trackingRefresh() {
|
fun refreshTrackers() {
|
||||||
refreshJob?.cancel()
|
refreshTrackersJob?.cancel()
|
||||||
refreshJob = launchIO {
|
refreshTrackersJob = launchIO {
|
||||||
supervisorScope {
|
supervisorScope {
|
||||||
try {
|
try {
|
||||||
trackList
|
trackList
|
||||||
@ -704,8 +704,8 @@ class MangaPresenter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun trackingSearch(query: String, service: TrackService) {
|
fun trackingSearch(query: String, service: TrackService) {
|
||||||
searchJob?.cancel()
|
searchTrackerJob?.cancel()
|
||||||
searchJob = launchIO {
|
searchTrackerJob = launchIO {
|
||||||
try {
|
try {
|
||||||
val results = service.search(query)
|
val results = service.search(query)
|
||||||
withUIContext { view?.onTrackingSearchResults(results) }
|
withUIContext { view?.onTrackingSearchResults(results) }
|
||||||
|
@ -50,7 +50,7 @@ class TrackSheet(
|
|||||||
|
|
||||||
override fun show() {
|
override fun show() {
|
||||||
super.show()
|
super.show()
|
||||||
controller.presenter.trackingRefresh()
|
controller.presenter.refreshTrackers()
|
||||||
sheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
|
sheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,16 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?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"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/track_recycler"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical">
|
android:layout_marginTop="4dp"
|
||||||
|
android:clipToPadding="false"
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
tools:listitem="@layout/track_item" />
|
||||||
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>
|
|
||||||
|
Loading…
Reference in New Issue
Block a user