diff --git a/app/build.gradle b/app/build.gradle index 42853d5dbd..ad83870f38 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -79,7 +79,6 @@ dependencies { final HAMCREST_VERSION = '1.3' final MOCKITO_VERSION = '1.10.19' final STORIO_VERSION = '1.6.1' - final NUCLEUS_VERSION = '2.0.3' final ICEPICK_VERSION = '3.1.0' compile fileTree(dir: 'libs', include: ['*.jar']) @@ -90,25 +89,24 @@ dependencies { compile "com.android.support:design:$SUPPORT_LIBRARY_VERSION" compile "com.android.support:recyclerview-v7:$SUPPORT_LIBRARY_VERSION" compile "com.android.support:support-annotations:$SUPPORT_LIBRARY_VERSION" - compile 'com.squareup.okhttp:okhttp-urlconnection:2.6.0' - compile 'com.squareup.okhttp:okhttp:2.6.0' + compile 'com.squareup.okhttp:okhttp-urlconnection:2.7.0' + compile 'com.squareup.okhttp:okhttp:2.7.0' compile 'com.squareup.okio:okio:1.6.0' compile 'com.google.code.gson:gson:2.4' compile 'com.jakewharton:disklrucache:2.0.2' compile 'org.jsoup:jsoup:1.8.3' - compile 'io.reactivex:rxandroid:1.0.1' + compile 'io.reactivex:rxandroid:1.1.0' compile 'io.reactivex:rxjava:1.1.0' compile 'com.f2prateek.rx.preferences:rx-preferences:1.0.1' compile "com.pushtorefresh.storio:sqlite:$STORIO_VERSION" compile "com.pushtorefresh.storio:sqlite-annotations:$STORIO_VERSION" - compile "info.android15.nucleus:nucleus:$NUCLEUS_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' compile 'uk.co.ribot:easyadapter:1.5.0@aar' - compile 'ch.acra:acra:4.6.2' - compile 'com.github.castorflex.verticalviewpager:library:19.0.1' + compile 'ch.acra:acra:4.7.0' compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.4.1' compile "frankiesardo:icepick:$ICEPICK_VERSION" provided "frankiesardo:icepick-processor:$ICEPICK_VERSION" @@ -121,7 +119,7 @@ dependencies { apt "com.pushtorefresh.storio:sqlite-annotations-processor:$STORIO_VERSION" provided 'org.glassfish:javax.annotation:10.0-b28' - compile('com.mikepenz:materialdrawer:4.4.8@aar') { + compile('com.mikepenz:materialdrawer:4.5.9@aar') { transitive = true } compile('com.github.afollestad.material-dialogs:core:0.8.5.2@aar') { diff --git a/app/src/main/java/eu/kanade/mangafeed/data/database/DatabaseHelper.java b/app/src/main/java/eu/kanade/mangafeed/data/database/DatabaseHelper.java index 0fe2a1261f..37c140c954 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/database/DatabaseHelper.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/database/DatabaseHelper.java @@ -17,7 +17,7 @@ import com.pushtorefresh.storio.sqlite.queries.RawQuery; import java.util.List; import eu.kanade.mangafeed.data.database.models.MangaSync; -import eu.kanade.mangafeed.data.mangasync.base.BaseMangaSync; +import eu.kanade.mangafeed.data.mangasync.base.MangaSyncService; import eu.kanade.mangafeed.data.database.models.Chapter; import eu.kanade.mangafeed.data.database.models.ChapterStorIOSQLiteDeleteResolver; import eu.kanade.mangafeed.data.database.models.ChapterStorIOSQLiteGetResolver; @@ -303,8 +303,7 @@ public class DatabaseHelper { // Manga sync related queries - public PreparedGetListOfObjects getMangaSync(Manga manga, BaseMangaSync sync) { - + public PreparedGetListOfObjects getMangaSync(Manga manga, MangaSyncService sync) { return db.get() .listOfObjects(MangaSync.class) .withQuery(Query.builder() @@ -316,6 +315,17 @@ public class DatabaseHelper { .prepare(); } + public PreparedGetListOfObjects getMangaSync(Manga manga) { + return db.get() + .listOfObjects(MangaSync.class) + .withQuery(Query.builder() + .table(MangaSyncTable.TABLE) + .where(MangaSyncTable.COLUMN_MANGA_ID + "=?") + .whereArgs(manga.id) + .build()) + .prepare(); + } + public PreparedPutObject insertMangaSync(MangaSync manga) { return db.put() .object(manga) diff --git a/app/src/main/java/eu/kanade/mangafeed/data/database/models/MangaSync.java b/app/src/main/java/eu/kanade/mangafeed/data/database/models/MangaSync.java index 9cbb87f732..e95e5ca20d 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/database/models/MangaSync.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/database/models/MangaSync.java @@ -3,11 +3,13 @@ package eu.kanade.mangafeed.data.database.models; import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteColumn; import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteType; -import eu.kanade.mangafeed.data.mangasync.base.BaseMangaSync; +import java.io.Serializable; + +import eu.kanade.mangafeed.data.mangasync.base.MangaSyncService; import eu.kanade.mangafeed.data.database.tables.MangaSyncTable; @StorIOSQLiteType(table = MangaSyncTable.TABLE) -public class MangaSync { +public class MangaSync implements Serializable { @StorIOSQLiteColumn(name = MangaSyncTable.COLUMN_ID, key = true) public Long id; @@ -33,7 +35,7 @@ public class MangaSync { @StorIOSQLiteColumn(name = MangaSyncTable.COLUMN_STATUS) public int status; - public static MangaSync create(BaseMangaSync service) { + public static MangaSync create(MangaSyncService service) { MangaSync mangasync = new MangaSync(); mangasync.sync_id = service.getId(); return mangasync; diff --git a/app/src/main/java/eu/kanade/mangafeed/data/mangasync/MangaSyncManager.java b/app/src/main/java/eu/kanade/mangafeed/data/mangasync/MangaSyncManager.java index 065ad30eb1..63176e2ac2 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/mangasync/MangaSyncManager.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/mangasync/MangaSyncManager.java @@ -5,12 +5,12 @@ import android.content.Context; import java.util.ArrayList; import java.util.List; -import eu.kanade.mangafeed.data.mangasync.base.BaseMangaSync; +import eu.kanade.mangafeed.data.mangasync.base.MangaSyncService; import eu.kanade.mangafeed.data.mangasync.services.MyAnimeList; public class MangaSyncManager { - private List services; + private List services; private MyAnimeList myAnimeList; public static final int MYANIMELIST = 1; @@ -25,11 +25,11 @@ public class MangaSyncManager { return myAnimeList; } - public List getSyncServices() { + public List getSyncServices() { return services; } - public BaseMangaSync getSyncService(int id) { + public MangaSyncService getSyncService(int id) { switch (id) { case MYANIMELIST: return myAnimeList; diff --git a/app/src/main/java/eu/kanade/mangafeed/data/mangasync/base/BaseMangaSync.java b/app/src/main/java/eu/kanade/mangafeed/data/mangasync/base/MangaSyncService.java similarity index 94% rename from app/src/main/java/eu/kanade/mangafeed/data/mangasync/base/BaseMangaSync.java rename to app/src/main/java/eu/kanade/mangafeed/data/mangasync/base/MangaSyncService.java index 97562ac907..e94dc43f5b 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/mangasync/base/BaseMangaSync.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/mangasync/base/MangaSyncService.java @@ -5,7 +5,7 @@ import com.squareup.okhttp.Response; import eu.kanade.mangafeed.data.database.models.MangaSync; import rx.Observable; -public abstract class BaseMangaSync { +public abstract class MangaSyncService { // Name of the manga sync service to display public abstract String getName(); diff --git a/app/src/main/java/eu/kanade/mangafeed/data/mangasync/services/MyAnimeList.java b/app/src/main/java/eu/kanade/mangafeed/data/mangasync/services/MyAnimeList.java index 8f1c6910a1..8b4fbca81a 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/mangasync/services/MyAnimeList.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/mangasync/services/MyAnimeList.java @@ -22,12 +22,12 @@ import javax.inject.Inject; import eu.kanade.mangafeed.App; import eu.kanade.mangafeed.data.database.models.MangaSync; import eu.kanade.mangafeed.data.mangasync.MangaSyncManager; -import eu.kanade.mangafeed.data.mangasync.base.BaseMangaSync; +import eu.kanade.mangafeed.data.mangasync.base.MangaSyncService; import eu.kanade.mangafeed.data.network.NetworkHelper; import eu.kanade.mangafeed.data.preference.PreferencesHelper; import rx.Observable; -public class MyAnimeList extends BaseMangaSync { +public class MyAnimeList extends MangaSyncService { @Inject PreferencesHelper preferences; @Inject NetworkHelper networkService; diff --git a/app/src/main/java/eu/kanade/mangafeed/data/preference/PreferencesHelper.java b/app/src/main/java/eu/kanade/mangafeed/data/preference/PreferencesHelper.java index 38ce41a51a..77992cce99 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/preference/PreferencesHelper.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/preference/PreferencesHelper.java @@ -11,7 +11,7 @@ import com.f2prateek.rx.preferences.RxSharedPreferences; import java.io.File; import eu.kanade.mangafeed.R; -import eu.kanade.mangafeed.data.mangasync.base.BaseMangaSync; +import eu.kanade.mangafeed.data.mangasync.base.MangaSyncService; import eu.kanade.mangafeed.data.source.base.Source; import rx.Observable; @@ -106,15 +106,15 @@ public class PreferencesHelper { .apply(); } - public String getMangaSyncUsername(BaseMangaSync sync) { + public String getMangaSyncUsername(MangaSyncService sync) { return prefs.getString(MANGASYNC_ACCOUNT_USERNAME + sync.getId(), ""); } - public String getMangaSyncPassword(BaseMangaSync sync) { + public String getMangaSyncPassword(MangaSyncService sync) { return prefs.getString(MANGASYNC_ACCOUNT_PASSWORD + sync.getId(), ""); } - public void setMangaSyncCredentials(BaseMangaSync sync, String username, String password) { + public void setMangaSyncCredentials(MangaSyncService sync, String username, String password) { prefs.edit() .putString(MANGASYNC_ACCOUNT_USERNAME + sync.getId(), username) .putString(MANGASYNC_ACCOUNT_PASSWORD + sync.getId(), password) diff --git a/app/src/main/java/eu/kanade/mangafeed/data/sync/UpdateMangaSyncService.java b/app/src/main/java/eu/kanade/mangafeed/data/sync/UpdateMangaSyncService.java index 3c974a25e3..cd0f6dacc3 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/sync/UpdateMangaSyncService.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/sync/UpdateMangaSyncService.java @@ -7,14 +7,12 @@ import android.os.IBinder; import javax.inject.Inject; -import de.greenrobot.event.EventBus; import eu.kanade.mangafeed.App; import eu.kanade.mangafeed.data.database.DatabaseHelper; import eu.kanade.mangafeed.data.database.models.MangaSync; import eu.kanade.mangafeed.data.mangasync.MangaSyncManager; -import eu.kanade.mangafeed.data.mangasync.base.BaseMangaSync; -import eu.kanade.mangafeed.event.UpdateMangaSyncEvent; -import eu.kanade.mangafeed.util.EventBusHook; +import eu.kanade.mangafeed.data.mangasync.base.MangaSyncService; +import rx.Observable; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; import rx.subscriptions.CompositeSubscription; @@ -26,8 +24,12 @@ public class UpdateMangaSyncService extends Service { private CompositeSubscription subscriptions; - public static void start(Context context) { - context.startService(new Intent(context, UpdateMangaSyncService.class)); + private static final String EXTRA_MANGASYNC = "extra_mangasync"; + + public static void start(Context context, MangaSync mangaSync) { + Intent intent = new Intent(context, UpdateMangaSyncService.class); + intent.putExtra(EXTRA_MANGASYNC, mangaSync); + context.startService(intent); } @Override @@ -35,17 +37,17 @@ public class UpdateMangaSyncService extends Service { super.onCreate(); App.get(this).getComponent().inject(this); subscriptions = new CompositeSubscription(); - EventBus.getDefault().registerSticky(this); } @Override public int onStartCommand(Intent intent, int flags, int startId) { + MangaSync mangaSync = (MangaSync) intent.getSerializableExtra(EXTRA_MANGASYNC); + updateLastChapterRead(mangaSync, startId); return START_STICKY; } @Override public void onDestroy() { - EventBus.getDefault().unregister(this); subscriptions.unsubscribe(); super.onDestroy(); } @@ -55,22 +57,17 @@ public class UpdateMangaSyncService extends Service { return null; } - @EventBusHook - public void onEventMainThread(UpdateMangaSyncEvent event) { - updateLastChapteRead(event.getMangaSync()); - } + private void updateLastChapterRead(MangaSync mangaSync, int startId) { + MangaSyncService sync = syncManager.getSyncService(mangaSync.sync_id); - private void updateLastChapteRead(MangaSync mangaSync) { - BaseMangaSync sync = syncManager.getSyncService(mangaSync.sync_id); - - subscriptions.add(sync.update(mangaSync) + subscriptions.add(Observable.fromCallable(() -> sync.update(mangaSync)) .flatMap(response -> db.insertMangaSync(mangaSync).createObservable()) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(result -> { - stopSelf(); + stopSelf(startId); }, error -> { - stopSelf(); + stopSelf(startId); })); } diff --git a/app/src/main/java/eu/kanade/mangafeed/event/UpdateMangaSyncEvent.java b/app/src/main/java/eu/kanade/mangafeed/event/UpdateMangaSyncEvent.java deleted file mode 100644 index 8fb9a06ab5..0000000000 --- a/app/src/main/java/eu/kanade/mangafeed/event/UpdateMangaSyncEvent.java +++ /dev/null @@ -1,17 +0,0 @@ -package eu.kanade.mangafeed.event; - -import eu.kanade.mangafeed.data.database.models.MangaSync; - -public class UpdateMangaSyncEvent { - - private MangaSync mangaSync; - - public UpdateMangaSyncEvent(MangaSync mangaSync) { - this.mangaSync = mangaSync; - } - - public MangaSync getMangaSync() { - return mangaSync; - } - -} diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderPresenter.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderPresenter.java index 3ffc02c02a..d646158fb2 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderPresenter.java @@ -8,25 +8,22 @@ import java.util.List; import javax.inject.Inject; import de.greenrobot.event.EventBus; -import eu.kanade.mangafeed.data.mangasync.MangaSyncManager; -import eu.kanade.mangafeed.data.mangasync.services.MyAnimeList; -import eu.kanade.mangafeed.data.sync.UpdateMangaSyncService; import eu.kanade.mangafeed.data.database.DatabaseHelper; import eu.kanade.mangafeed.data.database.models.Chapter; -import eu.kanade.mangafeed.data.database.models.MangaSync; import eu.kanade.mangafeed.data.database.models.Manga; import eu.kanade.mangafeed.data.download.DownloadManager; +import eu.kanade.mangafeed.data.mangasync.MangaSyncManager; +import eu.kanade.mangafeed.data.mangasync.base.MangaSyncService; import eu.kanade.mangafeed.data.preference.PreferencesHelper; import eu.kanade.mangafeed.data.source.SourceManager; import eu.kanade.mangafeed.data.source.base.Source; import eu.kanade.mangafeed.data.source.model.Page; +import eu.kanade.mangafeed.data.sync.UpdateMangaSyncService; import eu.kanade.mangafeed.event.ReaderEvent; -import eu.kanade.mangafeed.event.UpdateMangaSyncEvent; import eu.kanade.mangafeed.ui.base.presenter.BasePresenter; import eu.kanade.mangafeed.util.EventBusHook; import icepick.State; import rx.Observable; -import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; import rx.subjects.PublishSubject; @@ -53,9 +50,6 @@ public class ReaderPresenter extends BasePresenter { private PublishSubject retryPageSubject; - private Subscription nextChapterSubscription; - private Subscription previousChapterSubscription; - private static final int GET_PAGE_LIST = 1; private static final int GET_PAGE_IMAGES = 2; private static final int RETRY_IMAGES = 3; @@ -110,6 +104,9 @@ public class ReaderPresenter extends BasePresenter { @Override protected void onDestroy() { unregisterForEvents(); + if (pageList != null && isChapterFinished()) { + updateMangaSyncLastChapterRead(); + } onChapterLeft(); super.onDestroy(); } @@ -231,13 +228,11 @@ public class ReaderPresenter extends BasePresenter { source.savePageList(chapter.url, pageList); // Save current progress of the chapter. Mark as read if the chapter is finished - // and update progress in remote services (like MyAnimeList) chapter.last_page_read = currentPage; if (isChapterFinished()) { chapter.read = true; - updateMangaSyncLastChapterRead(); } - db.insertChapter(chapter).executeAsBlocking(); + db.insertChapter(chapter).createObservable().subscribe(); } // Check whether the chapter has been read @@ -246,26 +241,23 @@ public class ReaderPresenter extends BasePresenter { } private void updateMangaSyncLastChapterRead() { - // TODO don't use MAL methods for possible alternatives to MAL - MyAnimeList mal = syncManager.getMyAnimeList(); + db.getMangaSync(manga).createObservable() + .take(1) + .flatMap(Observable::from) + .doOnNext(mangaSync -> { + MangaSyncService service = syncManager.getSyncService(mangaSync.sync_id); + if (!service.isLogged()) + return; - if (!mal.isLogged()) - return; + int lastChapterReadLocal = (int) Math.floor(chapter.chapter_number); + int lastChapterReadRemote = mangaSync.last_chapter_read; - List result = db.getMangaSync(manga, mal).executeAsBlocking(); - if (result.isEmpty()) - return; - - MangaSync mangaSync = result.get(0); - - int lastChapterReadLocal = (int) Math.floor(chapter.chapter_number); - int lastChapterReadRemote = mangaSync.last_chapter_read; - - if (lastChapterReadLocal > lastChapterReadRemote) { - mangaSync.last_chapter_read = lastChapterReadLocal; - EventBus.getDefault().postSticky(new UpdateMangaSyncEvent(mangaSync)); - UpdateMangaSyncService.start(getContext()); - } + if (lastChapterReadLocal > lastChapterReadRemote) { + mangaSync.last_chapter_read = lastChapterReadLocal; + UpdateMangaSyncService.start(getContext(), mangaSync); + } + }) + .subscribe(); } public void setCurrentPage(int currentPage) { @@ -273,20 +265,14 @@ public class ReaderPresenter extends BasePresenter { } private void getAdjacentChapters() { - if (nextChapterSubscription != null) - remove(nextChapterSubscription); - - add(nextChapterSubscription = db.getNextChapter(chapter).createObservable() + add(db.getNextChapter(chapter).createObservable() + .take(1) .flatMap(Observable::from) - .subscribeOn(Schedulers.io()) .subscribe(result -> nextChapter = result)); - if (previousChapterSubscription != null) - remove(previousChapterSubscription); - - add(previousChapterSubscription = db.getPreviousChapter(chapter).createObservable() + add(db.getPreviousChapter(chapter).createObservable() + .take(1) .flatMap(Observable::from) - .subscribeOn(Schedulers.io()) .subscribe(result -> previousChapter = result)); } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/setting/SettingsAccountsFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/setting/SettingsAccountsFragment.java index 7f9063907e..b504080d38 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/setting/SettingsAccountsFragment.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/setting/SettingsAccountsFragment.java @@ -12,7 +12,7 @@ import java.util.List; import javax.inject.Inject; import eu.kanade.mangafeed.App; -import eu.kanade.mangafeed.data.mangasync.base.BaseMangaSync; +import eu.kanade.mangafeed.data.mangasync.base.MangaSyncService; import eu.kanade.mangafeed.data.mangasync.MangaSyncManager; import eu.kanade.mangafeed.data.source.SourceManager; import eu.kanade.mangafeed.data.source.base.Source; @@ -60,7 +60,7 @@ public class SettingsAccountsFragment extends SettingsNestedFragment { mangaSyncCategory.setTitle("Sync"); screen.addPreference(mangaSyncCategory); - for (BaseMangaSync sync : syncManager.getSyncServices()) { + for (MangaSyncService sync : syncManager.getSyncServices()) { MangaSyncLoginDialog dialog = new MangaSyncLoginDialog( screen.getContext(), preferences, sync); dialog.setTitle(sync.getName()); diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/setting/preference/MangaSyncLoginDialog.java b/app/src/main/java/eu/kanade/mangafeed/ui/setting/preference/MangaSyncLoginDialog.java index 15c9b13cfd..663e12b936 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/setting/preference/MangaSyncLoginDialog.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/setting/preference/MangaSyncLoginDialog.java @@ -5,7 +5,7 @@ import android.content.DialogInterface; import android.view.View; import eu.kanade.mangafeed.R; -import eu.kanade.mangafeed.data.mangasync.base.BaseMangaSync; +import eu.kanade.mangafeed.data.mangasync.base.MangaSyncService; import eu.kanade.mangafeed.data.preference.PreferencesHelper; import eu.kanade.mangafeed.util.ToastUtil; import rx.android.schedulers.AndroidSchedulers; @@ -13,9 +13,9 @@ import rx.schedulers.Schedulers; public class MangaSyncLoginDialog extends LoginDialogPreference { - private BaseMangaSync sync; + private MangaSyncService sync; - public MangaSyncLoginDialog(Context context, PreferencesHelper preferences, BaseMangaSync sync) { + public MangaSyncLoginDialog(Context context, PreferencesHelper preferences, MangaSyncService sync) { super(context, preferences); this.sync = sync; } diff --git a/build.gradle b/build.gradle index 4a3d4254d6..5a595d4a21 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:1.5.0' classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+' - classpath 'com.neenbedankt.gradle.plugins:android-apt:1.7' + classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' classpath 'me.tatarka:gradle-retrolambda:3.2.4' classpath 'com.github.ben-manes:gradle-versions-plugin:0.11.3' // NOTE: Do not place your application dependencies here; they belong