Search in sources :

Example 6 with Announcer

use of com.hippo.scene.Announcer in project EhViewer by seven332.

the class MainActivity method onUnrecognizedIntent.

@Override
protected void onUnrecognizedIntent(@Nullable Intent intent) {
    Class<?> clazz = getTopSceneClass();
    if (clazz != null && SolidScene.class.isAssignableFrom(clazz)) {
        // TODO the intent lost
        return;
    }
    if (!handleIntent(intent)) {
        boolean handleUrl = false;
        if (intent != null && Intent.ACTION_VIEW.equals(intent.getAction())) {
            handleUrl = true;
            Toast.makeText(this, R.string.error_cannot_parse_the_url, Toast.LENGTH_SHORT).show();
        }
        if (0 == getSceneCount()) {
            if (handleUrl) {
                finish();
            } else {
                Bundle args = new Bundle();
                args.putString(GalleryListScene.KEY_ACTION, GalleryListScene.ACTION_HOMEPAGE);
                startScene(processAnnouncer(new Announcer(GalleryListScene.class).setArgs(args)));
            }
        }
    }
}
Also used : GalleryListScene(com.hippo.ehviewer.ui.scene.GalleryListScene) Announcer(com.hippo.scene.Announcer) Bundle(android.os.Bundle) PersistableBundle(android.os.PersistableBundle) SolidScene(com.hippo.ehviewer.ui.scene.SolidScene)

Example 7 with Announcer

use of com.hippo.scene.Announcer in project EhViewer by seven332.

the class MainActivity method onNavigationItemSelected.

@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Don't select twice
    if (item.isChecked()) {
        return false;
    }
    int id = item.getItemId();
    if (id == R.id.nav_homepage) {
        Bundle args = new Bundle();
        args.putString(GalleryListScene.KEY_ACTION, GalleryListScene.ACTION_HOMEPAGE);
        startSceneFirstly(new Announcer(GalleryListScene.class).setArgs(args));
    } else if (id == R.id.nav_whats_hot) {
        Bundle args = new Bundle();
        args.putString(GalleryListScene.KEY_ACTION, GalleryListScene.ACTION_WHATS_HOT);
        startSceneFirstly(new Announcer(GalleryListScene.class).setArgs(args));
    } else if (id == R.id.nav_favourite) {
        startScene(new Announcer(FavoritesScene.class));
    } else if (id == R.id.nav_history) {
        startScene(new Announcer(HistoryScene.class));
    } else if (id == R.id.nav_downloads) {
        startScene(new Announcer(DownloadsScene.class));
    } else if (id == R.id.nav_settings) {
        Intent intent = new Intent(this, SettingsActivity.class);
        startActivityForResult(intent, REQUEST_CODE_SETTINGS);
    }
    if (id != R.id.nav_stub && mDrawerLayout != null) {
        mDrawerLayout.closeDrawers();
    }
    return true;
}
Also used : FavoritesScene(com.hippo.ehviewer.ui.scene.FavoritesScene) GalleryListScene(com.hippo.ehviewer.ui.scene.GalleryListScene) Announcer(com.hippo.scene.Announcer) Bundle(android.os.Bundle) PersistableBundle(android.os.PersistableBundle) DownloadsScene(com.hippo.ehviewer.ui.scene.DownloadsScene) Intent(android.content.Intent)

Example 8 with Announcer

use of com.hippo.scene.Announcer in project EhViewer by seven332.

the class MainActivity method processAnnouncer.

// Sometimes scene can't show directly
private Announcer processAnnouncer(Announcer announcer) {
    if (0 == getSceneCount()) {
        if (!TextUtils.isEmpty(Settings.getSecurity())) {
            Bundle newArgs = new Bundle();
            newArgs.putString(SecurityScene.KEY_TARGET_SCENE, announcer.getClazz().getName());
            newArgs.putBundle(SecurityScene.KEY_TARGET_ARGS, announcer.getArgs());
            return new Announcer(SecurityScene.class).setArgs(newArgs);
        } else if (Settings.getShowWarning()) {
            Bundle newArgs = new Bundle();
            newArgs.putString(WarningScene.KEY_TARGET_SCENE, announcer.getClazz().getName());
            newArgs.putBundle(WarningScene.KEY_TARGET_ARGS, announcer.getArgs());
            return new Announcer(WarningScene.class).setArgs(newArgs);
        } else if (Settings.getAskAnalytics()) {
            Bundle newArgs = new Bundle();
            newArgs.putString(AnalyticsScene.KEY_TARGET_SCENE, announcer.getClazz().getName());
            newArgs.putBundle(AnalyticsScene.KEY_TARGET_ARGS, announcer.getArgs());
            return new Announcer(AnalyticsScene.class).setArgs(newArgs);
        } else if (Crash.hasCrashFile()) {
            Bundle newArgs = new Bundle();
            newArgs.putString(CrashScene.KEY_TARGET_SCENE, announcer.getClazz().getName());
            newArgs.putBundle(CrashScene.KEY_TARGET_ARGS, announcer.getArgs());
            return new Announcer(CrashScene.class).setArgs(newArgs);
        } else if (EhUtils.needSignedIn(this)) {
            Bundle newArgs = new Bundle();
            newArgs.putString(SignInScene.KEY_TARGET_SCENE, announcer.getClazz().getName());
            newArgs.putBundle(SignInScene.KEY_TARGET_ARGS, announcer.getArgs());
            return new Announcer(SignInScene.class).setArgs(newArgs);
        } else if (Settings.getSelectSite()) {
            Bundle newArgs = new Bundle();
            newArgs.putString(SelectSiteScene.KEY_TARGET_SCENE, announcer.getClazz().getName());
            newArgs.putBundle(SelectSiteScene.KEY_TARGET_ARGS, announcer.getArgs());
            return new Announcer(SelectSiteScene.class).setArgs(newArgs);
        }
    }
    return announcer;
}
Also used : SignInScene(com.hippo.ehviewer.ui.scene.SignInScene) CookieSignInScene(com.hippo.ehviewer.ui.scene.CookieSignInScene) WebViewSignInScene(com.hippo.ehviewer.ui.scene.WebViewSignInScene) Announcer(com.hippo.scene.Announcer) AnalyticsScene(com.hippo.ehviewer.ui.scene.AnalyticsScene) Bundle(android.os.Bundle) PersistableBundle(android.os.PersistableBundle) SecurityScene(com.hippo.ehviewer.ui.scene.SecurityScene)

