diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadProvider.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadProvider.kt index 79eabc70b0..018126b900 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadProvider.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadProvider.kt @@ -6,6 +6,7 @@ import com.hippo.unifile.UniFile import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.source.Source import eu.kanade.tachiyomi.util.DiskUtil import uy.kohesive.injekt.injectLazy @@ -26,10 +27,13 @@ class DownloadProvider(private val context: Context) { /** * The root directory for downloads. */ - private lateinit var downloadsDir: UniFile + private var downloadsDir = preferences.downloadsDirectory().getOrDefault().let { + UniFile.fromUri(context, Uri.parse(it)) + } init { preferences.downloadsDirectory().asObservable() + .skip(1) .subscribe { downloadsDir = UniFile.fromUri(context, Uri.parse(it)) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt index 751818c82e..cb36629478 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt @@ -11,4 +11,16 @@ abstract class BaseActivity : AppCompatActivity(), ActivityMixin { override fun getActivity() = this + var isResumed = false + + override fun onResume() { + super.onResume() + isResumed = true + } + + override fun onPause() { + isResumed = false + super.onPause() + } + } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt index 59aa6b961d..0b480cd41e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt @@ -25,4 +25,16 @@ abstract class BaseRxActivity
> : NucleusAppCompatActivity
() {
val fromLauncher = intent.getBooleanExtra(FROM_LAUNCHER_EXTRA, false)
- //Remove any current manga if we are launching from launcher
- if(fromLauncher) SharedData.remove(MangaEvent::class.java)
+ // Remove any current manga if we are launching from launcher
+ if (fromLauncher) SharedData.remove(MangaEvent::class.java)
presenter.setMangaEvent(SharedData.getOrPut(MangaEvent::class.java) {
val id = intent.getLongExtra(MANGA_EXTRA, 0)
- MangaEvent(presenter.db.getManga(id).executeAsBlocking()!!)
+ val dbManga = presenter.db.getManga(id).executeAsBlocking()
+ if (dbManga != null) {
+ MangaEvent(dbManga)
+ } else {
+ toast(R.string.manga_not_in_db)
+ finish()
+ return
+ }
})
setupToolbar(toolbar)
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.kt
index 2fe17d0526..04cb5bac0f 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.kt
@@ -394,7 +394,8 @@ class ChaptersFragment : BaseRxFragment