Search in sources :

Example 1 with HistoryPage

use of acr.browser.lightning.constant.HistoryPage in project Lightning-Browser by anthonycr.

the class TabsManager method restoreLostTabs.

private void restoreLostTabs(@Nullable final String url, @NonNull final Activity activity, @NonNull final CompletableSubscriber subscriber) {
    restoreState().subscribeOn(Schedulers.io()).observeOn(Schedulers.main()).subscribe(new StreamOnSubscribe<Bundle>() {

        @Override
        public void onNext(@Nullable Bundle item) {
            final LightningView tab = newTab(activity, "", false);
            Preconditions.checkNonNull(item);
            String url = item.getString(URL_KEY);
            if (url != null && tab.getWebView() != null) {
                if (UrlUtils.isBookmarkUrl(url)) {
                    new BookmarkPage(activity).getBookmarkPage().subscribeOn(Schedulers.io()).observeOn(Schedulers.main()).subscribe(new SingleOnSubscribe<String>() {

                        @Override
                        public void onItem(@Nullable String item) {
                            Preconditions.checkNonNull(item);
                            tab.loadUrl(item);
                        }
                    });
                } else if (UrlUtils.isDownloadsUrl(url)) {
                    new DownloadsPage().getDownloadsPage().subscribeOn(Schedulers.io()).observeOn(Schedulers.main()).subscribe(new SingleOnSubscribe<String>() {

                        @Override
                        public void onItem(@Nullable String item) {
                            Preconditions.checkNonNull(item);
                            tab.loadUrl(item);
                        }
                    });
                } else if (UrlUtils.isStartPageUrl(url)) {
                    new StartPage().getHomepage().subscribeOn(Schedulers.io()).observeOn(Schedulers.main()).subscribe(new SingleOnSubscribe<String>() {

                        @Override
                        public void onItem(@Nullable String item) {
                            Preconditions.checkNonNull(item);
                            tab.loadUrl(item);
                        }
                    });
                } else if (UrlUtils.isHistoryUrl(url)) {
                    new HistoryPage().getHistoryPage().subscribeOn(Schedulers.io()).observeOn(Schedulers.main()).subscribe(new SingleOnSubscribe<String>() {

                        @Override
                        public void onItem(@Nullable String item) {
                            Preconditions.checkNonNull(item);
                            tab.loadUrl(item);
                        }
                    });
                }
            } else if (tab.getWebView() != null) {
                tab.getWebView().restoreState(item);
            }
        }

        @Override
        public void onComplete() {
            if (url != null) {
                if (url.startsWith(Constants.FILE)) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
                    Dialog dialog = builder.setCancelable(true).setTitle(R.string.title_warning).setMessage(R.string.message_blocked_local).setOnDismissListener(new DialogInterface.OnDismissListener() {

                        @Override
                        public void onDismiss(DialogInterface dialog) {
                            if (mTabList.isEmpty()) {
                                newTab(activity, null, false);
                            }
                            finishInitialization();
                            subscriber.onComplete();
                        }
                    }).setNegativeButton(android.R.string.cancel, null).setPositiveButton(R.string.action_open, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            newTab(activity, url, false);
                        }
                    }).show();
                    BrowserDialog.setDialogSize(activity, dialog);
                } else {
                    newTab(activity, url, false);
                    if (mTabList.isEmpty()) {
                        newTab(activity, null, false);
                    }
                    finishInitialization();
                    subscriber.onComplete();
                }
            } else {
                if (mTabList.isEmpty()) {
                    newTab(activity, null, false);
                }
                finishInitialization();
                subscriber.onComplete();
            }
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) HistoryPage(acr.browser.lightning.constant.HistoryPage) DialogInterface(android.content.DialogInterface) Bundle(android.os.Bundle) SingleOnSubscribe(com.anthonycr.bonsai.SingleOnSubscribe) BookmarkPage(acr.browser.lightning.constant.BookmarkPage) DownloadsPage(acr.browser.lightning.constant.DownloadsPage) StartPage(acr.browser.lightning.constant.StartPage) Dialog(android.app.Dialog) BrowserDialog(acr.browser.lightning.dialog.BrowserDialog) AlertDialog(android.support.v7.app.AlertDialog) LightningView(acr.browser.lightning.view.LightningView) Nullable(android.support.annotation.Nullable)

Aggregations

BookmarkPage (acr.browser.lightning.constant.BookmarkPage)1 DownloadsPage (acr.browser.lightning.constant.DownloadsPage)1 HistoryPage (acr.browser.lightning.constant.HistoryPage)1 StartPage (acr.browser.lightning.constant.StartPage)1 BrowserDialog (acr.browser.lightning.dialog.BrowserDialog)1 LightningView (acr.browser.lightning.view.LightningView)1 Dialog (android.app.Dialog)1 DialogInterface (android.content.DialogInterface)1 Bundle (android.os.Bundle)1 Nullable (android.support.annotation.Nullable)1 AlertDialog (android.support.v7.app.AlertDialog)1 SingleOnSubscribe (com.anthonycr.bonsai.SingleOnSubscribe)1