Example 9 with Announcer

use of com.hippo.scene.Announcer 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 10 with Announcer

use of com.hippo.scene.Announcer in project EhViewer by seven332.

the class DownloadsScene method onCreateDrawerView.

@Override
public View onCreateDrawerView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.drawer_list, container, false);
    final Context context = getContext2();
    Assert.assertNotNull(context);
    Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
    toolbar.setTitle(R.string.download_labels);
    toolbar.inflateMenu(R.menu.drawer_download);
    toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            int id = item.getItemId();
            switch(id) {
                case R.id.action_settings:
                    startScene(new Announcer(DownloadLabelsScene.class));
                    return true;
                case R.id.action_default_download_label:
                    DownloadManager dm = mDownloadManager;
                    if (null == dm) {
                        return true;
                    }
                    List<DownloadLabel> list = dm.getLabelList();
                    final String[] items = new String[list.size() + 2];
                    items[0] = getString(R.string.let_me_select);
                    items[1] = getString(R.string.default_download_label_name);
                    for (int i = 0, n = list.size(); i < n; i++) {
                        items[i + 2] = list.get(i).getLabel();
                    }
                    new AlertDialog.Builder(context).setTitle(R.string.default_download_label).setItems(items, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (which == 0) {
                                Settings.putHasDefaultDownloadLabel(false);
                            } else {
                                Settings.putHasDefaultDownloadLabel(true);
                                String label;
                                if (which == 1) {
                                    label = null;
                                } else {
                                    label = items[which];
                                }
                                Settings.putDefaultDownloadLabel(label);
                            }
                        }
                    }).show();
                    return true;
            }
            return false;
        }
    });
    List<DownloadLabel> list = EhApplication.getDownloadManager(context).getLabelList();
    final List<String> labels = new ArrayList<>(list.size() + 1);
    // Add default label name
    labels.add(getString(R.string.default_download_label_name));
    for (DownloadLabel raw : list) {
        labels.add(raw.getLabel());
    }
    // TODO handle download label items update
    ListView listView = (ListView) view.findViewById(R.id.list_view);
    listView.setAdapter(new ArrayAdapter<>(context, R.layout.item_simple_list, labels));
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String label;
            if (position == 0) {
                label = null;
            } else {
                label = labels.get(position);
            }
            if (!ObjectUtils.equal(label, mLabel)) {
                mLabel = label;
                updateForLabel();
                updateView();
                closeDrawer(Gravity.RIGHT);
            }
        }
    });
    return view;
}
Also used : Context(android.content.Context) DialogInterface(android.content.DialogInterface) CheckBoxDialogBuilder(com.hippo.app.CheckBoxDialogBuilder) ArrayList(java.util.ArrayList) MenuItem(android.view.MenuItem) EasyRecyclerView(com.hippo.easyrecyclerview.EasyRecyclerView) ShowcaseView(com.github.amlcurran.showcaseview.ShowcaseView) View(android.view.View) AdapterView(android.widget.AdapterView) SimpleRatingView(com.hippo.ehviewer.widget.SimpleRatingView) LoadImageView(com.hippo.widget.LoadImageView) TextView(android.widget.TextView) ListView(android.widget.ListView) RecyclerView(android.support.v7.widget.RecyclerView) DownloadManager(com.hippo.ehviewer.download.DownloadManager) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) ListView(android.widget.ListView) Announcer(com.hippo.scene.Announcer) List(java.util.List) LongList(com.hippo.yorozuya.collect.LongList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) AdapterView(android.widget.AdapterView) DownloadLabel(com.hippo.ehviewer.dao.DownloadLabel) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

Announcer (com.hippo.scene.Announcer)16 Bundle (android.os.Bundle)11 RecyclerView (android.support.v7.widget.RecyclerView)4 View (android.view.View)4 TextView (android.widget.TextView)4 EasyRecyclerView (com.hippo.easyrecyclerview.EasyRecyclerView)4 Context (android.content.Context)3 Intent (android.content.Intent)3 Point (android.graphics.Point)3 PersistableBundle (android.os.PersistableBundle)3 AdapterView (android.widget.AdapterView)3 ListView (android.widget.ListView)3 ShowcaseView (com.github.amlcurran.showcaseview.ShowcaseView)3 ListUrlBuilder (com.hippo.ehviewer.client.data.ListUrlBuilder)3 MainActivity (com.hippo.ehviewer.ui.MainActivity)3 GalleryListScene (com.hippo.ehviewer.ui.scene.GalleryListScene)3 Uri (android.net.Uri)2 Toolbar (android.support.v7.widget.Toolbar)2 MenuItem (android.view.MenuItem)2 GalleryInfo (com.hippo.ehviewer.client.data.GalleryInfo)2