Search in sources :

Example 21 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, String referer) throws Throwable {
    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();
    String origin = EhUrl.getOrigin();
    Log.d(TAG, url);
    Request request = new EhRequestBuilder(url, referer, origin).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 (Throwable e) {
        ExceptionUtils.throwIfFatal(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)

Example 22 with GalleryInfo

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

the class EhEngine method fillGalleryList.

private static void fillGalleryList(@Nullable EhClient.Task task, OkHttpClient okHttpClient, List<GalleryInfo> list, String url, boolean filter) throws Throwable {
    // Filter title and uploader
    if (filter) {
        for (int i = 0, n = list.size(); i < n; i++) {
            GalleryInfo info = list.get(i);
            if (!sEhFilter.filterTitle(info) || !sEhFilter.filterUploader(info)) {
                list.remove(i);
                i--;
                n--;
            }
        }
    }
    boolean hasTags = false;
    boolean hasPages = false;
    boolean hasRated = false;
    for (GalleryInfo gi : list) {
        if (gi.simpleTags != null) {
            hasTags = true;
        }
        if (gi.pages != 0) {
            hasPages = true;
        }
        if (gi.rated) {
            hasRated = true;
        }
    }
    boolean needApi = (filter && sEhFilter.needTags() && !hasTags) || (Settings.getShowGalleryPages() && !hasPages) || hasRated;
    if (needApi) {
        fillGalleryListByApi(task, okHttpClient, list, url);
    }
    // Filter tag
    if (filter) {
        for (int i = 0, n = list.size(); i < n; i++) {
            GalleryInfo info = list.get(i);
            // Thumbnail mode need filter uploader again
            if (!sEhFilter.filterUploader(info) || !sEhFilter.filterTag(info) || !sEhFilter.filterTagNamespace(info)) {
                list.remove(i);
                i--;
                n--;
            }
        }
    }
    for (GalleryInfo info : list) {
        info.thumb = EhUrl.getFixedPreviewThumbUrl(info.thumb);
    }
}
Also used : GalleryInfo(com.hippo.ehviewer.client.data.GalleryInfo)

Example 23 with GalleryInfo

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

the class HistoryScene method onItemLongClick.

@Override
public boolean onItemLongClick(EasyRecyclerView parent, View view, int position, long id) {
    final Context context = getContext2();
    final MainActivity activity = getActivity2();
    if (null == context || null == activity || null == mLazyList) {
        return false;
    }
    final GalleryInfo gi = mLazyList.get(position);
    new AlertDialog.Builder(context).setTitle(EhUtils.getSuitableTitle(gi)).setItems(R.array.gallery_list_menu_entries, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            switch(which) {
                case // Download
                0:
                    CommonOperations.startDownload(activity, gi, false);
                    break;
                case // Favorites
                1:
                    CommonOperations.addToFavorites(activity, gi, new addToFavoriteListener(context, activity.getStageId(), getTag()));
                    break;
            }
        }
    }).show();
    return true;
}
Also used : Context(android.content.Context) AlertDialog(androidx.appcompat.app.AlertDialog) DialogInterface(android.content.DialogInterface) GalleryInfo(com.hippo.ehviewer.client.data.GalleryInfo) MainActivity(com.hippo.ehviewer.ui.MainActivity)

Example 24 with GalleryInfo

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

the class ThumbSpanHelper method append.

