Remove unnecessary base Nucleus classes

The reader still uses it, but we just move stuff to there.
This commit is contained in:
arkon
2022-12-02 13:23:26 -05:00
parent 5b189a909b
commit 5313a5d5d2
13 changed files with 48 additions and 251 deletions
@@ -44,13 +44,17 @@ import com.google.android.material.slider.Slider
import com.google.android.material.transition.platform.MaterialContainerTransform
import com.google.android.material.transition.platform.MaterialContainerTransformSharedElementCallback
import dev.chrisbanes.insetter.applyInsetter
import eu.kanade.domain.base.BasePreferences
import eu.kanade.tachiyomi.BuildConfig
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.databinding.ReaderActivityBinding
import eu.kanade.tachiyomi.ui.base.activity.BaseRxActivity
import eu.kanade.tachiyomi.ui.base.delegate.SecureActivityDelegate
import eu.kanade.tachiyomi.ui.base.delegate.SecureActivityDelegateImpl
import eu.kanade.tachiyomi.ui.base.delegate.ThemingDelegate
import eu.kanade.tachiyomi.ui.base.delegate.ThemingDelegateImpl
import eu.kanade.tachiyomi.ui.main.MainActivity
import eu.kanade.tachiyomi.ui.manga.MangaController
import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.AddToLibraryFirst
@@ -74,6 +78,7 @@ import eu.kanade.tachiyomi.util.system.getThemeColor
import eu.kanade.tachiyomi.util.system.hasDisplayCutout
import eu.kanade.tachiyomi.util.system.isNightMode
import eu.kanade.tachiyomi.util.system.logcat
import eu.kanade.tachiyomi.util.system.prepareTabletUiContext
import eu.kanade.tachiyomi.util.system.toShareIntent
import eu.kanade.tachiyomi.util.system.toast
import eu.kanade.tachiyomi.util.view.copy
@@ -87,6 +92,7 @@ import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.sample
import logcat.LogPriority
import nucleus.factory.RequiresPresenter
import nucleus.view.NucleusAppCompatActivity
import uy.kohesive.injekt.injectLazy
import kotlin.math.abs
import kotlin.math.max
@@ -96,10 +102,12 @@ import kotlin.math.max
* viewers, to which calls from the presenter or UI events are delegated.
*/
@RequiresPresenter(ReaderPresenter::class)
class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
class ReaderActivity :
NucleusAppCompatActivity<ReaderPresenter>(),
SecureActivityDelegate by SecureActivityDelegateImpl(),
ThemingDelegate by ThemingDelegateImpl() {
companion object {
fun newIntent(context: Context, mangaId: Long?, chapterId: Long?): Intent {
return Intent(context, ReaderActivity::class.java).apply {
putExtra("manga", mangaId)
@@ -116,6 +124,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
}
private val readerPreferences: ReaderPreferences by injectLazy()
private val preferences: BasePreferences by injectLazy()
lateinit var binding: ReaderActivityBinding
@@ -155,10 +164,15 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
var isScrollingThroughPages = false
private set
override fun attachBaseContext(newBase: Context) {
super.attachBaseContext(newBase.prepareTabletUiContext())
}
/**
* Called when the activity is created. Initializes the presenter and configuration.
*/
override fun onCreate(savedInstanceState: Bundle?) {
applyAppTheme(this)
registerSecureActivity(this)
// Setup shared element transitions
@@ -37,7 +37,6 @@ import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
import eu.kanade.tachiyomi.ui.reader.loader.ChapterLoader
import eu.kanade.tachiyomi.ui.reader.loader.DownloadPageLoader
import eu.kanade.tachiyomi.ui.reader.loader.HttpPageLoader
@@ -60,17 +59,20 @@ import eu.kanade.tachiyomi.util.storage.DiskUtil
import eu.kanade.tachiyomi.util.storage.cacheImageDir
import eu.kanade.tachiyomi.util.system.isOnline
import eu.kanade.tachiyomi.util.system.logcat
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.cancel
import kotlinx.coroutines.runBlocking
import logcat.LogPriority
import nucleus.presenter.RxPresenter
import rx.Observable
import rx.Subscription
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
import java.util.Date
import java.util.concurrent.TimeUnit
import eu.kanade.domain.manga.model.Manga as DomainManga
@@ -82,6 +84,7 @@ class ReaderPresenter(
private val sourceManager: SourceManager = Injekt.get(),
private val downloadManager: DownloadManager = Injekt.get(),
private val downloadProvider: DownloadProvider = Injekt.get(),
private val imageSaver: ImageSaver = Injekt.get(),
preferences: BasePreferences = Injekt.get(),
private val downloadPreferences: DownloadPreferences = Injekt.get(),
private val readerPreferences: ReaderPreferences = Injekt.get(),
@@ -95,7 +98,9 @@ class ReaderPresenter(
private val upsertHistory: UpsertHistory = Injekt.get(),
private val updateChapter: UpdateChapter = Injekt.get(),
private val setMangaViewerFlags: SetMangaViewerFlags = Injekt.get(),
) : BasePresenter<ReaderActivity>() {
) : RxPresenter<ReaderActivity>() {
private val coroutineScope: CoroutineScope = MainScope()
/**
* The manga loaded in the reader. It can be null when instantiated for a short time.
@@ -133,8 +138,6 @@ class ReaderPresenter(
*/
private val isLoadingAdjacentChapterRelay = BehaviorRelay.create<Boolean>()
private val imageSaver: ImageSaver by injectLazy()
private var chapterToDownload: Download? = null
/**
@@ -205,6 +208,7 @@ class ReaderPresenter(
*/
override fun onDestroy() {
super.onDestroy()
coroutineScope.cancel()
val currentChapters = viewerChaptersRelay.value
if (currentChapters != null) {
currentChapters.unref()
@@ -242,7 +246,7 @@ class ReaderPresenter(
*/
fun onSaveInstanceStateNonConfigurationChange() {
val currentChapter = getCurrentChapter() ?: return
presenterScope.launchNonCancellable {
coroutineScope.launchNonCancellable {
saveChapterProgress(currentChapter)
}
}
@@ -261,7 +265,7 @@ class ReaderPresenter(
fun init(mangaId: Long, initialChapterId: Long) {
if (!needsInit()) return
presenterScope.launchIO {
coroutineScope.launchIO {
try {
val manga = getManga.await(mangaId)
withUIContext {
@@ -467,7 +471,7 @@ class ReaderPresenter(
if (getCurrentChapter()?.pageLoader !is DownloadPageLoader) return
val nextChapter = viewerChaptersRelay.value?.nextChapter?.chapter ?: return
presenterScope.launchIO {
coroutineScope.launchIO {
val isNextChapterDownloaded = downloadManager.isChapterDownloaded(
nextChapter.name,
nextChapter.scanlator,
@@ -523,7 +527,7 @@ class ReaderPresenter(
* Called when reader chapter is changed in reader or when activity is paused.
*/
private fun saveReadingProgress(readerChapter: ReaderChapter) {
presenterScope.launchNonCancellable {
coroutineScope.launchNonCancellable {
saveChapterProgress(readerChapter)
saveChapterHistory(readerChapter)
}
@@ -613,7 +617,7 @@ class ReaderPresenter(
fun bookmarkCurrentChapter(bookmarked: Boolean) {
val chapter = getCurrentChapter()?.chapter ?: return
chapter.bookmark = bookmarked // Otherwise the bookmark icon doesn't update
presenterScope.launchNonCancellable {
coroutineScope.launchNonCancellable {
updateChapter.await(
ChapterUpdate(
id = chapter.id!!.toLong(),
@@ -726,7 +730,7 @@ class ReaderPresenter(
// Copy file in background.
try {
presenterScope.launchNonCancellable {
coroutineScope.launchNonCancellable {
val uri = imageSaver.save(
image = Image.Page(
inputStream = page.stream!!,
@@ -762,7 +766,7 @@ class ReaderPresenter(
val filename = generateFilename(manga, page)
try {
presenterScope.launchNonCancellable {
coroutineScope.launchNonCancellable {
destDir.deleteRecursively()
val uri = imageSaver.save(
image = Image.Page(
@@ -788,7 +792,7 @@ class ReaderPresenter(
val manga = manga?.toDomainManga() ?: return
val stream = page.stream ?: return
presenterScope.launchNonCancellable {
coroutineScope.launchNonCancellable {
try {
manga.editCover(context, stream())
withUIContext {
@@ -834,7 +838,7 @@ class ReaderPresenter(
val trackManager = Injekt.get<TrackManager>()
val context = Injekt.get<Application>()
presenterScope.launchNonCancellable {
coroutineScope.launchNonCancellable {
getTracks.await(manga.id!!)
.mapNotNull { track ->
val service = trackManager.getService(track.syncId)
@@ -874,7 +878,7 @@ class ReaderPresenter(
if (!chapter.chapter.read) return
val manga = manga ?: return
presenterScope.launchNonCancellable {
coroutineScope.launchNonCancellable {
downloadManager.enqueueChaptersToDelete(listOf(chapter.chapter.toDomainChapter()!!), manga.toDomainManga()!!)
}
}
@@ -884,11 +888,17 @@ class ReaderPresenter(
* are ignored.
*/
private fun deletePendingChapters() {
presenterScope.launchNonCancellable {
coroutineScope.launchNonCancellable {
downloadManager.deletePendingChapters()
}
}
// We're trying to avoid using Rx, so we "undeprecate" this
@Suppress("DEPRECATION")
override fun getView(): ReaderActivity? {
return super.getView()
}
/**
* Subscribes an observable with [deliverFirst] and adds it to the presenter's lifecycle
* subscription list.