|
|
|
@ -1,5 +1,6 @@
|
|
|
|
package org.koitharu.kotatsu.ui.details
|
|
|
|
package org.koitharu.kotatsu.ui.details
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.util.Log
|
|
|
|
import kotlinx.coroutines.CancellationException
|
|
|
|
import kotlinx.coroutines.CancellationException
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
import kotlinx.coroutines.flow.*
|
|
|
|
import kotlinx.coroutines.flow.*
|
|
|
|
@ -21,13 +22,13 @@ import org.koitharu.kotatsu.domain.history.HistoryRepository
|
|
|
|
import org.koitharu.kotatsu.domain.history.OnHistoryChangeListener
|
|
|
|
import org.koitharu.kotatsu.domain.history.OnHistoryChangeListener
|
|
|
|
import org.koitharu.kotatsu.domain.tracking.TrackingRepository
|
|
|
|
import org.koitharu.kotatsu.domain.tracking.TrackingRepository
|
|
|
|
import org.koitharu.kotatsu.ui.common.BasePresenter
|
|
|
|
import org.koitharu.kotatsu.ui.common.BasePresenter
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.ui.common.SharedPresenterHolder
|
|
|
|
import org.koitharu.kotatsu.utils.ext.safe
|
|
|
|
import org.koitharu.kotatsu.utils.ext.safe
|
|
|
|
import java.io.IOException
|
|
|
|
import java.io.IOException
|
|
|
|
|
|
|
|
|
|
|
|
@InjectViewState
|
|
|
|
@InjectViewState
|
|
|
|
class MangaDetailsPresenter private constructor() : BasePresenter<MangaDetailsView>(),
|
|
|
|
class MangaDetailsPresenter private constructor(private val key: Int) :
|
|
|
|
OnHistoryChangeListener,
|
|
|
|
BasePresenter<MangaDetailsView>(), OnHistoryChangeListener, OnFavouritesChangeListener {
|
|
|
|
OnFavouritesChangeListener {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private lateinit var historyRepository: HistoryRepository
|
|
|
|
private lateinit var historyRepository: HistoryRepository
|
|
|
|
private lateinit var favouritesRepository: FavouritesRepository
|
|
|
|
private lateinit var favouritesRepository: FavouritesRepository
|
|
|
|
@ -55,7 +56,7 @@ class MangaDetailsPresenter private constructor() : BasePresenter<MangaDetailsVi
|
|
|
|
} ?: throw MangaNotFoundException("Cannot find manga by id")
|
|
|
|
} ?: throw MangaNotFoundException("Cannot find manga by id")
|
|
|
|
viewState.onMangaUpdated(manga)
|
|
|
|
viewState.onMangaUpdated(manga)
|
|
|
|
loadDetails(manga, true)
|
|
|
|
loadDetails(manga, true)
|
|
|
|
} catch (_: CancellationException){
|
|
|
|
} catch (_: CancellationException) {
|
|
|
|
} catch (e: Throwable) {
|
|
|
|
} catch (e: Throwable) {
|
|
|
|
if (BuildConfig.DEBUG) {
|
|
|
|
if (BuildConfig.DEBUG) {
|
|
|
|
e.printStackTrace()
|
|
|
|
e.printStackTrace()
|
|
|
|
@ -83,7 +84,7 @@ class MangaDetailsPresenter private constructor() : BasePresenter<MangaDetailsVi
|
|
|
|
viewState.onMangaUpdated(data)
|
|
|
|
viewState.onMangaUpdated(data)
|
|
|
|
this@MangaDetailsPresenter.manga = data
|
|
|
|
this@MangaDetailsPresenter.manga = data
|
|
|
|
viewState.onNewChaptersChanged(trackingRepository.getNewChaptersCount(manga.id))
|
|
|
|
viewState.onNewChaptersChanged(trackingRepository.getNewChaptersCount(manga.id))
|
|
|
|
} catch (_: CancellationException){
|
|
|
|
} catch (_: CancellationException) {
|
|
|
|
} catch (e: Throwable) {
|
|
|
|
} catch (e: Throwable) {
|
|
|
|
if (BuildConfig.DEBUG) {
|
|
|
|
if (BuildConfig.DEBUG) {
|
|
|
|
e.printStackTrace()
|
|
|
|
e.printStackTrace()
|
|
|
|
@ -198,18 +199,12 @@ class MangaDetailsPresenter private constructor() : BasePresenter<MangaDetailsVi
|
|
|
|
override fun onDestroy() {
|
|
|
|
override fun onDestroy() {
|
|
|
|
HistoryRepository.unsubscribe(this)
|
|
|
|
HistoryRepository.unsubscribe(this)
|
|
|
|
FavouritesRepository.unsubscribe(this)
|
|
|
|
FavouritesRepository.unsubscribe(this)
|
|
|
|
instance = null
|
|
|
|
clear(key)
|
|
|
|
super.onDestroy()
|
|
|
|
super.onDestroy()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
companion object Holder : SharedPresenterHolder<MangaDetailsPresenter>() {
|
|
|
|
|
|
|
|
|
|
|
|
private var instance: MangaDetailsPresenter? = null
|
|
|
|
override fun onCreatePresenter(key: Int) = MangaDetailsPresenter(key)
|
|
|
|
|
|
|
|
|
|
|
|
fun getInstance(): MangaDetailsPresenter = instance ?: synchronized(this) {
|
|
|
|
|
|
|
|
MangaDetailsPresenter().also {
|
|
|
|
|
|
|
|
instance = it
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|