Update dependencies. Update last chapter read in MAL only when the reader is left, instead of on every chapter change. Other minor improvements.

This commit is contained in:
inorichi 2015-12-16 15:37:00 +01:00
parent 273527e7fb
commit 04d9176c3c
13 changed files with 82 additions and 106 deletions

View file

@ -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') {

View file

@ -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<MangaSync> getMangaSync(Manga manga, BaseMangaSync sync) {
public PreparedGetListOfObjects<MangaSync> getMangaSync(Manga manga, MangaSyncService sync) {
return db.get()
.listOfObjects(MangaSync.class)
.withQuery(Query.builder()
@ -316,6 +315,17 @@ public class DatabaseHelper {
.prepare();
}
public PreparedGetListOfObjects<MangaSync> 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<MangaSync> insertMangaSync(MangaSync manga) {
return db.put()
.object(manga)

View file

@ -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;

View file

@ -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<BaseMangaSync> services;
private List<MangaSyncService> services;
private MyAnimeList myAnimeList;
public static final int MYANIMELIST = 1;
@ -25,11 +25,11 @@ public class MangaSyncManager {
return myAnimeList;
}
public List<BaseMangaSync> getSyncServices() {
public List<MangaSyncService> getSyncServices() {
return services;
}
public BaseMangaSync getSyncService(int id) {
public MangaSyncService getSyncService(int id) {
switch (id) {
case MYANIMELIST:
return myAnimeList;

View file

@ -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();

View file

@ -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;

View file

@ -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)

View file

@ -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);
}));
}

View file

@ -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;
}
}

View file

@ -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<ReaderActivity> {
private PublishSubject<Page> 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<ReaderActivity> {
@Override
protected void onDestroy() {
unregisterForEvents();
if (pageList != null && isChapterFinished()) {
updateMangaSyncLastChapterRead();
}
onChapterLeft();
super.onDestroy();
}
@ -231,13 +228,11 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
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<ReaderActivity> {
}
private void updateMangaSyncLastChapterRead() {
// TODO don't use MAL methods for possible alternatives to MAL
MyAnimeList mal = syncManager.getMyAnimeList();
if (!mal.isLogged())
db.getMangaSync(manga).createObservable()
.take(1)
.flatMap(Observable::from)
.doOnNext(mangaSync -> {
MangaSyncService service = syncManager.getSyncService(mangaSync.sync_id);
if (!service.isLogged())
return;
List<MangaSync> 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());
UpdateMangaSyncService.start(getContext(), mangaSync);
}
})
.subscribe();
}
public void setCurrentPage(int currentPage) {
@ -273,20 +265,14 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
}
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));
}

View file

@ -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());

View file

@ -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;
}

View file

@ -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