Upgrade to nucleus 3
This commit is contained in:
parent
50ae08ed8d
commit
9f0da3f1d6
@ -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"
|
||||
|
@ -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<P extends Presenter> extends BaseActivity i
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
presenterDelegate.onPause(isFinishing());
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
presenterDelegate.onDropView();
|
||||
presenterDelegate.onDestroy(!isChangingConfigurations());
|
||||
}
|
||||
}
|
||||
|
@ -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<P extends Presenter> 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());
|
||||
}
|
||||
}
|
||||
|
@ -458,8 +458,7 @@ class CatalogueFragment : BaseRxFragment<CataloguePresenter>(), 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
|
||||
}
|
||||
|
@ -23,21 +23,24 @@ class MangaActivity : BaseRxActivity<MangaPresenter>() {
|
||||
|
||||
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<MangaPresenter>() {
|
||||
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<MangaPresenter>() {
|
||||
|
||||
init {
|
||||
pageCount = 2
|
||||
if (!activity.isCatalogueManga && activity.presenter.syncManager.myAnimeList.isLogged)
|
||||
if (!activity.fromCatalogue && activity.presenter.syncManager.myAnimeList.isLogged)
|
||||
pageCount++
|
||||
}
|
||||
|
||||
|
@ -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<MangaActivity>() {
|
||||
*/
|
||||
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) })
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -181,11 +181,10 @@ class ChaptersFragment : BaseRxFragment<ChaptersPresenter>(), 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)
|
||||
}
|
||||
|
@ -159,10 +159,6 @@ class ChaptersPresenter : BasePresenter<ChaptersFragment>() {
|
||||
refreshChapters()
|
||||
}
|
||||
|
||||
fun onOpenChapter(chapter: Chapter) {
|
||||
SharedData.put(ReaderEvent(manga, chapter))
|
||||
}
|
||||
|
||||
fun getNextUnreadChapter(): Chapter? {
|
||||
return db.getNextUnreadChapter(manga).executeAsBlocking()
|
||||
}
|
||||
|
@ -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<ReaderPresenter>() {
|
||||
|
||||
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<ReaderPresenter>() {
|
||||
super.onCreate(savedState)
|
||||
setContentView(R.layout.activity_reader)
|
||||
|
||||
if (savedState == null && SharedData.get(ReaderEvent::class.java) == null) {
|
||||
finish()
|
||||
return
|
||||
}
|
||||
|
||||
setupToolbar(toolbar)
|
||||
subscriptions = CompositeSubscription()
|
||||
|
||||
|
@ -71,7 +71,7 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
|
||||
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 {
|
||||
|
@ -103,21 +103,17 @@ class RecentChaptersFragment : BaseRxFragment<RecentChaptersPresenter>(), 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<Any>) {
|
||||
|
@ -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<RecentChaptersFragment>() {
|
||||
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
|
||||
|
@ -14,7 +14,7 @@ object SharedData {
|
||||
/**
|
||||
* Map where the objects are saved.
|
||||
*/
|
||||
private val map = HashMap<Class<*>, Any>()
|
||||
val map = HashMap<Class<*>, Any>()
|
||||
|
||||
/**
|
||||
* Publish an object to the shared data.
|
||||
@ -42,4 +42,14 @@ object SharedData {
|
||||
*/
|
||||
fun <T : Any> remove(classType: Class<T>) = 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 <T : Any> getOrPut(classType: Class<T>, fn: () -> T) = map.getOrPut(classType, fn) as T
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user