Search in sources :

Example 1 with ListUrlBuilder

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

the class GalleryDetailScene method onClick.

@Override
public void onClick(View v) {
    Context context = getContext2();
    MainActivity activity = getActivity2();
    if (null == context || null == activity) {
        return;
    }
    if (mTip == v) {
        if (request()) {
            adjustViewVisibility(STATE_REFRESH, true);
        }
    } else if (mOtherActions == v) {
        ensurePopMenu();
        if (mPopupMenu != null) {
            mPopupMenu.show();
        }
    } else if (mUploader == v) {
        String uploader = getUploader();
        if (TextUtils.isEmpty(uploader)) {
            return;
        }
        ListUrlBuilder lub = new ListUrlBuilder();
        lub.setMode(ListUrlBuilder.MODE_UPLOADER);
        lub.setKeyword(uploader);
        GalleryListScene.startScene(this, lub);
    } else if (mCategory == v) {
        int category = getCategory();
        if (category == -1) {
            return;
        }
        ListUrlBuilder lub = new ListUrlBuilder();
        lub.setCategory(category);
        GalleryListScene.startScene(this, lub);
    } else if (mDownload == v) {
        GalleryInfo galleryInfo = getGalleryInfo();
        if (galleryInfo != null) {
            CommonOperations.startDownload(activity, galleryInfo, false);
        }
    } else if (mRead == v) {
        GalleryInfo galleryInfo = null;
        if (mGalleryInfo != null) {
            galleryInfo = mGalleryInfo;
        } else if (mGalleryDetail != null) {
            galleryInfo = mGalleryDetail;
        }
        if (galleryInfo != null) {
            Intent intent = new Intent(activity, GalleryActivity.class);
            intent.setAction(GalleryActivity.ACTION_EH);
            intent.putExtra(GalleryActivity.KEY_GALLERY_INFO, galleryInfo);
            startActivity(intent);
        }
    } else if (mInfo == v) {
        Bundle args = new Bundle();
        args.putParcelable(GalleryInfoScene.KEY_GALLERY_DETAIL, mGalleryDetail);
        startScene(new Announcer(GalleryInfoScene.class).setArgs(args));
    } else if (mHeartGroup == v) {
        if (mGalleryDetail != null && !mModifingFavorites) {
            boolean remove = false;
            if (EhDB.containLocalFavorites(mGalleryDetail.gid)) {
                EhDB.removeLocalFavorites(mGalleryDetail.gid);
                remove = true;
            }
            if (mGalleryDetail.isFavorited) {
                mModifingFavorites = true;
                CommonOperations.removeFromFavorites(activity, mGalleryDetail, new ModifyFavoritesListener(context, activity.getStageId(), getTag(), true));
                remove = true;
            }
            if (!remove) {
                mModifingFavorites = true;
                CommonOperations.addToFavorites(activity, mGalleryDetail, new ModifyFavoritesListener(context, activity.getStageId(), getTag(), false));
            }
            // Update UI
            updateFavoriteDrawable();
        }
    } else if (mShare == v) {
        String url = getGalleryDetailUrl(false);
        if (url != null) {
            AppHelper.share(activity, url);
        }
    } else if (mTorrent == v) {
        if (mGalleryDetail != null) {
            TorrentListDialogHelper helper = new TorrentListDialogHelper();
            Dialog dialog = new AlertDialog.Builder(context).setTitle(R.string.torrents).setView(R.layout.dialog_torrent_list).setOnDismissListener(helper).show();
            helper.setDialog(dialog, mGalleryDetail.torrentUrl);
        }
    } else if (mArchive == v) {
        if (mGalleryDetail == null) {
            return;
        }
        if (mGalleryDetail.apiUid < 0) {
            showTip(R.string.sign_in_first, LENGTH_SHORT);
            return;
        }
        ArchiveListDialogHelper helper = new ArchiveListDialogHelper();
        Dialog dialog = new AlertDialog.Builder(context).setTitle(R.string.dialog_archive_title).setView(R.layout.dialog_archive_list).setOnDismissListener(helper).show();
        helper.setDialog(dialog, mGalleryDetail.archiveUrl);
    } else if (mRate == v) {
        if (mGalleryDetail == null) {
            return;
        }
        if (mGalleryDetail.apiUid < 0) {
            showTip(R.string.sign_in_first, LENGTH_SHORT);
            return;
        }
        RateDialogHelper helper = new RateDialogHelper();
        Dialog dialog = new AlertDialog.Builder(context).setTitle(R.string.rate).setView(R.layout.dialog_rate).setNegativeButton(android.R.string.cancel, null).setPositiveButton(android.R.string.ok, helper).show();
        helper.setDialog(dialog, mGalleryDetail.rating);
    } else if (mSimilar == v) {
        showSimilarGalleryList();
    } else if (mSearchCover == v) {
        showCoverGalleryList();
    } else if (mComments == v) {
        if (mGalleryDetail == null) {
            return;
        }
        Bundle args = new Bundle();
        args.putLong(GalleryCommentsScene.KEY_API_UID, mGalleryDetail.apiUid);
        args.putString(GalleryCommentsScene.KEY_API_KEY, mGalleryDetail.apiKey);
        args.putLong(GalleryCommentsScene.KEY_GID, mGalleryDetail.gid);
        args.putString(GalleryCommentsScene.KEY_TOKEN, mGalleryDetail.token);
        args.putParcelableArray(GalleryCommentsScene.KEY_COMMENTS, mGalleryDetail.comments);
        startScene(new Announcer(GalleryCommentsScene.class).setArgs(args).setRequestCode(this, REQUEST_CODE_COMMENT_GALLERY));
    } else if (mPreviews == v) {
        if (null != mGalleryDetail) {
            Bundle args = new Bundle();
            args.putParcelable(GalleryPreviewsScene.KEY_GALLERY_INFO, mGalleryDetail);
            startScene(new Announcer(GalleryPreviewsScene.class).setArgs(args));
        }
    } else {
        Object o = v.getTag(R.id.tag);
        if (o instanceof String) {
            String tag = (String) o;
            ListUrlBuilder lub = new ListUrlBuilder();
            lub.setMode(ListUrlBuilder.MODE_TAG);
            lub.setKeyword(tag);
            GalleryListScene.startScene(this, lub);
            return;
        }
        GalleryInfo galleryInfo = getGalleryInfo();
        o = v.getTag(R.id.index);
        if (null != galleryInfo && o instanceof Integer) {
            int index = (Integer) o;
            Intent intent = new Intent(context, GalleryActivity.class);
            intent.setAction(GalleryActivity.ACTION_EH);
            intent.putExtra(GalleryActivity.KEY_GALLERY_INFO, galleryInfo);
            intent.putExtra(GalleryActivity.KEY_PAGE, index);
            startActivity(intent);
            return;
        }
    }
}
Also used : Context(android.content.Context) AlertDialog(android.support.v7.app.AlertDialog) Bundle(android.os.Bundle) ListUrlBuilder(com.hippo.ehviewer.client.data.ListUrlBuilder) GalleryInfo(com.hippo.ehviewer.client.data.GalleryInfo) Intent(android.content.Intent) MainActivity(com.hippo.ehviewer.ui.MainActivity) GalleryActivity(com.hippo.ehviewer.ui.GalleryActivity) ListUrlBuilder(com.hippo.ehviewer.client.data.ListUrlBuilder) Announcer(com.hippo.scene.Announcer) Dialog(android.app.Dialog) AlertDialog(android.support.v7.app.AlertDialog)

