Show new chapters on details
This commit is contained in:
@@ -16,6 +16,13 @@ class ChaptersAdapter(onItemClickListener: OnRecyclerItemClickListener<MangaChap
|
||||
updateCurrentPosition()
|
||||
}
|
||||
|
||||
var newChaptersCount: Int = 0
|
||||
set(value) {
|
||||
val updated = maxOf(field, value)
|
||||
field = value
|
||||
notifyItemRangeChanged(itemCount - updated, updated)
|
||||
}
|
||||
|
||||
var currentChapterPosition = RecyclerView.NO_POSITION
|
||||
private set
|
||||
|
||||
@@ -24,9 +31,13 @@ class ChaptersAdapter(onItemClickListener: OnRecyclerItemClickListener<MangaChap
|
||||
override fun onGetItemId(item: MangaChapter) = item.id
|
||||
|
||||
override fun getExtra(item: MangaChapter, position: Int): ChapterExtra = when {
|
||||
currentChapterPosition == RecyclerView.NO_POSITION -> ChapterExtra.UNREAD
|
||||
currentChapterPosition == RecyclerView.NO_POSITION
|
||||
|| currentChapterPosition < position -> if (position >= itemCount - newChaptersCount) {
|
||||
ChapterExtra.NEW
|
||||
} else {
|
||||
ChapterExtra.UNREAD
|
||||
}
|
||||
currentChapterPosition == position -> ChapterExtra.CURRENT
|
||||
currentChapterPosition < position -> ChapterExtra.UNREAD
|
||||
currentChapterPosition > position -> ChapterExtra.READ
|
||||
else -> ChapterExtra.UNREAD
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.DividerItemDecoration
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kotlinx.android.synthetic.main.fragment_chapters.*
|
||||
import moxy.ktx.moxyPresenter
|
||||
@@ -44,6 +45,7 @@ class ChaptersFragment : BaseFragment(R.layout.fragment_chapters), MangaDetailsV
|
||||
override fun onMangaUpdated(manga: Manga) {
|
||||
this.manga = manga
|
||||
adapter.replaceData(manga.chapters.orEmpty())
|
||||
scrollToCurrent()
|
||||
}
|
||||
|
||||
override fun onLoadingStateChanged(isLoading: Boolean) {
|
||||
@@ -56,6 +58,11 @@ class ChaptersFragment : BaseFragment(R.layout.fragment_chapters), MangaDetailsV
|
||||
|
||||
override fun onHistoryChanged(history: MangaHistory?) {
|
||||
adapter.currentChapterId = history?.chapterId
|
||||
scrollToCurrent()
|
||||
}
|
||||
|
||||
override fun onNewChaptersChanged(newChapters: Int) {
|
||||
adapter.newChaptersCount = newChapters
|
||||
}
|
||||
|
||||
override fun onFavouriteChanged(categories: List<FavouriteCategory>) = Unit
|
||||
@@ -86,4 +93,13 @@ class ChaptersFragment : BaseFragment(R.layout.fragment_chapters), MangaDetailsV
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun scrollToCurrent() {
|
||||
val pos = (recyclerView_chapters.adapter as? ChaptersAdapter)?.currentChapterPosition
|
||||
?: RecyclerView.NO_POSITION
|
||||
if (pos != RecyclerView.NO_POSITION) {
|
||||
(recyclerView_chapters.layoutManager as? LinearLayoutManager)
|
||||
?.scrollToPositionWithOffset(pos, 100)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,6 +80,17 @@ class MangaDetailsActivity : BaseActivity(), MangaDetailsView {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNewChaptersChanged(newChapters: Int) {
|
||||
val tab = tabs.getTabAt(1) ?: return
|
||||
if (newChapters == 0) {
|
||||
tab.removeBadge()
|
||||
} else {
|
||||
val badge = tab.orCreateBadge
|
||||
badge.number = newChapters
|
||||
badge.isVisible = true
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
menuInflater.inflate(R.menu.opt_details, menu)
|
||||
return super.onCreateOptionsMenu(menu)
|
||||
|
||||
@@ -93,6 +93,8 @@ class MangaDetailsFragment : BaseFragment(R.layout.fragment_details), MangaDetai
|
||||
|
||||
override fun onMangaRemoved(manga: Manga) = Unit //handled in activity
|
||||
|
||||
override fun onNewChaptersChanged(newChapters: Int) = Unit
|
||||
|
||||
override fun onClick(v: View) {
|
||||
if (v is Chip) {
|
||||
when(val tag = v.tag) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.koitharu.kotatsu.domain.favourites.FavouritesRepository
|
||||
import org.koitharu.kotatsu.domain.favourites.OnFavouritesChangeListener
|
||||
import org.koitharu.kotatsu.domain.history.HistoryRepository
|
||||
import org.koitharu.kotatsu.domain.history.OnHistoryChangeListener
|
||||
import org.koitharu.kotatsu.domain.tracking.TrackingRepository
|
||||
import org.koitharu.kotatsu.ui.common.BasePresenter
|
||||
import org.koitharu.kotatsu.utils.ext.safe
|
||||
import java.io.IOException
|
||||
@@ -28,12 +29,14 @@ class MangaDetailsPresenter private constructor() : BasePresenter<MangaDetailsVi
|
||||
|
||||
private lateinit var historyRepository: HistoryRepository
|
||||
private lateinit var favouritesRepository: FavouritesRepository
|
||||
private lateinit var trackingRepository: TrackingRepository
|
||||
|
||||
private var manga: Manga? = null
|
||||
|
||||
override fun onFirstViewAttach() {
|
||||
historyRepository = HistoryRepository()
|
||||
favouritesRepository = FavouritesRepository()
|
||||
trackingRepository = TrackingRepository()
|
||||
super.onFirstViewAttach()
|
||||
HistoryRepository.subscribe(this)
|
||||
FavouritesRepository.subscribe(this)
|
||||
@@ -75,6 +78,7 @@ class MangaDetailsPresenter private constructor() : BasePresenter<MangaDetailsVi
|
||||
}
|
||||
viewState.onMangaUpdated(data)
|
||||
this@MangaDetailsPresenter.manga = data
|
||||
viewState.onNewChaptersChanged(trackingRepository.getNewChaptersCount(manga.id))
|
||||
} catch (_: CancellationException){
|
||||
} catch (e: Throwable) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package org.koitharu.kotatsu.ui.details
|
||||
|
||||
import moxy.MvpView
|
||||
import moxy.viewstate.strategy.alias.AddToEndSingle
|
||||
import moxy.viewstate.strategy.alias.OneExecution
|
||||
import moxy.viewstate.strategy.alias.SingleState
|
||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||
import org.koitharu.kotatsu.core.model.Manga
|
||||
@@ -22,4 +20,7 @@ interface MangaDetailsView : BaseMvpView {
|
||||
|
||||
@SingleState
|
||||
fun onMangaRemoved(manga: Manga)
|
||||
|
||||
@AddToEndSingle
|
||||
fun onNewChaptersChanged(newChapters: Int)
|
||||
}
|
||||
Reference in New Issue
Block a user