Upgrade storio to 1.7.0

This commit is contained in:
inorichi 2015-12-29 21:47:03 +01:00
parent 62535c77ae
commit b0ad72afad
9 changed files with 35 additions and 64 deletions

View File

@ -78,7 +78,7 @@ dependencies {
final DAGGER_VERSION = '2.0.2' final DAGGER_VERSION = '2.0.2'
final HAMCREST_VERSION = '1.3' final HAMCREST_VERSION = '1.3'
final MOCKITO_VERSION = '1.10.19' final MOCKITO_VERSION = '1.10.19'
final STORIO_VERSION = '1.6.1' final STORIO_VERSION = '1.7.0'
final ICEPICK_VERSION = '3.1.0' final ICEPICK_VERSION = '3.1.0'
compile fileTree(dir: 'libs', include: ['*.jar']) compile fileTree(dir: 'libs', include: ['*.jar'])

View File

@ -3,13 +3,13 @@ package eu.kanade.mangafeed.data.database;
import android.content.Context; import android.content.Context;
import com.pushtorefresh.storio.Queries; import com.pushtorefresh.storio.Queries;
import com.pushtorefresh.storio.sqlite.SQLiteTypeMapping;
import com.pushtorefresh.storio.sqlite.StorIOSQLite; import com.pushtorefresh.storio.sqlite.StorIOSQLite;
import com.pushtorefresh.storio.sqlite.impl.DefaultStorIOSQLite; import com.pushtorefresh.storio.sqlite.impl.DefaultStorIOSQLite;
import com.pushtorefresh.storio.sqlite.operations.delete.PreparedDeleteByQuery; import com.pushtorefresh.storio.sqlite.operations.delete.PreparedDeleteByQuery;
import com.pushtorefresh.storio.sqlite.operations.delete.PreparedDeleteCollectionOfObjects; import com.pushtorefresh.storio.sqlite.operations.delete.PreparedDeleteCollectionOfObjects;
import com.pushtorefresh.storio.sqlite.operations.delete.PreparedDeleteObject; import com.pushtorefresh.storio.sqlite.operations.delete.PreparedDeleteObject;
import com.pushtorefresh.storio.sqlite.operations.get.PreparedGetListOfObjects; import com.pushtorefresh.storio.sqlite.operations.get.PreparedGetListOfObjects;
import com.pushtorefresh.storio.sqlite.operations.get.PreparedGetObject;
import com.pushtorefresh.storio.sqlite.operations.put.PreparedPutCollectionOfObjects; import com.pushtorefresh.storio.sqlite.operations.put.PreparedPutCollectionOfObjects;
import com.pushtorefresh.storio.sqlite.operations.put.PreparedPutObject; import com.pushtorefresh.storio.sqlite.operations.put.PreparedPutObject;
import com.pushtorefresh.storio.sqlite.operations.put.PutResults; import com.pushtorefresh.storio.sqlite.operations.put.PutResults;
@ -20,25 +20,15 @@ import com.pushtorefresh.storio.sqlite.queries.RawQuery;
import java.util.List; import java.util.List;
import eu.kanade.mangafeed.data.database.models.Category; import eu.kanade.mangafeed.data.database.models.Category;
import eu.kanade.mangafeed.data.database.models.CategoryStorIOSQLiteDeleteResolver; import eu.kanade.mangafeed.data.database.models.CategorySQLiteTypeMapping;
import eu.kanade.mangafeed.data.database.models.CategoryStorIOSQLiteGetResolver;
import eu.kanade.mangafeed.data.database.models.CategoryStorIOSQLitePutResolver;
import eu.kanade.mangafeed.data.database.models.Chapter; import eu.kanade.mangafeed.data.database.models.Chapter;
import eu.kanade.mangafeed.data.database.models.ChapterStorIOSQLiteDeleteResolver; import eu.kanade.mangafeed.data.database.models.ChapterSQLiteTypeMapping;
import eu.kanade.mangafeed.data.database.models.ChapterStorIOSQLiteGetResolver;
import eu.kanade.mangafeed.data.database.models.ChapterStorIOSQLitePutResolver;
import eu.kanade.mangafeed.data.database.models.Manga; import eu.kanade.mangafeed.data.database.models.Manga;
import eu.kanade.mangafeed.data.database.models.MangaCategory; import eu.kanade.mangafeed.data.database.models.MangaCategory;
import eu.kanade.mangafeed.data.database.models.MangaCategoryStorIOSQLiteDeleteResolver; import eu.kanade.mangafeed.data.database.models.MangaCategorySQLiteTypeMapping;
import eu.kanade.mangafeed.data.database.models.MangaCategoryStorIOSQLiteGetResolver; import eu.kanade.mangafeed.data.database.models.MangaSQLiteTypeMapping;
import eu.kanade.mangafeed.data.database.models.MangaCategoryStorIOSQLitePutResolver;
import eu.kanade.mangafeed.data.database.models.MangaStorIOSQLiteDeleteResolver;
import eu.kanade.mangafeed.data.database.models.MangaStorIOSQLiteGetResolver;
import eu.kanade.mangafeed.data.database.models.MangaStorIOSQLitePutResolver;
import eu.kanade.mangafeed.data.database.models.MangaSync; import eu.kanade.mangafeed.data.database.models.MangaSync;
import eu.kanade.mangafeed.data.database.models.MangaSyncStorIOSQLiteDeleteResolver; import eu.kanade.mangafeed.data.database.models.MangaSyncSQLiteTypeMapping;
import eu.kanade.mangafeed.data.database.models.MangaSyncStorIOSQLiteGetResolver;
import eu.kanade.mangafeed.data.database.models.MangaSyncStorIOSQLitePutResolver;
import eu.kanade.mangafeed.data.database.resolvers.LibraryMangaGetResolver; import eu.kanade.mangafeed.data.database.resolvers.LibraryMangaGetResolver;
import eu.kanade.mangafeed.data.database.tables.CategoryTable; import eu.kanade.mangafeed.data.database.tables.CategoryTable;
import eu.kanade.mangafeed.data.database.tables.ChapterTable; import eu.kanade.mangafeed.data.database.tables.ChapterTable;
@ -58,31 +48,11 @@ public class DatabaseHelper {
db = DefaultStorIOSQLite.builder() db = DefaultStorIOSQLite.builder()
.sqliteOpenHelper(new DbOpenHelper(context)) .sqliteOpenHelper(new DbOpenHelper(context))
.addTypeMapping(Manga.class, SQLiteTypeMapping.<Manga>builder() .addTypeMapping(Manga.class, new MangaSQLiteTypeMapping())
.putResolver(new MangaStorIOSQLitePutResolver()) .addTypeMapping(Chapter.class, new ChapterSQLiteTypeMapping())
.getResolver(new MangaStorIOSQLiteGetResolver()) .addTypeMapping(MangaSync.class, new MangaSyncSQLiteTypeMapping())
.deleteResolver(new MangaStorIOSQLiteDeleteResolver()) .addTypeMapping(Category.class, new CategorySQLiteTypeMapping())
.build()) .addTypeMapping(MangaCategory.class, new MangaCategorySQLiteTypeMapping())
.addTypeMapping(Chapter.class, SQLiteTypeMapping.<Chapter>builder()
.putResolver(new ChapterStorIOSQLitePutResolver())
.getResolver(new ChapterStorIOSQLiteGetResolver())
.deleteResolver(new ChapterStorIOSQLiteDeleteResolver())
.build())
.addTypeMapping(MangaSync.class, SQLiteTypeMapping.<MangaSync>builder()
.putResolver(new MangaSyncStorIOSQLitePutResolver())
.getResolver(new MangaSyncStorIOSQLiteGetResolver())
.deleteResolver(new MangaSyncStorIOSQLiteDeleteResolver())
.build())
.addTypeMapping(Category.class, SQLiteTypeMapping.<Category>builder()
.putResolver(new CategoryStorIOSQLitePutResolver())
.getResolver(new CategoryStorIOSQLiteGetResolver())
.deleteResolver(new CategoryStorIOSQLiteDeleteResolver())
.build())
.addTypeMapping(MangaCategory.class, SQLiteTypeMapping.<MangaCategory>builder()
.putResolver(new MangaCategoryStorIOSQLitePutResolver())
.getResolver(new MangaCategoryStorIOSQLiteGetResolver())
.deleteResolver(new MangaCategoryStorIOSQLiteDeleteResolver())
.build())
.build(); .build();
} }
@ -115,13 +85,14 @@ public class DatabaseHelper {
.table(MangaTable.TABLE) .table(MangaTable.TABLE)
.where(MangaTable.COLUMN_FAVORITE + "=?") .where(MangaTable.COLUMN_FAVORITE + "=?")
.whereArgs(1) .whereArgs(1)
.orderBy(MangaTable.COLUMN_TITLE)
.build()) .build())
.prepare(); .prepare();
} }
public PreparedGetListOfObjects<Manga> getManga(String url, int sourceId) { public PreparedGetObject<Manga> getManga(String url, int sourceId) {
return db.get() return db.get()
.listOfObjects(Manga.class) .object(Manga.class)
.withQuery(Query.builder() .withQuery(Query.builder()
.table(MangaTable.TABLE) .table(MangaTable.TABLE)
.where(MangaTable.COLUMN_URL + "=? AND " + MangaTable.COLUMN_SOURCE + "=?") .where(MangaTable.COLUMN_URL + "=? AND " + MangaTable.COLUMN_SOURCE + "=?")
@ -130,9 +101,9 @@ public class DatabaseHelper {
.prepare(); .prepare();
} }
public PreparedGetListOfObjects<Manga> getManga(long id) { public PreparedGetObject<Manga> getManga(long id) {
return db.get() return db.get()
.listOfObjects(Manga.class) .object(Manga.class)
.withQuery(Query.builder() .withQuery(Query.builder()
.table(MangaTable.TABLE) .table(MangaTable.TABLE)
.where(MangaTable.COLUMN_ID + "=?") .where(MangaTable.COLUMN_ID + "=?")
@ -199,13 +170,13 @@ public class DatabaseHelper {
.prepare(); .prepare();
} }
public PreparedGetListOfObjects<Chapter> getNextChapter(Chapter chapter) { public PreparedGetObject<Chapter> getNextChapter(Chapter chapter) {
// Add a delta to the chapter number, because binary decimal representation // Add a delta to the chapter number, because binary decimal representation
// can retrieve the same chapter again // can retrieve the same chapter again
double chapterNumber = chapter.chapter_number + 0.00001; double chapterNumber = chapter.chapter_number + 0.00001;
return db.get() return db.get()
.listOfObjects(Chapter.class) .object(Chapter.class)
.withQuery(Query.builder() .withQuery(Query.builder()
.table(ChapterTable.TABLE) .table(ChapterTable.TABLE)
.where(ChapterTable.COLUMN_MANGA_ID + "=? AND " + .where(ChapterTable.COLUMN_MANGA_ID + "=? AND " +
@ -218,13 +189,13 @@ public class DatabaseHelper {
.prepare(); .prepare();
} }
public PreparedGetListOfObjects<Chapter> getPreviousChapter(Chapter chapter) { public PreparedGetObject<Chapter> getPreviousChapter(Chapter chapter) {
// Add a delta to the chapter number, because binary decimal representation // Add a delta to the chapter number, because binary decimal representation
// can retrieve the same chapter again // can retrieve the same chapter again
double chapterNumber = chapter.chapter_number - 0.00001; double chapterNumber = chapter.chapter_number - 0.00001;
return db.get() return db.get()
.listOfObjects(Chapter.class) .object(Chapter.class)
.withQuery(Query.builder() .withQuery(Query.builder()
.table(ChapterTable.TABLE) .table(ChapterTable.TABLE)
.where(ChapterTable.COLUMN_MANGA_ID + "=? AND " + .where(ChapterTable.COLUMN_MANGA_ID + "=? AND " +
@ -237,9 +208,9 @@ public class DatabaseHelper {
.prepare(); .prepare();
} }
public PreparedGetListOfObjects<Chapter> getNextUnreadChapter(Manga manga) { public PreparedGetObject<Chapter> getNextUnreadChapter(Manga manga) {
return db.get() return db.get()
.listOfObjects(Chapter.class) .object(Chapter.class)
.withQuery(Query.builder() .withQuery(Query.builder()
.table(ChapterTable.TABLE) .table(ChapterTable.TABLE)
.where(ChapterTable.COLUMN_MANGA_ID + "=? AND " + .where(ChapterTable.COLUMN_MANGA_ID + "=? AND " +
@ -312,9 +283,9 @@ public class DatabaseHelper {
// Manga sync related queries // Manga sync related queries
public PreparedGetListOfObjects<MangaSync> getMangaSync(Manga manga, MangaSyncService sync) { public PreparedGetObject<MangaSync> getMangaSync(Manga manga, MangaSyncService sync) {
return db.get() return db.get()
.listOfObjects(MangaSync.class) .object(MangaSync.class)
.withQuery(Query.builder() .withQuery(Query.builder()
.table(MangaSyncTable.TABLE) .table(MangaSyncTable.TABLE)
.where(MangaSyncTable.COLUMN_MANGA_ID + "=? AND " + .where(MangaSyncTable.COLUMN_MANGA_ID + "=? AND " +
@ -324,7 +295,7 @@ public class DatabaseHelper {
.prepare(); .prepare();
} }
public PreparedGetListOfObjects<MangaSync> getMangaSync(Manga manga) { public PreparedGetListOfObjects<MangaSync> getMangasSync(Manga manga) {
return db.get() return db.get()
.listOfObjects(MangaSync.class) .listOfObjects(MangaSync.class)
.withQuery(Query.builder() .withQuery(Query.builder()

View File

@ -29,6 +29,9 @@ public class MangaSync implements Serializable {
@StorIOSQLiteColumn(name = MangaSyncTable.COLUMN_LAST_CHAPTER_READ) @StorIOSQLiteColumn(name = MangaSyncTable.COLUMN_LAST_CHAPTER_READ)
public int last_chapter_read; public int last_chapter_read;
@StorIOSQLiteColumn(name = MangaSyncTable.COLUMN_TOTAL_CHAPTERS)
public int total_chapters;
@StorIOSQLiteColumn(name = MangaSyncTable.COLUMN_SCORE) @StorIOSQLiteColumn(name = MangaSyncTable.COLUMN_SCORE)
public float score; public float score;

View File

@ -22,6 +22,8 @@ public class MangaSyncTable {
public static final String COLUMN_SCORE = "score"; public static final String COLUMN_SCORE = "score";
public static final String COLUMN_TOTAL_CHAPTERS = "total_chapters";
@NonNull @NonNull
public static String getCreateTableQuery() { public static String getCreateTableQuery() {
return "CREATE TABLE " + TABLE + "(" return "CREATE TABLE " + TABLE + "("
@ -31,6 +33,7 @@ public class MangaSyncTable {
+ COLUMN_REMOTE_ID + " INTEGER NOT NULL, " + COLUMN_REMOTE_ID + " INTEGER NOT NULL, "
+ COLUMN_TITLE + " TEXT NOT NULL, " + COLUMN_TITLE + " TEXT NOT NULL, "
+ COLUMN_LAST_CHAPTER_READ + " INTEGER NOT NULL, " + COLUMN_LAST_CHAPTER_READ + " INTEGER NOT NULL, "
+ COLUMN_TOTAL_CHAPTERS + " INTEGER NOT NULL, "
+ COLUMN_STATUS + " INTEGER NOT NULL, " + COLUMN_STATUS + " INTEGER NOT NULL, "
+ COLUMN_SCORE + " FLOAT NOT NULL, " + COLUMN_SCORE + " FLOAT NOT NULL, "
+ "FOREIGN KEY(" + COLUMN_MANGA_ID + ") REFERENCES " + MangaTable.TABLE + "(" + MangaTable.COLUMN_ID + ") " + "FOREIGN KEY(" + COLUMN_MANGA_ID + ") REFERENCES " + MangaTable.TABLE + "(" + MangaTable.COLUMN_ID + ") "

View File

@ -134,8 +134,7 @@ public class CataloguePresenter extends BasePresenter<CatalogueFragment> {
} }
private Manga networkToLocalManga(Manga networkManga) { private Manga networkToLocalManga(Manga networkManga) {
List<Manga> dbResult = db.getManga(networkManga.url, source.getId()).executeAsBlocking(); Manga localManga = db.getManga(networkManga.url, source.getId()).executeAsBlocking();
Manga localManga = !dbResult.isEmpty() ? dbResult.get(0) : null;
if (localManga == null) { if (localManga == null) {
PutResult result = db.insertManga(networkManga).executeAsBlocking(); PutResult result = db.insertManga(networkManga).executeAsBlocking();
networkManga.id = result.insertedId(); networkManga.id = result.insertedId();

View File

@ -38,7 +38,6 @@ public class MangaPresenter extends BasePresenter<MangaActivity> {
private Observable<Manga> getDbMangaObservable() { private Observable<Manga> getDbMangaObservable() {
return db.getManga(mangaId).createObservable() return db.getManga(mangaId).createObservable()
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.flatMap(Observable::from)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.doOnNext(manga -> EventBus.getDefault().postSticky(manga)); .doOnNext(manga -> EventBus.getDefault().postSticky(manga));
} }

View File

@ -191,8 +191,7 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
} }
public Chapter getNextUnreadChapter() { public Chapter getNextUnreadChapter() {
List<Chapter> chapters = db.getNextUnreadChapter(manga).executeAsBlocking(); return db.getNextUnreadChapter(manga).executeAsBlocking();
return !chapters.isEmpty() ? chapters.get(0) : null;
} }
public void markChaptersRead(Observable<Chapter> selectedChapters, boolean read) { public void markChaptersRead(Observable<Chapter> selectedChapters, boolean read) {

View File

@ -45,7 +45,6 @@ public class MyAnimeListPresenter extends BasePresenter<MyAnimeListFragment> {
restartableLatestCache(GET_MANGA_SYNC, restartableLatestCache(GET_MANGA_SYNC,
() -> db.getMangaSync(manga, myAnimeList).createObservable() () -> db.getMangaSync(manga, myAnimeList).createObservable()
.flatMap(Observable::from)
.doOnNext(mangaSync -> this.mangaSync = mangaSync) .doOnNext(mangaSync -> this.mangaSync = mangaSync)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()), .observeOn(AndroidSchedulers.mainThread()),

View File

@ -249,7 +249,7 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
if (pageList == null) if (pageList == null)
return; return;
db.getMangaSync(manga).createObservable() db.getMangasSync(manga).createObservable()
.take(1) .take(1)
.flatMap(Observable::from) .flatMap(Observable::from)
.doOnNext(mangaSync -> { .doOnNext(mangaSync -> {
@ -281,12 +281,10 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
private void getAdjacentChapters() { private void getAdjacentChapters() {
add(db.getNextChapter(chapter).createObservable() add(db.getNextChapter(chapter).createObservable()
.take(1) .take(1)
.flatMap(Observable::from)
.subscribe(result -> nextChapter = result)); .subscribe(result -> nextChapter = result));
add(db.getPreviousChapter(chapter).createObservable() add(db.getPreviousChapter(chapter).createObservable()
.take(1) .take(1)
.flatMap(Observable::from)
.subscribe(result -> previousChapter = result)); .subscribe(result -> previousChapter = result));
} }