Upgrade to EventBus 3

This commit is contained in:
inorichi 2016-02-09 21:19:11 +01:00
parent 7835921045
commit e348d6c1cf
17 changed files with 83 additions and 88 deletions

View File

@ -82,13 +82,20 @@ android {
}
apt {
arguments {
eventBusIndex "eu.kanade.tachiyomi.EventBusIndex"
}
}
dependencies {
final SUPPORT_LIBRARY_VERSION = '23.1.1'
final DAGGER_VERSION = '2.0.2'
final EVENTBUS_VERSION = '3.0.0'
final OKHTTP_VERSION = '3.1.1'
final MOCKITO_VERSION = '1.10.19'
final STORIO_VERSION = '1.8.0'
final ICEPICK_VERSION = '3.1.0'
final MOCKITO_VERSION = '1.10.19'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(":SubsamplingScaleImageView")
@ -113,7 +120,6 @@ dependencies {
compile "com.pushtorefresh.storio:sqlite:$STORIO_VERSION"
compile "com.pushtorefresh.storio:sqlite-annotations:$STORIO_VERSION"
compile 'info.android15.nucleus:nucleus:2.0.4'
compile 'de.greenrobot:eventbus:2.4.0'
compile 'com.github.bumptech.glide:glide:3.6.1'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.jakewharton.timber:timber:4.1.0'
@ -127,6 +133,9 @@ dependencies {
compile 'com.github.amulyakhare:TextDrawable:558677e'
compile 'com.github.pwittchen:reactivenetwork:0.1.5'
compile "org.greenrobot:eventbus:$EVENTBUS_VERSION"
apt "org.greenrobot:eventbus-annotation-processor:$EVENTBUS_VERSION"
compile "com.google.dagger:dagger:$DAGGER_VERSION"
apt "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
apt "com.pushtorefresh.storio:sqlite-annotations-processor:$STORIO_VERSION"

View File

@ -5,6 +5,7 @@ import android.content.Context;
import org.acra.ACRA;
import org.acra.annotation.ReportsCrashes;
import org.greenrobot.eventbus.EventBus;
import eu.kanade.tachiyomi.injection.ComponentReflectionInjector;
import eu.kanade.tachiyomi.injection.component.AppComponent;
@ -39,6 +40,11 @@ public class App extends Application {
componentInjector =
new ComponentReflectionInjector<>(AppComponent.class, applicationComponent);
EventBus.builder()
.addIndex(new EventBusIndex())
.logNoSubscriberMessages(false)
.installDefaultEventBus();
ACRA.init(this);
}

View File

@ -8,14 +8,16 @@ import android.os.PowerManager;
import com.github.pwittchen.reactivenetwork.library.ReactiveNetwork;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import javax.inject.Inject;
import de.greenrobot.event.EventBus;
import eu.kanade.tachiyomi.App;
import eu.kanade.tachiyomi.R;
import eu.kanade.tachiyomi.data.preference.PreferencesHelper;
import eu.kanade.tachiyomi.event.DownloadChaptersEvent;
import eu.kanade.tachiyomi.util.EventBusHook;
import eu.kanade.tachiyomi.util.ToastUtil;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
@ -47,7 +49,7 @@ public class DownloadService extends Service {
createWakeLock();
listenQueueRunningChanges();
EventBus.getDefault().registerSticky(this);
EventBus.getDefault().register(this);
listenNetworkChanges();
}
@ -71,7 +73,7 @@ public class DownloadService extends Service {
return null;
}
@EventBusHook
@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
public void onEvent(DownloadChaptersEvent event) {
EventBus.getDefault().removeStickyEvent(event);
downloadManager.onDownloadChaptersEvent(event);

View File

@ -5,7 +5,8 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import de.greenrobot.event.EventBus;
import org.greenrobot.eventbus.EventBus;
import icepick.Icepick;
public class BaseActivity extends AppCompatActivity {
@ -58,20 +59,8 @@ public class BaseActivity extends AppCompatActivity {
return super.onOptionsItemSelected(item);
}
public void registerForStickyEvents() {
registerForStickyEvents(0);
}
public void registerForStickyEvents(int priority) {
EventBus.getDefault().registerSticky(this, priority);
}
public void registerForEvents() {
registerForEvents(0);
}
public void registerForEvents(int priority) {
EventBus.getDefault().register(this, priority);
EventBus.getDefault().register(this);
}
public void unregisterForEvents() {

View File

@ -3,7 +3,8 @@ package eu.kanade.tachiyomi.ui.base.fragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import de.greenrobot.event.EventBus;
import org.greenrobot.eventbus.EventBus;
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity;
import icepick.Icepick;
@ -33,20 +34,8 @@ public class BaseFragment extends Fragment {
return (BaseActivity) getActivity();
}
public void registerForStickyEvents() {
registerForStickyEvents(0);
}
public void registerForStickyEvents(int priority) {
EventBus.getDefault().registerSticky(this, priority);
}
public void registerForEvents() {
registerForEvents(0);
}
public void registerForEvents(int priority) {
EventBus.getDefault().register(this, priority);
EventBus.getDefault().register(this);
}
public void unregisterForEvents() {

View File

@ -4,7 +4,8 @@ import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import de.greenrobot.event.EventBus;
import org.greenrobot.eventbus.EventBus;
import icepick.Icepick;
import nucleus.view.ViewWithPresenter;
@ -24,10 +25,6 @@ public class BasePresenter<V extends ViewWithPresenter> extends RxPresenter<V> {
Icepick.saveInstanceState(this, state);
}
public void registerForStickyEvents() {
EventBus.getDefault().registerSticky(this);
}
public void registerForEvents() {
EventBus.getDefault().register(this);
}

View File

@ -9,6 +9,9 @@ import android.view.ViewGroup;
import com.f2prateek.rx.preferences.Preference;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.util.ArrayList;
import java.util.List;
@ -22,7 +25,6 @@ import eu.kanade.tachiyomi.event.LibraryMangasEvent;
import eu.kanade.tachiyomi.ui.base.adapter.FlexibleViewHolder;
import eu.kanade.tachiyomi.ui.base.fragment.BaseFragment;
import eu.kanade.tachiyomi.ui.manga.MangaActivity;
import eu.kanade.tachiyomi.util.EventBusHook;
import eu.kanade.tachiyomi.widget.AutofitRecyclerView;
import icepick.State;
import rx.Subscription;
@ -97,7 +99,7 @@ public class LibraryCategoryFragment extends BaseFragment
@Override
public void onResume() {
super.onResume();
registerForStickyEvents();
registerForEvents();
}
@Override
@ -112,8 +114,8 @@ public class LibraryCategoryFragment extends BaseFragment
super.onSaveInstanceState(outState);
}
@EventBusHook
public void onEventMainThread(LibraryMangasEvent event) {
@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
public void onEvent(LibraryMangasEvent event) {
List<Category> categories = getLibraryFragment().getAdapter().categories;
// When a category is deleted, the index can be greater than the number of categories
if (position >= categories.size())

View File

@ -18,13 +18,14 @@ import android.view.ViewGroup;
import com.afollestad.materialdialogs.MaterialDialog;
import org.greenrobot.eventbus.EventBus;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import butterknife.Bind;
import butterknife.ButterKnife;
import de.greenrobot.event.EventBus;
import eu.davidea.flexibleadapter.FlexibleAdapter;
import eu.kanade.tachiyomi.R;
import eu.kanade.tachiyomi.data.database.models.Category;
@ -90,12 +91,6 @@ public class LibraryFragment extends BaseRxFragment<LibraryPresenter>
super.onDestroyView();
}
@Override
public void onPause() {
EventBus.getDefault().removeStickyEvent(LibraryMangasEvent.class);
super.onPause();
}
@Override
public void onSaveInstanceState(Bundle bundle) {
activeCategory = viewPager.getCurrentItem();

View File

@ -3,13 +3,14 @@ package eu.kanade.tachiyomi.ui.library;
import android.os.Bundle;
import android.util.Pair;
import org.greenrobot.eventbus.EventBus;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import de.greenrobot.event.EventBus;
import eu.kanade.tachiyomi.data.cache.CoverCache;
import eu.kanade.tachiyomi.data.database.DatabaseHelper;
import eu.kanade.tachiyomi.data.database.models.Category;
@ -55,9 +56,9 @@ public class LibraryPresenter extends BasePresenter<LibraryFragment> {
}
@Override
protected void onDestroy() {
protected void onDropView() {
EventBus.getDefault().removeStickyEvent(LibraryMangasEvent.class);
super.onDestroy();
super.onDropView();
}
@Override

View File

@ -15,11 +15,12 @@ import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import org.greenrobot.eventbus.EventBus;
import javax.inject.Inject;
import butterknife.Bind;
import butterknife.ButterKnife;
import de.greenrobot.event.EventBus;
import eu.kanade.tachiyomi.App;
import eu.kanade.tachiyomi.R;
import eu.kanade.tachiyomi.data.database.models.Manga;

View File

@ -2,14 +2,16 @@ package eu.kanade.tachiyomi.ui.manga;
import android.os.Bundle;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import javax.inject.Inject;
import de.greenrobot.event.EventBus;
import eu.kanade.tachiyomi.data.database.DatabaseHelper;
import eu.kanade.tachiyomi.data.database.models.Manga;
import eu.kanade.tachiyomi.event.MangaEvent;
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter;
import eu.kanade.tachiyomi.util.EventBusHook;
import icepick.State;
import rx.Observable;
@ -28,7 +30,7 @@ public class MangaPresenter extends BasePresenter<MangaActivity> {
restartableLatestCache(GET_MANGA, this::getMangaObservable, MangaActivity::setManga);
if (savedState == null)
registerForStickyEvents();
registerForEvents();
}
@Override
@ -43,8 +45,8 @@ public class MangaPresenter extends BasePresenter<MangaActivity> {
.doOnNext(manga -> EventBus.getDefault().postSticky(new MangaEvent(manga)));
}
@EventBusHook
public void onEventMainThread(Manga manga) {
@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
public void onEvent(Manga manga) {
EventBus.getDefault().removeStickyEvent(manga);
unregisterForEvents();
this.manga = manga;

View File

@ -3,11 +3,14 @@ package eu.kanade.tachiyomi.ui.manga.chapter;
import android.os.Bundle;
import android.util.Pair;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.util.List;
import javax.inject.Inject;
import de.greenrobot.event.EventBus;
import eu.kanade.tachiyomi.data.database.DatabaseHelper;
import eu.kanade.tachiyomi.data.database.models.Chapter;
import eu.kanade.tachiyomi.data.database.models.Manga;
@ -21,7 +24,6 @@ import eu.kanade.tachiyomi.event.DownloadChaptersEvent;
import eu.kanade.tachiyomi.event.MangaEvent;
import eu.kanade.tachiyomi.event.ReaderEvent;
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter;
import eu.kanade.tachiyomi.util.EventBusHook;
import icepick.State;
import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
@ -72,7 +74,7 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
(view, download) -> view.onChapterStatusChange(download),
(view, error) -> Timber.e(error.getCause(), error.getMessage()));
registerForStickyEvents();
registerForEvents();
}
@Override
@ -82,8 +84,8 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
super.onDestroy();
}
@EventBusHook
public void onEventMainThread(MangaEvent event) {
@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
public void onEvent(MangaEvent event) {
this.manga = event.manga;
start(GET_MANGA);

View File

@ -3,6 +3,9 @@ package eu.kanade.tachiyomi.ui.manga.info;
import android.os.Bundle;
import android.widget.ImageView;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.io.File;
import java.io.IOException;
@ -16,7 +19,6 @@ import eu.kanade.tachiyomi.data.source.base.Source;
import eu.kanade.tachiyomi.event.ChapterCountEvent;
import eu.kanade.tachiyomi.event.MangaEvent;
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter;
import eu.kanade.tachiyomi.util.EventBusHook;
import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
@ -80,8 +82,8 @@ public class MangaInfoPresenter extends BasePresenter<MangaInfoFragment> {
(view, manga) -> view.onFetchMangaDone(),
(view, error) -> view.onFetchMangaError());
// onEventMainThread receives an event thanks to this line.
registerForStickyEvents();
// Listen for events
registerForEvents();
}
@Override
@ -90,15 +92,15 @@ public class MangaInfoPresenter extends BasePresenter<MangaInfoFragment> {
super.onDestroy();
}
@EventBusHook
public void onEventMainThread(MangaEvent event) {
@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
public void onEvent(MangaEvent event) {
this.manga = event.manga;
source = sourceManager.get(manga.source);
refreshManga();
}
@EventBusHook
public void onEventMainThread(ChapterCountEvent event) {
@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
public void onEvent(ChapterCountEvent event) {
if (count != event.getCount()) {
count = event.getCount();
start(GET_CHAPTER_COUNT);

View File

@ -4,6 +4,9 @@ import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.util.List;
import javax.inject.Inject;
@ -16,7 +19,6 @@ import eu.kanade.tachiyomi.data.mangasync.MangaSyncManager;
import eu.kanade.tachiyomi.data.mangasync.services.MyAnimeList;
import eu.kanade.tachiyomi.event.MangaEvent;
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter;
import eu.kanade.tachiyomi.util.EventBusHook;
import eu.kanade.tachiyomi.util.ToastUtil;
import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
@ -85,7 +87,7 @@ public class MyAnimeListPresenter extends BasePresenter<MyAnimeListFragment> {
@Override
protected void onTakeView(MyAnimeListFragment view) {
super.onTakeView(view);
registerForStickyEvents();
registerForEvents();
}
@Override
@ -94,8 +96,8 @@ public class MyAnimeListPresenter extends BasePresenter<MyAnimeListFragment> {
super.onDropView();
}
@EventBusHook
public void onEventMainThread(MangaEvent event) {
@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
public void onEvent(MangaEvent event) {
this.manga = event.manga;
start(GET_MANGA_SYNC);
}

View File

@ -4,12 +4,15 @@ import android.os.Bundle;
import android.support.annotation.NonNull;
import android.util.Pair;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.io.File;
import java.util.List;
import javax.inject.Inject;
import de.greenrobot.event.EventBus;
import eu.kanade.tachiyomi.data.database.DatabaseHelper;
import eu.kanade.tachiyomi.data.database.models.Chapter;
import eu.kanade.tachiyomi.data.database.models.Manga;
@ -25,7 +28,6 @@ import eu.kanade.tachiyomi.data.source.model.Page;
import eu.kanade.tachiyomi.data.sync.UpdateMangaSyncService;
import eu.kanade.tachiyomi.event.ReaderEvent;
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter;
import eu.kanade.tachiyomi.util.EventBusHook;
import icepick.State;
import rx.Observable;
import rx.Subscription;
@ -90,7 +92,7 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
(view, error) -> view.onChapterError());
if (savedState == null) {
registerForStickyEvents();
registerForEvents();
}
}
@ -106,8 +108,8 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
super.onSave(state);
}
@EventBusHook
public void onEventMainThread(ReaderEvent event) {
@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
public void onEvent(ReaderEvent event) {
EventBus.getDefault().removeStickyEvent(event);
manga = event.getManga();
source = event.getSource();

View File

@ -2,6 +2,8 @@ package eu.kanade.tachiyomi.ui.recent;
import android.os.Bundle;
import org.greenrobot.eventbus.EventBus;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
@ -12,7 +14,6 @@ import java.util.TreeMap;
import javax.inject.Inject;
import de.greenrobot.event.EventBus;
import eu.kanade.tachiyomi.data.database.DatabaseHelper;
import eu.kanade.tachiyomi.data.database.models.MangaChapter;
import eu.kanade.tachiyomi.data.source.SourceManager;

View File

@ -1,7 +0,0 @@
package eu.kanade.tachiyomi.util;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
@Target({ElementType.METHOD})
public @interface EventBusHook {}