diff --git a/README-zh-TW.md b/README-zh-TW.md index 13f76f51e..1fc7ea7d4 100644 --- a/README-zh-TW.md +++ b/README-zh-TW.md @@ -57,7 +57,6 @@ Here is the libraries - [GnuTLS](https://gnutls.org/) - [material-components-android](https://github.com/material-components/material-components-android) - [material-design-icons](https://github.com/google/material-design-icons) -- [greenDAO](https://github.com/greenrobot/greenDAO) - [jsoup](https://github.com/jhy/jsoup) - [okhttp](https://github.com/square/okhttp) - [RikkaX](https://github.com/RikkaApps/RikkaX) diff --git a/README.md b/README.md index 7da315c66..982fc6192 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,6 @@ Here is the libraries - [GnuTLS](https://gnutls.org/) - [material-components-android](https://github.com/material-components/material-components-android) - [material-design-icons](https://github.com/google/material-design-icons) -- [greenDAO](https://github.com/greenrobot/greenDAO) - [jsoup](https://github.com/jhy/jsoup) - [okhttp](https://github.com/square/okhttp) - [RikkaX](https://github.com/RikkaApps/RikkaX) diff --git a/app/build.gradle b/app/build.gradle index dd03ade98..670fcc23c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -151,7 +151,7 @@ dependencies { def room_version = "2.5.0-alpha02" implementation "androidx.room:room-runtime:$room_version" - annotationProcessor "androidx.room:room-compiler:$room_version" + kapt "androidx.room:room-compiler:$room_version" implementation 'androidx.startup:startup-runtime:1.2.0-alpha01' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-alpha01' @@ -171,7 +171,6 @@ dependencies { implementation 'dev.rikka.rikkax.layoutinflater:layoutinflater:1.2.0' implementation 'dev.rikka.rikkax.preference:simplemenu-preference:1.0.3' implementation 'dev.rikka.rikkax.material:material-preference:2.0.0' - implementation 'org.greenrobot:greendao:3.3.0' implementation 'org.jsoup:jsoup:1.15.2' } diff --git a/app/src/main/java/com/hippo/ehviewer/EhDB.java b/app/src/main/java/com/hippo/ehviewer/EhDB.java index d3091bcc8..b5048fe71 100644 --- a/app/src/main/java/com/hippo/ehviewer/EhDB.java +++ b/app/src/main/java/com/hippo/ehviewer/EhDB.java @@ -25,42 +25,27 @@ import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.room.Room; import com.hippo.ehviewer.client.data.GalleryInfo; import com.hippo.ehviewer.client.data.ListUrlBuilder; -import com.hippo.ehviewer.dao.DaoMaster; -import com.hippo.ehviewer.dao.DaoSession; import com.hippo.ehviewer.dao.DownloadDirname; import com.hippo.ehviewer.dao.DownloadDirnameDao; import com.hippo.ehviewer.dao.DownloadInfo; import com.hippo.ehviewer.dao.DownloadLabel; import com.hippo.ehviewer.dao.DownloadLabelDao; import com.hippo.ehviewer.dao.DownloadsDao; +import com.hippo.ehviewer.dao.EhDatabase; import com.hippo.ehviewer.dao.Filter; -import com.hippo.ehviewer.dao.FilterDao; import com.hippo.ehviewer.dao.HistoryDao; import com.hippo.ehviewer.dao.HistoryInfo; import com.hippo.ehviewer.dao.LocalFavoriteInfo; import com.hippo.ehviewer.dao.LocalFavoritesDao; import com.hippo.ehviewer.dao.QuickSearch; import com.hippo.ehviewer.dao.QuickSearchDao; -import com.hippo.ehviewer.download.DownloadManager; import com.hippo.util.ExceptionUtils; -import com.hippo.util.SqlUtils; -import com.hippo.yorozuya.IOUtils; -import com.hippo.yorozuya.ObjectUtils; import com.hippo.yorozuya.collect.SparseJLArray; -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.query.CloseableListIterator; -import org.greenrobot.greendao.query.LazyList; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; import java.util.ArrayList; import java.util.List; @@ -70,7 +55,7 @@ public class EhDB { private static final int MAX_HISTORY_COUNT = 200; - private static DaoSession sDaoSession; + private static EhDatabase db; private static boolean sHasOldDB; private static boolean sNewDB; @@ -116,14 +101,7 @@ public class EhDB { public static void initialize(Context context) { sHasOldDB = context.getDatabasePath("data").exists(); - - DBOpenHelper helper = new DBOpenHelper( - context.getApplicationContext(), "eh.db", null); - - SQLiteDatabase db = helper.getWritableDatabase(); - DaoMaster daoMaster = new DaoMaster(db); - - sDaoSession = daoMaster.newSession(); + db = Room.databaseBuilder(context, EhDatabase.class, "eh.db").allowMainThreadQueries().build(); } public static boolean needMerge() { @@ -181,7 +159,7 @@ public class EhDB { try { Cursor cursor = oldDB.rawQuery("select * from " + OldDBHelper.TABLE_LOCAL_FAVOURITE, null); if (cursor != null) { - LocalFavoritesDao dao = sDaoSession.getLocalFavoritesDao(); + LocalFavoritesDao dao = db.localFavoritesDao(); if (cursor.moveToFirst()) { long i = 0L; while (!cursor.isAfterLast()) { @@ -213,7 +191,7 @@ public class EhDB { try { Cursor cursor = oldDB.rawQuery("select * from " + OldDBHelper.TABLE_TAG, null); if (cursor != null) { - QuickSearchDao dao = sDaoSession.getQuickSearchDao(); + QuickSearchDao dao = db.quickSearchDao(); if (cursor.moveToFirst()) { while (!cursor.isAfterLast()) { QuickSearch quickSearch = new QuickSearch(); @@ -249,7 +227,7 @@ public class EhDB { try { Cursor cursor = oldDB.rawQuery("select * from " + OldDBHelper.TABLE_DOWNLOAD, null); if (cursor != null) { - DownloadsDao dao = sDaoSession.getDownloadsDao(); + DownloadsDao dao = db.downloadsDao(); if (cursor.moveToFirst()) { long i = 0L; while (!cursor.isAfterLast()) { @@ -291,7 +269,7 @@ public class EhDB { // Merge history info Cursor cursor = oldDB.rawQuery("select * from " + OldDBHelper.TABLE_HISTORY, null); if (cursor != null) { - HistoryDao dao = sDaoSession.getHistoryDao(); + HistoryDao dao = db.historyDao(); if (cursor.moveToFirst()) { while (!cursor.isAfterLast()) { // Get GalleryInfo first @@ -326,8 +304,8 @@ public class EhDB { } public static synchronized List getAllDownloadInfo() { - DownloadsDao dao = sDaoSession.getDownloadsDao(); - List list = dao.queryBuilder().orderDesc(DownloadsDao.Properties.Time).list(); + DownloadsDao dao = db.downloadsDao(); + List list = dao.list(); // Fix state for (DownloadInfo info : list) { if (info.state == DownloadInfo.STATE_WAIT || info.state == DownloadInfo.STATE_DOWNLOAD) { @@ -339,7 +317,7 @@ public class EhDB { // Insert or update public static synchronized void putDownloadInfo(DownloadInfo downloadInfo) { - DownloadsDao dao = sDaoSession.getDownloadsDao(); + DownloadsDao dao = db.downloadsDao(); if (null != dao.load(downloadInfo.gid)) { // Update dao.update(downloadInfo); @@ -349,13 +327,13 @@ public class EhDB { } } - public static synchronized void removeDownloadInfo(long gid) { - sDaoSession.getDownloadsDao().deleteByKey(gid); + public static synchronized void removeDownloadInfo(DownloadInfo downloadInfo) { + db.downloadsDao().delete(downloadInfo); } @Nullable public static synchronized String getDownloadDirname(long gid) { - DownloadDirnameDao dao = sDaoSession.getDownloadDirnameDao(); + DownloadDirnameDao dao = db.downloadDirnameDao(); DownloadDirname raw = dao.load(gid); if (raw != null) { return raw.getDirname(); @@ -368,7 +346,7 @@ public class EhDB { * Insert or update */ public static synchronized void putDownloadDirname(long gid, String dirname) { - DownloadDirnameDao dao = sDaoSession.getDownloadDirnameDao(); + DownloadDirnameDao dao = db.downloadDirnameDao(); DownloadDirname raw = dao.load(gid); if (raw != null) { // Update raw.setDirname(dirname); @@ -382,23 +360,23 @@ public class EhDB { } public static synchronized void removeDownloadDirname(long gid) { - DownloadDirnameDao dao = sDaoSession.getDownloadDirnameDao(); + DownloadDirnameDao dao = db.downloadDirnameDao(); dao.deleteByKey(gid); } public static synchronized void clearDownloadDirname() { - DownloadDirnameDao dao = sDaoSession.getDownloadDirnameDao(); + DownloadDirnameDao dao = db.downloadDirnameDao(); dao.deleteAll(); } @NonNull public static synchronized List getAllDownloadLabelList() { - DownloadLabelDao dao = sDaoSession.getDownloadLabelDao(); - return dao.queryBuilder().orderAsc(DownloadLabelDao.Properties.Time).list(); + DownloadLabelDao dao = db.downloadLabelDao(); + return dao.list(); } public static synchronized DownloadLabel addDownloadLabel(String label) { - DownloadLabelDao dao = sDaoSession.getDownloadLabelDao(); + DownloadLabelDao dao = db.downloadLabelDao(); DownloadLabel raw = new DownloadLabel(); raw.setLabel(label); raw.setTime(System.currentTimeMillis()); @@ -409,13 +387,13 @@ public class EhDB { public static synchronized DownloadLabel addDownloadLabel(DownloadLabel raw) { // Reset id raw.setId(null); - DownloadLabelDao dao = sDaoSession.getDownloadLabelDao(); + DownloadLabelDao dao = db.downloadLabelDao(); raw.setId(dao.insert(raw)); return raw; } public static synchronized void updateDownloadLabel(DownloadLabel raw) { - DownloadLabelDao dao = sDaoSession.getDownloadLabelDao(); + DownloadLabelDao dao = db.downloadLabelDao(); dao.update(raw); } @@ -428,9 +406,8 @@ public class EhDB { int offset = reverse ? toPosition : fromPosition; int limit = reverse ? fromPosition - toPosition + 1 : toPosition - fromPosition + 1; - DownloadLabelDao dao = sDaoSession.getDownloadLabelDao(); - List list = dao.queryBuilder().orderAsc(DownloadLabelDao.Properties.Time) - .offset(offset).limit(limit).list(); + DownloadLabelDao dao = db.downloadLabelDao(); + List list = dao.list(offset, limit); int step = reverse ? 1 : -1; int start = reverse ? limit - 1 : 0; @@ -441,50 +418,44 @@ public class EhDB { } list.get(start).setTime(toTime); - dao.updateInTx(list); + dao.update(list); } public static synchronized void removeDownloadLabel(DownloadLabel raw) { - DownloadLabelDao dao = sDaoSession.getDownloadLabelDao(); + DownloadLabelDao dao = db.downloadLabelDao(); dao.delete(raw); } public static synchronized List getAllLocalFavorites() { - LocalFavoritesDao dao = sDaoSession.getLocalFavoritesDao(); - List list = dao.queryBuilder().orderDesc(LocalFavoritesDao.Properties.Time).list(); - List result = new ArrayList<>(); - result.addAll(list); - return result; + LocalFavoritesDao dao = db.localFavoritesDao(); + List list = dao.list(); + return new ArrayList<>(list); } public static synchronized List searchLocalFavorites(String query) { - query = SqlUtils.sqlEscapeString("%" + query + "%"); - LocalFavoritesDao dao = sDaoSession.getLocalFavoritesDao(); - List list = dao.queryBuilder().orderDesc(LocalFavoritesDao.Properties.Time) - .where(LocalFavoritesDao.Properties.Title.like(query)).list(); - List result = new ArrayList<>(); - result.addAll(list); - return result; + LocalFavoritesDao dao = db.localFavoritesDao(); + List list = dao.list(); + return new ArrayList<>(list); } public static synchronized void removeLocalFavorites(long gid) { - sDaoSession.getLocalFavoritesDao().deleteByKey(gid); + db.localFavoritesDao().deleteByKey(gid); } public static synchronized void removeLocalFavorites(long[] gidArray) { - LocalFavoritesDao dao = sDaoSession.getLocalFavoritesDao(); + LocalFavoritesDao dao = db.localFavoritesDao(); for (long gid : gidArray) { dao.deleteByKey(gid); } } public static synchronized boolean containLocalFavorites(long gid) { - LocalFavoritesDao dao = sDaoSession.getLocalFavoritesDao(); + LocalFavoritesDao dao = db.localFavoritesDao(); return null != dao.load(gid); } public static synchronized void putLocalFavorites(GalleryInfo galleryInfo) { - LocalFavoritesDao dao = sDaoSession.getLocalFavoritesDao(); + LocalFavoritesDao dao = db.localFavoritesDao(); if (null == dao.load(galleryInfo.gid)) { LocalFavoriteInfo info; if (galleryInfo instanceof LocalFavoriteInfo) { @@ -504,31 +475,31 @@ public class EhDB { } public static synchronized List getAllQuickSearch() { - QuickSearchDao dao = sDaoSession.getQuickSearchDao(); - return dao.queryBuilder().orderAsc(QuickSearchDao.Properties.Time).list(); + QuickSearchDao dao = db.quickSearchDao(); + return dao.list(); } public static synchronized void insertQuickSearch(QuickSearch quickSearch) { - QuickSearchDao dao = sDaoSession.getQuickSearchDao(); + QuickSearchDao dao = db.quickSearchDao(); quickSearch.id = null; quickSearch.time = System.currentTimeMillis(); quickSearch.id = dao.insert(quickSearch); } public static synchronized void importQuickSearch(List quickSearchList) { - QuickSearchDao dao = sDaoSession.getQuickSearchDao(); + QuickSearchDao dao = db.quickSearchDao(); for (QuickSearch quickSearch : quickSearchList) { dao.insert(quickSearch); } } public static synchronized void updateQuickSearch(QuickSearch quickSearch) { - QuickSearchDao dao = sDaoSession.getQuickSearchDao(); + QuickSearchDao dao = db.quickSearchDao(); dao.update(quickSearch); } public static synchronized void deleteQuickSearch(QuickSearch quickSearch) { - QuickSearchDao dao = sDaoSession.getQuickSearchDao(); + QuickSearchDao dao = db.quickSearchDao(); dao.delete(quickSearch); } @@ -541,9 +512,8 @@ public class EhDB { int offset = reverse ? toPosition : fromPosition; int limit = reverse ? fromPosition - toPosition + 1 : toPosition - fromPosition + 1; - QuickSearchDao dao = sDaoSession.getQuickSearchDao(); - List list = dao.queryBuilder().orderAsc(QuickSearchDao.Properties.Time) - .offset(offset).limit(limit).list(); + QuickSearchDao dao = db.quickSearchDao(); + List list = dao.list(offset, limit); int step = reverse ? 1 : -1; int start = reverse ? limit - 1 : 0; @@ -554,15 +524,15 @@ public class EhDB { } list.get(start).setTime(toTime); - dao.updateInTx(list); + dao.update(list); } - public static synchronized LazyList getHistoryLazyList() { - return sDaoSession.getHistoryDao().queryBuilder().orderDesc(HistoryDao.Properties.Time).listLazy(); + public static synchronized List getHistoryLazyList() { + return db.historyDao().list(); } public static synchronized void putHistoryInfo(GalleryInfo galleryInfo) { - HistoryDao dao = sDaoSession.getHistoryDao(); + HistoryDao dao = db.historyDao(); HistoryInfo info = dao.load(galleryInfo.gid); if (null != info) { // Update time @@ -573,246 +543,61 @@ public class EhDB { info = new HistoryInfo(galleryInfo); info.time = System.currentTimeMillis(); dao.insert(info); - List list = dao.queryBuilder().orderDesc(HistoryDao.Properties.Time) - .limit(-1).offset(MAX_HISTORY_COUNT).list(); - dao.deleteInTx(list); + List list = dao.list(MAX_HISTORY_COUNT, -1); + dao.delete(list); } } public static synchronized void putHistoryInfo(List historyInfoList) { - HistoryDao dao = sDaoSession.getHistoryDao(); + HistoryDao dao = db.historyDao(); for (HistoryInfo info : historyInfoList) { if (null == dao.load(info.gid)) { dao.insert(info); } } - List list = dao.queryBuilder().orderDesc(HistoryDao.Properties.Time) - .limit(-1).offset(MAX_HISTORY_COUNT).list(); - dao.deleteInTx(list); + List list = dao.list(MAX_HISTORY_COUNT, -1); + dao.delete(list); } public static synchronized void deleteHistoryInfo(HistoryInfo info) { - HistoryDao dao = sDaoSession.getHistoryDao(); + HistoryDao dao = db.historyDao(); dao.delete(info); } public static synchronized void clearHistoryInfo() { - HistoryDao dao = sDaoSession.getHistoryDao(); + HistoryDao dao = db.historyDao(); dao.deleteAll(); } public static synchronized List getAllFilter() { - return sDaoSession.getFilterDao().queryBuilder().list(); + return db.filterDao().list(); } public static synchronized boolean addFilter(Filter filter) { - Filter existFilter; - try { - existFilter = sDaoSession.getFilterDao().queryBuilder().where(FilterDao.Properties.Text.eq(filter.text), FilterDao.Properties.Mode.eq(filter.mode)).unique(); - } catch (Exception e) { - existFilter = null; - } - if (existFilter == null) { - filter.setId(null); - filter.setId(sDaoSession.getFilterDao().insert(filter)); - return true; - } else { - return false; - } + db.filterDao().delete(filter); + db.filterDao().insert(filter); + return true; } public static synchronized void deleteFilter(Filter filter) { - sDaoSession.getFilterDao().delete(filter); + db.filterDao().delete(filter); } public static synchronized void triggerFilter(Filter filter) { filter.setEnable(!filter.enable); - sDaoSession.getFilterDao().update(filter); - } - - private static boolean copyDao(AbstractDao from, AbstractDao to) { - try (CloseableListIterator iterator = from.queryBuilder().listIterator()) { - while (iterator.hasNext()) { - to.insert(iterator.next()); - } - } catch (IOException e) { - return false; - } - return true; + db.filterDao().update(filter); } public static synchronized boolean exportDB(Context context, Uri uri) { - final String ehExportName = "eh.export.db"; - - // Delete old export db - context.deleteDatabase(ehExportName); - - DBOpenHelper helper = new DBOpenHelper(context.getApplicationContext(), ehExportName, null); - - try { - // Copy data to a export db - try (SQLiteDatabase db = helper.getWritableDatabase()) { - DaoMaster daoMaster = new DaoMaster(db); - DaoSession exportSession = daoMaster.newSession(); - if (!copyDao(sDaoSession.getDownloadsDao(), exportSession.getDownloadsDao())) - return false; - if (!copyDao(sDaoSession.getDownloadLabelDao(), exportSession.getDownloadLabelDao())) - return false; - if (!copyDao(sDaoSession.getDownloadDirnameDao(), exportSession.getDownloadDirnameDao())) - return false; - if (!copyDao(sDaoSession.getHistoryDao(), exportSession.getHistoryDao())) - return false; - if (!copyDao(sDaoSession.getQuickSearchDao(), exportSession.getQuickSearchDao())) - return false; - if (!copyDao(sDaoSession.getLocalFavoritesDao(), exportSession.getLocalFavoritesDao())) - return false; - if (!copyDao(sDaoSession.getBookmarksDao(), exportSession.getBookmarksDao())) - return false; - if (!copyDao(sDaoSession.getFilterDao(), exportSession.getFilterDao())) - return false; - } - - // Copy export db to data dir - File dbFile = context.getDatabasePath(ehExportName); - if (dbFile == null || !dbFile.isFile()) { - return false; - } - InputStream is = null; - OutputStream os = null; - try { - is = new FileInputStream(dbFile); - os = context.getContentResolver().openOutputStream(uri); - IOUtils.copy(is, os); - return true; - } catch (IOException e) { - e.printStackTrace(); - } finally { - IOUtils.closeQuietly(is); - IOUtils.closeQuietly(os); - } - // Delete failed file - return false; - } finally { - context.deleteDatabase(ehExportName); - } + return false; } /** * @return error string, null for no error */ public static synchronized String importDB(Context context, Uri uri) { - try { - InputStream inputStream = context.getContentResolver().openInputStream(uri); - File file = File.createTempFile("importDatabase", ""); - FileOutputStream outputStream = new FileOutputStream(file); - byte[] buff = new byte[1024]; - int read; - if (inputStream != null) { - while ((read = inputStream.read(buff, 0, buff.length)) > 0) { - outputStream.write(buff, 0, read); - } - } else { - return context.getString(R.string.cant_read_the_file); - } - inputStream.close(); - outputStream.close(); - - SQLiteDatabase db = SQLiteDatabase.openDatabase( - file.getPath(), null, SQLiteDatabase.NO_LOCALIZED_COLLATORS); - int newVersion = DaoMaster.SCHEMA_VERSION; - int oldVersion = db.getVersion(); - if (oldVersion < newVersion) { - upgradeDB(db, oldVersion); - db.setVersion(newVersion); - } else if (oldVersion > newVersion) { - return context.getString(R.string.cant_read_the_file); - } - - DaoMaster daoMaster = new DaoMaster(db); - DaoSession session = daoMaster.newSession(); - - // Downloads - DownloadManager manager = EhApplication.getDownloadManager(context); - List downloadInfoList = session.getDownloadsDao().queryBuilder().list(); - manager.addDownload(downloadInfoList, false); - - // Download label - List downloadLabelList = session.getDownloadLabelDao().queryBuilder().list(); - manager.addDownloadLabel(downloadLabelList); - - // Download dirname - List downloadDirnameList = session.getDownloadDirnameDao().queryBuilder().list(); - for (DownloadDirname dirname : downloadDirnameList) { - putDownloadDirname(dirname.getGid(), dirname.getDirname()); - } - - // History - List historyInfoList = session.getHistoryDao().queryBuilder().list(); - putHistoryInfo(historyInfoList); - - // QuickSearch - List quickSearchList = session.getQuickSearchDao().queryBuilder().list(); - List currentQuickSearchList = sDaoSession.getQuickSearchDao().queryBuilder().list(); - List importList = new ArrayList<>(); - for (QuickSearch quickSearch : quickSearchList) { - String name = quickSearch.name; - for (QuickSearch q : currentQuickSearchList) { - if (ObjectUtils.equal(q.name, name)) { - // The same name - name = null; - break; - } - } - if (null == name) { - continue; - } - importList.add(quickSearch); - } - importQuickSearch(importList); - - // LocalFavorites - List localFavoriteInfoList = session.getLocalFavoritesDao().queryBuilder().list(); - for (LocalFavoriteInfo info : localFavoriteInfoList) { - putLocalFavorites(info); - } - - // Bookmarks - // TODO - - // Filter - List filterList = session.getFilterDao().queryBuilder().list(); - List currentFilterList = sDaoSession.getFilterDao().queryBuilder().list(); - for (Filter filter : filterList) { - if (!currentFilterList.contains(filter)) { - addFilter(filter); - } - } - - return null; - } catch (Throwable e) { - ExceptionUtils.throwIfFatal(e); - // Ignore - return context.getString(R.string.cant_read_the_file); - } - } - - private static class DBOpenHelper extends DaoMaster.OpenHelper { - - public DBOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory) { - super(context, name, factory); - } - - @Override - public void onCreate(SQLiteDatabase db) { - super.onCreate(db); - sNewDB = true; - } - - @Override - public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - upgradeDB(db, oldVersion); - } + return ""; } private static class OldDBHelper extends SQLiteOpenHelper { diff --git a/app/src/main/java/com/hippo/ehviewer/client/data/GalleryInfo.java b/app/src/main/java/com/hippo/ehviewer/client/data/GalleryInfo.java index e86e048bc..6dd53d7f9 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/data/GalleryInfo.java +++ b/app/src/main/java/com/hippo/ehviewer/client/data/GalleryInfo.java @@ -20,6 +20,9 @@ import android.os.Parcel; import android.os.Parcelable; import androidx.annotation.Nullable; +import androidx.room.ColumnInfo; +import androidx.room.Ignore; +import androidx.room.PrimaryKey; import java.util.regex.Pattern; @@ -108,30 +111,52 @@ public class GalleryInfo implements Parcelable { return new GalleryInfo[size]; } }; + @PrimaryKey + @ColumnInfo(name = "GID") public long gid; + @ColumnInfo(name = "TOKEN") public String token; + @ColumnInfo(name = "TITLE") public String title; + @ColumnInfo(name = "TITLE_JPN") public String titleJpn; + @ColumnInfo(name = "THUMB") public String thumb; + @ColumnInfo(name = "CATEGORY") public int category; + @ColumnInfo(name = "POSTED") public String posted; + @ColumnInfo(name = "UPLOADER") public String uploader; + @Ignore public boolean disowned; + @ColumnInfo(name = "RATING") public float rating; + @Ignore public boolean rated; @Nullable + @Ignore public String[] simpleTags; + @Ignore public int pages; + @Ignore public int thumbWidth; + @Ignore public int thumbHeight; + @Ignore public int spanSize; + @Ignore public int spanIndex; + @Ignore public int spanGroupIndex; /** * language from title */ + @ColumnInfo(name = "SIMPLE_LANGUAGE") public String simpleLanguage; + @Ignore public int favoriteSlot = -2; + @Ignore public String favoriteName; public GalleryInfo() { diff --git a/app/src/main/java/com/hippo/ehviewer/dao/BookmarkInfo.java b/app/src/main/java/com/hippo/ehviewer/dao/BookmarkInfo.java index 8309456b7..328b836d9 100644 --- a/app/src/main/java/com/hippo/ehviewer/dao/BookmarkInfo.java +++ b/app/src/main/java/com/hippo/ehviewer/dao/BookmarkInfo.java @@ -1,183 +1,162 @@ package com.hippo.ehviewer.dao; -import org.greenrobot.greendao.annotation.*; import android.os.Parcel; + +import androidx.room.ColumnInfo; +import androidx.room.Entity; + import com.hippo.ehviewer.client.data.GalleryInfo; -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit. - -/** - * Entity mapped to table "BOOKMARKS". - */ -@Entity(nameInDb = "BOOKMARKS") +@Entity(tableName = "BOOKMARKS") public class BookmarkInfo extends GalleryInfo { - public int page; - public long time; + public static final Creator CREATOR = new Creator() { + @Override + public BookmarkInfo createFromParcel(Parcel source) { + return new BookmarkInfo(source); + } - public static final Creator CREATOR = new Creator() { - @Override - public BookmarkInfo createFromParcel(Parcel source) { - return new BookmarkInfo(source); - } + @Override + public BookmarkInfo[] newArray(int size) { + return new BookmarkInfo[size]; + } + }; + @ColumnInfo(name = "PAGE") + public int page; + @ColumnInfo(name = "TIME") + public long time; - @Override - public BookmarkInfo[] newArray(int size) { - return new BookmarkInfo[size]; - } - }; + protected BookmarkInfo(Parcel in) { + super(in); + this.page = in.readInt(); + this.time = in.readLong(); + } - @Generated - public BookmarkInfo() { - } + public BookmarkInfo(GalleryInfo galleryInfo) { + this.gid = galleryInfo.gid; + this.token = galleryInfo.token; + this.title = galleryInfo.title; + this.titleJpn = galleryInfo.titleJpn; + this.thumb = galleryInfo.thumb; + this.category = galleryInfo.category; + this.posted = galleryInfo.posted; + this.uploader = galleryInfo.uploader; + this.rating = galleryInfo.rating; + this.simpleTags = galleryInfo.simpleTags; + this.simpleLanguage = galleryInfo.simpleLanguage; + } - public BookmarkInfo(long gid) { - this.gid = gid; - } + public BookmarkInfo(int page, long time) { + this.page = page; + this.time = time; + } - @Generated - public BookmarkInfo(long gid, String token, String title, String titleJpn, String thumb, int category, - String posted, String uploader, float rating, String simpleLanguage, int page, long time) { - this.gid = gid; - this.token = token; - this.title = title; - this.titleJpn = titleJpn; - this.thumb = thumb; - this.category = category; - this.posted = posted; - this.uploader = uploader; - this.rating = rating; - this.simpleLanguage = simpleLanguage; - this.page = page; - this.time = time; - } + public long getGid() { + return gid; + } - public long getGid() { - return gid; - } + public void setGid(long gid) { + this.gid = gid; + } - public void setGid(long gid) { - this.gid = gid; - } + public String getToken() { + return token; + } - public String getToken() { - return token; - } + public void setToken(String token) { + this.token = token; + } - public void setToken(String token) { - this.token = token; - } + public String getTitle() { + return title; + } - public String getTitle() { - return title; - } + public void setTitle(String title) { + this.title = title; + } - public void setTitle(String title) { - this.title = title; - } + public String getTitleJpn() { + return titleJpn; + } - public String getTitleJpn() { - return titleJpn; - } + public void setTitleJpn(String titleJpn) { + this.titleJpn = titleJpn; + } - public void setTitleJpn(String titleJpn) { - this.titleJpn = titleJpn; - } + public String getThumb() { + return thumb; + } - public String getThumb() { - return thumb; - } + public void setThumb(String thumb) { + this.thumb = thumb; + } - public void setThumb(String thumb) { - this.thumb = thumb; - } + public int getCategory() { + return category; + } - public int getCategory() { - return category; - } + public void setCategory(int category) { + this.category = category; + } - public void setCategory(int category) { - this.category = category; - } + public String getPosted() { + return posted; + } - public String getPosted() { - return posted; - } + public void setPosted(String posted) { + this.posted = posted; + } - public void setPosted(String posted) { - this.posted = posted; - } + public String getUploader() { + return uploader; + } - public String getUploader() { - return uploader; - } + public void setUploader(String uploader) { + this.uploader = uploader; + } - public void setUploader(String uploader) { - this.uploader = uploader; - } + public float getRating() { + return rating; + } - public float getRating() { - return rating; - } + public void setRating(float rating) { + this.rating = rating; + } - public void setRating(float rating) { - this.rating = rating; - } + public String getSimpleLanguage() { + return simpleLanguage; + } - public String getSimpleLanguage() { - return simpleLanguage; - } + public void setSimpleLanguage(String simpleLanguage) { + this.simpleLanguage = simpleLanguage; + } - public void setSimpleLanguage(String simpleLanguage) { - this.simpleLanguage = simpleLanguage; - } + public int getPage() { + return page; + } - public int getPage() { - return page; - } + public void setPage(int page) { + this.page = page; + } - public void setPage(int page) { - this.page = page; - } + public long getTime() { + return time; + } - public long getTime() { - return time; - } + public void setTime(long time) { + this.time = time; + } - public void setTime(long time) { - this.time = time; - } + @Override + public int describeContents() { + return 0; + } - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - dest.writeInt(this.page); - dest.writeLong(this.time); - } - - protected BookmarkInfo(Parcel in) { - super(in); - this.page = in.readInt(); - this.time = in.readLong(); - } - - public BookmarkInfo(GalleryInfo galleryInfo) { - this.gid = galleryInfo.gid; - this.token = galleryInfo.token; - this.title = galleryInfo.title; - this.titleJpn = galleryInfo.titleJpn; - this.thumb = galleryInfo.thumb; - this.category = galleryInfo.category; - this.posted = galleryInfo.posted; - this.uploader = galleryInfo.uploader; - this.rating = galleryInfo.rating; - this.simpleTags = galleryInfo.simpleTags; - this.simpleLanguage = galleryInfo.simpleLanguage; - } + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + dest.writeInt(this.page); + dest.writeLong(this.time); + } } diff --git a/app/src/main/java/com/hippo/ehviewer/dao/BookmarksBao.java b/app/src/main/java/com/hippo/ehviewer/dao/BookmarksBao.java new file mode 100644 index 000000000..ede23fbc8 --- /dev/null +++ b/app/src/main/java/com/hippo/ehviewer/dao/BookmarksBao.java @@ -0,0 +1,16 @@ +package com.hippo.ehviewer.dao; + +import androidx.room.Dao; +import androidx.room.Delete; +import androidx.room.Insert; + +@Dao +public interface BookmarksBao { + + @Insert + void insert(BookmarkInfo bookmark); + + @Delete + void delete(BookmarkInfo bookmark); + +} diff --git a/app/src/main/java/com/hippo/ehviewer/dao/BookmarksDao.java b/app/src/main/java/com/hippo/ehviewer/dao/BookmarksDao.java deleted file mode 100644 index 4e601aba1..000000000 --- a/app/src/main/java/com/hippo/ehviewer/dao/BookmarksDao.java +++ /dev/null @@ -1,227 +0,0 @@ -package com.hippo.ehviewer.dao; - -import android.database.Cursor; -import android.database.sqlite.SQLiteStatement; - -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.Property; -import org.greenrobot.greendao.internal.DaoConfig; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseStatement; - -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** - * DAO for table "BOOKMARKS". -*/ -public class BookmarksDao extends AbstractDao { - - public static final String TABLENAME = "BOOKMARKS"; - - /** - * Properties of entity BookmarkInfo.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Gid = new Property(0, long.class, "gid", true, "GID"); - public final static Property Token = new Property(1, String.class, "token", false, "TOKEN"); - public final static Property Title = new Property(2, String.class, "title", false, "TITLE"); - public final static Property TitleJpn = new Property(3, String.class, "titleJpn", false, "TITLE_JPN"); - public final static Property Thumb = new Property(4, String.class, "thumb", false, "THUMB"); - public final static Property Category = new Property(5, int.class, "category", false, "CATEGORY"); - public final static Property Posted = new Property(6, String.class, "posted", false, "POSTED"); - public final static Property Uploader = new Property(7, String.class, "uploader", false, "UPLOADER"); - public final static Property Rating = new Property(8, float.class, "rating", false, "RATING"); - public final static Property SimpleLanguage = new Property(9, String.class, "simpleLanguage", false, "SIMPLE_LANGUAGE"); - public final static Property Page = new Property(10, int.class, "page", false, "PAGE"); - public final static Property Time = new Property(11, long.class, "time", false, "TIME"); - } - - - public BookmarksDao(DaoConfig config) { - super(config); - } - - public BookmarksDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } - - /** Creates the underlying database table. */ - public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"BOOKMARKS\" (" + // - "\"GID\" INTEGER PRIMARY KEY NOT NULL ," + // 0: gid - "\"TOKEN\" TEXT," + // 1: token - "\"TITLE\" TEXT," + // 2: title - "\"TITLE_JPN\" TEXT," + // 3: titleJpn - "\"THUMB\" TEXT," + // 4: thumb - "\"CATEGORY\" INTEGER NOT NULL ," + // 5: category - "\"POSTED\" TEXT," + // 6: posted - "\"UPLOADER\" TEXT," + // 7: uploader - "\"RATING\" REAL NOT NULL ," + // 8: rating - "\"SIMPLE_LANGUAGE\" TEXT," + // 9: simpleLanguage - "\"PAGE\" INTEGER NOT NULL ," + // 10: page - "\"TIME\" INTEGER NOT NULL );"); // 11: time - } - - /** Drops the underlying database table. */ - public static void dropTable(Database db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"BOOKMARKS\""; - db.execSQL(sql); - } - - @Override - protected final void bindValues(DatabaseStatement stmt, BookmarkInfo entity) { - stmt.clearBindings(); - stmt.bindLong(1, entity.getGid()); - - String token = entity.getToken(); - if (token != null) { - stmt.bindString(2, token); - } - - String title = entity.getTitle(); - if (title != null) { - stmt.bindString(3, title); - } - - String titleJpn = entity.getTitleJpn(); - if (titleJpn != null) { - stmt.bindString(4, titleJpn); - } - - String thumb = entity.getThumb(); - if (thumb != null) { - stmt.bindString(5, thumb); - } - stmt.bindLong(6, entity.getCategory()); - - String posted = entity.getPosted(); - if (posted != null) { - stmt.bindString(7, posted); - } - - String uploader = entity.getUploader(); - if (uploader != null) { - stmt.bindString(8, uploader); - } - stmt.bindDouble(9, entity.getRating()); - - String simpleLanguage = entity.getSimpleLanguage(); - if (simpleLanguage != null) { - stmt.bindString(10, simpleLanguage); - } - stmt.bindLong(11, entity.getPage()); - stmt.bindLong(12, entity.getTime()); - } - - @Override - protected final void bindValues(SQLiteStatement stmt, BookmarkInfo entity) { - stmt.clearBindings(); - stmt.bindLong(1, entity.getGid()); - - String token = entity.getToken(); - if (token != null) { - stmt.bindString(2, token); - } - - String title = entity.getTitle(); - if (title != null) { - stmt.bindString(3, title); - } - - String titleJpn = entity.getTitleJpn(); - if (titleJpn != null) { - stmt.bindString(4, titleJpn); - } - - String thumb = entity.getThumb(); - if (thumb != null) { - stmt.bindString(5, thumb); - } - stmt.bindLong(6, entity.getCategory()); - - String posted = entity.getPosted(); - if (posted != null) { - stmt.bindString(7, posted); - } - - String uploader = entity.getUploader(); - if (uploader != null) { - stmt.bindString(8, uploader); - } - stmt.bindDouble(9, entity.getRating()); - - String simpleLanguage = entity.getSimpleLanguage(); - if (simpleLanguage != null) { - stmt.bindString(10, simpleLanguage); - } - stmt.bindLong(11, entity.getPage()); - stmt.bindLong(12, entity.getTime()); - } - - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.getLong(offset + 0); - } - - @Override - public BookmarkInfo readEntity(Cursor cursor, int offset) { - BookmarkInfo entity = new BookmarkInfo( // - cursor.getLong(offset + 0), // gid - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // token - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // title - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // titleJpn - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // thumb - cursor.getInt(offset + 5), // category - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // posted - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // uploader - cursor.getFloat(offset + 8), // rating - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // simpleLanguage - cursor.getInt(offset + 10), // page - cursor.getLong(offset + 11) // time - ); - return entity; - } - - @Override - public void readEntity(Cursor cursor, BookmarkInfo entity, int offset) { - entity.setGid(cursor.getLong(offset + 0)); - entity.setToken(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setTitle(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setTitleJpn(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setThumb(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setCategory(cursor.getInt(offset + 5)); - entity.setPosted(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); - entity.setUploader(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); - entity.setRating(cursor.getFloat(offset + 8)); - entity.setSimpleLanguage(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - entity.setPage(cursor.getInt(offset + 10)); - entity.setTime(cursor.getLong(offset + 11)); - } - - @Override - protected final Long updateKeyAfterInsert(BookmarkInfo entity, long rowId) { - entity.setGid(rowId); - return rowId; - } - - @Override - public Long getKey(BookmarkInfo entity) { - if(entity != null) { - return entity.getGid(); - } else { - return null; - } - } - - @Override - public boolean hasKey(BookmarkInfo entity) { - throw new UnsupportedOperationException("Unsupported for entities with a non-null key"); - } - - @Override - protected final boolean isEntityUpdateable() { - return true; - } - -} diff --git a/app/src/main/java/com/hippo/ehviewer/dao/DaoMaster.java b/app/src/main/java/com/hippo/ehviewer/dao/DaoMaster.java deleted file mode 100644 index ac7c892e5..000000000 --- a/app/src/main/java/com/hippo/ehviewer/dao/DaoMaster.java +++ /dev/null @@ -1,117 +0,0 @@ -package com.hippo.ehviewer.dao; - -import android.content.Context; -import android.database.sqlite.SQLiteDatabase; -import android.database.sqlite.SQLiteDatabase.CursorFactory; -import android.util.Log; - -import org.greenrobot.greendao.AbstractDaoMaster; -import org.greenrobot.greendao.database.StandardDatabase; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseOpenHelper; -import org.greenrobot.greendao.identityscope.IdentityScopeType; - - -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** - * Master of DAO (schema version 4): knows all DAOs. - */ -public class DaoMaster extends AbstractDaoMaster { - public static final int SCHEMA_VERSION = 4; - - /** Creates underlying database table using DAOs. */ - public static void createAllTables(Database db, boolean ifNotExists) { - DownloadsDao.createTable(db, ifNotExists); - DownloadLabelDao.createTable(db, ifNotExists); - DownloadDirnameDao.createTable(db, ifNotExists); - HistoryDao.createTable(db, ifNotExists); - QuickSearchDao.createTable(db, ifNotExists); - LocalFavoritesDao.createTable(db, ifNotExists); - BookmarksDao.createTable(db, ifNotExists); - FilterDao.createTable(db, ifNotExists); - } - - /** Drops underlying database table using DAOs. */ - public static void dropAllTables(Database db, boolean ifExists) { - DownloadsDao.dropTable(db, ifExists); - DownloadLabelDao.dropTable(db, ifExists); - DownloadDirnameDao.dropTable(db, ifExists); - HistoryDao.dropTable(db, ifExists); - QuickSearchDao.dropTable(db, ifExists); - LocalFavoritesDao.dropTable(db, ifExists); - BookmarksDao.dropTable(db, ifExists); - FilterDao.dropTable(db, ifExists); - } - - /** - * WARNING: Drops all table on Upgrade! Use only during development. - * Convenience method using a {@link DevOpenHelper}. - */ - public static DaoSession newDevSession(Context context, String name) { - Database db = new DevOpenHelper(context, name).getWritableDb(); - DaoMaster daoMaster = new DaoMaster(db); - return daoMaster.newSession(); - } - - public DaoMaster(SQLiteDatabase db) { - this(new StandardDatabase(db)); - } - - public DaoMaster(Database db) { - super(db, SCHEMA_VERSION); - registerDaoClass(DownloadsDao.class); - registerDaoClass(DownloadLabelDao.class); - registerDaoClass(DownloadDirnameDao.class); - registerDaoClass(HistoryDao.class); - registerDaoClass(QuickSearchDao.class); - registerDaoClass(LocalFavoritesDao.class); - registerDaoClass(BookmarksDao.class); - registerDaoClass(FilterDao.class); - } - - public DaoSession newSession() { - return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); - } - - public DaoSession newSession(IdentityScopeType type) { - return new DaoSession(db, type, daoConfigMap); - } - - /** - * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - - */ - public static abstract class OpenHelper extends DatabaseOpenHelper { - public OpenHelper(Context context, String name) { - super(context, name, SCHEMA_VERSION); - } - - public OpenHelper(Context context, String name, CursorFactory factory) { - super(context, name, factory, SCHEMA_VERSION); - } - - @Override - public void onCreate(Database db) { - Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); - createAllTables(db, false); - } - } - - /** WARNING: Drops all table on Upgrade! Use only during development. */ - public static class DevOpenHelper extends OpenHelper { - public DevOpenHelper(Context context, String name) { - super(context, name); - } - - public DevOpenHelper(Context context, String name, CursorFactory factory) { - super(context, name, factory); - } - - @Override - public void onUpgrade(Database db, int oldVersion, int newVersion) { - Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); - dropAllTables(db, true); - onCreate(db); - } - } - -} diff --git a/app/src/main/java/com/hippo/ehviewer/dao/DaoSession.java b/app/src/main/java/com/hippo/ehviewer/dao/DaoSession.java deleted file mode 100644 index 5366a57f5..000000000 --- a/app/src/main/java/com/hippo/ehviewer/dao/DaoSession.java +++ /dev/null @@ -1,146 +0,0 @@ -package com.hippo.ehviewer.dao; - -import java.util.Map; - -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.AbstractDaoSession; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.identityscope.IdentityScopeType; -import org.greenrobot.greendao.internal.DaoConfig; - -import com.hippo.ehviewer.dao.DownloadInfo; -import com.hippo.ehviewer.dao.DownloadLabel; -import com.hippo.ehviewer.dao.DownloadDirname; -import com.hippo.ehviewer.dao.HistoryInfo; -import com.hippo.ehviewer.dao.QuickSearch; -import com.hippo.ehviewer.dao.LocalFavoriteInfo; -import com.hippo.ehviewer.dao.BookmarkInfo; -import com.hippo.ehviewer.dao.Filter; - -import com.hippo.ehviewer.dao.DownloadsDao; -import com.hippo.ehviewer.dao.DownloadLabelDao; -import com.hippo.ehviewer.dao.DownloadDirnameDao; -import com.hippo.ehviewer.dao.HistoryDao; -import com.hippo.ehviewer.dao.QuickSearchDao; -import com.hippo.ehviewer.dao.LocalFavoritesDao; -import com.hippo.ehviewer.dao.BookmarksDao; -import com.hippo.ehviewer.dao.FilterDao; - -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. - -/** - * {@inheritDoc} - * - * @see org.greenrobot.greendao.AbstractDaoSession - */ -public class DaoSession extends AbstractDaoSession { - - private final DaoConfig downloadsDaoConfig; - private final DaoConfig downloadLabelDaoConfig; - private final DaoConfig downloadDirnameDaoConfig; - private final DaoConfig historyDaoConfig; - private final DaoConfig quickSearchDaoConfig; - private final DaoConfig localFavoritesDaoConfig; - private final DaoConfig bookmarksDaoConfig; - private final DaoConfig filterDaoConfig; - - private final DownloadsDao downloadsDao; - private final DownloadLabelDao downloadLabelDao; - private final DownloadDirnameDao downloadDirnameDao; - private final HistoryDao historyDao; - private final QuickSearchDao quickSearchDao; - private final LocalFavoritesDao localFavoritesDao; - private final BookmarksDao bookmarksDao; - private final FilterDao filterDao; - - public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> - daoConfigMap) { - super(db); - - downloadsDaoConfig = daoConfigMap.get(DownloadsDao.class).clone(); - downloadsDaoConfig.initIdentityScope(type); - - downloadLabelDaoConfig = daoConfigMap.get(DownloadLabelDao.class).clone(); - downloadLabelDaoConfig.initIdentityScope(type); - - downloadDirnameDaoConfig = daoConfigMap.get(DownloadDirnameDao.class).clone(); - downloadDirnameDaoConfig.initIdentityScope(type); - - historyDaoConfig = daoConfigMap.get(HistoryDao.class).clone(); - historyDaoConfig.initIdentityScope(type); - - quickSearchDaoConfig = daoConfigMap.get(QuickSearchDao.class).clone(); - quickSearchDaoConfig.initIdentityScope(type); - - localFavoritesDaoConfig = daoConfigMap.get(LocalFavoritesDao.class).clone(); - localFavoritesDaoConfig.initIdentityScope(type); - - bookmarksDaoConfig = daoConfigMap.get(BookmarksDao.class).clone(); - bookmarksDaoConfig.initIdentityScope(type); - - filterDaoConfig = daoConfigMap.get(FilterDao.class).clone(); - filterDaoConfig.initIdentityScope(type); - - downloadsDao = new DownloadsDao(downloadsDaoConfig, this); - downloadLabelDao = new DownloadLabelDao(downloadLabelDaoConfig, this); - downloadDirnameDao = new DownloadDirnameDao(downloadDirnameDaoConfig, this); - historyDao = new HistoryDao(historyDaoConfig, this); - quickSearchDao = new QuickSearchDao(quickSearchDaoConfig, this); - localFavoritesDao = new LocalFavoritesDao(localFavoritesDaoConfig, this); - bookmarksDao = new BookmarksDao(bookmarksDaoConfig, this); - filterDao = new FilterDao(filterDaoConfig, this); - - registerDao(DownloadInfo.class, downloadsDao); - registerDao(DownloadLabel.class, downloadLabelDao); - registerDao(DownloadDirname.class, downloadDirnameDao); - registerDao(HistoryInfo.class, historyDao); - registerDao(QuickSearch.class, quickSearchDao); - registerDao(LocalFavoriteInfo.class, localFavoritesDao); - registerDao(BookmarkInfo.class, bookmarksDao); - registerDao(Filter.class, filterDao); - } - - public void clear() { - downloadsDaoConfig.clearIdentityScope(); - downloadLabelDaoConfig.clearIdentityScope(); - downloadDirnameDaoConfig.clearIdentityScope(); - historyDaoConfig.clearIdentityScope(); - quickSearchDaoConfig.clearIdentityScope(); - localFavoritesDaoConfig.clearIdentityScope(); - bookmarksDaoConfig.clearIdentityScope(); - filterDaoConfig.clearIdentityScope(); - } - - public DownloadsDao getDownloadsDao() { - return downloadsDao; - } - - public DownloadLabelDao getDownloadLabelDao() { - return downloadLabelDao; - } - - public DownloadDirnameDao getDownloadDirnameDao() { - return downloadDirnameDao; - } - - public HistoryDao getHistoryDao() { - return historyDao; - } - - public QuickSearchDao getQuickSearchDao() { - return quickSearchDao; - } - - public LocalFavoritesDao getLocalFavoritesDao() { - return localFavoritesDao; - } - - public BookmarksDao getBookmarksDao() { - return bookmarksDao; - } - - public FilterDao getFilterDao() { - return filterDao; - } - -} diff --git a/app/src/main/java/com/hippo/ehviewer/dao/DownloadDirname.java b/app/src/main/java/com/hippo/ehviewer/dao/DownloadDirname.java index e39a1afd5..2b5df9fb3 100644 --- a/app/src/main/java/com/hippo/ehviewer/dao/DownloadDirname.java +++ b/app/src/main/java/com/hippo/ehviewer/dao/DownloadDirname.java @@ -1,33 +1,18 @@ package com.hippo.ehviewer.dao; -import org.greenrobot.greendao.annotation.*; +import androidx.room.ColumnInfo; +import androidx.room.Entity; +import androidx.room.PrimaryKey; -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit. - -/** - * Entity mapped to table "DOWNLOAD_DIRNAME". - */ -@Entity(nameInDb = "DOWNLOAD_DIRNAME") +@Entity(tableName = "DOWNLOAD_DIRNAME") public class DownloadDirname { - @Id + @PrimaryKey + @ColumnInfo(name = "GID") private long gid; + @ColumnInfo(name = "DIRNAME") private String dirname; - @Generated - public DownloadDirname() { - } - - public DownloadDirname(long gid) { - this.gid = gid; - } - - @Generated - public DownloadDirname(long gid, String dirname) { - this.gid = gid; - this.dirname = dirname; - } - public long getGid() { return gid; } diff --git a/app/src/main/java/com/hippo/ehviewer/dao/DownloadDirnameDao.java b/app/src/main/java/com/hippo/ehviewer/dao/DownloadDirnameDao.java index a8231da31..319205be4 100644 --- a/app/src/main/java/com/hippo/ehviewer/dao/DownloadDirnameDao.java +++ b/app/src/main/java/com/hippo/ehviewer/dao/DownloadDirnameDao.java @@ -1,119 +1,25 @@ package com.hippo.ehviewer.dao; -import android.database.Cursor; -import android.database.sqlite.SQLiteStatement; +import androidx.room.Dao; +import androidx.room.Insert; +import androidx.room.Query; +import androidx.room.Update; -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.Property; -import org.greenrobot.greendao.internal.DaoConfig; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseStatement; +@Dao +public interface DownloadDirnameDao { -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** - * DAO for table "DOWNLOAD_DIRNAME". -*/ -public class DownloadDirnameDao extends AbstractDao { + @Query("SELECT * FROM DOWNLOAD_DIRNAME WHERE GID = :gid") + DownloadDirname load(long gid); - public static final String TABLENAME = "DOWNLOAD_DIRNAME"; + @Update + void update(DownloadDirname downloadDirname); - /** - * Properties of entity DownloadDirname.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Gid = new Property(0, long.class, "gid", true, "GID"); - public final static Property Dirname = new Property(1, String.class, "dirname", false, "DIRNAME"); - } + @Insert + void insert(DownloadDirname downloadDirname); + @Query("DELETE FROM DOWNLOAD_DIRNAME WHERE GID = :gid") + void deleteByKey(long gid); - public DownloadDirnameDao(DaoConfig config) { - super(config); - } - - public DownloadDirnameDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } - - /** Creates the underlying database table. */ - public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"DOWNLOAD_DIRNAME\" (" + // - "\"GID\" INTEGER PRIMARY KEY NOT NULL ," + // 0: gid - "\"DIRNAME\" TEXT);"); // 1: dirname - } - - /** Drops the underlying database table. */ - public static void dropTable(Database db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"DOWNLOAD_DIRNAME\""; - db.execSQL(sql); - } - - @Override - protected final void bindValues(DatabaseStatement stmt, DownloadDirname entity) { - stmt.clearBindings(); - stmt.bindLong(1, entity.getGid()); - - String dirname = entity.getDirname(); - if (dirname != null) { - stmt.bindString(2, dirname); - } - } - - @Override - protected final void bindValues(SQLiteStatement stmt, DownloadDirname entity) { - stmt.clearBindings(); - stmt.bindLong(1, entity.getGid()); - - String dirname = entity.getDirname(); - if (dirname != null) { - stmt.bindString(2, dirname); - } - } - - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.getLong(offset + 0); - } - - @Override - public DownloadDirname readEntity(Cursor cursor, int offset) { - DownloadDirname entity = new DownloadDirname( // - cursor.getLong(offset + 0), // gid - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1) // dirname - ); - return entity; - } - - @Override - public void readEntity(Cursor cursor, DownloadDirname entity, int offset) { - entity.setGid(cursor.getLong(offset + 0)); - entity.setDirname(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - } - - @Override - protected final Long updateKeyAfterInsert(DownloadDirname entity, long rowId) { - entity.setGid(rowId); - return rowId; - } - - @Override - public Long getKey(DownloadDirname entity) { - if(entity != null) { - return entity.getGid(); - } else { - return null; - } - } - - @Override - public boolean hasKey(DownloadDirname entity) { - throw new UnsupportedOperationException("Unsupported for entities with a non-null key"); - } - - @Override - protected final boolean isEntityUpdateable() { - return true; - } - + @Query("DELETE FROM DOWNLOAD_DIRNAME") + void deleteAll(); } diff --git a/app/src/main/java/com/hippo/ehviewer/dao/DownloadInfo.java b/app/src/main/java/com/hippo/ehviewer/dao/DownloadInfo.java index ebb669759..15c52de37 100644 --- a/app/src/main/java/com/hippo/ehviewer/dao/DownloadInfo.java +++ b/app/src/main/java/com/hippo/ehviewer/dao/DownloadInfo.java @@ -1,219 +1,254 @@ package com.hippo.ehviewer.dao; -import org.greenrobot.greendao.annotation.*; import android.os.Parcel; + +import androidx.room.ColumnInfo; +import androidx.room.Entity; +import androidx.room.Ignore; + import com.hippo.ehviewer.client.data.GalleryInfo; -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit. - -/** - * Entity mapped to table "DOWNLOADS". - */ -@Entity(nameInDb = "DOWNLOADS") +@Entity(tableName = "DOWNLOADS") public class DownloadInfo extends GalleryInfo { - public int state; - public int legacy; - public long time; - public String label; + public static final Creator CREATOR = new Creator() { + @Override + public DownloadInfo createFromParcel(Parcel source) { + return new DownloadInfo(source); + } - public static final Creator CREATOR = new Creator() { - @Override - public DownloadInfo createFromParcel(Parcel source) { - return new DownloadInfo(source); - } + @Override + public DownloadInfo[] newArray(int size) { + return new DownloadInfo[size]; + } + }; + public static final int STATE_INVALID = -1; + public static final int STATE_NONE = 0; + public static final int STATE_WAIT = 1; + public static final int STATE_DOWNLOAD = 2; + public static final int STATE_FINISH = 3; + public static final int STATE_FAILED = 4; + @ColumnInfo(name = "STATE") + public int state; + @ColumnInfo(name = "LEGACY") + public int legacy; + @ColumnInfo(name = "TIME") + public long time; + @ColumnInfo(name = "LABEL") + public String label; + @Ignore + public long speed; + @Ignore + public long remaining; + @Ignore + public int finished; + @Ignore + public int downloaded; + @Ignore + public int total; - @Override - public DownloadInfo[] newArray(int size) { - return new DownloadInfo[size]; - } - }; - public static final int STATE_INVALID = -1; - public static final int STATE_NONE = 0; - public static final int STATE_WAIT = 1; - public static final int STATE_DOWNLOAD = 2; - public static final int STATE_FINISH = 3; - public static final int STATE_FAILED = 4; - public long speed; - public long remaining; - public int finished; - public int downloaded; - public int total; + DownloadInfo() { + } - @Generated - public DownloadInfo() { - } + protected DownloadInfo(Parcel in) { + super(in); + this.state = in.readInt(); + this.legacy = in.readInt(); + this.time = in.readLong(); + this.label = in.readString(); + } - public DownloadInfo(long gid) { - this.gid = gid; - } + public DownloadInfo(GalleryInfo galleryInfo) { + this.gid = galleryInfo.gid; + this.token = galleryInfo.token; + this.title = galleryInfo.title; + this.titleJpn = galleryInfo.titleJpn; + this.thumb = galleryInfo.thumb; + this.category = galleryInfo.category; + this.posted = galleryInfo.posted; + this.uploader = galleryInfo.uploader; + this.rating = galleryInfo.rating; + this.simpleTags = galleryInfo.simpleTags; + this.simpleLanguage = galleryInfo.simpleLanguage; + } - @Generated - public DownloadInfo(long gid, String token, String title, String titleJpn, String thumb, int category, - String posted, String uploader, float rating, String simpleLanguage, int state, int legacy, long time, - String label) { - this.gid = gid; - this.token = token; - this.title = title; - this.titleJpn = titleJpn; - this.thumb = thumb; - this.category = category; - this.posted = posted; - this.uploader = uploader; - this.rating = rating; - this.simpleLanguage = simpleLanguage; - this.state = state; - this.legacy = legacy; - this.time = time; - this.label = label; - } + public DownloadInfo(int state, int legacy, long time, String label, long speed, long remaining, + int finished, int downloaded, int total) { + this.state = state; + this.legacy = legacy; + this.time = time; + this.label = label; + this.speed = speed; + this.remaining = remaining; + this.finished = finished; + this.downloaded = downloaded; + this.total = total; + } - public long getGid() { - return gid; - } + public long getGid() { + return gid; + } - public void setGid(long gid) { - this.gid = gid; - } + public void setGid(long gid) { + this.gid = gid; + } - public String getToken() { - return token; - } + public String getToken() { + return token; + } - public void setToken(String token) { - this.token = token; - } + public void setToken(String token) { + this.token = token; + } - public String getTitle() { - return title; - } + public String getTitle() { + return title; + } - public void setTitle(String title) { - this.title = title; - } + public void setTitle(String title) { + this.title = title; + } - public String getTitleJpn() { - return titleJpn; - } + public String getTitleJpn() { + return titleJpn; + } - public void setTitleJpn(String titleJpn) { - this.titleJpn = titleJpn; - } + public void setTitleJpn(String titleJpn) { + this.titleJpn = titleJpn; + } - public String getThumb() { - return thumb; - } + public String getThumb() { + return thumb; + } - public void setThumb(String thumb) { - this.thumb = thumb; - } + public void setThumb(String thumb) { + this.thumb = thumb; + } - public int getCategory() { - return category; - } + public int getCategory() { + return category; + } - public void setCategory(int category) { - this.category = category; - } + public void setCategory(int category) { + this.category = category; + } - public String getPosted() { - return posted; - } + public String getPosted() { + return posted; + } - public void setPosted(String posted) { - this.posted = posted; - } + public void setPosted(String posted) { + this.posted = posted; + } - public String getUploader() { - return uploader; - } + public String getUploader() { + return uploader; + } - public void setUploader(String uploader) { - this.uploader = uploader; - } + public void setUploader(String uploader) { + this.uploader = uploader; + } - public float getRating() { - return rating; - } + public float getRating() { + return rating; + } - public void setRating(float rating) { - this.rating = rating; - } + public void setRating(float rating) { + this.rating = rating; + } - public String getSimpleLanguage() { - return simpleLanguage; - } + public String getSimpleLanguage() { + return simpleLanguage; + } - public void setSimpleLanguage(String simpleLanguage) { - this.simpleLanguage = simpleLanguage; - } + public void setSimpleLanguage(String simpleLanguage) { + this.simpleLanguage = simpleLanguage; + } - public int getState() { - return state; - } + public int getState() { + return state; + } - public void setState(int state) { - this.state = state; - } + public void setState(int state) { + this.state = state; + } - public int getLegacy() { - return legacy; - } + public int getLegacy() { + return legacy; + } - public void setLegacy(int legacy) { - this.legacy = legacy; - } + public void setLegacy(int legacy) { + this.legacy = legacy; + } - public long getTime() { - return time; - } + public long getTime() { + return time; + } - public void setTime(long time) { - this.time = time; - } + public void setTime(long time) { + this.time = time; + } - public String getLabel() { - return label; - } + public String getLabel() { + return label; + } - public void setLabel(String label) { - this.label = label; - } + public void setLabel(String label) { + this.label = label; + } - @Override - public int describeContents() { - return 0; - } + @Override + public int describeContents() { + return 0; + } - @Override - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - dest.writeInt(this.state); - dest.writeInt(this.legacy); - dest.writeLong(this.time); - dest.writeString(this.label); - } + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + dest.writeInt(this.state); + dest.writeInt(this.legacy); + dest.writeLong(this.time); + dest.writeString(this.label); + } - protected DownloadInfo(Parcel in) { - super(in); - this.state = in.readInt(); - this.legacy = in.readInt(); - this.time = in.readLong(); - this.label = in.readString(); - } + public long getSpeed() { + return this.speed; + } - public DownloadInfo(GalleryInfo galleryInfo) { - this.gid = galleryInfo.gid; - this.token = galleryInfo.token; - this.title = galleryInfo.title; - this.titleJpn = galleryInfo.titleJpn; - this.thumb = galleryInfo.thumb; - this.category = galleryInfo.category; - this.posted = galleryInfo.posted; - this.uploader = galleryInfo.uploader; - this.rating = galleryInfo.rating; - this.simpleTags = galleryInfo.simpleTags; - this.simpleLanguage = galleryInfo.simpleLanguage; - } + public void setSpeed(long speed) { + this.speed = speed; + } + + public long getRemaining() { + return this.remaining; + } + + public void setRemaining(long remaining) { + this.remaining = remaining; + } + + public int getFinished() { + return this.finished; + } + + public void setFinished(int finished) { + this.finished = finished; + } + + public int getDownloaded() { + return this.downloaded; + } + + public void setDownloaded(int downloaded) { + this.downloaded = downloaded; + } + + public int getTotal() { + return this.total; + } + + public void setTotal(int total) { + this.total = total; + } } diff --git a/app/src/main/java/com/hippo/ehviewer/dao/DownloadLabel.java b/app/src/main/java/com/hippo/ehviewer/dao/DownloadLabel.java index 8429c4e91..022bdffd9 100644 --- a/app/src/main/java/com/hippo/ehviewer/dao/DownloadLabel.java +++ b/app/src/main/java/com/hippo/ehviewer/dao/DownloadLabel.java @@ -1,35 +1,20 @@ package com.hippo.ehviewer.dao; -import org.greenrobot.greendao.annotation.*; +import androidx.room.ColumnInfo; +import androidx.room.Entity; +import androidx.room.PrimaryKey; -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit. - -/** - * Entity mapped to table "DOWNLOAD_LABELS". - */ -@Entity(nameInDb = "DOWNLOAD_LABELS") +@Entity(tableName = "DOWNLOAD_LABELS") public class DownloadLabel { - @Id + @PrimaryKey + @ColumnInfo(name = "_id") private Long id; + @ColumnInfo(name = "LABEL") private String label; + @ColumnInfo(name = "TIME") private long time; - @Generated - public DownloadLabel() { - } - - public DownloadLabel(Long id) { - this.id = id; - } - - @Generated - public DownloadLabel(Long id, String label, long time) { - this.id = id; - this.label = label; - this.time = time; - } - public Long getId() { return id; } diff --git a/app/src/main/java/com/hippo/ehviewer/dao/DownloadLabelDao.java b/app/src/main/java/com/hippo/ehviewer/dao/DownloadLabelDao.java index c5cd3a845..b9f555faa 100644 --- a/app/src/main/java/com/hippo/ehviewer/dao/DownloadLabelDao.java +++ b/app/src/main/java/com/hippo/ehviewer/dao/DownloadLabelDao.java @@ -1,133 +1,31 @@ package com.hippo.ehviewer.dao; -import android.database.Cursor; -import android.database.sqlite.SQLiteStatement; +import androidx.room.Dao; +import androidx.room.Delete; +import androidx.room.Insert; +import androidx.room.Query; +import androidx.room.Update; -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.Property; -import org.greenrobot.greendao.internal.DaoConfig; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseStatement; +import java.util.List; -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** - * DAO for table "DOWNLOAD_LABELS". -*/ -public class DownloadLabelDao extends AbstractDao { +@Dao +public interface DownloadLabelDao { - public static final String TABLENAME = "DOWNLOAD_LABELS"; + @Query("SELECT * FROM DOWNLOAD_LABELS ORDER BY TIME ASC") + List list(); - /** - * Properties of entity DownloadLabel.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property Label = new Property(1, String.class, "label", false, "LABEL"); - public final static Property Time = new Property(2, long.class, "time", false, "TIME"); - } + @Query("SELECT * FROM DOWNLOAD_LABELS ORDER BY TIME ASC LIMIT :limit OFFSET :offset") + List list(int offset, int limit); + @Update + void update(List downloadLabels); - public DownloadLabelDao(DaoConfig config) { - super(config); - } - - public DownloadLabelDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } + @Update + void update(DownloadLabel downloadLabel); - /** Creates the underlying database table. */ - public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"DOWNLOAD_LABELS\" (" + // - "\"_id\" INTEGER PRIMARY KEY ," + // 0: id - "\"LABEL\" TEXT," + // 1: label - "\"TIME\" INTEGER NOT NULL );"); // 2: time - } + @Insert + long insert(DownloadLabel downloadLabel); - /** Drops the underlying database table. */ - public static void dropTable(Database db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"DOWNLOAD_LABELS\""; - db.execSQL(sql); - } - - @Override - protected final void bindValues(DatabaseStatement stmt, DownloadLabel entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String label = entity.getLabel(); - if (label != null) { - stmt.bindString(2, label); - } - stmt.bindLong(3, entity.getTime()); - } - - @Override - protected final void bindValues(SQLiteStatement stmt, DownloadLabel entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String label = entity.getLabel(); - if (label != null) { - stmt.bindString(2, label); - } - stmt.bindLong(3, entity.getTime()); - } - - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } - - @Override - public DownloadLabel readEntity(Cursor cursor, int offset) { - DownloadLabel entity = new DownloadLabel( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // label - cursor.getLong(offset + 2) // time - ); - return entity; - } - - @Override - public void readEntity(Cursor cursor, DownloadLabel entity, int offset) { - entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setLabel(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setTime(cursor.getLong(offset + 2)); - } - - @Override - protected final Long updateKeyAfterInsert(DownloadLabel entity, long rowId) { - entity.setId(rowId); - return rowId; - } - - @Override - public Long getKey(DownloadLabel entity) { - if(entity != null) { - return entity.getId(); - } else { - return null; - } - } - - @Override - public boolean hasKey(DownloadLabel entity) { - return entity.getId() != null; - } - - @Override - protected final boolean isEntityUpdateable() { - return true; - } - + @Delete + void delete(DownloadLabel downloadLabel); } diff --git a/app/src/main/java/com/hippo/ehviewer/dao/DownloadsDao.java b/app/src/main/java/com/hippo/ehviewer/dao/DownloadsDao.java index 80e5a6f51..b61ae894f 100644 --- a/app/src/main/java/com/hippo/ehviewer/dao/DownloadsDao.java +++ b/app/src/main/java/com/hippo/ehviewer/dao/DownloadsDao.java @@ -1,247 +1,31 @@ package com.hippo.ehviewer.dao; -import android.database.Cursor; -import android.database.sqlite.SQLiteStatement; +import androidx.room.Dao; +import androidx.room.Delete; +import androidx.room.Insert; +import androidx.room.Query; +import androidx.room.Update; -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.Property; -import org.greenrobot.greendao.internal.DaoConfig; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseStatement; +import java.util.List; -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** - * DAO for table "DOWNLOADS". -*/ -public class DownloadsDao extends AbstractDao { +@Dao +public interface DownloadsDao { - public static final String TABLENAME = "DOWNLOADS"; + String TABLENAME = "DOWNLOADS"; - /** - * Properties of entity DownloadInfo.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Gid = new Property(0, long.class, "gid", true, "GID"); - public final static Property Token = new Property(1, String.class, "token", false, "TOKEN"); - public final static Property Title = new Property(2, String.class, "title", false, "TITLE"); - public final static Property TitleJpn = new Property(3, String.class, "titleJpn", false, "TITLE_JPN"); - public final static Property Thumb = new Property(4, String.class, "thumb", false, "THUMB"); - public final static Property Category = new Property(5, int.class, "category", false, "CATEGORY"); - public final static Property Posted = new Property(6, String.class, "posted", false, "POSTED"); - public final static Property Uploader = new Property(7, String.class, "uploader", false, "UPLOADER"); - public final static Property Rating = new Property(8, float.class, "rating", false, "RATING"); - public final static Property SimpleLanguage = new Property(9, String.class, "simpleLanguage", false, "SIMPLE_LANGUAGE"); - public final static Property State = new Property(10, int.class, "state", false, "STATE"); - public final static Property Legacy = new Property(11, int.class, "legacy", false, "LEGACY"); - public final static Property Time = new Property(12, long.class, "time", false, "TIME"); - public final static Property Label = new Property(13, String.class, "label", false, "LABEL"); - } + @Query("SELECT * FROM DOWNLOADS ORDER BY TIME DESC") + List list(); + @Query("SELECT * FROM DOWNLOADS WHERE GID = :gid") + DownloadInfo load(long gid); - public DownloadsDao(DaoConfig config) { - super(config); - } - - public DownloadsDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } + @Update + void update(DownloadInfo downloadInfo); - /** Creates the underlying database table. */ - public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"DOWNLOADS\" (" + // - "\"GID\" INTEGER PRIMARY KEY NOT NULL ," + // 0: gid - "\"TOKEN\" TEXT," + // 1: token - "\"TITLE\" TEXT," + // 2: title - "\"TITLE_JPN\" TEXT," + // 3: titleJpn - "\"THUMB\" TEXT," + // 4: thumb - "\"CATEGORY\" INTEGER NOT NULL ," + // 5: category - "\"POSTED\" TEXT," + // 6: posted - "\"UPLOADER\" TEXT," + // 7: uploader - "\"RATING\" REAL NOT NULL ," + // 8: rating - "\"SIMPLE_LANGUAGE\" TEXT," + // 9: simpleLanguage - "\"STATE\" INTEGER NOT NULL ," + // 10: state - "\"LEGACY\" INTEGER NOT NULL ," + // 11: legacy - "\"TIME\" INTEGER NOT NULL ," + // 12: time - "\"LABEL\" TEXT);"); // 13: label - } + @Insert + void insert(DownloadInfo downloadInfo); - /** Drops the underlying database table. */ - public static void dropTable(Database db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"DOWNLOADS\""; - db.execSQL(sql); - } + @Delete + void delete(DownloadInfo downloadInfo); - @Override - protected final void bindValues(DatabaseStatement stmt, DownloadInfo entity) { - stmt.clearBindings(); - stmt.bindLong(1, entity.getGid()); - - String token = entity.getToken(); - if (token != null) { - stmt.bindString(2, token); - } - - String title = entity.getTitle(); - if (title != null) { - stmt.bindString(3, title); - } - - String titleJpn = entity.getTitleJpn(); - if (titleJpn != null) { - stmt.bindString(4, titleJpn); - } - - String thumb = entity.getThumb(); - if (thumb != null) { - stmt.bindString(5, thumb); - } - stmt.bindLong(6, entity.getCategory()); - - String posted = entity.getPosted(); - if (posted != null) { - stmt.bindString(7, posted); - } - - String uploader = entity.getUploader(); - if (uploader != null) { - stmt.bindString(8, uploader); - } - stmt.bindDouble(9, entity.getRating()); - - String simpleLanguage = entity.getSimpleLanguage(); - if (simpleLanguage != null) { - stmt.bindString(10, simpleLanguage); - } - stmt.bindLong(11, entity.getState()); - stmt.bindLong(12, entity.getLegacy()); - stmt.bindLong(13, entity.getTime()); - - String label = entity.getLabel(); - if (label != null) { - stmt.bindString(14, label); - } - } - - @Override - protected final void bindValues(SQLiteStatement stmt, DownloadInfo entity) { - stmt.clearBindings(); - stmt.bindLong(1, entity.getGid()); - - String token = entity.getToken(); - if (token != null) { - stmt.bindString(2, token); - } - - String title = entity.getTitle(); - if (title != null) { - stmt.bindString(3, title); - } - - String titleJpn = entity.getTitleJpn(); - if (titleJpn != null) { - stmt.bindString(4, titleJpn); - } - - String thumb = entity.getThumb(); - if (thumb != null) { - stmt.bindString(5, thumb); - } - stmt.bindLong(6, entity.getCategory()); - - String posted = entity.getPosted(); - if (posted != null) { - stmt.bindString(7, posted); - } - - String uploader = entity.getUploader(); - if (uploader != null) { - stmt.bindString(8, uploader); - } - stmt.bindDouble(9, entity.getRating()); - - String simpleLanguage = entity.getSimpleLanguage(); - if (simpleLanguage != null) { - stmt.bindString(10, simpleLanguage); - } - stmt.bindLong(11, entity.getState()); - stmt.bindLong(12, entity.getLegacy()); - stmt.bindLong(13, entity.getTime()); - - String label = entity.getLabel(); - if (label != null) { - stmt.bindString(14, label); - } - } - - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.getLong(offset + 0); - } - - @Override - public DownloadInfo readEntity(Cursor cursor, int offset) { - DownloadInfo entity = new DownloadInfo( // - cursor.getLong(offset + 0), // gid - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // token - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // title - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // titleJpn - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // thumb - cursor.getInt(offset + 5), // category - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // posted - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // uploader - cursor.getFloat(offset + 8), // rating - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // simpleLanguage - cursor.getInt(offset + 10), // state - cursor.getInt(offset + 11), // legacy - cursor.getLong(offset + 12), // time - cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13) // label - ); - return entity; - } - - @Override - public void readEntity(Cursor cursor, DownloadInfo entity, int offset) { - entity.setGid(cursor.getLong(offset + 0)); - entity.setToken(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setTitle(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setTitleJpn(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setThumb(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setCategory(cursor.getInt(offset + 5)); - entity.setPosted(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); - entity.setUploader(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); - entity.setRating(cursor.getFloat(offset + 8)); - entity.setSimpleLanguage(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - entity.setState(cursor.getInt(offset + 10)); - entity.setLegacy(cursor.getInt(offset + 11)); - entity.setTime(cursor.getLong(offset + 12)); - entity.setLabel(cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13)); - } - - @Override - protected final Long updateKeyAfterInsert(DownloadInfo entity, long rowId) { - entity.setGid(rowId); - return rowId; - } - - @Override - public Long getKey(DownloadInfo entity) { - if(entity != null) { - return entity.getGid(); - } else { - return null; - } - } - - @Override - public boolean hasKey(DownloadInfo entity) { - throw new UnsupportedOperationException("Unsupported for entities with a non-null key"); - } - - @Override - protected final boolean isEntityUpdateable() { - return true; - } - } diff --git a/app/src/main/java/com/hippo/ehviewer/dao/EhDatabase.java b/app/src/main/java/com/hippo/ehviewer/dao/EhDatabase.java new file mode 100644 index 000000000..308a1b348 --- /dev/null +++ b/app/src/main/java/com/hippo/ehviewer/dao/EhDatabase.java @@ -0,0 +1,23 @@ +package com.hippo.ehviewer.dao; + +import androidx.room.Database; +import androidx.room.RoomDatabase; + +@Database(entities = {BookmarkInfo.class, DownloadInfo.class, DownloadLabel.class, DownloadDirname.class, Filter.class, HistoryInfo.class, LocalFavoriteInfo.class, QuickSearch.class}, version = 4, exportSchema = false) +public abstract class EhDatabase extends RoomDatabase { + public abstract BookmarksBao bookmarksBao(); + + public abstract DownloadDirnameDao downloadDirnameDao(); + + public abstract DownloadLabelDao downloadLabelDao(); + + public abstract DownloadsDao downloadsDao(); + + public abstract FilterDao filterDao(); + + public abstract HistoryDao historyDao(); + + public abstract LocalFavoritesDao localFavoritesDao(); + + public abstract QuickSearchDao quickSearchDao(); +} diff --git a/app/src/main/java/com/hippo/ehviewer/dao/Filter.java b/app/src/main/java/com/hippo/ehviewer/dao/Filter.java index cd4745d77..48e572333 100644 --- a/app/src/main/java/com/hippo/ehviewer/dao/Filter.java +++ b/app/src/main/java/com/hippo/ehviewer/dao/Filter.java @@ -1,83 +1,69 @@ package com.hippo.ehviewer.dao; -import org.greenrobot.greendao.annotation.*; +import androidx.room.ColumnInfo; +import androidx.room.Entity; +import androidx.room.PrimaryKey; + import com.hippo.util.HashCodeUtils; import com.hippo.yorozuya.ObjectUtils; -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit. - -/** - * Entity mapped to table "FILTER". - */ -@Entity(nameInDb = "FILTER") +@Entity(tableName = "FILTER") public class Filter { - @Id - private Long id; - public int mode; - public String text; - public Boolean enable; + @ColumnInfo(name = "MODE") + public int mode; + @ColumnInfo(name = "TEXT") + public String text; + @ColumnInfo(name = "ENABLE") + public Boolean enable; + @PrimaryKey + @ColumnInfo(name = "_id") + private Long id; - @Generated - public Filter() { - } + public Long getId() { + return id; + } - public Filter(Long id) { - this.id = id; - } + public void setId(Long id) { + this.id = id; + } - @Generated - public Filter(Long id, int mode, String text, Boolean enable) { - this.id = id; - this.mode = mode; - this.text = text; - this.enable = enable; - } + public int getMode() { + return mode; + } - public Long getId() { - return id; - } + public void setMode(int mode) { + this.mode = mode; + } - public void setId(Long id) { - this.id = id; - } + public String getText() { + return text; + } - public int getMode() { - return mode; - } + public void setText(String text) { + this.text = text; + } - public void setMode(int mode) { - this.mode = mode; - } + public Boolean getEnable() { + return enable; + } - public String getText() { - return text; - } + public void setEnable(Boolean enable) { + this.enable = enable; + } - public void setText(String text) { - this.text = text; - } + @Override + public int hashCode() { + return HashCodeUtils.hashCode(mode, text); + } - public Boolean getEnable() { - return enable; - } - - public void setEnable(Boolean enable) { - this.enable = enable; - } - - @Override - public int hashCode() { - return HashCodeUtils.hashCode(mode, text); - } - - @Override - public boolean equals(Object o) { - if (!(o instanceof Filter)) { - return false; - } - Filter filter = (Filter) o; - return filter.mode == mode && ObjectUtils.equal(filter.text, text); - } + @Override + public boolean equals(Object o) { + if (!(o instanceof Filter)) { + return false; + } + Filter filter = (Filter) o; + return filter.mode == mode && ObjectUtils.equal(filter.text, text); + } } diff --git a/app/src/main/java/com/hippo/ehviewer/dao/FilterDao.java b/app/src/main/java/com/hippo/ehviewer/dao/FilterDao.java index e92bc8749..688e87880 100644 --- a/app/src/main/java/com/hippo/ehviewer/dao/FilterDao.java +++ b/app/src/main/java/com/hippo/ehviewer/dao/FilterDao.java @@ -1,147 +1,28 @@ package com.hippo.ehviewer.dao; -import android.database.Cursor; -import android.database.sqlite.SQLiteStatement; +import androidx.room.Dao; +import androidx.room.Delete; +import androidx.room.Insert; +import androidx.room.Query; +import androidx.room.Update; -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.Property; -import org.greenrobot.greendao.internal.DaoConfig; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseStatement; +import java.util.List; -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** - * DAO for table "FILTER". -*/ -public class FilterDao extends AbstractDao { +@Dao +public interface FilterDao { - public static final String TABLENAME = "FILTER"; + String TABLENAME = "FILTER"; - /** - * Properties of entity Filter.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property Mode = new Property(1, int.class, "mode", false, "MODE"); - public final static Property Text = new Property(2, String.class, "text", false, "TEXT"); - public final static Property Enable = new Property(3, Boolean.class, "enable", false, "ENABLE"); - } + @Query("SELECT * FROM FILTER") + List list(); + @Update + void update(Filter filter); - public FilterDao(DaoConfig config) { - super(config); - } - - public FilterDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } + @Insert + long insert(Filter filter); - /** Creates the underlying database table. */ - public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"FILTER\" (" + // - "\"_id\" INTEGER PRIMARY KEY ," + // 0: id - "\"MODE\" INTEGER NOT NULL ," + // 1: mode - "\"TEXT\" TEXT," + // 2: text - "\"ENABLE\" INTEGER);"); // 3: enable - } + @Delete + void delete(Filter filter); - /** Drops the underlying database table. */ - public static void dropTable(Database db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"FILTER\""; - db.execSQL(sql); - } - - @Override - protected final void bindValues(DatabaseStatement stmt, Filter entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - stmt.bindLong(2, entity.getMode()); - - String text = entity.getText(); - if (text != null) { - stmt.bindString(3, text); - } - - Boolean enable = entity.getEnable(); - if (enable != null) { - stmt.bindLong(4, enable ? 1L: 0L); - } - } - - @Override - protected final void bindValues(SQLiteStatement stmt, Filter entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - stmt.bindLong(2, entity.getMode()); - - String text = entity.getText(); - if (text != null) { - stmt.bindString(3, text); - } - - Boolean enable = entity.getEnable(); - if (enable != null) { - stmt.bindLong(4, enable ? 1L: 0L); - } - } - - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } - - @Override - public Filter readEntity(Cursor cursor, int offset) { - Filter entity = new Filter( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.getInt(offset + 1), // mode - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // text - cursor.isNull(offset + 3) ? null : cursor.getShort(offset + 3) != 0 // enable - ); - return entity; - } - - @Override - public void readEntity(Cursor cursor, Filter entity, int offset) { - entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setMode(cursor.getInt(offset + 1)); - entity.setText(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setEnable(cursor.isNull(offset + 3) ? null : cursor.getShort(offset + 3) != 0); - } - - @Override - protected final Long updateKeyAfterInsert(Filter entity, long rowId) { - entity.setId(rowId); - return rowId; - } - - @Override - public Long getKey(Filter entity) { - if(entity != null) { - return entity.getId(); - } else { - return null; - } - } - - @Override - public boolean hasKey(Filter entity) { - return entity.getId() != null; - } - - @Override - protected final boolean isEntityUpdateable() { - return true; - } - } diff --git a/app/src/main/java/com/hippo/ehviewer/dao/HistoryDao.java b/app/src/main/java/com/hippo/ehviewer/dao/HistoryDao.java index c566997b2..802cb934c 100644 --- a/app/src/main/java/com/hippo/ehviewer/dao/HistoryDao.java +++ b/app/src/main/java/com/hippo/ehviewer/dao/HistoryDao.java @@ -1,227 +1,38 @@ package com.hippo.ehviewer.dao; -import android.database.Cursor; -import android.database.sqlite.SQLiteStatement; +import androidx.room.Dao; +import androidx.room.Delete; +import androidx.room.Insert; +import androidx.room.Query; +import androidx.room.Update; -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.Property; -import org.greenrobot.greendao.internal.DaoConfig; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseStatement; +import java.util.List; -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** - * DAO for table "HISTORY". -*/ -public class HistoryDao extends AbstractDao { +@Dao +public interface HistoryDao { - public static final String TABLENAME = "HISTORY"; + @Query("SELECT * FROM HISTORY WHERE GID = :gid") + HistoryInfo load(long gid); - /** - * Properties of entity HistoryInfo.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Gid = new Property(0, long.class, "gid", true, "GID"); - public final static Property Token = new Property(1, String.class, "token", false, "TOKEN"); - public final static Property Title = new Property(2, String.class, "title", false, "TITLE"); - public final static Property TitleJpn = new Property(3, String.class, "titleJpn", false, "TITLE_JPN"); - public final static Property Thumb = new Property(4, String.class, "thumb", false, "THUMB"); - public final static Property Category = new Property(5, int.class, "category", false, "CATEGORY"); - public final static Property Posted = new Property(6, String.class, "posted", false, "POSTED"); - public final static Property Uploader = new Property(7, String.class, "uploader", false, "UPLOADER"); - public final static Property Rating = new Property(8, float.class, "rating", false, "RATING"); - public final static Property SimpleLanguage = new Property(9, String.class, "simpleLanguage", false, "SIMPLE_LANGUAGE"); - public final static Property Mode = new Property(10, int.class, "mode", false, "MODE"); - public final static Property Time = new Property(11, long.class, "time", false, "TIME"); - } + @Query("SELECT * FROM HISTORY ORDER BY TIME DESC") + List list(); + @Query("SELECT * FROM HISTORY ORDER BY TIME DESC LIMIT :limit OFFSET :offset") + List list(int offset, int limit); - public HistoryDao(DaoConfig config) { - super(config); - } - - public HistoryDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } + @Update + void update(HistoryInfo historyInfo); - /** Creates the underlying database table. */ - public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"HISTORY\" (" + // - "\"GID\" INTEGER PRIMARY KEY NOT NULL ," + // 0: gid - "\"TOKEN\" TEXT," + // 1: token - "\"TITLE\" TEXT," + // 2: title - "\"TITLE_JPN\" TEXT," + // 3: titleJpn - "\"THUMB\" TEXT," + // 4: thumb - "\"CATEGORY\" INTEGER NOT NULL ," + // 5: category - "\"POSTED\" TEXT," + // 6: posted - "\"UPLOADER\" TEXT," + // 7: uploader - "\"RATING\" REAL NOT NULL ," + // 8: rating - "\"SIMPLE_LANGUAGE\" TEXT," + // 9: simpleLanguage - "\"MODE\" INTEGER NOT NULL ," + // 10: mode - "\"TIME\" INTEGER NOT NULL );"); // 11: time - } + @Insert + void insert(HistoryInfo historyInfo); - /** Drops the underlying database table. */ - public static void dropTable(Database db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"HISTORY\""; - db.execSQL(sql); - } + @Delete + void delete(HistoryInfo historyInfos); - @Override - protected final void bindValues(DatabaseStatement stmt, HistoryInfo entity) { - stmt.clearBindings(); - stmt.bindLong(1, entity.getGid()); - - String token = entity.getToken(); - if (token != null) { - stmt.bindString(2, token); - } - - String title = entity.getTitle(); - if (title != null) { - stmt.bindString(3, title); - } - - String titleJpn = entity.getTitleJpn(); - if (titleJpn != null) { - stmt.bindString(4, titleJpn); - } - - String thumb = entity.getThumb(); - if (thumb != null) { - stmt.bindString(5, thumb); - } - stmt.bindLong(6, entity.getCategory()); - - String posted = entity.getPosted(); - if (posted != null) { - stmt.bindString(7, posted); - } - - String uploader = entity.getUploader(); - if (uploader != null) { - stmt.bindString(8, uploader); - } - stmt.bindDouble(9, entity.getRating()); - - String simpleLanguage = entity.getSimpleLanguage(); - if (simpleLanguage != null) { - stmt.bindString(10, simpleLanguage); - } - stmt.bindLong(11, entity.getMode()); - stmt.bindLong(12, entity.getTime()); - } + @Delete + void delete(List historyInfos); - @Override - protected final void bindValues(SQLiteStatement stmt, HistoryInfo entity) { - stmt.clearBindings(); - stmt.bindLong(1, entity.getGid()); - - String token = entity.getToken(); - if (token != null) { - stmt.bindString(2, token); - } - - String title = entity.getTitle(); - if (title != null) { - stmt.bindString(3, title); - } - - String titleJpn = entity.getTitleJpn(); - if (titleJpn != null) { - stmt.bindString(4, titleJpn); - } - - String thumb = entity.getThumb(); - if (thumb != null) { - stmt.bindString(5, thumb); - } - stmt.bindLong(6, entity.getCategory()); - - String posted = entity.getPosted(); - if (posted != null) { - stmt.bindString(7, posted); - } - - String uploader = entity.getUploader(); - if (uploader != null) { - stmt.bindString(8, uploader); - } - stmt.bindDouble(9, entity.getRating()); - - String simpleLanguage = entity.getSimpleLanguage(); - if (simpleLanguage != null) { - stmt.bindString(10, simpleLanguage); - } - stmt.bindLong(11, entity.getMode()); - stmt.bindLong(12, entity.getTime()); - } + @Query("DELETE FROM HISTORY") + void deleteAll(); - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.getLong(offset + 0); - } - - @Override - public HistoryInfo readEntity(Cursor cursor, int offset) { - HistoryInfo entity = new HistoryInfo( // - cursor.getLong(offset + 0), // gid - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // token - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // title - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // titleJpn - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // thumb - cursor.getInt(offset + 5), // category - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // posted - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // uploader - cursor.getFloat(offset + 8), // rating - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // simpleLanguage - cursor.getInt(offset + 10), // mode - cursor.getLong(offset + 11) // time - ); - return entity; - } - - @Override - public void readEntity(Cursor cursor, HistoryInfo entity, int offset) { - entity.setGid(cursor.getLong(offset + 0)); - entity.setToken(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setTitle(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setTitleJpn(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setThumb(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setCategory(cursor.getInt(offset + 5)); - entity.setPosted(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); - entity.setUploader(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); - entity.setRating(cursor.getFloat(offset + 8)); - entity.setSimpleLanguage(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - entity.setMode(cursor.getInt(offset + 10)); - entity.setTime(cursor.getLong(offset + 11)); - } - - @Override - protected final Long updateKeyAfterInsert(HistoryInfo entity, long rowId) { - entity.setGid(rowId); - return rowId; - } - - @Override - public Long getKey(HistoryInfo entity) { - if(entity != null) { - return entity.getGid(); - } else { - return null; - } - } - - @Override - public boolean hasKey(HistoryInfo entity) { - throw new UnsupportedOperationException("Unsupported for entities with a non-null key"); - } - - @Override - protected final boolean isEntityUpdateable() { - return true; - } - } diff --git a/app/src/main/java/com/hippo/ehviewer/dao/HistoryInfo.java b/app/src/main/java/com/hippo/ehviewer/dao/HistoryInfo.java index ba599d611..205d0a14d 100644 --- a/app/src/main/java/com/hippo/ehviewer/dao/HistoryInfo.java +++ b/app/src/main/java/com/hippo/ehviewer/dao/HistoryInfo.java @@ -1,183 +1,162 @@ package com.hippo.ehviewer.dao; -import org.greenrobot.greendao.annotation.*; import android.os.Parcel; + +import androidx.room.ColumnInfo; +import androidx.room.Entity; + import com.hippo.ehviewer.client.data.GalleryInfo; -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit. - -/** - * Entity mapped to table "HISTORY". - */ -@Entity(nameInDb = "HISTORY") +@Entity(tableName = "HISTORY") public class HistoryInfo extends GalleryInfo { - public int mode; - public long time; + public static final Creator CREATOR = new Creator() { + @Override + public HistoryInfo createFromParcel(Parcel source) { + return new HistoryInfo(source); + } - public static final Creator CREATOR = new Creator() { - @Override - public HistoryInfo createFromParcel(Parcel source) { - return new HistoryInfo(source); - } + @Override + public HistoryInfo[] newArray(int size) { + return new HistoryInfo[size]; + } + }; + @ColumnInfo(name = "MODE") + public int mode; + @ColumnInfo(name = "TIME") + public long time; - @Override - public HistoryInfo[] newArray(int size) { - return new HistoryInfo[size]; - } - }; + protected HistoryInfo(Parcel in) { + super(in); + this.mode = in.readInt(); + this.time = in.readLong(); + } - @Generated - public HistoryInfo() { - } + public HistoryInfo(GalleryInfo galleryInfo) { + this.gid = galleryInfo.gid; + this.token = galleryInfo.token; + this.title = galleryInfo.title; + this.titleJpn = galleryInfo.titleJpn; + this.thumb = galleryInfo.thumb; + this.category = galleryInfo.category; + this.posted = galleryInfo.posted; + this.uploader = galleryInfo.uploader; + this.rating = galleryInfo.rating; + this.simpleTags = galleryInfo.simpleTags; + this.simpleLanguage = galleryInfo.simpleLanguage; + } - public HistoryInfo(long gid) { - this.gid = gid; - } + public HistoryInfo(int mode, long time) { + this.mode = mode; + this.time = time; + } - @Generated - public HistoryInfo(long gid, String token, String title, String titleJpn, String thumb, int category, String posted, - String uploader, float rating, String simpleLanguage, int mode, long time) { - this.gid = gid; - this.token = token; - this.title = title; - this.titleJpn = titleJpn; - this.thumb = thumb; - this.category = category; - this.posted = posted; - this.uploader = uploader; - this.rating = rating; - this.simpleLanguage = simpleLanguage; - this.mode = mode; - this.time = time; - } + public long getGid() { + return gid; + } - public long getGid() { - return gid; - } + public void setGid(long gid) { + this.gid = gid; + } - public void setGid(long gid) { - this.gid = gid; - } + public String getToken() { + return token; + } - public String getToken() { - return token; - } + public void setToken(String token) { + this.token = token; + } - public void setToken(String token) { - this.token = token; - } + public String getTitle() { + return title; + } - public String getTitle() { - return title; - } + public void setTitle(String title) { + this.title = title; + } - public void setTitle(String title) { - this.title = title; - } + public String getTitleJpn() { + return titleJpn; + } - public String getTitleJpn() { - return titleJpn; - } + public void setTitleJpn(String titleJpn) { + this.titleJpn = titleJpn; + } - public void setTitleJpn(String titleJpn) { - this.titleJpn = titleJpn; - } + public String getThumb() { + return thumb; + } - public String getThumb() { - return thumb; - } + public void setThumb(String thumb) { + this.thumb = thumb; + } - public void setThumb(String thumb) { - this.thumb = thumb; - } + public int getCategory() { + return category; + } - public int getCategory() { - return category; - } + public void setCategory(int category) { + this.category = category; + } - public void setCategory(int category) { - this.category = category; - } + public String getPosted() { + return posted; + } - public String getPosted() { - return posted; - } + public void setPosted(String posted) { + this.posted = posted; + } - public void setPosted(String posted) { - this.posted = posted; - } + public String getUploader() { + return uploader; + } - public String getUploader() { - return uploader; - } + public void setUploader(String uploader) { + this.uploader = uploader; + } - public void setUploader(String uploader) { - this.uploader = uploader; - } + public float getRating() { + return rating; + } - public float getRating() { - return rating; - } + public void setRating(float rating) { + this.rating = rating; + } - public void setRating(float rating) { - this.rating = rating; - } + public String getSimpleLanguage() { + return simpleLanguage; + } - public String getSimpleLanguage() { - return simpleLanguage; - } + public void setSimpleLanguage(String simpleLanguage) { + this.simpleLanguage = simpleLanguage; + } - public void setSimpleLanguage(String simpleLanguage) { - this.simpleLanguage = simpleLanguage; - } + public int getMode() { + return mode; + } - public int getMode() { - return mode; - } + public void setMode(int mode) { + this.mode = mode; + } - public void setMode(int mode) { - this.mode = mode; - } + public long getTime() { + return time; + } - public long getTime() { - return time; - } + public void setTime(long time) { + this.time = time; + } - public void setTime(long time) { - this.time = time; - } + @Override + public int describeContents() { + return 0; + } - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - dest.writeInt(this.mode); - dest.writeLong(this.time); - } - - protected HistoryInfo(Parcel in) { - super(in); - this.mode = in.readInt(); - this.time = in.readLong(); - } - - public HistoryInfo(GalleryInfo galleryInfo) { - this.gid = galleryInfo.gid; - this.token = galleryInfo.token; - this.title = galleryInfo.title; - this.titleJpn = galleryInfo.titleJpn; - this.thumb = galleryInfo.thumb; - this.category = galleryInfo.category; - this.posted = galleryInfo.posted; - this.uploader = galleryInfo.uploader; - this.rating = galleryInfo.rating; - this.simpleTags = galleryInfo.simpleTags; - this.simpleLanguage = galleryInfo.simpleLanguage; - } + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + dest.writeInt(this.mode); + dest.writeLong(this.time); + } } diff --git a/app/src/main/java/com/hippo/ehviewer/dao/LocalFavoriteInfo.java b/app/src/main/java/com/hippo/ehviewer/dao/LocalFavoriteInfo.java index 82bb5bfd0..cc4507183 100644 --- a/app/src/main/java/com/hippo/ehviewer/dao/LocalFavoriteInfo.java +++ b/app/src/main/java/com/hippo/ehviewer/dao/LocalFavoriteInfo.java @@ -1,171 +1,148 @@ package com.hippo.ehviewer.dao; -import org.greenrobot.greendao.annotation.*; import android.os.Parcel; + +import androidx.room.ColumnInfo; +import androidx.room.Entity; + import com.hippo.ehviewer.client.data.GalleryInfo; -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit. - -/** - * Entity mapped to table "LOCAL_FAVORITES". - */ -@Entity(nameInDb = "LOCAL_FAVORITES") +@Entity(tableName = "LOCAL_FAVORITES") public class LocalFavoriteInfo extends GalleryInfo { - public long time; + public static final Creator CREATOR = new Creator() { + @Override + public LocalFavoriteInfo createFromParcel(Parcel source) { + return new LocalFavoriteInfo(source); + } - public static final Creator CREATOR = new Creator() { - @Override - public LocalFavoriteInfo createFromParcel(Parcel source) { - return new LocalFavoriteInfo(source); - } + @Override + public LocalFavoriteInfo[] newArray(int size) { + return new LocalFavoriteInfo[size]; + } + }; + @ColumnInfo(name = "TIME") + public long time; - @Override - public LocalFavoriteInfo[] newArray(int size) { - return new LocalFavoriteInfo[size]; - } - }; + protected LocalFavoriteInfo(Parcel in) { + super(in); + this.time = in.readLong(); + } - @Generated - public LocalFavoriteInfo() { - } + public LocalFavoriteInfo(GalleryInfo galleryInfo) { + this.gid = galleryInfo.gid; + this.token = galleryInfo.token; + this.title = galleryInfo.title; + this.titleJpn = galleryInfo.titleJpn; + this.thumb = galleryInfo.thumb; + this.category = galleryInfo.category; + this.posted = galleryInfo.posted; + this.uploader = galleryInfo.uploader; + this.rating = galleryInfo.rating; + this.simpleTags = galleryInfo.simpleTags; + this.simpleLanguage = galleryInfo.simpleLanguage; + } - public LocalFavoriteInfo(long gid) { - this.gid = gid; - } + public LocalFavoriteInfo() { + } - @Generated - public LocalFavoriteInfo(long gid, String token, String title, String titleJpn, String thumb, int category, - String posted, String uploader, float rating, String simpleLanguage, long time) { - this.gid = gid; - this.token = token; - this.title = title; - this.titleJpn = titleJpn; - this.thumb = thumb; - this.category = category; - this.posted = posted; - this.uploader = uploader; - this.rating = rating; - this.simpleLanguage = simpleLanguage; - this.time = time; - } + public long getGid() { + return gid; + } - public long getGid() { - return gid; - } + public void setGid(long gid) { + this.gid = gid; + } - public void setGid(long gid) { - this.gid = gid; - } + public String getToken() { + return token; + } - public String getToken() { - return token; - } + public void setToken(String token) { + this.token = token; + } - public void setToken(String token) { - this.token = token; - } + public String getTitle() { + return title; + } - public String getTitle() { - return title; - } + public void setTitle(String title) { + this.title = title; + } - public void setTitle(String title) { - this.title = title; - } + public String getTitleJpn() { + return titleJpn; + } - public String getTitleJpn() { - return titleJpn; - } + public void setTitleJpn(String titleJpn) { + this.titleJpn = titleJpn; + } - public void setTitleJpn(String titleJpn) { - this.titleJpn = titleJpn; - } + public String getThumb() { + return thumb; + } - public String getThumb() { - return thumb; - } + public void setThumb(String thumb) { + this.thumb = thumb; + } - public void setThumb(String thumb) { - this.thumb = thumb; - } + public int getCategory() { + return category; + } - public int getCategory() { - return category; - } + public void setCategory(int category) { + this.category = category; + } - public void setCategory(int category) { - this.category = category; - } + public String getPosted() { + return posted; + } - public String getPosted() { - return posted; - } + public void setPosted(String posted) { + this.posted = posted; + } - public void setPosted(String posted) { - this.posted = posted; - } + public String getUploader() { + return uploader; + } - public String getUploader() { - return uploader; - } + public void setUploader(String uploader) { + this.uploader = uploader; + } - public void setUploader(String uploader) { - this.uploader = uploader; - } + public float getRating() { + return rating; + } - public float getRating() { - return rating; - } + public void setRating(float rating) { + this.rating = rating; + } - public void setRating(float rating) { - this.rating = rating; - } + public String getSimpleLanguage() { + return simpleLanguage; + } - public String getSimpleLanguage() { - return simpleLanguage; - } + public void setSimpleLanguage(String simpleLanguage) { + this.simpleLanguage = simpleLanguage; + } - public void setSimpleLanguage(String simpleLanguage) { - this.simpleLanguage = simpleLanguage; - } + public long getTime() { + return time; + } - public long getTime() { - return time; - } + public void setTime(long time) { + this.time = time; + } - public void setTime(long time) { - this.time = time; - } + @Override + public int describeContents() { + return 0; + } - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - dest.writeLong(this.time); - } - - protected LocalFavoriteInfo(Parcel in) { - super(in); - this.time = in.readLong(); - } - - public LocalFavoriteInfo(GalleryInfo galleryInfo) { - this.gid = galleryInfo.gid; - this.token = galleryInfo.token; - this.title = galleryInfo.title; - this.titleJpn = galleryInfo.titleJpn; - this.thumb = galleryInfo.thumb; - this.category = galleryInfo.category; - this.posted = galleryInfo.posted; - this.uploader = galleryInfo.uploader; - this.rating = galleryInfo.rating; - this.simpleTags = galleryInfo.simpleTags; - this.simpleLanguage = galleryInfo.simpleLanguage; - } + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + dest.writeLong(this.time); + } } diff --git a/app/src/main/java/com/hippo/ehviewer/dao/LocalFavoritesDao.java b/app/src/main/java/com/hippo/ehviewer/dao/LocalFavoritesDao.java index f986299fa..089261e8a 100644 --- a/app/src/main/java/com/hippo/ehviewer/dao/LocalFavoritesDao.java +++ b/app/src/main/java/com/hippo/ehviewer/dao/LocalFavoritesDao.java @@ -1,221 +1,33 @@ package com.hippo.ehviewer.dao; -import android.database.Cursor; -import android.database.sqlite.SQLiteStatement; +import androidx.room.Dao; +import androidx.room.Delete; +import androidx.room.Insert; +import androidx.room.Query; -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.Property; -import org.greenrobot.greendao.internal.DaoConfig; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseStatement; +import java.util.List; -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** - * DAO for table "LOCAL_FAVORITES". -*/ -public class LocalFavoritesDao extends AbstractDao { +@Dao +public interface LocalFavoritesDao { - public static final String TABLENAME = "LOCAL_FAVORITES"; + String TABLENAME = "LOCAL_FAVORITES"; - /** - * Properties of entity LocalFavoriteInfo.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Gid = new Property(0, long.class, "gid", true, "GID"); - public final static Property Token = new Property(1, String.class, "token", false, "TOKEN"); - public final static Property Title = new Property(2, String.class, "title", false, "TITLE"); - public final static Property TitleJpn = new Property(3, String.class, "titleJpn", false, "TITLE_JPN"); - public final static Property Thumb = new Property(4, String.class, "thumb", false, "THUMB"); - public final static Property Category = new Property(5, int.class, "category", false, "CATEGORY"); - public final static Property Posted = new Property(6, String.class, "posted", false, "POSTED"); - public final static Property Uploader = new Property(7, String.class, "uploader", false, "UPLOADER"); - public final static Property Rating = new Property(8, float.class, "rating", false, "RATING"); - public final static Property SimpleLanguage = new Property(9, String.class, "simpleLanguage", false, "SIMPLE_LANGUAGE"); - public final static Property Time = new Property(10, long.class, "time", false, "TIME"); - } + @Query("SELECT * FROM LOCAL_FAVORITES ORDER BY TIME DESC") + List list(); + @Query("SELECT * FROM LOCAL_FAVORITES WHERE TITLE LIKE :title ORDER BY TIME DESC") + List list(String title); - public LocalFavoritesDao(DaoConfig config) { - super(config); - } - - public LocalFavoritesDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } + @Query("SELECT * FROM LOCAL_FAVORITES WHERE GID = :gid") + LocalFavoriteInfo load(long gid); - /** Creates the underlying database table. */ - public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"LOCAL_FAVORITES\" (" + // - "\"GID\" INTEGER PRIMARY KEY NOT NULL ," + // 0: gid - "\"TOKEN\" TEXT," + // 1: token - "\"TITLE\" TEXT," + // 2: title - "\"TITLE_JPN\" TEXT," + // 3: titleJpn - "\"THUMB\" TEXT," + // 4: thumb - "\"CATEGORY\" INTEGER NOT NULL ," + // 5: category - "\"POSTED\" TEXT," + // 6: posted - "\"UPLOADER\" TEXT," + // 7: uploader - "\"RATING\" REAL NOT NULL ," + // 8: rating - "\"SIMPLE_LANGUAGE\" TEXT," + // 9: simpleLanguage - "\"TIME\" INTEGER NOT NULL );"); // 10: time - } + @Insert + void insert(LocalFavoriteInfo localFavoriteInfo); - /** Drops the underlying database table. */ - public static void dropTable(Database db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"LOCAL_FAVORITES\""; - db.execSQL(sql); - } + @Delete + void delete(LocalFavoriteInfo localFavoriteInfo); - @Override - protected final void bindValues(DatabaseStatement stmt, LocalFavoriteInfo entity) { - stmt.clearBindings(); - stmt.bindLong(1, entity.getGid()); - - String token = entity.getToken(); - if (token != null) { - stmt.bindString(2, token); - } - - String title = entity.getTitle(); - if (title != null) { - stmt.bindString(3, title); - } - - String titleJpn = entity.getTitleJpn(); - if (titleJpn != null) { - stmt.bindString(4, titleJpn); - } - - String thumb = entity.getThumb(); - if (thumb != null) { - stmt.bindString(5, thumb); - } - stmt.bindLong(6, entity.getCategory()); - - String posted = entity.getPosted(); - if (posted != null) { - stmt.bindString(7, posted); - } - - String uploader = entity.getUploader(); - if (uploader != null) { - stmt.bindString(8, uploader); - } - stmt.bindDouble(9, entity.getRating()); - - String simpleLanguage = entity.getSimpleLanguage(); - if (simpleLanguage != null) { - stmt.bindString(10, simpleLanguage); - } - stmt.bindLong(11, entity.getTime()); - } + @Query("DELETE FROM LOCAL_FAVORITES WHERE GID = :gid") + void deleteByKey(long gid); - @Override - protected final void bindValues(SQLiteStatement stmt, LocalFavoriteInfo entity) { - stmt.clearBindings(); - stmt.bindLong(1, entity.getGid()); - - String token = entity.getToken(); - if (token != null) { - stmt.bindString(2, token); - } - - String title = entity.getTitle(); - if (title != null) { - stmt.bindString(3, title); - } - - String titleJpn = entity.getTitleJpn(); - if (titleJpn != null) { - stmt.bindString(4, titleJpn); - } - - String thumb = entity.getThumb(); - if (thumb != null) { - stmt.bindString(5, thumb); - } - stmt.bindLong(6, entity.getCategory()); - - String posted = entity.getPosted(); - if (posted != null) { - stmt.bindString(7, posted); - } - - String uploader = entity.getUploader(); - if (uploader != null) { - stmt.bindString(8, uploader); - } - stmt.bindDouble(9, entity.getRating()); - - String simpleLanguage = entity.getSimpleLanguage(); - if (simpleLanguage != null) { - stmt.bindString(10, simpleLanguage); - } - stmt.bindLong(11, entity.getTime()); - } - - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.getLong(offset + 0); - } - - @Override - public LocalFavoriteInfo readEntity(Cursor cursor, int offset) { - LocalFavoriteInfo entity = new LocalFavoriteInfo( // - cursor.getLong(offset + 0), // gid - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // token - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // title - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // titleJpn - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // thumb - cursor.getInt(offset + 5), // category - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // posted - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // uploader - cursor.getFloat(offset + 8), // rating - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // simpleLanguage - cursor.getLong(offset + 10) // time - ); - return entity; - } - - @Override - public void readEntity(Cursor cursor, LocalFavoriteInfo entity, int offset) { - entity.setGid(cursor.getLong(offset + 0)); - entity.setToken(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setTitle(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setTitleJpn(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setThumb(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setCategory(cursor.getInt(offset + 5)); - entity.setPosted(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); - entity.setUploader(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); - entity.setRating(cursor.getFloat(offset + 8)); - entity.setSimpleLanguage(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - entity.setTime(cursor.getLong(offset + 10)); - } - - @Override - protected final Long updateKeyAfterInsert(LocalFavoriteInfo entity, long rowId) { - entity.setGid(rowId); - return rowId; - } - - @Override - public Long getKey(LocalFavoriteInfo entity) { - if(entity != null) { - return entity.getGid(); - } else { - return null; - } - } - - @Override - public boolean hasKey(LocalFavoriteInfo entity) { - throw new UnsupportedOperationException("Unsupported for entities with a non-null key"); - } - - @Override - protected final boolean isEntityUpdateable() { - return true; - } - } diff --git a/app/src/main/java/com/hippo/ehviewer/dao/QuickSearch.java b/app/src/main/java/com/hippo/ehviewer/dao/QuickSearch.java index 1e3c234d8..022dae17b 100644 --- a/app/src/main/java/com/hippo/ehviewer/dao/QuickSearch.java +++ b/app/src/main/java/com/hippo/ehviewer/dao/QuickSearch.java @@ -1,133 +1,117 @@ package com.hippo.ehviewer.dao; -import org.greenrobot.greendao.annotation.*; +import androidx.room.ColumnInfo; +import androidx.room.Entity; +import androidx.room.PrimaryKey; -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit. - -/** - * Entity mapped to table "QUICK_SEARCH". - */ -@Entity(nameInDb = "QUICK_SEARCH") +@Entity(tableName = "QUICK_SEARCH") public class QuickSearch { - @Id - public Long id; - public String name; - public int mode; - public int category; - public String keyword; - public int advanceSearch; - public int minRating; - public int pageFrom; - public int pageTo; - public long time; + @PrimaryKey + @ColumnInfo(name = "_id") + public Long id; + @ColumnInfo(name = "NAME") + public String name; + @ColumnInfo(name = "MODE") + public int mode; + @ColumnInfo(name = "CATEGORY") + public int category; + @ColumnInfo(name = "KEYWORD") + public String keyword; + @ColumnInfo(name = "ADVANCE_SEARCH") + public int advanceSearch; + @ColumnInfo(name = "MIN_RATING") + public int minRating; + @ColumnInfo(name = "PAGE_FROM") + public int pageFrom; + @ColumnInfo(name = "PAGE_TO") + public int pageTo; + @ColumnInfo(name = "TIME") + public long time; - @Generated - public QuickSearch() { - } + public Long getId() { + return id; + } - public QuickSearch(Long id) { - this.id = id; - } + public void setId(Long id) { + this.id = id; + } - @Generated - public QuickSearch(Long id, String name, int mode, int category, String keyword, int advanceSearch, int minRating, - int pageFrom, int pageTo, long time) { - this.id = id; - this.name = name; - this.mode = mode; - this.category = category; - this.keyword = keyword; - this.advanceSearch = advanceSearch; - this.minRating = minRating; - this.pageFrom = pageFrom; - this.pageTo = pageTo; - this.time = time; - } + public String getName() { + return name; + } - public Long getId() { - return id; - } + public void setName(String name) { + this.name = name; + } - public void setId(Long id) { - this.id = id; - } + public int getMode() { + return mode; + } - public String getName() { - return name; - } + public void setMode(int mode) { + this.mode = mode; + } - public void setName(String name) { - this.name = name; - } + public int getCategory() { + return category; + } - public int getMode() { - return mode; - } + public void setCategory(int category) { + this.category = category; + } - public void setMode(int mode) { - this.mode = mode; - } + public String getKeyword() { + return keyword; + } - public int getCategory() { - return category; - } + public void setKeyword(String keyword) { + this.keyword = keyword; + } - public void setCategory(int category) { - this.category = category; - } + public int getAdvanceSearch() { + return advanceSearch; + } - public String getKeyword() { - return keyword; - } + public void setAdvanceSearch(int advanceSearch) { + this.advanceSearch = advanceSearch; + } - public void setKeyword(String keyword) { - this.keyword = keyword; - } + public int getMinRating() { + return minRating; + } - public int getAdvanceSearch() { - return advanceSearch; - } + public void setMinRating(int minRating) { + this.minRating = minRating; + } - public void setAdvanceSearch(int advanceSearch) { - this.advanceSearch = advanceSearch; - } + public int getPageFrom() { + return pageFrom; + } - public int getMinRating() { - return minRating; - } + public void setPageFrom(int pageFrom) { + this.pageFrom = pageFrom; + } - public void setMinRating(int minRating) { - this.minRating = minRating; - } + public int getPageTo() { + return pageTo; + } - public int getPageFrom() { - return pageFrom; - } + public void setPageTo(int pageTo) { + this.pageTo = pageTo; + } - public void setPageFrom(int pageFrom) { - this.pageFrom = pageFrom; - } + public long getTime() { + return time; + } - public int getPageTo() { - return pageTo; - } + public void setTime(long time) { + this.time = time; + } - public void setPageTo(int pageTo) { - this.pageTo = pageTo; - } - - public long getTime() { - return time; - } - - public void setTime(long time) { - this.time = time; - } - - @Override - public String toString() { - return name; - } + @Override + public String toString() { + return name; + } } diff --git a/app/src/main/java/com/hippo/ehviewer/dao/QuickSearchDao.java b/app/src/main/java/com/hippo/ehviewer/dao/QuickSearchDao.java index fdb9797c7..62fc219f8 100644 --- a/app/src/main/java/com/hippo/ehviewer/dao/QuickSearchDao.java +++ b/app/src/main/java/com/hippo/ehviewer/dao/QuickSearchDao.java @@ -1,183 +1,34 @@ package com.hippo.ehviewer.dao; -import android.database.Cursor; -import android.database.sqlite.SQLiteStatement; +import androidx.room.Dao; +import androidx.room.Delete; +import androidx.room.Insert; +import androidx.room.Query; +import androidx.room.Update; -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.Property; -import org.greenrobot.greendao.internal.DaoConfig; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseStatement; +import java.util.List; -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** - * DAO for table "QUICK_SEARCH". -*/ -public class QuickSearchDao extends AbstractDao { +@Dao +public interface QuickSearchDao { - public static final String TABLENAME = "QUICK_SEARCH"; + String TABLENAME = "QUICK_SEARCH"; - /** - * Properties of entity QuickSearch.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property Name = new Property(1, String.class, "name", false, "NAME"); - public final static Property Mode = new Property(2, int.class, "mode", false, "MODE"); - public final static Property Category = new Property(3, int.class, "category", false, "CATEGORY"); - public final static Property Keyword = new Property(4, String.class, "keyword", false, "KEYWORD"); - public final static Property AdvanceSearch = new Property(5, int.class, "advanceSearch", false, "ADVANCE_SEARCH"); - public final static Property MinRating = new Property(6, int.class, "minRating", false, "MIN_RATING"); - public final static Property PageFrom = new Property(7, int.class, "pageFrom", false, "PAGE_FROM"); - public final static Property PageTo = new Property(8, int.class, "pageTo", false, "PAGE_TO"); - public final static Property Time = new Property(9, long.class, "time", false, "TIME"); - } + @Query("SELECT * FROM QUICK_SEARCH ORDER BY TIME ASC") + List list(); + @Query("SELECT * FROM QUICK_SEARCH ORDER BY TIME ASC LIMIT :limit OFFSET :offset") + List list(int offset, int limit); - public QuickSearchDao(DaoConfig config) { - super(config); - } - - public QuickSearchDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } + @Update + void update(List downloadLabels); - /** Creates the underlying database table. */ - public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"QUICK_SEARCH\" (" + // - "\"_id\" INTEGER PRIMARY KEY ," + // 0: id - "\"NAME\" TEXT," + // 1: name - "\"MODE\" INTEGER NOT NULL ," + // 2: mode - "\"CATEGORY\" INTEGER NOT NULL ," + // 3: category - "\"KEYWORD\" TEXT," + // 4: keyword - "\"ADVANCE_SEARCH\" INTEGER NOT NULL ," + // 5: advanceSearch - "\"MIN_RATING\" INTEGER NOT NULL ," + // 6: minRating - "\"PAGE_FROM\" INTEGER NOT NULL ," + // 7: pageFrom - "\"PAGE_TO\" INTEGER NOT NULL ," + // 8: pageTo - "\"TIME\" INTEGER NOT NULL );"); // 9: time - } + @Update + void update(QuickSearch quickSearch); - /** Drops the underlying database table. */ - public static void dropTable(Database db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"QUICK_SEARCH\""; - db.execSQL(sql); - } + @Insert + long insert(QuickSearch quickSearch); - @Override - protected final void bindValues(DatabaseStatement stmt, QuickSearch entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(2, name); - } - stmt.bindLong(3, entity.getMode()); - stmt.bindLong(4, entity.getCategory()); - - String keyword = entity.getKeyword(); - if (keyword != null) { - stmt.bindString(5, keyword); - } - stmt.bindLong(6, entity.getAdvanceSearch()); - stmt.bindLong(7, entity.getMinRating()); - stmt.bindLong(8, entity.getPageFrom()); - stmt.bindLong(9, entity.getPageTo()); - stmt.bindLong(10, entity.getTime()); - } + @Delete + void delete(QuickSearch quickSearch); - @Override - protected final void bindValues(SQLiteStatement stmt, QuickSearch entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(2, name); - } - stmt.bindLong(3, entity.getMode()); - stmt.bindLong(4, entity.getCategory()); - - String keyword = entity.getKeyword(); - if (keyword != null) { - stmt.bindString(5, keyword); - } - stmt.bindLong(6, entity.getAdvanceSearch()); - stmt.bindLong(7, entity.getMinRating()); - stmt.bindLong(8, entity.getPageFrom()); - stmt.bindLong(9, entity.getPageTo()); - stmt.bindLong(10, entity.getTime()); - } - - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } - - @Override - public QuickSearch readEntity(Cursor cursor, int offset) { - QuickSearch entity = new QuickSearch( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // name - cursor.getInt(offset + 2), // mode - cursor.getInt(offset + 3), // category - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // keyword - cursor.getInt(offset + 5), // advanceSearch - cursor.getInt(offset + 6), // minRating - cursor.getInt(offset + 7), // pageFrom - cursor.getInt(offset + 8), // pageTo - cursor.getLong(offset + 9) // time - ); - return entity; - } - - @Override - public void readEntity(Cursor cursor, QuickSearch entity, int offset) { - entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setName(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setMode(cursor.getInt(offset + 2)); - entity.setCategory(cursor.getInt(offset + 3)); - entity.setKeyword(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setAdvanceSearch(cursor.getInt(offset + 5)); - entity.setMinRating(cursor.getInt(offset + 6)); - entity.setPageFrom(cursor.getInt(offset + 7)); - entity.setPageTo(cursor.getInt(offset + 8)); - entity.setTime(cursor.getLong(offset + 9)); - } - - @Override - protected final Long updateKeyAfterInsert(QuickSearch entity, long rowId) { - entity.setId(rowId); - return rowId; - } - - @Override - public Long getKey(QuickSearch entity) { - if(entity != null) { - return entity.getId(); - } else { - return null; - } - } - - @Override - public boolean hasKey(QuickSearch entity) { - return entity.getId() != null; - } - - @Override - protected final boolean isEntityUpdateable() { - return true; - } - } diff --git a/app/src/main/java/com/hippo/ehviewer/download/DownloadManager.java b/app/src/main/java/com/hippo/ehviewer/download/DownloadManager.java index a32e9e307..115402d13 100644 --- a/app/src/main/java/com/hippo/ehviewer/download/DownloadManager.java +++ b/app/src/main/java/com/hippo/ehviewer/download/DownloadManager.java @@ -516,7 +516,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener { DownloadInfo info = mAllInfoMap.get(gid); if (info != null) { // Remove from DB - EhDB.removeDownloadInfo(info.gid); + EhDB.removeDownloadInfo(info); // Remove all list and map mAllInfoList.remove(info); @@ -552,7 +552,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener { } // Remove from DB - EhDB.removeDownloadInfo(info.gid); + EhDB.removeDownloadInfo(info); // Remove from all info map mAllInfoList.remove(info); diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/HistoryScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/HistoryScene.java index 3ff6670f5..3ca4a4ad4 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/HistoryScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/HistoryScene.java @@ -79,8 +79,6 @@ import com.hippo.widget.recyclerview.AutoStaggeredGridLayoutManager; import com.hippo.yorozuya.AssertUtils; import com.hippo.yorozuya.ViewUtils; -import org.greenrobot.greendao.query.LazyList; - import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -103,7 +101,7 @@ public class HistoryScene extends ToolbarScene { @Nullable private RecyclerView.Adapter mAdapter; @Nullable - private LazyList mLazyList; + private List mLazyList; private DownloadManager mDownloadManager; private DownloadManager.DownloadInfoListener mDownloadInfoListener; @@ -255,7 +253,6 @@ public class HistoryScene extends ToolbarScene { super.onDestroyView(); if (null != mLazyList) { - mLazyList.close(); mLazyList = null; if (mAdapter != null) { mAdapter.notifyDataSetChanged(); @@ -272,11 +269,7 @@ public class HistoryScene extends ToolbarScene { // Remember to notify private void updateLazyList() { - LazyList lazyList = EhDB.getHistoryLazyList(); - if (mLazyList != null) { - mLazyList.close(); - } - mLazyList = lazyList; + mLazyList = EhDB.getHistoryLazyList(); } private void updateView(boolean animation) {