Search in sources :

Example 1 with QuickSearchDao

use of com.hippo.ehviewer.dao.QuickSearchDao in project EhViewer by seven332.

the class EhDB method mergeOldDB.

public static void mergeOldDB(Context context) {
    sNewDB = false;
    OldDBHelper oldDBHelper = new OldDBHelper(context);
    SQLiteDatabase oldDB;
    try {
        oldDB = oldDBHelper.getReadableDatabase();
    } catch (Exception e) {
        return;
    }
    // Get GalleryInfo list
    SparseJLArray<GalleryInfo> map = new SparseJLArray<>();
    try {
        Cursor cursor = oldDB.rawQuery("select * from " + OldDBHelper.TABLE_GALLERY, null);
        if (cursor != null) {
            if (cursor.moveToFirst()) {
                while (!cursor.isAfterLast()) {
                    GalleryInfo gi = new GalleryInfo();
                    gi.gid = cursor.getInt(0);
                    gi.token = cursor.getString(1);
                    gi.title = cursor.getString(2);
                    gi.posted = cursor.getString(3);
                    gi.category = cursor.getInt(4);
                    gi.thumb = cursor.getString(5);
                    gi.uploader = cursor.getString(6);
                    try {
                        // In 0.6.x version, NaN is stored
                        gi.rating = cursor.getFloat(7);
                    } catch (Exception e) {
                        gi.rating = -1.0f;
                    }
                    map.put(gi.gid, gi);
                    cursor.moveToNext();
                }
            }
            cursor.close();
        }
    } catch (Exception e) {
    // Ignore
    }
    // Merge local favorites
    try {
        Cursor cursor = oldDB.rawQuery("select * from " + OldDBHelper.TABLE_LOCAL_FAVOURITE, null);
        if (cursor != null) {
            LocalFavoritesDao dao = sDaoSession.getLocalFavoritesDao();
            if (cursor.moveToFirst()) {
                long i = 0L;
                while (!cursor.isAfterLast()) {
                    // Get GalleryInfo first
                    long gid = cursor.getInt(0);
                    GalleryInfo gi = map.get(gid);
                    if (gi == null) {
                        Log.e(TAG, "Can't get GalleryInfo with gid: " + gid);
                        cursor.moveToNext();
                        continue;
                    }
                    LocalFavoriteInfo info = new LocalFavoriteInfo(gi);
                    info.setTime(i);
                    dao.insert(info);
                    cursor.moveToNext();
                    i++;
                }
            }
            cursor.close();
        }
    } catch (Exception e) {
    // Ignore
    }
    // Merge quick search
    try {
        Cursor cursor = oldDB.rawQuery("select * from " + OldDBHelper.TABLE_TAG, null);
        if (cursor != null) {
            QuickSearchDao dao = sDaoSession.getQuickSearchDao();
            if (cursor.moveToFirst()) {
                while (!cursor.isAfterLast()) {
                    QuickSearch quickSearch = new QuickSearch();
                    int mode = cursor.getInt(2);
                    String search = cursor.getString(4);
                    String tag = cursor.getString(7);
                    if (mode == ListUrlBuilder.MODE_UPLOADER && search != null && search.startsWith("uploader:")) {
                        search = search.substring("uploader:".length());
                    }
                    quickSearch.setTime((long) cursor.getInt(0));
                    quickSearch.setName(cursor.getString(1));
                    quickSearch.setMode(mode);
                    quickSearch.setCategory(cursor.getInt(3));
                    quickSearch.setKeyword(mode == ListUrlBuilder.MODE_TAG ? tag : search);
                    quickSearch.setAdvanceSearch(cursor.getInt(5));
                    quickSearch.setMinRating(cursor.getInt(6));
                    dao.insert(quickSearch);
                    cursor.moveToNext();
                }
            }
            cursor.close();
        }
    } catch (Exception e) {
    // Ignore
    }
    // Merge download info
    try {
        Cursor cursor = oldDB.rawQuery("select * from " + OldDBHelper.TABLE_DOWNLOAD, null);
        if (cursor != null) {
            DownloadsDao dao = sDaoSession.getDownloadsDao();
            if (cursor.moveToFirst()) {
                long i = 0L;
                while (!cursor.isAfterLast()) {
                    // Get GalleryInfo first
                    long gid = cursor.getInt(0);
                    GalleryInfo gi = map.get(gid);
                    if (gi == null) {
                        Log.e(TAG, "Can't get GalleryInfo with gid: " + gid);
                        cursor.moveToNext();
                        continue;
                    }
                    DownloadInfo info = new DownloadInfo(gi);
                    int state = cursor.getInt(2);
                    int legacy = cursor.getInt(3);
                    if (state == DownloadInfo.STATE_FINISH && legacy > 0) {
                        state = DownloadInfo.STATE_FAILED;
                    }
                    info.setState(state);
                    info.setLegacy(legacy);
                    if (cursor.getColumnCount() == 5) {
                        info.setTime(cursor.getLong(4));
                    } else {
                        info.setTime(i);
                    }
                    dao.insert(info);
                    cursor.moveToNext();
                    i++;
                }
            }
            cursor.close();
        }
    } catch (Exception e) {
    // Ignore
    }
    try {
        // Merge history info
        Cursor cursor = oldDB.rawQuery("select * from " + OldDBHelper.TABLE_HISTORY, null);
        if (cursor != null) {
            HistoryDao dao = sDaoSession.getHistoryDao();
            if (cursor.moveToFirst()) {
                while (!cursor.isAfterLast()) {
                    // Get GalleryInfo first
                    long gid = cursor.getInt(0);
                    GalleryInfo gi = map.get(gid);
                    if (gi == null) {
                        Log.e(TAG, "Can't get GalleryInfo with gid: " + gid);
                        cursor.moveToNext();
                        continue;
                    }
                    HistoryInfo info = new HistoryInfo(gi);
                    info.setMode(cursor.getInt(1));
                    info.setTime(cursor.getLong(2));
                    dao.insert(info);
                    cursor.moveToNext();
                }
            }
            cursor.close();
        }
    } catch (Exception e) {
    // Ignore
    }
    try {
        oldDBHelper.close();
    } catch (Exception e) {
    // Ignore
    }
}
Also used : QuickSearchDao(com.hippo.ehviewer.dao.QuickSearchDao) LocalFavoriteInfo(com.hippo.ehviewer.dao.LocalFavoriteInfo) LocalFavoritesDao(com.hippo.ehviewer.dao.LocalFavoritesDao) HistoryDao(com.hippo.ehviewer.dao.HistoryDao) GalleryInfo(com.hippo.ehviewer.client.data.GalleryInfo) Cursor(android.database.Cursor) IOException(java.io.IOException) DownloadsDao(com.hippo.ehviewer.dao.DownloadsDao) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) DownloadInfo(com.hippo.ehviewer.dao.DownloadInfo) QuickSearch(com.hippo.ehviewer.dao.QuickSearch) SparseJLArray(com.hippo.yorozuya.collect.SparseJLArray) HistoryInfo(com.hippo.ehviewer.dao.HistoryInfo)

