Show tracker status in button

This commit is contained in:
arkon 2020-07-18 16:37:00 -04:00
parent 4e6cc013e5
commit a443dc3040
5 changed files with 55 additions and 18 deletions

View File

@ -356,6 +356,10 @@ class MangaController :
activity?.toast(error.message) activity?.toast(error.message)
} }
fun onTrackingCount(trackCount: Int) {
mangaInfoAdapter?.setTrackingCount(trackCount)
}
fun openMangaInWebView() { fun openMangaInWebView() {
val source = presenter.source as? HttpSource ?: return val source = presenter.source as? HttpSource ?: return

View File

@ -13,6 +13,7 @@ import eu.kanade.tachiyomi.data.database.models.MangaCategory
import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.download.DownloadManager
import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.data.download.model.Download
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.source.LocalSource
import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
@ -39,6 +40,7 @@ class MangaPresenter(
val source: Source, val source: Source,
val preferences: PreferencesHelper = Injekt.get(), val preferences: PreferencesHelper = Injekt.get(),
private val db: DatabaseHelper = Injekt.get(), private val db: DatabaseHelper = Injekt.get(),
private val trackManager: TrackManager = Injekt.get(),
private val downloadManager: DownloadManager = Injekt.get(), private val downloadManager: DownloadManager = Injekt.get(),
private val coverCache: CoverCache = Injekt.get() private val coverCache: CoverCache = Injekt.get()
) : BasePresenter<MangaController>() { ) : BasePresenter<MangaController>() {
@ -83,8 +85,13 @@ class MangaPresenter(
// Manga info - start // Manga info - start
getMangaObservable() getMangaObservable()
.observeOn(AndroidSchedulers.mainThread())
.subscribeLatestCache({ view, manga -> view.onNextMangaInfo(manga, source) }) .subscribeLatestCache({ view, manga -> view.onNextMangaInfo(manga, source) })
getTrackingObservable()
.observeOn(AndroidSchedulers.mainThread())
.subscribeLatestCache(MangaController::onTrackingCount) { _, error -> Timber.e(error) }
// Prepare the relay. // Prepare the relay.
chaptersRelay.flatMap { applyChapterFilters(it) } chaptersRelay.flatMap { applyChapterFilters(it) }
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
@ -122,7 +129,19 @@ class MangaPresenter(
private fun getMangaObservable(): Observable<Manga> { private fun getMangaObservable(): Observable<Manga> {
return db.getManga(manga.url, manga.source).asRxObservable() return db.getManga(manga.url, manga.source).asRxObservable()
.observeOn(AndroidSchedulers.mainThread()) }
private fun getTrackingObservable(): Observable<Int> {
if (!trackManager.hasLoggedServices()) {
return Observable.just(0)
}
return db.getTracks(manga).asRxObservable()
.map { tracks ->
val loggedServices = trackManager.services.filter { it.isLogged }.map { it.id }
tracks.filter { it.sync_id in loggedServices }
}
.map { it.size }
} }
/** /**

View File

@ -14,7 +14,6 @@ import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.data.glide.GlideApp
import eu.kanade.tachiyomi.data.glide.MangaThumbnail import eu.kanade.tachiyomi.data.glide.MangaThumbnail
import eu.kanade.tachiyomi.data.glide.toMangaThumbnail import eu.kanade.tachiyomi.data.glide.toMangaThumbnail
import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.databinding.MangaInfoHeaderBinding import eu.kanade.tachiyomi.databinding.MangaInfoHeaderBinding
import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.SourceManager
@ -47,6 +46,7 @@ class MangaInfoHeaderAdapter(
private var manga: Manga = controller.presenter.manga private var manga: Manga = controller.presenter.manga
private var source: Source = controller.presenter.source private var source: Source = controller.presenter.source
private var trackCount: Int = 0
private val scope = CoroutineScope(Job() + Dispatchers.Main) private val scope = CoroutineScope(Job() + Dispatchers.Main)
private lateinit var binding: MangaInfoHeaderBinding private lateinit var binding: MangaInfoHeaderBinding
@ -78,6 +78,12 @@ class MangaInfoHeaderAdapter(
notifyDataSetChanged() notifyDataSetChanged()
} }
fun setTrackingCount(trackCount: Int) {
this.trackCount = trackCount
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() {
// For rounded corners // For rounded corners
@ -93,13 +99,26 @@ class MangaInfoHeaderAdapter(
.launchIn(scope) .launchIn(scope)
} }
if (controller.presenter.manga.favorite && Injekt.get<TrackManager>().hasLoggedServices()) { with(binding.btnTracking) {
binding.btnTracking.visible() if (controller.presenter.manga.favorite) {
binding.btnTracking.clicks() visible()
.onEach { controller.onTrackingClick() }
.launchIn(scope) if (trackCount > 0) {
} else { setIconResource(R.drawable.ic_done_24dp)
binding.btnTracking.gone() text = view.context.resources.getQuantityString(R.plurals.num_trackers, trackCount, trackCount)
isChecked = true
} else {
setIconResource(R.drawable.ic_sync_24dp)
text = view.context.getString(R.string.manga_tracking_tab)
isChecked = false
}
clicks()
.onEach { controller.onTrackingClick() }
.launchIn(scope)
} else {
gone()
}
} }
if (controller.presenter.source is HttpSource) { if (controller.presenter.source is HttpSource) {

View File

@ -1,9 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="18dp"
android:height="18dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M9,16.2L4.8,12l-1.4,1.4L9,19 21,7l-1.4,-1.4L9,16.2z"/>
</vector>

View File

@ -514,6 +514,10 @@
<!-- Tracking Screen --> <!-- Tracking Screen -->
<string name="manga_tracking_tab">Tracking</string> <string name="manga_tracking_tab">Tracking</string>
<plurals name="num_trackers">
<item quantity="one">1 tracker</item>
<item quantity="other">%d trackers</item>
</plurals>
<string name="add_tracking">Add tracking</string> <string name="add_tracking">Add tracking</string>
<string name="reading">Reading</string> <string name="reading">Reading</string>
<string name="currently_reading">Currently reading</string> <string name="currently_reading">Currently reading</string>