|
|
|
@ -4,6 +4,7 @@ import kotlinx.coroutines.Dispatchers
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
import kotlinx.coroutines.withContext
|
|
|
|
import kotlinx.coroutines.withContext
|
|
|
|
import moxy.InjectViewState
|
|
|
|
import moxy.InjectViewState
|
|
|
|
|
|
|
|
import moxy.presenterScope
|
|
|
|
import org.koitharu.kotatsu.BuildConfig
|
|
|
|
import org.koitharu.kotatsu.BuildConfig
|
|
|
|
import org.koitharu.kotatsu.core.model.Manga
|
|
|
|
import org.koitharu.kotatsu.core.model.Manga
|
|
|
|
import org.koitharu.kotatsu.domain.MangaProviderFactory
|
|
|
|
import org.koitharu.kotatsu.domain.MangaProviderFactory
|
|
|
|
@ -14,7 +15,7 @@ import org.koitharu.kotatsu.domain.history.OnHistoryChangeListener
|
|
|
|
import org.koitharu.kotatsu.ui.common.BasePresenter
|
|
|
|
import org.koitharu.kotatsu.ui.common.BasePresenter
|
|
|
|
|
|
|
|
|
|
|
|
@InjectViewState
|
|
|
|
@InjectViewState
|
|
|
|
class MangaDetailsPresenter : BasePresenter<MangaDetailsView>(), OnHistoryChangeListener,
|
|
|
|
class MangaDetailsPresenter private constructor(): BasePresenter<MangaDetailsView>(), OnHistoryChangeListener,
|
|
|
|
OnFavouritesChangeListener {
|
|
|
|
OnFavouritesChangeListener {
|
|
|
|
|
|
|
|
|
|
|
|
private lateinit var historyRepository: HistoryRepository
|
|
|
|
private lateinit var historyRepository: HistoryRepository
|
|
|
|
@ -37,7 +38,7 @@ class MangaDetailsPresenter : BasePresenter<MangaDetailsView>(), OnHistoryChange
|
|
|
|
loadHistory(manga)
|
|
|
|
loadHistory(manga)
|
|
|
|
viewState.onMangaUpdated(manga)
|
|
|
|
viewState.onMangaUpdated(manga)
|
|
|
|
loadFavourite(manga)
|
|
|
|
loadFavourite(manga)
|
|
|
|
launch {
|
|
|
|
presenterScope.launch {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
viewState.onLoadingStateChanged(true)
|
|
|
|
viewState.onLoadingStateChanged(true)
|
|
|
|
val data = withContext(Dispatchers.IO) {
|
|
|
|
val data = withContext(Dispatchers.IO) {
|
|
|
|
@ -57,7 +58,7 @@ class MangaDetailsPresenter : BasePresenter<MangaDetailsView>(), OnHistoryChange
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun loadHistory(manga: Manga) {
|
|
|
|
private fun loadHistory(manga: Manga) {
|
|
|
|
launch {
|
|
|
|
presenterScope.launch {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
val history = withContext(Dispatchers.IO) {
|
|
|
|
val history = withContext(Dispatchers.IO) {
|
|
|
|
historyRepository.getOne(manga)
|
|
|
|
historyRepository.getOne(manga)
|
|
|
|
@ -72,7 +73,7 @@ class MangaDetailsPresenter : BasePresenter<MangaDetailsView>(), OnHistoryChange
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun loadFavourite(manga: Manga) {
|
|
|
|
private fun loadFavourite(manga: Manga) {
|
|
|
|
launch {
|
|
|
|
presenterScope.launch {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
val categories = withContext(Dispatchers.IO) {
|
|
|
|
val categories = withContext(Dispatchers.IO) {
|
|
|
|
favouritesRepository.getCategories(manga.id)
|
|
|
|
favouritesRepository.getCategories(manga.id)
|
|
|
|
@ -99,6 +100,18 @@ class MangaDetailsPresenter : BasePresenter<MangaDetailsView>(), OnHistoryChange
|
|
|
|
override fun onDestroy() {
|
|
|
|
override fun onDestroy() {
|
|
|
|
HistoryRepository.unsubscribe(this)
|
|
|
|
HistoryRepository.unsubscribe(this)
|
|
|
|
FavouritesRepository.unsubscribe(this)
|
|
|
|
FavouritesRepository.unsubscribe(this)
|
|
|
|
|
|
|
|
instance = null
|
|
|
|
super.onDestroy()
|
|
|
|
super.onDestroy()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private var instance: MangaDetailsPresenter? = null
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun getInstance(): MangaDetailsPresenter = instance ?: synchronized(this) {
|
|
|
|
|
|
|
|
MangaDetailsPresenter().also {
|
|
|
|
|
|
|
|
instance = it
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|