mirror of
https://git.mihon.tech/mihonapp/mihon
synced 2024-11-29 11:08:53 +03:00
Minor changes. Also fix #240
This commit is contained in:
parent
a598ebf72f
commit
7c503648ff
10 changed files with 28 additions and 127 deletions
|
@ -53,7 +53,6 @@ open class App : Application() {
|
|||
|
||||
protected open fun setupEventBus() {
|
||||
EventBus.builder()
|
||||
.addIndex(EventBusIndex())
|
||||
.logNoSubscriberMessages(false)
|
||||
.installDefaultEventBus()
|
||||
}
|
||||
|
|
|
@ -1,75 +0,0 @@
|
|||
package eu.kanade.tachiyomi;
|
||||
|
||||
import org.greenrobot.eventbus.meta.SimpleSubscriberInfo;
|
||||
import org.greenrobot.eventbus.meta.SubscriberMethodInfo;
|
||||
import org.greenrobot.eventbus.meta.SubscriberInfo;
|
||||
import org.greenrobot.eventbus.meta.SubscriberInfoIndex;
|
||||
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/** This class is generated by EventBus, do not edit. */
|
||||
public class EventBusIndex implements SubscriberInfoIndex {
|
||||
private static final Map<Class<?>, SubscriberInfo> SUBSCRIBER_INDEX;
|
||||
|
||||
static {
|
||||
SUBSCRIBER_INDEX = new HashMap<Class<?>, SubscriberInfo>();
|
||||
|
||||
putIndex(new SimpleSubscriberInfo(eu.kanade.tachiyomi.ui.manga.MangaPresenter.class, true,
|
||||
new SubscriberMethodInfo[] {
|
||||
new SubscriberMethodInfo("onEvent", eu.kanade.tachiyomi.data.database.models.Manga.class, ThreadMode.MAIN, 0,
|
||||
true),
|
||||
}));
|
||||
|
||||
putIndex(new SimpleSubscriberInfo(eu.kanade.tachiyomi.ui.manga.myanimelist.MyAnimeListPresenter.class, true,
|
||||
new SubscriberMethodInfo[] {
|
||||
new SubscriberMethodInfo("onEvent", eu.kanade.tachiyomi.event.MangaEvent.class, ThreadMode.MAIN, 0, true),
|
||||
}));
|
||||
|
||||
putIndex(new SimpleSubscriberInfo(eu.kanade.tachiyomi.ui.reader.ReaderPresenter.class, true,
|
||||
new SubscriberMethodInfo[] {
|
||||
new SubscriberMethodInfo("onEvent", eu.kanade.tachiyomi.event.ReaderEvent.class, ThreadMode.MAIN, 0, true),
|
||||
}));
|
||||
|
||||
putIndex(new SimpleSubscriberInfo(eu.kanade.tachiyomi.ui.library.LibraryCategoryFragment.class, true,
|
||||
new SubscriberMethodInfo[] {
|
||||
new SubscriberMethodInfo("onEvent", eu.kanade.tachiyomi.event.LibraryMangasEvent.class, ThreadMode.MAIN, 0,
|
||||
true),
|
||||
}));
|
||||
|
||||
putIndex(new SimpleSubscriberInfo(eu.kanade.tachiyomi.data.download.DownloadService.class, true,
|
||||
new SubscriberMethodInfo[] {
|
||||
new SubscriberMethodInfo("onEvent", eu.kanade.tachiyomi.event.DownloadChaptersEvent.class, ThreadMode.MAIN,
|
||||
0, true),
|
||||
}));
|
||||
|
||||
putIndex(new SimpleSubscriberInfo(eu.kanade.tachiyomi.ui.manga.chapter.ChaptersPresenter.class, true,
|
||||
new SubscriberMethodInfo[] {
|
||||
new SubscriberMethodInfo("onEvent", eu.kanade.tachiyomi.event.MangaEvent.class, ThreadMode.MAIN, 0, true),
|
||||
}));
|
||||
|
||||
putIndex(new SimpleSubscriberInfo(eu.kanade.tachiyomi.ui.manga.info.MangaInfoPresenter.class, true,
|
||||
new SubscriberMethodInfo[] {
|
||||
new SubscriberMethodInfo("onEvent", eu.kanade.tachiyomi.event.MangaEvent.class, ThreadMode.MAIN, 0, true),
|
||||
new SubscriberMethodInfo("onEvent", eu.kanade.tachiyomi.event.ChapterCountEvent.class, ThreadMode.MAIN, 0,
|
||||
true),
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
private static void putIndex(SubscriberInfo info) {
|
||||
SUBSCRIBER_INDEX.put(info.getSubscriberClass(), info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubscriberInfo getSubscriberInfo(Class<?> subscriberClass) {
|
||||
SubscriberInfo info = SUBSCRIBER_INDEX.get(subscriberClass);
|
||||
if (info != null) {
|
||||
return info;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@ package eu.kanade.tachiyomi.event
|
|||
import eu.kanade.tachiyomi.data.database.models.Category
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
|
||||
class LibraryMangasEvent(val mangas: Map<Int, List<Manga>>) {
|
||||
class LibraryMangaEvent(val mangas: Map<Int, List<Manga>>) {
|
||||
|
||||
fun getMangasForCategory(category: Category): List<Manga>? {
|
||||
return mangas[category.id]
|
|
@ -9,7 +9,6 @@ import android.view.View
|
|||
import android.widget.TextView
|
||||
import eu.kanade.tachiyomi.App
|
||||
import eu.kanade.tachiyomi.R
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
|
||||
open class BaseActivity : AppCompatActivity() {
|
||||
|
||||
|
@ -51,14 +50,6 @@ open class BaseActivity : AppCompatActivity() {
|
|||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
fun registerForEvents() {
|
||||
EventBus.getDefault().register(this)
|
||||
}
|
||||
|
||||
fun unregisterForEvents() {
|
||||
EventBus.getDefault().unregister(this)
|
||||
}
|
||||
|
||||
fun snack(text: String?, duration: Int = Snackbar.LENGTH_LONG) {
|
||||
val snack = Snackbar.make(findViewById(android.R.id.content)!!, text ?: getString(R.string.unknown_error), duration)
|
||||
val textView = snack.view.findViewById(android.support.design.R.id.snackbar_text) as TextView
|
||||
|
|
|
@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.ui.base.fragment
|
|||
|
||||
import android.support.v4.app.Fragment
|
||||
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
|
||||
open class BaseFragment : Fragment() {
|
||||
|
||||
|
@ -17,12 +16,4 @@ open class BaseFragment : Fragment() {
|
|||
val baseActivity: BaseActivity
|
||||
get() = activity as BaseActivity
|
||||
|
||||
fun registerForEvents() {
|
||||
EventBus.getDefault().register(this)
|
||||
}
|
||||
|
||||
fun unregisterForEvents() {
|
||||
EventBus.getDefault().unregister(this)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,21 +2,12 @@ package eu.kanade.tachiyomi.ui.base.presenter
|
|||
|
||||
import android.content.Context
|
||||
import nucleus.view.ViewWithPresenter
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import rx.Observable
|
||||
|
||||
open class BasePresenter<V : ViewWithPresenter<*>> : RxPresenter<V>() {
|
||||
|
||||
lateinit var context: Context
|
||||
|
||||
fun registerForEvents() {
|
||||
EventBus.getDefault().register(this)
|
||||
}
|
||||
|
||||
fun unregisterForEvents() {
|
||||
EventBus.getDefault().unregister(this)
|
||||
}
|
||||
|
||||
fun <T> Observable<T>.subscribeFirst(onNext: (V, T) -> Unit, onError: ((V, Throwable) -> Unit)? = null)
|
||||
= compose(deliverFirst<T>()).subscribe(split(onNext, onError))
|
||||
|
||||
|
|
|
@ -9,13 +9,11 @@ import com.f2prateek.rx.preferences.Preference
|
|||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.event.LibraryMangasEvent
|
||||
import eu.kanade.tachiyomi.event.LibraryMangaEvent
|
||||
import eu.kanade.tachiyomi.ui.base.adapter.FlexibleViewHolder
|
||||
import eu.kanade.tachiyomi.ui.base.fragment.BaseFragment
|
||||
import eu.kanade.tachiyomi.ui.manga.MangaActivity
|
||||
import kotlinx.android.synthetic.main.fragment_library_category.*
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
import rx.Subscription
|
||||
import java.util.*
|
||||
|
||||
|
@ -44,6 +42,11 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli
|
|||
field = value ?: ArrayList()
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscription for the library manga.
|
||||
*/
|
||||
private var libraryMangaSubscription: Subscription? = null
|
||||
|
||||
/**
|
||||
* Subscription of the number of manga per row.
|
||||
*/
|
||||
|
@ -115,11 +118,12 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli
|
|||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
registerForEvents()
|
||||
libraryMangaSubscription = libraryPresenter.libraryMangaSubject
|
||||
.subscribe({ onNextLibraryManga(it) })
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
unregisterForEvents()
|
||||
libraryMangaSubscription?.unsubscribe()
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
|
@ -130,13 +134,12 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli
|
|||
}
|
||||
|
||||
/**
|
||||
* Subscribe to [LibraryMangasEvent]. When an event is received, it updates [mangas] if needed
|
||||
* Subscribe to [LibraryMangaEvent]. When an event is received, it updates [mangas] if needed
|
||||
* and refresh the content of the adapter.
|
||||
*
|
||||
* @param event the event received.
|
||||
*/
|
||||
@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
|
||||
fun onEvent(event: LibraryMangasEvent) {
|
||||
fun onNextLibraryManga(event: LibraryMangaEvent?) {
|
||||
// Get the categories from the parent fragment.
|
||||
val categories = libraryFragment.adapter.categories ?: return
|
||||
|
||||
|
@ -144,13 +147,13 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli
|
|||
if (position >= categories.size) return
|
||||
|
||||
// Get the manga list for this category
|
||||
val mangaForCategory = event.getMangasForCategory(categories[position])
|
||||
val mangaForCategory = event?.getMangasForCategory(categories[position])
|
||||
|
||||
// Update the list only if the reference to the list is different, avoiding reseting the
|
||||
// adapter after every onResume.
|
||||
if (mangas !== mangaForCategory) {
|
||||
mangas = mangaForCategory
|
||||
mangas?.let { adapter.setItems(it) }
|
||||
adapter.setItems(mangas ?: emptyList())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ import eu.kanade.tachiyomi.R
|
|||
import eu.kanade.tachiyomi.data.database.models.Category
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.library.LibraryUpdateService
|
||||
import eu.kanade.tachiyomi.event.LibraryMangasEvent
|
||||
import eu.kanade.tachiyomi.event.LibraryMangaEvent
|
||||
import eu.kanade.tachiyomi.ui.base.fragment.BaseRxFragment
|
||||
import eu.kanade.tachiyomi.ui.category.CategoryActivity
|
||||
import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||
|
@ -23,7 +23,6 @@ import eu.kanade.tachiyomi.util.toast
|
|||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import kotlinx.android.synthetic.main.fragment_library.*
|
||||
import nucleus.factory.RequiresPresenter
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import java.io.IOException
|
||||
|
||||
/**
|
||||
|
@ -273,7 +272,7 @@ class LibraryFragment : BaseRxFragment<LibraryPresenter>(), ActionMode.Callback
|
|||
}
|
||||
|
||||
// Send the manga map to child fragments after the adapter is updated.
|
||||
EventBus.getDefault().postSticky(LibraryMangasEvent(mangaMap))
|
||||
presenter.libraryMangaSubject.onNext(LibraryMangaEvent(mangaMap))
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,9 +11,8 @@ import eu.kanade.tachiyomi.data.download.DownloadManager
|
|||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.data.source.SourceManager
|
||||
import eu.kanade.tachiyomi.event.LibraryMangasEvent
|
||||
import eu.kanade.tachiyomi.event.LibraryMangaEvent
|
||||
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import rx.Observable
|
||||
import rx.android.schedulers.AndroidSchedulers
|
||||
import rx.subjects.BehaviorSubject
|
||||
|
@ -35,12 +34,17 @@ class LibraryPresenter : BasePresenter<LibraryFragment>() {
|
|||
/**
|
||||
* Currently selected manga.
|
||||
*/
|
||||
lateinit var selectedMangas: MutableList<Manga>
|
||||
var selectedMangas = mutableListOf<Manga>()
|
||||
|
||||
/**
|
||||
* Search query of the library.
|
||||
*/
|
||||
lateinit var searchSubject: BehaviorSubject<String>
|
||||
val searchSubject = BehaviorSubject.create<String>()
|
||||
|
||||
/**
|
||||
* Subject to notify the library's viewpager for updates.
|
||||
*/
|
||||
val libraryMangaSubject = BehaviorSubject.create<LibraryMangaEvent?>()
|
||||
|
||||
/**
|
||||
* Database.
|
||||
|
@ -77,10 +81,6 @@ class LibraryPresenter : BasePresenter<LibraryFragment>() {
|
|||
override fun onCreate(savedState: Bundle?) {
|
||||
super.onCreate(savedState)
|
||||
|
||||
selectedMangas = ArrayList()
|
||||
|
||||
searchSubject = BehaviorSubject.create()
|
||||
|
||||
restartableLatestCache(GET_LIBRARY,
|
||||
{ getLibraryObservable() },
|
||||
{ view, pair -> view.onNextLibraryUpdate(pair.first, pair.second) })
|
||||
|
@ -92,7 +92,7 @@ class LibraryPresenter : BasePresenter<LibraryFragment>() {
|
|||
}
|
||||
|
||||
override fun onDropView() {
|
||||
EventBus.getDefault().removeStickyEvent(LibraryMangasEvent::class.java)
|
||||
libraryMangaSubject.onNext(null)
|
||||
super.onDropView()
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,9 @@ class MangaInfoPresenter : BasePresenter<MangaInfoFragment>() {
|
|||
|
||||
// Update chapter count
|
||||
SharedData.get(ChapterCountEvent::class.java)?.let {
|
||||
add(it.observable.subscribeLatestCache({ view, count -> view.setChapterCount(count) }))
|
||||
add(it.observable
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeLatestCache({ view, count -> view.setChapterCount(count) }))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue