mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Upgrade to nucleus 3
This commit is contained in:
parent
50ae08ed8d
commit
9f0da3f1d6
13 changed files with 66 additions and 75 deletions
|
@ -142,7 +142,7 @@ dependencies {
|
||||||
kapt "com.pushtorefresh.storio:sqlite-annotations-processor:$STORIO_VERSION"
|
kapt "com.pushtorefresh.storio:sqlite-annotations-processor:$STORIO_VERSION"
|
||||||
|
|
||||||
// Model View Presenter
|
// Model View Presenter
|
||||||
compile 'info.android15.nucleus:nucleus:2.0.5'
|
compile 'info.android15.nucleus:nucleus:3.0.0-beta'
|
||||||
|
|
||||||
// Dependency injection
|
// Dependency injection
|
||||||
compile "com.google.dagger:dagger:$DAGGER_VERSION"
|
compile "com.google.dagger:dagger:$DAGGER_VERSION"
|
||||||
|
|
|
@ -11,7 +11,6 @@ import nucleus.presenter.Presenter;
|
||||||
import nucleus.view.PresenterLifecycleDelegate;
|
import nucleus.view.PresenterLifecycleDelegate;
|
||||||
import nucleus.view.ViewWithPresenter;
|
import nucleus.view.ViewWithPresenter;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is an example of how an activity could controls it's presenter.
|
* 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
|
* 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
|
@Override
|
||||||
protected void onPause() {
|
protected void onDestroy() {
|
||||||
super.onPause();
|
super.onDestroy();
|
||||||
presenterDelegate.onPause(isFinishing());
|
presenterDelegate.onDropView();
|
||||||
|
presenterDelegate.onDestroy(!isChangingConfigurations());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package eu.kanade.tachiyomi.ui.base.fragment;
|
package eu.kanade.tachiyomi.ui.base.fragment;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
|
||||||
|
|
||||||
import eu.kanade.tachiyomi.App;
|
import eu.kanade.tachiyomi.App;
|
||||||
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter;
|
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter;
|
||||||
|
@ -85,13 +84,14 @@ public abstract class BaseRxFragment<P extends Presenter> extends BaseFragment i
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onDestroyView() {
|
||||||
super.onPause();
|
super.onDestroyView();
|
||||||
presenterDelegate.onPause(getActivity().isFinishing() || isRemoving(this));
|
presenterDelegate.onDropView();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isRemoving(Fragment fragment) {
|
@Override
|
||||||
Fragment parent = fragment.getParentFragment();
|
public void onDestroy() {
|
||||||
return fragment.isRemoving() || (parent != null && isRemoving(parent));
|
super.onDestroy();
|
||||||
|
presenterDelegate.onDestroy(!getActivity().isChangingConfigurations());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -458,8 +458,7 @@ class CatalogueFragment : BaseRxFragment<CataloguePresenter>(), FlexibleViewHold
|
||||||
override fun onListItemClick(position: Int): Boolean {
|
override fun onListItemClick(position: Int): Boolean {
|
||||||
val item = adapter.getItem(position) ?: return false
|
val item = adapter.getItem(position) ?: return false
|
||||||
|
|
||||||
val intent = MangaActivity.newIntent(activity, item)
|
val intent = MangaActivity.newIntent(activity, item, true)
|
||||||
intent.putExtra(MangaActivity.FROM_CATALOGUE, true)
|
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,21 +23,24 @@ class MangaActivity : BaseRxActivity<MangaPresenter>() {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
val FROM_CATALOGUE = "from_catalogue"
|
const val FROM_CATALOGUE_EXTRA = "from_catalogue"
|
||||||
val INFO_FRAGMENT = 0
|
const val MANGA_EXTRA = "manga"
|
||||||
val CHAPTERS_FRAGMENT = 1
|
const val INFO_FRAGMENT = 0
|
||||||
val MYANIMELIST_FRAGMENT = 2
|
const val CHAPTERS_FRAGMENT = 1
|
||||||
|
const val MYANIMELIST_FRAGMENT = 2
|
||||||
|
|
||||||
fun newIntent(context: Context, manga: Manga): Intent {
|
fun newIntent(context: Context, manga: Manga, fromCatalogue: Boolean = false): Intent {
|
||||||
val intent = Intent(context, MangaActivity::class.java)
|
|
||||||
SharedData.put(MangaEvent(manga))
|
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
|
private lateinit var adapter: MangaDetailAdapter
|
||||||
|
|
||||||
var isCatalogueManga: Boolean = false
|
var fromCatalogue: Boolean = false
|
||||||
private set
|
private set
|
||||||
|
|
||||||
override fun onCreate(savedState: Bundle?) {
|
override fun onCreate(savedState: Bundle?) {
|
||||||
|
@ -45,16 +48,21 @@ class MangaActivity : BaseRxActivity<MangaPresenter>() {
|
||||||
super.onCreate(savedState)
|
super.onCreate(savedState)
|
||||||
setContentView(R.layout.activity_manga)
|
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)
|
setupToolbar(toolbar)
|
||||||
|
|
||||||
isCatalogueManga = intent.getBooleanExtra(FROM_CATALOGUE, false)
|
fromCatalogue = intent.getBooleanExtra(FROM_CATALOGUE_EXTRA, false)
|
||||||
|
|
||||||
adapter = MangaDetailAdapter(supportFragmentManager, this)
|
adapter = MangaDetailAdapter(supportFragmentManager, this)
|
||||||
view_pager.adapter = adapter
|
view_pager.adapter = adapter
|
||||||
|
|
||||||
tabs.setupWithViewPager(view_pager)
|
tabs.setupWithViewPager(view_pager)
|
||||||
|
|
||||||
if (!isCatalogueManga)
|
if (!fromCatalogue)
|
||||||
view_pager.currentItem = CHAPTERS_FRAGMENT
|
view_pager.currentItem = CHAPTERS_FRAGMENT
|
||||||
|
|
||||||
requestPermissionsOnMarshmallow()
|
requestPermissionsOnMarshmallow()
|
||||||
|
@ -72,7 +80,7 @@ class MangaActivity : BaseRxActivity<MangaPresenter>() {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
pageCount = 2
|
pageCount = 2
|
||||||
if (!activity.isCatalogueManga && activity.presenter.syncManager.myAnimeList.isLogged)
|
if (!activity.fromCatalogue && activity.presenter.syncManager.myAnimeList.isLogged)
|
||||||
pageCount++
|
pageCount++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import eu.kanade.tachiyomi.event.MangaEvent
|
||||||
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
||||||
import eu.kanade.tachiyomi.util.SharedData
|
import eu.kanade.tachiyomi.util.SharedData
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
|
import rx.Subscription
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,37 +32,21 @@ class MangaPresenter : BasePresenter<MangaActivity>() {
|
||||||
*/
|
*/
|
||||||
lateinit var manga: Manga
|
lateinit var manga: Manga
|
||||||
|
|
||||||
/**
|
var mangaSubscription: Subscription? = null
|
||||||
* Key to save and restore [manga] from a bundle.
|
|
||||||
*/
|
|
||||||
private val MANGA_KEY = "manga_key"
|
|
||||||
|
|
||||||
override fun onCreate(savedState: Bundle?) {
|
override fun onCreate(savedState: Bundle?) {
|
||||||
super.onCreate(savedState)
|
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.
|
// Prepare a subject to communicate the chapters and info presenters for the chapter count.
|
||||||
SharedData.put(ChapterCountEvent())
|
SharedData.put(ChapterCountEvent())
|
||||||
|
}
|
||||||
|
|
||||||
Observable.just(manga)
|
fun setMangaEvent(event: MangaEvent) {
|
||||||
|
if (isUnsubscribed(mangaSubscription)) {
|
||||||
|
manga = event.manga
|
||||||
|
mangaSubscription = Observable.just(manga)
|
||||||
.subscribeLatestCache({ view, manga -> view.onSetManga(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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,11 +181,10 @@ class ChaptersFragment : BaseRxFragment<ChaptersPresenter>(), ActionMode.Callbac
|
||||||
}
|
}
|
||||||
|
|
||||||
val isCatalogueManga: Boolean
|
val isCatalogueManga: Boolean
|
||||||
get() = (activity as MangaActivity).isCatalogueManga
|
get() = (activity as MangaActivity).fromCatalogue
|
||||||
|
|
||||||
fun openChapter(chapter: Chapter, hasAnimation: Boolean = false) {
|
fun openChapter(chapter: Chapter, hasAnimation: Boolean = false) {
|
||||||
presenter.onOpenChapter(chapter)
|
val intent = ReaderActivity.newIntent(activity, presenter.manga, chapter)
|
||||||
val intent = ReaderActivity.newIntent(activity)
|
|
||||||
if (hasAnimation) {
|
if (hasAnimation) {
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION)
|
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION)
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,10 +159,6 @@ class ChaptersPresenter : BasePresenter<ChaptersFragment>() {
|
||||||
refreshChapters()
|
refreshChapters()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onOpenChapter(chapter: Chapter) {
|
|
||||||
SharedData.put(ReaderEvent(manga, chapter))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getNextUnreadChapter(): Chapter? {
|
fun getNextUnreadChapter(): Chapter? {
|
||||||
return db.getNextUnreadChapter(manga).executeAsBlocking()
|
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.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||||
import eu.kanade.tachiyomi.data.source.model.Page
|
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.activity.BaseRxActivity
|
||||||
import eu.kanade.tachiyomi.ui.base.listener.SimpleAnimationListener
|
import eu.kanade.tachiyomi.ui.base.listener.SimpleAnimationListener
|
||||||
import eu.kanade.tachiyomi.ui.base.listener.SimpleSeekBarListener
|
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.pager.vertical.VerticalReader
|
||||||
import eu.kanade.tachiyomi.ui.reader.viewer.webtoon.WebtoonReader
|
import eu.kanade.tachiyomi.ui.reader.viewer.webtoon.WebtoonReader
|
||||||
import eu.kanade.tachiyomi.util.GLUtil
|
import eu.kanade.tachiyomi.util.GLUtil
|
||||||
|
import eu.kanade.tachiyomi.util.SharedData
|
||||||
import eu.kanade.tachiyomi.util.toast
|
import eu.kanade.tachiyomi.util.toast
|
||||||
import kotlinx.android.synthetic.main.activity_reader.*
|
import kotlinx.android.synthetic.main.activity_reader.*
|
||||||
import kotlinx.android.synthetic.main.reader_menu.*
|
import kotlinx.android.synthetic.main.reader_menu.*
|
||||||
|
@ -53,7 +55,8 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
||||||
|
|
||||||
const val MENU_VISIBLE = "menu_visible"
|
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)
|
return Intent(context, ReaderActivity::class.java)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,6 +93,11 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
||||||
super.onCreate(savedState)
|
super.onCreate(savedState)
|
||||||
setContentView(R.layout.activity_reader)
|
setContentView(R.layout.activity_reader)
|
||||||
|
|
||||||
|
if (savedState == null && SharedData.get(ReaderEvent::class.java) == null) {
|
||||||
|
finish()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
setupToolbar(toolbar)
|
setupToolbar(toolbar)
|
||||||
subscriptions = CompositeSubscription()
|
subscriptions = CompositeSubscription()
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
|
||||||
super.onCreate(savedState)
|
super.onCreate(savedState)
|
||||||
|
|
||||||
if (savedState == null) {
|
if (savedState == null) {
|
||||||
val event = SharedData.remove(ReaderEvent::class.java) ?: return
|
val event = SharedData.get(ReaderEvent::class.java) ?: return
|
||||||
manga = event.manga
|
manga = event.manga
|
||||||
chapter = event.chapter
|
chapter = event.chapter
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -103,21 +103,17 @@ class RecentChaptersFragment : BaseRxFragment<RecentChaptersPresenter>(), Flexib
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open chapter in reader
|
* Open chapter in reader
|
||||||
|
*
|
||||||
* @param chapter selected chapter
|
* @param chapter selected chapter
|
||||||
*/
|
*/
|
||||||
private fun openChapter(chapter: MangaChapter) {
|
private fun openChapter(chapter: MangaChapter) {
|
||||||
// Start reader event
|
val intent = ReaderActivity.newIntent(activity, chapter.manga, chapter.chapter)
|
||||||
presenter.onOpenChapter(chapter)
|
|
||||||
|
|
||||||
//Start reader intent
|
|
||||||
val intent = ReaderActivity.newIntent(activity)
|
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Populate adapter with chapters
|
* Populate adapter with chapters
|
||||||
|
*
|
||||||
* @param chapters list of chapters
|
* @param chapters list of chapters
|
||||||
*/
|
*/
|
||||||
fun onNextMangaChapters(chapters: List<Any>) {
|
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.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.data.source.SourceManager
|
import eu.kanade.tachiyomi.data.source.SourceManager
|
||||||
import eu.kanade.tachiyomi.event.DownloadChaptersEvent
|
import eu.kanade.tachiyomi.event.DownloadChaptersEvent
|
||||||
import eu.kanade.tachiyomi.event.ReaderEvent
|
|
||||||
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
||||||
import eu.kanade.tachiyomi.util.SharedData
|
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
import rx.android.schedulers.AndroidSchedulers
|
import rx.android.schedulers.AndroidSchedulers
|
||||||
import rx.schedulers.Schedulers
|
import rx.schedulers.Schedulers
|
||||||
|
@ -251,14 +249,6 @@ class RecentChaptersPresenter : BasePresenter<RecentChaptersFragment>() {
|
||||||
return cal.time
|
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
|
* Download selected chapter
|
||||||
* @param selectedChapter chapter that is selected
|
* @param selectedChapter chapter that is selected
|
||||||
|
|
|
@ -14,7 +14,7 @@ object SharedData {
|
||||||
/**
|
/**
|
||||||
* Map where the objects are saved.
|
* Map where the objects are saved.
|
||||||
*/
|
*/
|
||||||
private val map = HashMap<Class<*>, Any>()
|
val map = HashMap<Class<*>, Any>()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Publish an object to the shared data.
|
* 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) }
|
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 a new issue