diff --git a/app/build.gradle b/app/build.gradle
index 3b36c4c74..cb7bff0d1 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -142,7 +142,7 @@ dependencies {
kapt "com.pushtorefresh.storio:sqlite-annotations-processor:$STORIO_VERSION"
// Model View Presenter
- compile 'info.android15.nucleus:nucleus:2.0.5'
+ compile 'info.android15.nucleus:nucleus:3.0.0-beta'
// Dependency injection
compile "com.google.dagger:dagger:$DAGGER_VERSION"
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.java b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.java
index ec5a12b5b..359254793 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.java
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.java
@@ -11,7 +11,6 @@ import nucleus.presenter.Presenter;
import nucleus.view.PresenterLifecycleDelegate;
import nucleus.view.ViewWithPresenter;
-
/**
* This class is an example of how an activity could controls it's presenter.
* You can inherit from this class or copy/paste this class's code to
@@ -87,8 +86,9 @@ public abstract class BaseRxActivity
extends BaseActivity i
}
@Override
- protected void onPause() {
- super.onPause();
- presenterDelegate.onPause(isFinishing());
+ protected void onDestroy() {
+ super.onDestroy();
+ presenterDelegate.onDropView();
+ presenterDelegate.onDestroy(!isChangingConfigurations());
}
}
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/fragment/BaseRxFragment.java b/app/src/main/java/eu/kanade/tachiyomi/ui/base/fragment/BaseRxFragment.java
index 84044cdc8..e03e6a1ca 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/fragment/BaseRxFragment.java
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/fragment/BaseRxFragment.java
@@ -1,7 +1,6 @@
package eu.kanade.tachiyomi.ui.base.fragment;
import android.os.Bundle;
-import android.support.v4.app.Fragment;
import eu.kanade.tachiyomi.App;
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter;
@@ -85,13 +84,14 @@ public abstract class BaseRxFragment
extends BaseFragment i
}
@Override
- public void onPause() {
- super.onPause();
- presenterDelegate.onPause(getActivity().isFinishing() || isRemoving(this));
+ public void onDestroyView() {
+ super.onDestroyView();
+ presenterDelegate.onDropView();
}
- private static boolean isRemoving(Fragment fragment) {
- Fragment parent = fragment.getParentFragment();
- return fragment.isRemoving() || (parent != null && isRemoving(parent));
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ presenterDelegate.onDestroy(!getActivity().isChangingConfigurations());
}
}
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueFragment.kt
index d7736dee6..3981f5a0f 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueFragment.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueFragment.kt
@@ -458,8 +458,7 @@ class CatalogueFragment : BaseRxFragment(), FlexibleViewHold
override fun onListItemClick(position: Int): Boolean {
val item = adapter.getItem(position) ?: return false
- val intent = MangaActivity.newIntent(activity, item)
- intent.putExtra(MangaActivity.FROM_CATALOGUE, true)
+ val intent = MangaActivity.newIntent(activity, item, true)
startActivity(intent)
return false
}
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaActivity.kt
index 00e74d7f7..ae325be9b 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaActivity.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaActivity.kt
@@ -23,21 +23,24 @@ class MangaActivity : BaseRxActivity() {
companion object {
- val FROM_CATALOGUE = "from_catalogue"
- val INFO_FRAGMENT = 0
- val CHAPTERS_FRAGMENT = 1
- val MYANIMELIST_FRAGMENT = 2
+ const val FROM_CATALOGUE_EXTRA = "from_catalogue"
+ const val MANGA_EXTRA = "manga"
+ const val INFO_FRAGMENT = 0
+ const val CHAPTERS_FRAGMENT = 1
+ const val MYANIMELIST_FRAGMENT = 2
- fun newIntent(context: Context, manga: Manga): Intent {
- val intent = Intent(context, MangaActivity::class.java)
+ fun newIntent(context: Context, manga: Manga, fromCatalogue: Boolean = false): Intent {
SharedData.put(MangaEvent(manga))
- return intent
+ return Intent(context, MangaActivity::class.java).apply {
+ putExtra(FROM_CATALOGUE_EXTRA, fromCatalogue)
+ putExtra(MANGA_EXTRA, manga.id)
+ }
}
}
private lateinit var adapter: MangaDetailAdapter
- var isCatalogueManga: Boolean = false
+ var fromCatalogue: Boolean = false
private set
override fun onCreate(savedState: Bundle?) {
@@ -45,16 +48,21 @@ class MangaActivity : BaseRxActivity() {
super.onCreate(savedState)
setContentView(R.layout.activity_manga)
+ presenter.setMangaEvent(SharedData.getOrPut(MangaEvent::class.java) {
+ val id = intent.getLongExtra(MANGA_EXTRA, 0)
+ MangaEvent(presenter.db.getManga(id).executeAsBlocking()!!)
+ })
+
setupToolbar(toolbar)
- isCatalogueManga = intent.getBooleanExtra(FROM_CATALOGUE, false)
+ fromCatalogue = intent.getBooleanExtra(FROM_CATALOGUE_EXTRA, false)
adapter = MangaDetailAdapter(supportFragmentManager, this)
view_pager.adapter = adapter
tabs.setupWithViewPager(view_pager)
- if (!isCatalogueManga)
+ if (!fromCatalogue)
view_pager.currentItem = CHAPTERS_FRAGMENT
requestPermissionsOnMarshmallow()
@@ -72,7 +80,7 @@ class MangaActivity : BaseRxActivity() {
init {
pageCount = 2
- if (!activity.isCatalogueManga && activity.presenter.syncManager.myAnimeList.isLogged)
+ if (!activity.fromCatalogue && activity.presenter.syncManager.myAnimeList.isLogged)
pageCount++
}
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt
index 825eba8cf..5cc19fe07 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt
@@ -9,6 +9,7 @@ import eu.kanade.tachiyomi.event.MangaEvent
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
import eu.kanade.tachiyomi.util.SharedData
import rx.Observable
+import rx.Subscription
import javax.inject.Inject
/**
@@ -31,37 +32,21 @@ class MangaPresenter : BasePresenter() {
*/
lateinit var manga: Manga
- /**
- * Key to save and restore [manga] from a bundle.
- */
- private val MANGA_KEY = "manga_key"
+ var mangaSubscription: Subscription? = null
override fun onCreate(savedState: Bundle?) {
super.onCreate(savedState)
- if (savedState == null) {
- manga = SharedData.get(MangaEvent::class.java)!!.manga
- } else {
- manga = savedState.getSerializable(MANGA_KEY) as Manga
- SharedData.put(MangaEvent(manga))
- }
-
// Prepare a subject to communicate the chapters and info presenters for the chapter count.
SharedData.put(ChapterCountEvent())
-
- Observable.just(manga)
- .subscribeLatestCache({ view, manga -> view.onSetManga(manga) })
}
- override fun onDestroy() {
- SharedData.remove(MangaEvent::class.java)
- SharedData.remove(ChapterCountEvent::class.java)
- super.onDestroy()
- }
-
- override fun onSave(state: Bundle) {
- state.putSerializable(MANGA_KEY, manga)
- super.onSave(state)
+ fun setMangaEvent(event: MangaEvent) {
+ if (isUnsubscribed(mangaSubscription)) {
+ manga = event.manga
+ mangaSubscription = Observable.just(manga)
+ .subscribeLatestCache({ view, manga -> view.onSetManga(manga) })
+ }
}
}
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 c70d7f3fe..ca59d0bbc 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
@@ -181,11 +181,10 @@ class ChaptersFragment : BaseRxFragment(), ActionMode.Callbac
}
val isCatalogueManga: Boolean
- get() = (activity as MangaActivity).isCatalogueManga
+ get() = (activity as MangaActivity).fromCatalogue
fun openChapter(chapter: Chapter, hasAnimation: Boolean = false) {
- presenter.onOpenChapter(chapter)
- val intent = ReaderActivity.newIntent(activity)
+ val intent = ReaderActivity.newIntent(activity, presenter.manga, chapter)
if (hasAnimation) {
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION)
}
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt
index 38eb5be3d..ea83b97c6 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt
@@ -159,10 +159,6 @@ class ChaptersPresenter : BasePresenter() {
refreshChapters()
}
- fun onOpenChapter(chapter: Chapter) {
- SharedData.put(ReaderEvent(manga, chapter))
- }
-
fun getNextUnreadChapter(): Chapter? {
return db.getNextUnreadChapter(manga).executeAsBlocking()
}
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt
index bf359d5ea..86ee4d628 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt
@@ -21,6 +21,7 @@ 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.model.Page
+import eu.kanade.tachiyomi.event.ReaderEvent
import eu.kanade.tachiyomi.ui.base.activity.BaseRxActivity
import eu.kanade.tachiyomi.ui.base.listener.SimpleAnimationListener
import eu.kanade.tachiyomi.ui.base.listener.SimpleSeekBarListener
@@ -30,6 +31,7 @@ import eu.kanade.tachiyomi.ui.reader.viewer.pager.horizontal.RightToLeftReader
import eu.kanade.tachiyomi.ui.reader.viewer.pager.vertical.VerticalReader
import eu.kanade.tachiyomi.ui.reader.viewer.webtoon.WebtoonReader
import eu.kanade.tachiyomi.util.GLUtil
+import eu.kanade.tachiyomi.util.SharedData
import eu.kanade.tachiyomi.util.toast
import kotlinx.android.synthetic.main.activity_reader.*
import kotlinx.android.synthetic.main.reader_menu.*
@@ -53,7 +55,8 @@ class ReaderActivity : BaseRxActivity() {
const val MENU_VISIBLE = "menu_visible"
- fun newIntent(context: Context): Intent {
+ fun newIntent(context: Context, manga: Manga, chapter: Chapter): Intent {
+ SharedData.put(ReaderEvent(manga, chapter))
return Intent(context, ReaderActivity::class.java)
}
}
@@ -90,6 +93,11 @@ class ReaderActivity : BaseRxActivity() {
super.onCreate(savedState)
setContentView(R.layout.activity_reader)
+ if (savedState == null && SharedData.get(ReaderEvent::class.java) == null) {
+ finish()
+ return
+ }
+
setupToolbar(toolbar)
subscriptions = CompositeSubscription()
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt
index 70d522c96..748afa58d 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt
@@ -71,7 +71,7 @@ class ReaderPresenter : BasePresenter() {
super.onCreate(savedState)
if (savedState == null) {
- val event = SharedData.remove(ReaderEvent::class.java) ?: return
+ val event = SharedData.get(ReaderEvent::class.java) ?: return
manga = event.manga
chapter = event.chapter
} else {
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersFragment.kt
index fbaa5c7cb..a84b86f53 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersFragment.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersFragment.kt
@@ -103,21 +103,17 @@ class RecentChaptersFragment : BaseRxFragment(), Flexib
/**
* Open chapter in reader
-
+ *
* @param chapter selected chapter
*/
private fun openChapter(chapter: MangaChapter) {
- // Start reader event
- presenter.onOpenChapter(chapter)
-
- //Start reader intent
- val intent = ReaderActivity.newIntent(activity)
+ val intent = ReaderActivity.newIntent(activity, chapter.manga, chapter.chapter)
startActivity(intent)
}
/**
* Populate adapter with chapters
-
+ *
* @param chapters list of chapters
*/
fun onNextMangaChapters(chapters: List) {
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersPresenter.kt
index 0fbd17a23..97e5ee33d 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersPresenter.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersPresenter.kt
@@ -10,9 +10,7 @@ import eu.kanade.tachiyomi.data.download.model.Download
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.source.SourceManager
import eu.kanade.tachiyomi.event.DownloadChaptersEvent
-import eu.kanade.tachiyomi.event.ReaderEvent
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
-import eu.kanade.tachiyomi.util.SharedData
import rx.Observable
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
@@ -251,14 +249,6 @@ class RecentChaptersPresenter : BasePresenter() {
return cal.time
}
- /**
- * Open chapter in reader
- * @param item chapter that is opened
- */
- fun onOpenChapter(item: MangaChapter) {
- SharedData.put(ReaderEvent(item.manga, item.chapter))
- }
-
/**
* Download selected chapter
* @param selectedChapter chapter that is selected
diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/SharedData.kt b/app/src/main/java/eu/kanade/tachiyomi/util/SharedData.kt
index 6c0daedc2..98d10b2d4 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/util/SharedData.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/util/SharedData.kt
@@ -14,7 +14,7 @@ object SharedData {
/**
* Map where the objects are saved.
*/
- private val map = HashMap, Any>()
+ val map = HashMap, Any>()
/**
* Publish an object to the shared data.
@@ -42,4 +42,14 @@ object SharedData {
*/
fun remove(classType: Class) = get(classType)?.apply { map.remove(classType) }
+ /**
+ * Returns an object from the shared data or introduces a new one with the given function.
+ *
+ * @param classType the class of the object to retrieve.
+ * @param fn the function to execute if it didn't find the object.
+ * @return an object of type T.
+ */
+ @Suppress("UNCHECKED_CAST")
+ inline fun getOrPut(classType: Class, fn: () -> T) = map.getOrPut(classType, fn) as T
+
}