len vor 8 Jahren
Ursprung
Commit
e1a3ee1b81

+ 5 - 1
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)) }
     }
 

+ 12 - 0
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()
+    }
+
 }

+ 12 - 0
app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt

@@ -25,4 +25,16 @@ abstract class BaseRxActivity<P : BasePresenter<*>> : NucleusAppCompatActivity<P
 
     override fun getActivity() = this
 
+    var isResumed = false
+
+    override fun onResume() {
+        super.onResume()
+        isResumed = true
+    }
+
+    override fun onPause() {
+        isResumed = false
+        super.onPause()
+    }
+
 }

+ 4 - 2
app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadHolder.kt

@@ -48,8 +48,9 @@ class DownloadHolder(private val view: View) : RecyclerView.ViewHolder(view) {
      * Updates the progress bar of the download.
      */
     fun notifyProgress() {
+        val pages = download.pages ?: return
         if (view.download_progress.max == 1) {
-            view.download_progress.max = download.pages!!.size * 100
+            view.download_progress.max = pages.size * 100
         }
         view.download_progress.progress = download.totalProgress
     }
@@ -58,7 +59,8 @@ class DownloadHolder(private val view: View) : RecyclerView.ViewHolder(view) {
      * Updates the text field of the number of downloaded pages.
      */
     fun notifyDownloadedPages() {
-        view.download_progress_text.text = "${download.downloadedImages}/${download.pages!!.size}"
+        val pages = download.pages ?: return
+        view.download_progress_text.text = "${download.downloadedImages}/${pages.size}"
     }
 
 }

+ 3 - 1
app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt

@@ -94,7 +94,9 @@ class MainActivity : BaseActivity() {
     override fun onBackPressed() {
         val fragment = supportFragmentManager.findFragmentById(R.id.frame_container)
         if (fragment != null && fragment.tag.toInt() != startScreenId) {
-            setSelectedDrawerItem(startScreenId)
+            if (isResumed) {
+                setSelectedDrawerItem(startScreenId)
+            }
         } else {
             super.onBackPressed()
         }

+ 11 - 3
app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaActivity.kt

@@ -13,6 +13,7 @@ import eu.kanade.tachiyomi.ui.manga.chapter.ChaptersFragment
 import eu.kanade.tachiyomi.ui.manga.info.MangaInfoFragment
 import eu.kanade.tachiyomi.ui.manga.myanimelist.MyAnimeListFragment
 import eu.kanade.tachiyomi.util.SharedData
+import eu.kanade.tachiyomi.util.toast
 import kotlinx.android.synthetic.main.activity_manga.*
 import kotlinx.android.synthetic.main.toolbar.*
 import nucleus.factory.RequiresPresenter
@@ -50,12 +51,19 @@ class MangaActivity : BaseRxActivity<MangaPresenter>() {
 
         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)

+ 2 - 1
app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.kt

@@ -394,7 +394,8 @@ class ChaptersFragment : BaseRxFragment<ChaptersPresenter>(), ActionMode.Callbac
     }
 
     fun dismissDeletingDialog() {
-        (childFragmentManager.findFragmentByTag(DeletingChaptersDialog.TAG) as? DialogFragment)?.dismiss()
+        (childFragmentManager.findFragmentByTag(DeletingChaptersDialog.TAG) as? DialogFragment)
+                ?.dismissAllowingStateLoss()
     }
 
     override fun onListItemClick(position: Int): Boolean {

+ 3 - 0
app/src/main/res/values/strings.xml

@@ -226,6 +226,9 @@
     <string name="select_source">Select a source</string>
     <string name="no_valid_sources">Please enable at least one valid source</string>
 
+    <!-- Manga activity -->
+    <string name="manga_not_in_db">This manga was removed from the database!</string>
+
     <!-- Manga info fragment -->
     <string name="manga_detail_tab">Info</string>
     <string name="description">Description</string>