Example 2 with ListUrlBuilder

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

the class GalleryDetailScene method showCoverGalleryList.

private void showCoverGalleryList() {
    Context context = getContext2();
    if (null == context) {
        return;
    }
    long gid = getGid();
    if (-1L == gid) {
        return;
    }
    File temp = AppConfig.createTempFile();
    if (null == temp) {
        return;
    }
    BeerBelly beerBelly = EhApplication.getConaco(context).getBeerBelly();
    OutputStream os = null;
    try {
        os = new FileOutputStream(temp);
        if (beerBelly.pullFromDiskCache(EhCacheKeyFactory.getThumbKey(gid), os)) {
            ListUrlBuilder lub = new ListUrlBuilder();
            lub.setMode(ListUrlBuilder.MODE_IMAGE_SEARCH);
            lub.setImagePath(temp.getPath());
            lub.setUseSimilarityScan(true);
            lub.setShowExpunged(true);
            GalleryListScene.startScene(this, lub);
        }
    } catch (FileNotFoundException e) {
    // Ignore
    } finally {
        IOUtils.closeQuietly(os);
    }
}
Also used : Context(android.content.Context) ListUrlBuilder(com.hippo.ehviewer.client.data.ListUrlBuilder) FileOutputStream(java.io.FileOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) BeerBelly(com.hippo.beerbelly.BeerBelly) File(java.io.File)

Example 3 with ListUrlBuilder

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

the class GalleryListScene method onUpdateUrlBuilder.