Example 2 with QuickSearchDao

use of com.hippo.ehviewer.dao.QuickSearchDao in project EhViewer by seven332.

the class EhDB method deleteQuickSearch.

public static synchronized void deleteQuickSearch(QuickSearch quickSearch) {
    QuickSearchDao dao = sDaoSession.getQuickSearchDao();
    dao.delete(quickSearch);
}
Also used : QuickSearchDao(com.hippo.ehviewer.dao.QuickSearchDao)

Example 3 with QuickSearchDao

use of com.hippo.ehviewer.dao.QuickSearchDao in project EhViewer by seven332.

the class EhDB method insertQuickSearch.

public static synchronized void insertQuickSearch(QuickSearch quickSearch) {
    QuickSearchDao dao = sDaoSession.getQuickSearchDao();
    quickSearch.id = null;
    quickSearch.time = System.currentTimeMillis();
    quickSearch.id = dao.insert(quickSearch);
}
Also used : QuickSearchDao(com.hippo.ehviewer.dao.QuickSearchDao)

Example 4 with QuickSearchDao

use of com.hippo.ehviewer.dao.QuickSearchDao in project EhViewer by seven332.

the class EhDB method updateQuickSearch.

public static synchronized void updateQuickSearch(QuickSearch quickSearch) {
    QuickSearchDao dao = sDaoSession.getQuickSearchDao();
    dao.update(quickSearch);
}
Also used : QuickSearchDao(com.hippo.ehviewer.dao.QuickSearchDao)

Example 5 with QuickSearchDao

use of com.hippo.ehviewer.dao.QuickSearchDao in project EhViewer by seven332.

the class EhDB method moveQuickSearch.

public static synchronized void moveQuickSearch(int fromPosition, int toPosition) {
    if (fromPosition == toPosition) {
        return;
    }
    boolean reverse = fromPosition > toPosition;
    int offset = reverse ? toPosition : fromPosition;
    int limit = reverse ? fromPosition - toPosition + 1 : toPosition - fromPosition + 1;
    QuickSearchDao dao = sDaoSession.getQuickSearchDao();
    List<QuickSearch> list = dao.queryBuilder().orderAsc(QuickSearchDao.Properties.Time).offset(offset).limit(limit).list();
    int step = reverse ? 1 : -1;
    int start = reverse ? limit - 1 : 0;
    int end = reverse ? 0 : limit - 1;
    long toTime = list.get(end).getTime();
    for (int i = end; reverse ? i < start : i > start; i += step) {
        list.get(i).setTime(list.get(i + step).getTime());
    }
    list.get(start).setTime(toTime);
    dao.updateInTx(list);
}
Also used : QuickSearchDao(com.hippo.ehviewer.dao.QuickSearchDao) QuickSearch(com.hippo.ehviewer.dao.QuickSearch)

Aggregations

QuickSearchDao (com.hippo.ehviewer.dao.QuickSearchDao)5 QuickSearch (com.hippo.ehviewer.dao.QuickSearch)2 Cursor (android.database.Cursor)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 GalleryInfo (com.hippo.ehviewer.client.data.GalleryInfo)1 DownloadInfo (com.hippo.ehviewer.dao.DownloadInfo)1 DownloadsDao (com.hippo.ehviewer.dao.DownloadsDao)1 HistoryDao (com.hippo.ehviewer.dao.HistoryDao)1 HistoryInfo (com.hippo.ehviewer.dao.HistoryInfo)1 LocalFavoriteInfo (com.hippo.ehviewer.dao.LocalFavoriteInfo)1 LocalFavoritesDao (com.hippo.ehviewer.dao.LocalFavoritesDao)1 SparseJLArray (com.hippo.yorozuya.collect.SparseJLArray)1 IOException (java.io.IOException)1