Search in sources :

Example 6 with ListUrlBuilder

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

the class EhUrlOpener method parseUrl.

@Nullable
public static Announcer parseUrl(String url) {
    if (TextUtils.isEmpty(url)) {
        return null;
    }
    ListUrlBuilder listUrlBuilder = GalleryListUrlParser.parse(url);
    if (listUrlBuilder != null) {
        Bundle args = new Bundle();
        args.putString(GalleryListScene.KEY_ACTION, GalleryListScene.ACTION_LIST_URL_BUILDER);
        args.putParcelable(GalleryListScene.KEY_LIST_URL_BUILDER, listUrlBuilder);
        return new Announcer(GalleryListScene.class).setArgs(args);
    }
    GalleryDetailUrlParser.Result result1 = GalleryDetailUrlParser.parse(url);
    if (result1 != null) {
        Bundle args = new Bundle();
        args.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_GID_TOKEN);
        args.putLong(GalleryDetailScene.KEY_GID, result1.gid);
        args.putString(GalleryDetailScene.KEY_TOKEN, result1.token);
        return new Announcer(GalleryDetailScene.class).setArgs(args);
    }
    GalleryPageUrlParser.Result result2 = GalleryPageUrlParser.parse(url);
    if (result2 != null) {
        Bundle args = new Bundle();
        args.putString(ProgressScene.KEY_ACTION, ProgressScene.ACTION_GALLERY_TOKEN);
        args.putLong(ProgressScene.KEY_GID, result2.gid);
        args.putString(ProgressScene.KEY_PTOKEN, result2.pToken);
        args.putInt(ProgressScene.KEY_PAGE, result2.page);
        return new Announcer(ProgressScene.class).setArgs(args);
    }
    Log.i(TAG, "Can't parse url: " + url);
    return null;
}
Also used : ListUrlBuilder(com.hippo.ehviewer.client.data.ListUrlBuilder) ProgressScene(com.hippo.ehviewer.ui.scene.ProgressScene) GalleryListScene(com.hippo.ehviewer.ui.scene.GalleryListScene) GalleryDetailUrlParser(com.hippo.ehviewer.client.parser.GalleryDetailUrlParser) Announcer(com.hippo.scene.Announcer) Bundle(android.os.Bundle) GalleryPageUrlParser(com.hippo.ehviewer.client.parser.GalleryPageUrlParser) GalleryDetailScene(com.hippo.ehviewer.ui.scene.GalleryDetailScene) Nullable(android.support.annotation.Nullable)

Example 7 with ListUrlBuilder

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

the class GalleryListUrlParser method parseTag.

// TODO get page
private static ListUrlBuilder parseTag(String path) {
    String tag;
    int prefixLength = PATH_TAG.length();
    int index = path.indexOf('/', prefixLength);
    if (index < 0) {
        tag = path.substring(prefixLength);
    } else {
        tag = path.substring(prefixLength, index);
    }
    try {
        tag = URLDecoder.decode(tag, "utf-8");
    } catch (UnsupportedEncodingException e) {
        return null;
    }
    if (TextUtils.isEmpty(tag)) {
        return null;
    }
    ListUrlBuilder builder = new ListUrlBuilder();
    builder.setMode(ListUrlBuilder.MODE_TAG);
    builder.setKeyword(tag);
    return builder;
}
Also used : ListUrlBuilder(com.hippo.ehviewer.client.data.ListUrlBuilder) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 8 with ListUrlBuilder

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

the class MainActivity method handleIntent.

private boolean handleIntent(Intent intent) {
    if (intent == null) {
        return false;
    }
    String action = intent.getAction();
    if (Intent.ACTION_VIEW.equals(action)) {
        Announcer announcer = EhUrlOpener.parseUrl(intent.getData().toString());
        if (announcer != null) {
            startScene(processAnnouncer(announcer));
            return true;
        }
    } else if (Intent.ACTION_SEND.equals(action)) {
        String type = intent.getType();
        if ("text/plain".equals(type)) {
            ListUrlBuilder builder = new ListUrlBuilder();
            builder.setKeyword(intent.getStringExtra(Intent.EXTRA_TEXT));
            startScene(processAnnouncer(GalleryListScene.getStartAnnouncer(builder)));
            return true;
        } else if (type.startsWith("image/")) {
            Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
            if (null != uri) {
                UniFile file = UniFile.fromUri(this, uri);
                File temp = saveImageToTempFile(file);
                if (null != temp) {
                    ListUrlBuilder builder = new ListUrlBuilder();
                    builder.setMode(ListUrlBuilder.MODE_IMAGE_SEARCH);
                    builder.setImagePath(temp.getPath());
                    builder.setUseSimilarityScan(true);
                    builder.setShowExpunged(true);
                    startScene(processAnnouncer(GalleryListScene.getStartAnnouncer(builder)));
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : ListUrlBuilder(com.hippo.ehviewer.client.data.ListUrlBuilder) UniFile(com.hippo.unifile.UniFile) Announcer(com.hippo.scene.Announcer) Uri(android.net.Uri) UniFile(com.hippo.unifile.UniFile) File(java.io.File)

Example 9 with ListUrlBuilder

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

the class GalleryDetailScene method showSimilarGalleryList.

private void showSimilarGalleryList() {
    GalleryDetail gd = mGalleryDetail;
    if (null == gd) {
        return;
    }
    String keyword = EhUtils.extractTitle(gd.title);
    if (null != keyword) {
        ListUrlBuilder lub = new ListUrlBuilder();
        lub.setMode(ListUrlBuilder.MODE_NORMAL);
        lub.setKeyword(keyword);
        GalleryListScene.startScene(this, lub);
        return;
    }
    String artist = getArtist(gd.tags);
    if (null != artist) {
        ListUrlBuilder lub = new ListUrlBuilder();
        lub.setMode(ListUrlBuilder.MODE_TAG);
        lub.setKeyword("artist:" + artist);
        GalleryListScene.startScene(this, lub);
        return;
    }
    if (null != gd.uploader) {
        ListUrlBuilder lub = new ListUrlBuilder();
        lub.setMode(ListUrlBuilder.MODE_UPLOADER);
        lub.setKeyword(gd.uploader);
        GalleryListScene.startScene(this, lub);
    }
}
Also used : ListUrlBuilder(com.hippo.ehviewer.client.data.ListUrlBuilder) GalleryDetail(com.hippo.ehviewer.client.data.GalleryDetail)

Example 10 with ListUrlBuilder

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

the class GalleryListUrlParser method parseUploader.

// TODO get page
private static ListUrlBuilder parseUploader(String path) {
    String uploader;
    int prefixLength = PATH_UPLOADER.length();
    int index = path.indexOf('/', prefixLength);
    if (index < 0) {
        uploader = path.substring(prefixLength);
    } else {
        uploader = path.substring(prefixLength, index);
    }
    try {
        uploader = URLDecoder.decode(uploader, "utf-8");
    } catch (UnsupportedEncodingException e) {
        return null;
    }
    if (TextUtils.isEmpty(uploader)) {
        return null;
    }
    ListUrlBuilder builder = new ListUrlBuilder();
    builder.setMode(ListUrlBuilder.MODE_UPLOADER);
    builder.setKeyword(uploader);
    return builder;
}
Also used : ListUrlBuilder(com.hippo.ehviewer.client.data.ListUrlBuilder) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

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