diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt index eac86a4201..2e8ba19f07 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt @@ -28,6 +28,7 @@ import eu.kanade.tachiyomi.ui.manga.chapter.ChaptersController import eu.kanade.tachiyomi.ui.manga.info.MangaInfoController import eu.kanade.tachiyomi.ui.manga.track.TrackController import eu.kanade.tachiyomi.util.system.toast +import java.util.Date import kotlinx.android.synthetic.main.main_activity.tabs import rx.Subscription import uy.kohesive.injekt.Injekt @@ -64,6 +65,10 @@ class MangaController : RxController, TabbedController { val fromSource = args.getBoolean(FROM_SOURCE_EXTRA, false) + val lastUpdateRelay: BehaviorRelay = BehaviorRelay.create() + + val chapterCountRelay: BehaviorRelay = BehaviorRelay.create() + val mangaFavoriteRelay: PublishRelay = PublishRelay.create() private val trackingIconRelay: BehaviorRelay = BehaviorRelay.create() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt index 290e731ee4..8a8db8140e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt @@ -71,7 +71,10 @@ class ChaptersController : override fun createPresenter(): ChaptersPresenter { val ctrl = parentController as MangaController - return ChaptersPresenter(ctrl.manga!!, ctrl.source!!, ctrl.mangaFavoriteRelay) + return ChaptersPresenter( + ctrl.manga!!, ctrl.source!!, + ctrl.chapterCountRelay, ctrl.lastUpdateRelay, ctrl.mangaFavoriteRelay + ) } override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt index d28f1f6129..fdef7d1128 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.ui.manga.chapter import android.os.Bundle +import com.jakewharton.rxrelay.BehaviorRelay import com.jakewharton.rxrelay.PublishRelay import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Chapter @@ -13,6 +14,7 @@ import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource import eu.kanade.tachiyomi.util.lang.isNullOrUnsubscribed +import java.util.Date import rx.Observable import rx.Subscription import rx.android.schedulers.AndroidSchedulers @@ -27,6 +29,8 @@ import uy.kohesive.injekt.api.get class ChaptersPresenter( val manga: Manga, val source: Source, + private val chapterCountRelay: BehaviorRelay, + private val lastUpdateRelay: BehaviorRelay, private val mangaFavoriteRelay: PublishRelay, val preferences: PreferencesHelper = Injekt.get(), private val db: DatabaseHelper = Injekt.get(), @@ -86,6 +90,20 @@ class ChaptersPresenter( // Listen for download status changes observeDownloads() + + // Emit the number of chapters to the info tab. + chapterCountRelay.call( + chapters.maxBy { it.chapter_number }?.chapter_number + ?: 0f + ) + + // Emit the upload date of the most recent chapter + lastUpdateRelay.call( + Date( + chapters.maxBy { it.date_upload }?.date_upload + ?: 0 + ) + ) } .subscribe { chaptersRelay.call(it) } ) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt index 1f3c760105..8ac9698702 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt @@ -14,6 +14,7 @@ import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.data.glide.toMangaThumbnail import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.databinding.MangaInfoControllerBinding import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.SourceManager @@ -37,6 +38,9 @@ import eu.kanade.tachiyomi.util.view.setChips import eu.kanade.tachiyomi.util.view.snack import eu.kanade.tachiyomi.util.view.visible import eu.kanade.tachiyomi.util.view.visibleIf +import java.text.DateFormat +import java.text.DecimalFormat +import java.util.Date import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import reactivecircus.flowbinding.android.view.clicks @@ -57,13 +61,20 @@ class MangaInfoController(private val fromSource: Boolean = false) : private val preferences: PreferencesHelper by injectLazy() + private val dateFormat: DateFormat by lazy { + preferences.dateFormat().getOrDefault() + } + private var initialLoad: Boolean = true private var thumbnailUrl: String? = null override fun createPresenter(): MangaInfoPresenter { val ctrl = parentController as MangaController - return MangaInfoPresenter(ctrl.manga!!, ctrl.source!!, ctrl.mangaFavoriteRelay) + return MangaInfoPresenter( + ctrl.manga!!, ctrl.source!!, + ctrl.chapterCountRelay, ctrl.lastUpdateRelay, ctrl.mangaFavoriteRelay + ) } override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { @@ -316,6 +327,27 @@ class MangaInfoController(private val fromSource: Boolean = false) : binding.mangaGenresTagsFullChips.visibleIf { !isExpanded } } + /** + * Update chapter count TextView. + * + * @param count number of chapters. + */ + fun setChapterCount(count: Float) { + if (count > 0f) { + binding.mangaChapters.text = DecimalFormat("#.#").format(count) + } else { + binding.mangaChapters.text = resources?.getString(R.string.unknown) + } + } + + fun setLastUpdateDate(date: Date) { + if (date.time != 0L) { + binding.mangaLastUpdate.text = dateFormat.format(date) + } else { + binding.mangaLastUpdate.text = resources?.getString(R.string.unknown) + } + } + /** * Toggles the favorite status and asks for confirmation to delete downloaded chapters. */ diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoPresenter.kt index 9113b6ea1f..e92257841d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoPresenter.kt @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.ui.manga.info import android.os.Bundle +import com.jakewharton.rxrelay.BehaviorRelay import com.jakewharton.rxrelay.PublishRelay import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.database.DatabaseHelper @@ -11,6 +12,7 @@ import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.util.lang.isNullOrUnsubscribed +import java.util.Date import rx.Observable import rx.Subscription import rx.android.schedulers.AndroidSchedulers @@ -26,6 +28,8 @@ import uy.kohesive.injekt.api.get class MangaInfoPresenter( val manga: Manga, val source: Source, + private val chapterCountRelay: BehaviorRelay, + private val lastUpdateRelay: BehaviorRelay, private val mangaFavoriteRelay: PublishRelay, private val db: DatabaseHelper = Injekt.get(), private val downloadManager: DownloadManager = Injekt.get(), @@ -46,10 +50,18 @@ class MangaInfoPresenter( super.onCreate(savedState) sendMangaToView() + // Update chapter count + chapterCountRelay.observeOn(AndroidSchedulers.mainThread()) + .subscribeLatestCache(MangaInfoController::setChapterCount) + // Update favorite status mangaFavoriteRelay.observeOn(AndroidSchedulers.mainThread()) .subscribe { setFavorite(it) } .apply { add(this) } + + // update last update date + lastUpdateRelay.observeOn(AndroidSchedulers.mainThread()) + .subscribeLatestCache(MangaInfoController::setLastUpdateDate) } /** diff --git a/app/src/main/res/layout/manga_info_controller.xml b/app/src/main/res/layout/manga_info_controller.xml index 38e7c9944d..30b81448aa 100644 --- a/app/src/main/res/layout/manga_info_controller.xml +++ b/app/src/main/res/layout/manga_info_controller.xml @@ -98,6 +98,7 @@ android:layout_height="wrap_content" android:text="@string/manga_info_author_label" android:textIsSelectable="false" + app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/manga_full_title" /> @@ -137,6 +138,52 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/manga_artist_label" /> + + + + + + + + + app:layout_constraintTop_toBottomOf="@+id/manga_last_update_label" /> Author Artist Chapters + Last chapter + Updated Status Source Genres