// Update search bar title, drawer checked item
private void onUpdateUrlBuilder() {
    ListUrlBuilder builder = mUrlBuilder;
    Resources resources = getResources2();
    if (null == resources || null == builder) {
        return;
    }
    String keyword = builder.getKeyword();
    int category = builder.getCategory();
    // Update search edit text
    if (!TextUtils.isEmpty(keyword) && null != mSearchBar) {
        mSearchBar.setText(keyword);
        mSearchBar.cursorToEnd();
    }
    // Update title
    String title = getSuitableTitleForUrlBuilder(resources, builder, true);
    if (null == title) {
        title = resources.getString(R.string.search);
    }
    if (null != mSearchBar) {
        mSearchBar.setTitle(title);
    }
    // Update nav checked item
    int checkedItemId;
    if (ListUrlBuilder.MODE_NORMAL == builder.getMode() && EhUtils.NONE == category && TextUtils.isEmpty(keyword)) {
        checkedItemId = R.id.nav_homepage;
    } else if (ListUrlBuilder.MODE_WHATS_HOT == builder.getMode()) {
        checkedItemId = R.id.nav_whats_hot;
    } else {
        checkedItemId = 0;
    }
    setNavCheckedItem(checkedItemId);
    mNavCheckedId = checkedItemId;
}
Also used : ListUrlBuilder(com.hippo.ehviewer.client.data.ListUrlBuilder) Resources(android.content.res.Resources) Point(android.graphics.Point)

Example 4 with ListUrlBuilder

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

the class GalleryListScene method onInit.

public void onInit() {
    mUrlBuilder = new ListUrlBuilder();
    handleArgs(getArguments());
}
Also used : ListUrlBuilder(com.hippo.ehviewer.client.data.ListUrlBuilder)

Example 5 with ListUrlBuilder

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

the class GalleryListScene method showAddQuickSearchDialog.

private void showAddQuickSearchDialog(final List<QuickSearch> list, final ArrayAdapter<QuickSearch> adapter, final ListView listView, final TextView tip) {
    Context context = getContext2();
    final ListUrlBuilder urlBuilder = mUrlBuilder;
    if (null == context || null == urlBuilder) {
        return;
    }
    // Can't add image search as quick search
    if (ListUrlBuilder.MODE_IMAGE_SEARCH == urlBuilder.getMode()) {
        showTip(R.string.image_search_not_quick_search, LENGTH_SHORT);
        return;
    }
    // Check duplicate
    for (QuickSearch q : list) {
        if (urlBuilder.equalsQuickSearch(q)) {
            showTip(getString(R.string.duplicate_quick_search, q.name), LENGTH_SHORT);
            return;
        }
    }
    final EditTextDialogBuilder builder = new EditTextDialogBuilder(context, getSuitableTitleForUrlBuilder(context.getResources(), urlBuilder, false), getString(R.string.quick_search));
    builder.setTitle(R.string.add_quick_search_dialog_title);
    builder.setPositiveButton(android.R.string.ok, null);
    final AlertDialog dialog = builder.show();
    dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            String text = builder.getText().trim();
            // Check name empty
            if (TextUtils.isEmpty(text)) {
                builder.setError(getString(R.string.name_is_empty));
                return;
            }
            // Check name duplicate
            for (QuickSearch q : list) {
                if (text.equals(q.name)) {
                    builder.setError(getString(R.string.duplicate_name));
                    return;
                }
            }
            builder.setError(null);
            dialog.dismiss();
            QuickSearch quickSearch = urlBuilder.toQuickSearch();
            quickSearch.name = text;
            EhDB.insertQuickSearch(quickSearch);
            list.add(quickSearch);
            adapter.notifyDataSetChanged();
            if (0 == list.size()) {
                tip.setVisibility(View.VISIBLE);
                listView.setVisibility(View.GONE);
            } else {
                tip.setVisibility(View.GONE);
                listView.setVisibility(View.VISIBLE);
            }
        }
    });
}
Also used : Context(android.content.Context) AlertDialog(android.support.v7.app.AlertDialog) ListUrlBuilder(com.hippo.ehviewer.client.data.ListUrlBuilder) QuickSearch(com.hippo.ehviewer.dao.QuickSearch) EditTextDialogBuilder(com.hippo.app.EditTextDialogBuilder) EasyRecyclerView(com.hippo.easyrecyclerview.EasyRecyclerView) ShowcaseView(com.github.amlcurran.showcaseview.ShowcaseView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

ListUrlBuilder (com.hippo.ehviewer.client.data.ListUrlBuilder)11 Context (android.content.Context)3 Announcer (com.hippo.scene.Announcer)3 Bundle (android.os.Bundle)2 AlertDialog (android.support.v7.app.AlertDialog)2 File (java.io.File)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Dialog (android.app.Dialog)1 Intent (android.content.Intent)1 Resources (android.content.res.Resources)1 Point (android.graphics.Point)1 Uri (android.net.Uri)1 Nullable (android.support.annotation.Nullable)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 ShowcaseView (com.github.amlcurran.showcaseview.ShowcaseView)1 EditTextDialogBuilder (com.hippo.app.EditTextDialogBuilder)1