private void append() {
    if (1 == mSpanCount) {
        for (int i = mAttachedCount, n = mData.size(); i < n; i++) {
            GalleryInfo gi = mData.get(i);
            gi.spanSize = 1;
            gi.spanGroupIndex = i;
            gi.spanIndex = 0;
        }
        mAttachedCount = mData.size();
    } else if (mSpanCount >= 2) {
        for (int i = mAttachedCount, n = mData.size(); i < n; i++) {
            GalleryInfo gi = mData.get(i);
            int spanSize = gi.thumbWidth <= gi.thumbHeight ? 1 : 2;
            gi.spanSize = spanSize;
            if (1 == spanSize) {
                // Update near space
                updateNearSpace();
                Log.d("TAG", "Update mNearSpaceGroupIndex = " + mNearSpaceGroupIndex + ", mNearSpaceIndex = " + mNearSpaceIndex);
                if (mNextIndex == mNearSpaceIndex && mNextGroupIndex == mNearSpaceGroupIndex) {
                    // No space, just append
                    gi.spanIndex = mNextIndex;
                    gi.spanGroupIndex = mNextGroupIndex;
                    // Update cell
                    int start = gi.spanGroupIndex * mSpanCount + gi.spanIndex;
                    fillCell(start, start + 1);
                    // Update field
                    mNextIndex++;
                    if (mSpanCount == mNextIndex) {
                        mNextIndex = 0;
                        mNextGroupIndex++;
                    }
                    mNearSpaceIndex = mNextIndex;
                    mNearSpaceGroupIndex = mNextGroupIndex;
                    Log.d("TAG", "type 0");
                    Log.d("TAG", "i = " + i + ", spanSize = " + spanSize + ", spanGroupIndex = " + gi.spanGroupIndex + ", spanIndex = " + gi.spanIndex);
                    Log.d("TAG", "mNextGroupIndex = " + mNextGroupIndex + ", mNextIndex = " + mNextIndex);
                    Log.d("TAG", "mNearSpaceGroupIndex = " + mNearSpaceGroupIndex + ", mNearSpaceIndex = " + mNearSpaceIndex);
                } else {
                    // Found space
                    gi.spanIndex = mNearSpaceIndex;
                    gi.spanGroupIndex = mNearSpaceGroupIndex;
                    // Update cell
                    int start = gi.spanGroupIndex * mSpanCount + gi.spanIndex;
                    fillCell(start, start + 1);
                    // Find near space
                    findNearSpace(start + 1);
                    Log.d("TAG", "type 1");
                    Log.d("TAG", "i = " + i + ", spanSize = " + spanSize + ", spanGroupIndex = " + gi.spanGroupIndex + ", spanIndex = " + gi.spanIndex);
                    Log.d("TAG", "mNextGroupIndex = " + mNextGroupIndex + ", mNextIndex = " + mNextIndex);
                    Log.d("TAG", "mNearSpaceGroupIndex = " + mNearSpaceGroupIndex + ", mNearSpaceIndex = " + mNearSpaceIndex);
                }
            } else {
                boolean syncNear = mNextIndex == mNearSpaceIndex && mNextGroupIndex == mNearSpaceGroupIndex;
                // false for old, true for new
                boolean oldOrNew;
                if (mSpanCount - mNextIndex >= 2) {
                    gi.spanIndex = mNextIndex;
                    gi.spanGroupIndex = mNextGroupIndex;
                    oldOrNew = true;
                } else {
                    // Go to next row
                    gi.spanIndex = 0;
                    gi.spanGroupIndex = mNextGroupIndex + 1;
                    oldOrNew = false;
                }
                // Update cell
                int start = gi.spanGroupIndex * mSpanCount + gi.spanIndex;
                fillCell(start, start + 2);
                // Update field
                if (syncNear && !oldOrNew) {
                    mNearSpaceIndex = mNextIndex;
                    mNearSpaceGroupIndex = mNextGroupIndex;
                }
                mNextIndex = gi.spanIndex + 2;
                mNextGroupIndex = gi.spanGroupIndex;
                if (mSpanCount == mNextIndex) {
                    mNextIndex = 0;
                    mNextGroupIndex++;
                }
                if (syncNear && oldOrNew) {
                    mNearSpaceIndex = mNextIndex;
                    mNearSpaceGroupIndex = mNextGroupIndex;
                }
                Log.d("TAG", "type 2");
                Log.d("TAG", "i = " + i + ", spanSize = " + spanSize + ", spanGroupIndex = " + gi.spanGroupIndex + ", spanIndex = " + gi.spanIndex);
                Log.d("TAG", "mNextGroupIndex = " + mNextGroupIndex + ", mNextIndex = " + mNextIndex);
                Log.d("TAG", "mNearSpaceGroupIndex = " + mNearSpaceGroupIndex + ", mNearSpaceIndex = " + mNearSpaceIndex);
            }
        }
        mAttachedCount = mData.size();
    }
}
Also used : GalleryInfo(com.hippo.ehviewer.client.data.GalleryInfo)

Example 25 with GalleryInfo

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

the class GalleryListScene method onItemClick.

@Override
public boolean onItemClick(EasyRecyclerView parent, View view, int position, long id) {
    if (null == mHelper || null == mRecyclerView) {
        return false;
    }
    GalleryInfo gi = mHelper.getDataAtEx(position);
    if (gi == null) {
        return true;
    }
    Bundle args = new Bundle();
    args.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_GALLERY_INFO);
    args.putParcelable(GalleryDetailScene.KEY_GALLERY_INFO, gi);
    Announcer announcer = new Announcer(GalleryDetailScene.class).setArgs(args);
    View thumb;
    if (null != (thumb = view.findViewById(R.id.thumb))) {
        announcer.setTranHelper(new EnterGalleryDetailTransaction(thumb));
    }
    startScene(announcer);
    return true;
}
Also used : Announcer(com.hippo.scene.Announcer) Bundle(android.os.Bundle) GalleryInfo(com.hippo.ehviewer.client.data.GalleryInfo) EasyRecyclerView(com.hippo.easyrecyclerview.EasyRecyclerView) ShowcaseView(com.github.amlcurran.showcaseview.ShowcaseView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) ListView(android.widget.ListView)

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