diff --git a/app/build.gradle b/app/build.gradle index 3350298b4..1ffd51528 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -78,7 +78,7 @@ dependencies { final DAGGER_VERSION = '2.0.2' final HAMCREST_VERSION = '1.3' final MOCKITO_VERSION = '1.10.19' - final STORIO_VERSION = '1.6.1' + final STORIO_VERSION = '1.7.0' final ICEPICK_VERSION = '3.1.0' compile fileTree(dir: 'libs', include: ['*.jar']) 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 f0ece368a..9fc064d47 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 @@ -3,13 +3,13 @@ package eu.kanade.mangafeed.data.database; import android.content.Context; import com.pushtorefresh.storio.Queries; -import com.pushtorefresh.storio.sqlite.SQLiteTypeMapping; import com.pushtorefresh.storio.sqlite.StorIOSQLite; import com.pushtorefresh.storio.sqlite.impl.DefaultStorIOSQLite; import com.pushtorefresh.storio.sqlite.operations.delete.PreparedDeleteByQuery; import com.pushtorefresh.storio.sqlite.operations.delete.PreparedDeleteCollectionOfObjects; import com.pushtorefresh.storio.sqlite.operations.delete.PreparedDeleteObject; 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.PreparedPutObject; import com.pushtorefresh.storio.sqlite.operations.put.PutResults; @@ -20,25 +20,15 @@ import com.pushtorefresh.storio.sqlite.queries.RawQuery; import java.util.List; import eu.kanade.mangafeed.data.database.models.Category; -import eu.kanade.mangafeed.data.database.models.CategoryStorIOSQLiteDeleteResolver; -import eu.kanade.mangafeed.data.database.models.CategoryStorIOSQLiteGetResolver; -import eu.kanade.mangafeed.data.database.models.CategoryStorIOSQLitePutResolver; +import eu.kanade.mangafeed.data.database.models.CategorySQLiteTypeMapping; import eu.kanade.mangafeed.data.database.models.Chapter; -import eu.kanade.mangafeed.data.database.models.ChapterStorIOSQLiteDeleteResolver; -import eu.kanade.mangafeed.data.database.models.ChapterStorIOSQLiteGetResolver; -import eu.kanade.mangafeed.data.database.models.ChapterStorIOSQLitePutResolver; +import eu.kanade.mangafeed.data.database.models.ChapterSQLiteTypeMapping; import eu.kanade.mangafeed.data.database.models.Manga; import eu.kanade.mangafeed.data.database.models.MangaCategory; -import eu.kanade.mangafeed.data.database.models.MangaCategoryStorIOSQLiteDeleteResolver; -import eu.kanade.mangafeed.data.database.models.MangaCategoryStorIOSQLiteGetResolver; -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.MangaCategorySQLiteTypeMapping; +import eu.kanade.mangafeed.data.database.models.MangaSQLiteTypeMapping; import eu.kanade.mangafeed.data.database.models.MangaSync; -import eu.kanade.mangafeed.data.database.models.MangaSyncStorIOSQLiteDeleteResolver; -import eu.kanade.mangafeed.data.database.models.MangaSyncStorIOSQLiteGetResolver; -import eu.kanade.mangafeed.data.database.models.MangaSyncStorIOSQLitePutResolver; +import eu.kanade.mangafeed.data.database.models.MangaSyncSQLiteTypeMapping; import eu.kanade.mangafeed.data.database.resolvers.LibraryMangaGetResolver; import eu.kanade.mangafeed.data.database.tables.CategoryTable; import eu.kanade.mangafeed.data.database.tables.ChapterTable; @@ -58,31 +48,11 @@ public class DatabaseHelper { db = DefaultStorIOSQLite.builder() .sqliteOpenHelper(new DbOpenHelper(context)) - .addTypeMapping(Manga.class, SQLiteTypeMapping.builder() - .putResolver(new MangaStorIOSQLitePutResolver()) - .getResolver(new MangaStorIOSQLiteGetResolver()) - .deleteResolver(new MangaStorIOSQLiteDeleteResolver()) - .build()) - .addTypeMapping(Chapter.class, SQLiteTypeMapping.builder() - .putResolver(new ChapterStorIOSQLitePutResolver()) - .getResolver(new ChapterStorIOSQLiteGetResolver()) - .deleteResolver(new ChapterStorIOSQLiteDeleteResolver()) - .build()) - .addTypeMapping(MangaSync.class, SQLiteTypeMapping.builder() - .putResolver(new MangaSyncStorIOSQLitePutResolver()) - .getResolver(new MangaSyncStorIOSQLiteGetResolver()) - .deleteResolver(new MangaSyncStorIOSQLiteDeleteResolver()) - .build()) - .addTypeMapping(Category.class, SQLiteTypeMapping.builder() - .putResolver(new CategoryStorIOSQLitePutResolver()) - .getResolver(new CategoryStorIOSQLiteGetResolver()) - .deleteResolver(new CategoryStorIOSQLiteDeleteResolver()) - .build()) - .addTypeMapping(MangaCategory.class, SQLiteTypeMapping.builder() - .putResolver(new MangaCategoryStorIOSQLitePutResolver()) - .getResolver(new MangaCategoryStorIOSQLiteGetResolver()) - .deleteResolver(new MangaCategoryStorIOSQLiteDeleteResolver()) - .build()) + .addTypeMapping(Manga.class, new MangaSQLiteTypeMapping()) + .addTypeMapping(Chapter.class, new ChapterSQLiteTypeMapping()) + .addTypeMapping(MangaSync.class, new MangaSyncSQLiteTypeMapping()) + .addTypeMapping(Category.class, new CategorySQLiteTypeMapping()) + .addTypeMapping(MangaCategory.class, new MangaCategorySQLiteTypeMapping()) .build(); } @@ -115,13 +85,14 @@ public class DatabaseHelper { .table(MangaTable.TABLE) .where(MangaTable.COLUMN_FAVORITE + "=?") .whereArgs(1) + .orderBy(MangaTable.COLUMN_TITLE) .build()) .prepare(); } - public PreparedGetListOfObjects getManga(String url, int sourceId) { + public PreparedGetObject getManga(String url, int sourceId) { return db.get() - .listOfObjects(Manga.class) + .object(Manga.class) .withQuery(Query.builder() .table(MangaTable.TABLE) .where(MangaTable.COLUMN_URL + "=? AND " + MangaTable.COLUMN_SOURCE + "=?") @@ -130,9 +101,9 @@ public class DatabaseHelper { .prepare(); } - public PreparedGetListOfObjects getManga(long id) { + public PreparedGetObject getManga(long id) { return db.get() - .listOfObjects(Manga.class) + .object(Manga.class) .withQuery(Query.builder() .table(MangaTable.TABLE) .where(MangaTable.COLUMN_ID + "=?") @@ -199,13 +170,13 @@ public class DatabaseHelper { .prepare(); } - public PreparedGetListOfObjects getNextChapter(Chapter chapter) { + public PreparedGetObject getNextChapter(Chapter chapter) { // Add a delta to the chapter number, because binary decimal representation // can retrieve the same chapter again double chapterNumber = chapter.chapter_number + 0.00001; return db.get() - .listOfObjects(Chapter.class) + .object(Chapter.class) .withQuery(Query.builder() .table(ChapterTable.TABLE) .where(ChapterTable.COLUMN_MANGA_ID + "=? AND " + @@ -218,13 +189,13 @@ public class DatabaseHelper { .prepare(); } - public PreparedGetListOfObjects getPreviousChapter(Chapter chapter) { + public PreparedGetObject getPreviousChapter(Chapter chapter) { // Add a delta to the chapter number, because binary decimal representation // can retrieve the same chapter again double chapterNumber = chapter.chapter_number - 0.00001; return db.get() - .listOfObjects(Chapter.class) + .object(Chapter.class) .withQuery(Query.builder() .table(ChapterTable.TABLE) .where(ChapterTable.COLUMN_MANGA_ID + "=? AND " + @@ -237,9 +208,9 @@ public class DatabaseHelper { .prepare(); } - public PreparedGetListOfObjects getNextUnreadChapter(Manga manga) { + public PreparedGetObject getNextUnreadChapter(Manga manga) { return db.get() - .listOfObjects(Chapter.class) + .object(Chapter.class) .withQuery(Query.builder() .table(ChapterTable.TABLE) .where(ChapterTable.COLUMN_MANGA_ID + "=? AND " + @@ -312,9 +283,9 @@ public class DatabaseHelper { // Manga sync related queries - public PreparedGetListOfObjects getMangaSync(Manga manga, MangaSyncService sync) { + public PreparedGetObject getMangaSync(Manga manga, MangaSyncService sync) { return db.get() - .listOfObjects(MangaSync.class) + .object(MangaSync.class) .withQuery(Query.builder() .table(MangaSyncTable.TABLE) .where(MangaSyncTable.COLUMN_MANGA_ID + "=? AND " + @@ -324,7 +295,7 @@ public class DatabaseHelper { .prepare(); } - public PreparedGetListOfObjects getMangaSync(Manga manga) { + public PreparedGetListOfObjects getMangasSync(Manga manga) { return db.get() .listOfObjects(MangaSync.class) .withQuery(Query.builder() 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 e95e5ca20..a9c40f203 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 @@ -29,6 +29,9 @@ public class MangaSync implements Serializable { @StorIOSQLiteColumn(name = MangaSyncTable.COLUMN_LAST_CHAPTER_READ) public int last_chapter_read; + @StorIOSQLiteColumn(name = MangaSyncTable.COLUMN_TOTAL_CHAPTERS) + public int total_chapters; + @StorIOSQLiteColumn(name = MangaSyncTable.COLUMN_SCORE) public float score; diff --git a/app/src/main/java/eu/kanade/mangafeed/data/database/tables/MangaSyncTable.java b/app/src/main/java/eu/kanade/mangafeed/data/database/tables/MangaSyncTable.java index 6e2a679ad..7dcdd86b4 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/database/tables/MangaSyncTable.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/database/tables/MangaSyncTable.java @@ -22,6 +22,8 @@ public class MangaSyncTable { public static final String COLUMN_SCORE = "score"; + public static final String COLUMN_TOTAL_CHAPTERS = "total_chapters"; + @NonNull public static String getCreateTableQuery() { return "CREATE TABLE " + TABLE + "(" @@ -31,6 +33,7 @@ public class MangaSyncTable { + COLUMN_REMOTE_ID + " INTEGER NOT NULL, " + COLUMN_TITLE + " TEXT NOT NULL, " + COLUMN_LAST_CHAPTER_READ + " INTEGER NOT NULL, " + + COLUMN_TOTAL_CHAPTERS + " INTEGER NOT NULL, " + COLUMN_STATUS + " INTEGER NOT NULL, " + COLUMN_SCORE + " FLOAT NOT NULL, " + "FOREIGN KEY(" + COLUMN_MANGA_ID + ") REFERENCES " + MangaTable.TABLE + "(" + MangaTable.COLUMN_ID + ") " diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CataloguePresenter.java b/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CataloguePresenter.java index 62db49da9..208e60337 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CataloguePresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CataloguePresenter.java @@ -134,8 +134,7 @@ public class CataloguePresenter extends BasePresenter { } private Manga networkToLocalManga(Manga networkManga) { - List dbResult = db.getManga(networkManga.url, source.getId()).executeAsBlocking(); - Manga localManga = !dbResult.isEmpty() ? dbResult.get(0) : null; + Manga localManga = db.getManga(networkManga.url, source.getId()).executeAsBlocking(); if (localManga == null) { PutResult result = db.insertManga(networkManga).executeAsBlocking(); networkManga.id = result.insertedId(); diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/manga/MangaPresenter.java b/app/src/main/java/eu/kanade/mangafeed/ui/manga/MangaPresenter.java index 803b9dea9..d7548743a 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/manga/MangaPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/manga/MangaPresenter.java @@ -38,7 +38,6 @@ public class MangaPresenter extends BasePresenter { private Observable getDbMangaObservable() { return db.getManga(mangaId).createObservable() .subscribeOn(Schedulers.io()) - .flatMap(Observable::from) .observeOn(AndroidSchedulers.mainThread()) .doOnNext(manga -> EventBus.getDefault().postSticky(manga)); } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/manga/chapter/ChaptersPresenter.java b/app/src/main/java/eu/kanade/mangafeed/ui/manga/chapter/ChaptersPresenter.java index 069a4f327..a97d0638f 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/manga/chapter/ChaptersPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/manga/chapter/ChaptersPresenter.java @@ -191,8 +191,7 @@ public class ChaptersPresenter extends BasePresenter { } public Chapter getNextUnreadChapter() { - List chapters = db.getNextUnreadChapter(manga).executeAsBlocking(); - return !chapters.isEmpty() ? chapters.get(0) : null; + return db.getNextUnreadChapter(manga).executeAsBlocking(); } public void markChaptersRead(Observable selectedChapters, boolean read) { diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/manga/myanimelist/MyAnimeListPresenter.java b/app/src/main/java/eu/kanade/mangafeed/ui/manga/myanimelist/MyAnimeListPresenter.java index d6eaf297a..c9ca4cb38 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/manga/myanimelist/MyAnimeListPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/manga/myanimelist/MyAnimeListPresenter.java @@ -45,7 +45,6 @@ public class MyAnimeListPresenter extends BasePresenter { restartableLatestCache(GET_MANGA_SYNC, () -> db.getMangaSync(manga, myAnimeList).createObservable() - .flatMap(Observable::from) .doOnNext(mangaSync -> this.mangaSync = mangaSync) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()), 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 78f5fc88c..6b47ff820 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 @@ -249,7 +249,7 @@ public class ReaderPresenter extends BasePresenter { if (pageList == null) return; - db.getMangaSync(manga).createObservable() + db.getMangasSync(manga).createObservable() .take(1) .flatMap(Observable::from) .doOnNext(mangaSync -> { @@ -281,12 +281,10 @@ public class ReaderPresenter extends BasePresenter { private void getAdjacentChapters() { add(db.getNextChapter(chapter).createObservable() .take(1) - .flatMap(Observable::from) .subscribe(result -> nextChapter = result)); add(db.getPreviousChapter(chapter).createObservable() .take(1) - .flatMap(Observable::from) .subscribe(result -> previousChapter = result)); }