Search in sources :

Example 11 with GalleryInfo

use of com.hippo.ehviewer.client.data.GalleryInfo 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 (Throwable e) {
        ExceptionUtils.throwIfFatal(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 (Throwable e) {
                        ExceptionUtils.throwIfFatal(e);
                        gi.rating = -1.0f;
                    }
                    map.put(gi.gid, gi);
                    cursor.moveToNext();
                }
            }
            cursor.close();
        }
    } catch (Throwable e) {
        ExceptionUtils.throwIfFatal(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 (Throwable e) {
        ExceptionUtils.throwIfFatal(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 (Throwable e) {
        ExceptionUtils.throwIfFatal(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 (Throwable e) {
        ExceptionUtils.throwIfFatal(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 (Throwable e) {
        ExceptionUtils.throwIfFatal(e);
    // Ignore
    }
    try {
        oldDBHelper.close();
    } catch (Throwable e) {
        ExceptionUtils.throwIfFatal(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) 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 12 with GalleryInfo

use of com.hippo.ehviewer.client.data.GalleryInfo in project EhViewer by seven332.

the class EhEngine method getWhatsHot.

public static List<GalleryInfo> getWhatsHot(@Nullable EhClient.Task task, OkHttpClient okHttpClient) throws Exception {
    String url = EhUrl.HOST_E;
    Log.d(TAG, url);
    Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
    Call call = okHttpClient.newCall(request);
    // Put call
    if (null != task) {
        task.setCall(call);
    }
    String body = null;
    Headers headers = null;
    List<GalleryInfo> list;
    int code = -1;
    try {
        Response response = call.execute();
        code = response.code();
        headers = response.headers();
        body = response.body().string();
        list = WhatsHotParser.parse(body);
    } catch (Exception e) {
        throwException(call, code, headers, body, e);
        throw e;
    }
    if (list.size() > 0) {
        // Fill by api
        fillGalleryListByApi(task, okHttpClient, list);
    }
    for (GalleryInfo info : list) {
        info.thumb = EhUrl.getFixedPreviewThumbUrl(info.thumb);
    }
    return list;
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) Headers(okhttp3.Headers) Request(okhttp3.Request) GalleryInfo(com.hippo.ehviewer.client.data.GalleryInfo) EhException(com.hippo.ehviewer.client.exception.EhException) ParseException(com.hippo.ehviewer.client.exception.ParseException) CancelledException(com.hippo.ehviewer.client.exception.CancelledException) NoHAtHClientException(com.hippo.ehviewer.client.exception.NoHAtHClientException) StatusCodeException(com.hippo.network.StatusCodeException)

Example 13 with GalleryInfo

use of com.hippo.ehviewer.client.data.GalleryInfo in project EhViewer by seven332.

the class EhEngine method doFillGalleryListByApi.

private static void doFillGalleryListByApi(@Nullable EhClient.Task task, OkHttpClient okHttpClient, List<GalleryInfo> galleryInfoList) throws Exception {
    JSONObject json = new JSONObject();
    json.put("method", "gdata");
    JSONArray ja = new JSONArray();
    for (int i = 0, size = galleryInfoList.size(); i < size; i++) {
        GalleryInfo gi = galleryInfoList.get(i);
        JSONArray g = new JSONArray();
        g.put(gi.gid);
        g.put(gi.token);
        ja.put(g);
    }
    json.put("gidlist", ja);
    json.put("namespace", 1);
    String url = EhUrl.getApiUrl();
    Log.d(TAG, url);
    Request request = new EhRequestBuilder(url).post(RequestBody.create(MEDIA_TYPE_JSON, json.toString())).build();
    Call call = okHttpClient.newCall(request);
    // Put call
    if (null != task) {
        task.setCall(call);
    }
    String body = null;
    Headers headers = null;
    int code = -1;
    try {
        Response response = call.execute();
        code = response.code();
        headers = response.headers();
        body = response.body().string();
        GalleryApiParser.parse(body, galleryInfoList);
    } catch (Exception e) {
        throwException(call, code, headers, body, e);
        throw e;
    }
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) JSONObject(org.json.JSONObject) Headers(okhttp3.Headers) JSONArray(org.json.JSONArray) GalleryInfo(com.hippo.ehviewer.client.data.GalleryInfo) Request(okhttp3.Request) EhException(com.hippo.ehviewer.client.exception.EhException) ParseException(com.hippo.ehviewer.client.exception.ParseException) CancelledException(com.hippo.ehviewer.client.exception.CancelledException) NoHAtHClientException(com.hippo.ehviewer.client.exception.NoHAtHClientException) StatusCodeException(com.hippo.network.StatusCodeException)

Example 14 with GalleryInfo

use of com.hippo.ehviewer.client.data.GalleryInfo in project EhViewer by seven332.

the class EhDB method searchLocalFavorites.

public static synchronized List<GalleryInfo> searchLocalFavorites(String query) {
    query = SqlUtils.sqlEscapeString("%" + query + "%");
    LocalFavoritesDao dao = sDaoSession.getLocalFavoritesDao();
    List<LocalFavoriteInfo> list = dao.queryBuilder().orderDesc(LocalFavoritesDao.Properties.Time).where(LocalFavoritesDao.Properties.Title.like(query)).list();
    List<GalleryInfo> result = new ArrayList<>();
    result.addAll(list);
    return result;
}
Also used : LocalFavoriteInfo(com.hippo.ehviewer.dao.LocalFavoriteInfo) LocalFavoritesDao(com.hippo.ehviewer.dao.LocalFavoritesDao) GalleryInfo(com.hippo.ehviewer.client.data.GalleryInfo) ArrayList(java.util.ArrayList)

Example 15 with GalleryInfo

use of com.hippo.ehviewer.client.data.GalleryInfo in project EhViewer by seven332.

the class GalleryDetailScene method bindViewFirst.

private void bindViewFirst() {
    if (mGalleryDetail != null) {
        return;
    }
    if (mThumb == null || mTitle == null || mUploader == null || mCategory == null) {
        return;
    }
    if (ACTION_GALLERY_INFO.equals(mAction) && mGalleryInfo != null) {
        GalleryInfo gi = mGalleryInfo;
        mThumb.load(EhCacheKeyFactory.getThumbKey(gi.gid), gi.thumb);
        mTitle.setText(EhUtils.getSuitableTitle(gi));
        mUploader.setText(gi.uploader);
        mCategory.setText(EhUtils.getCategory(gi.category));
        mCategory.setTextColor(EhUtils.getCategoryColor(gi.category));
        updateDownloadText();
    }
}
Also used : GalleryInfo(com.hippo.ehviewer.client.data.GalleryInfo)

Aggregations

GalleryInfo (com.hippo.ehviewer.client.data.GalleryInfo)25 ArrayList (java.util.ArrayList)7 AlertDialog (androidx.appcompat.app.AlertDialog)6 SuppressLint (android.annotation.SuppressLint)5 Bundle (android.os.Bundle)5 View (android.view.View)5 TextView (android.widget.TextView)5 Activity (android.app.Activity)4 Context (android.content.Context)4 DialogInterface (android.content.DialogInterface)4 Intent (android.content.Intent)4 RecyclerView (androidx.recyclerview.widget.RecyclerView)4 DownloadInfo (com.hippo.ehviewer.dao.DownloadInfo)4 MainActivity (com.hippo.ehviewer.ui.MainActivity)4 Point (android.graphics.Point)3 Drawable (android.graphics.drawable.Drawable)3 AdapterView (android.widget.AdapterView)3 ListView (android.widget.ListView)3 EhApplication (com.hippo.ehviewer.EhApplication)3 EhDB (com.hippo.ehviewer.EhDB)3