Search in sources :

Example 1 with CompletableOnSubscribe

use of com.anthonycr.bonsai.CompletableOnSubscribe in project Lightning-Browser by anthonycr.

the class PrivacySettingsFragment method clearHistoryDialog.

private void clearHistoryDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
    builder.setTitle(getResources().getString(R.string.title_clear_history));
    Dialog dialog = builder.setMessage(getResources().getString(R.string.dialog_history)).setPositiveButton(getResources().getString(R.string.action_yes), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface arg0, int arg1) {
            clearHistory().subscribeOn(Schedulers.io()).observeOn(Schedulers.main()).subscribe(new CompletableOnSubscribe() {

                @Override
                public void onComplete() {
                    Utils.showSnackbar(getActivity(), R.string.message_clear_history);
                }
            });
        }
    }).setNegativeButton(getResources().getString(R.string.action_no), null).show();
    BrowserDialog.setDialogSize(mActivity, dialog);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) Dialog(android.app.Dialog) BrowserDialog(acr.browser.lightning.dialog.BrowserDialog) AlertDialog(android.support.v7.app.AlertDialog) CompletableOnSubscribe(com.anthonycr.bonsai.CompletableOnSubscribe)

Example 2 with CompletableOnSubscribe

use of com.anthonycr.bonsai.CompletableOnSubscribe in project Lightning-Browser by anthonycr.

the class LightningDialogBuilder method showEditBookmarkDialog.

private void showEditBookmarkDialog(@NonNull final Activity activity, @NonNull final UIController uiController, @NonNull final HistoryItem item) {
    final AlertDialog.Builder editBookmarkDialog = new AlertDialog.Builder(activity);
    editBookmarkDialog.setTitle(R.string.title_edit_bookmark);
    final View dialogLayout = View.inflate(activity, R.layout.dialog_edit_bookmark, null);
    final EditText getTitle = (EditText) dialogLayout.findViewById(R.id.bookmark_title);
    getTitle.setText(item.getTitle());
    final EditText getUrl = (EditText) dialogLayout.findViewById(R.id.bookmark_url);
    getUrl.setText(item.getUrl());
    final AutoCompleteTextView getFolder = (AutoCompleteTextView) dialogLayout.findViewById(R.id.bookmark_folder);
    getFolder.setHint(R.string.folder);
    getFolder.setText(item.getFolder());
    mBookmarkManager.getFolderNames().subscribeOn(Schedulers.io()).observeOn(Schedulers.main()).subscribe(new SingleOnSubscribe<List<String>>() {

        @Override
        public void onItem(@Nullable List<String> folders) {
            Preconditions.checkNonNull(folders);
            final ArrayAdapter<String> suggestionsAdapter = new ArrayAdapter<>(activity, android.R.layout.simple_dropdown_item_1line, folders);
            getFolder.setThreshold(1);
            getFolder.setAdapter(suggestionsAdapter);
            editBookmarkDialog.setView(dialogLayout);
            editBookmarkDialog.setPositiveButton(activity.getString(R.string.action_ok), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    HistoryItem editedItem = new HistoryItem();
                    editedItem.setTitle(getTitle.getText().toString());
                    editedItem.setUrl(getUrl.getText().toString());
                    editedItem.setUrl(getUrl.getText().toString());
                    editedItem.setFolder(getFolder.getText().toString());
                    mBookmarkManager.editBookmark(item, editedItem).subscribeOn(Schedulers.io()).observeOn(Schedulers.main()).subscribe(new CompletableOnSubscribe() {

                        @Override
                        public void onComplete() {
                            uiController.handleBookmarksChange();
                        }
                    });
                }
            });
            Dialog dialog = editBookmarkDialog.show();
            BrowserDialog.setDialogSize(activity, dialog);
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) EditText(android.widget.EditText) DialogInterface(android.content.DialogInterface) HistoryItem(acr.browser.lightning.database.HistoryItem) View(android.view.View) AutoCompleteTextView(android.widget.AutoCompleteTextView) Dialog(android.app.Dialog) AlertDialog(android.support.v7.app.AlertDialog) List(java.util.List) CompletableOnSubscribe(com.anthonycr.bonsai.CompletableOnSubscribe) ArrayAdapter(android.widget.ArrayAdapter) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 3 with CompletableOnSubscribe

use of com.anthonycr.bonsai.CompletableOnSubscribe in project Lightning-Browser by anthonycr.

the class BookmarkSettingsFragment method createDialog.

private void createDialog() {
    if (mActivity == null) {
        return;
    }
    final AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
    final String title = getString(R.string.title_chooser);
    builder.setTitle(title + ": " + Environment.getExternalStorageDirectory());
    if (mFileList == null) {
        Dialog dialog = builder.show();
        BrowserDialog.setDialogSize(mActivity, dialog);
        return;
    }
    builder.setItems(mFileNameList, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (mFileList[which].isDirectory()) {
                builder.setTitle(title + ": " + mFileList[which]);
                loadFileList(mFileList[which]);
                builder.setItems(mFileNameList, this);
                Dialog dialog1 = builder.show();
                BrowserDialog.setDialogSize(mActivity, dialog1);
            } else {
                BookmarkExporter.importBookmarksFromFile(mFileList[which]).subscribeOn(Schedulers.io()).subscribe(new SingleOnSubscribe<List<HistoryItem>>() {

                    @Override
                    public void onItem(@Nullable final List<HistoryItem> importList) {
                        Preconditions.checkNonNull(importList);
                        mBookmarkManager.addBookmarkList(importList).observeOn(Schedulers.main()).subscribe(new CompletableOnSubscribe() {

                            @Override
                            public void onComplete() {
                                Activity activity = getActivity();
                                if (activity != null) {
                                    String message = activity.getResources().getString(R.string.message_import);
                                    Utils.showSnackbar(activity, importList.size() + " " + message);
                                }
                            }
                        });
                    }

                    @Override
                    public void onError(@NonNull Throwable throwable) {
                        Log.e(TAG, "onError: importing bookmarks", throwable);
                        Utils.createInformativeDialog(getActivity(), R.string.title_error, R.string.import_bookmark_error);
                    }
                });
            }
        }
    });
    Dialog dialog = builder.show();
    BrowserDialog.setDialogSize(mActivity, dialog);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) HistoryItem(acr.browser.lightning.database.HistoryItem) SingleOnSubscribe(com.anthonycr.bonsai.SingleOnSubscribe) Activity(android.app.Activity) Dialog(android.app.Dialog) BrowserDialog(acr.browser.lightning.dialog.BrowserDialog) AlertDialog(android.support.v7.app.AlertDialog) NonNull(android.support.annotation.NonNull) ArrayList(java.util.ArrayList) List(java.util.List) CompletableOnSubscribe(com.anthonycr.bonsai.CompletableOnSubscribe) Nullable(android.support.annotation.Nullable)

Example 4 with CompletableOnSubscribe

use of com.anthonycr.bonsai.CompletableOnSubscribe in project Lightning-Browser by anthonycr.

the class BookmarkSettingsFragment method onPreferenceClick.

@Override
public boolean onPreferenceClick(@NonNull Preference preference) {
    switch(preference.getKey()) {
        case SETTINGS_EXPORT:
            PermissionsManager.getInstance().requestPermissionsIfNecessaryForResult(getActivity(), REQUIRED_PERMISSIONS, new PermissionsResultAction() {

                @Override
                public void onGranted() {
                    mBookmarkManager.getAllBookmarks().subscribeOn(Schedulers.io()).subscribe(new SingleOnSubscribe<List<HistoryItem>>() {

                        @Override
                        public void onItem(@Nullable List<HistoryItem> item) {
                            Preconditions.checkNonNull(item);
                            final File exportFile = BookmarkExporter.createNewExportFile();
                            BookmarkExporter.exportBookmarksToFile(item, exportFile).subscribeOn(Schedulers.io()).observeOn(Schedulers.main()).subscribe(new CompletableOnSubscribe() {

                                @Override
                                public void onComplete() {
                                    Activity activity = getActivity();
                                    if (activity != null) {
                                        Utils.showSnackbar(activity, activity.getString(R.string.bookmark_export_path) + ' ' + exportFile.getPath());
                                    }
                                }
                            });
                        }
                    });
                }

                @Override
                public void onDenied(String permission) {
                //TODO Show message
                }
            });
            return true;
        case SETTINGS_IMPORT:
            PermissionsManager.getInstance().requestPermissionsIfNecessaryForResult(getActivity(), REQUIRED_PERMISSIONS, new PermissionsResultAction() {

                @Override
                public void onGranted() {
                    loadFileList(null);
                    createDialog();
                }

                @Override
                public void onDenied(String permission) {
                //TODO Show message
                }
            });
            return true;
        case SETTINGS_IMPORT_BROWSER:
            getSync().getSupportedBrowsers().subscribeOn(Schedulers.worker()).observeOn(Schedulers.main()).subscribe(new SingleOnSubscribe<List<Source>>() {

                @Override
                public void onItem(@Nullable List<Source> item) {
                    Activity activity = getActivity();
                    if (item == null || activity == null) {
                        return;
                    }
                    List<String> titles = buildTitleList(activity, item);
                    showChooserDialog(activity, titles);
                }
            });
            return true;
        case SETTINGS_DELETE_BOOKMARKS:
            showDeleteBookmarksDialog();
            return true;
        default:
            return false;
    }
}
Also used : HistoryItem(acr.browser.lightning.database.HistoryItem) SingleOnSubscribe(com.anthonycr.bonsai.SingleOnSubscribe) Activity(android.app.Activity) Source(acr.browser.lightning.database.bookmark.BookmarkLocalSync.Source) PermissionsResultAction(com.anthonycr.grant.PermissionsResultAction) ArrayList(java.util.ArrayList) List(java.util.List) CompletableOnSubscribe(com.anthonycr.bonsai.CompletableOnSubscribe) File(java.io.File) Nullable(android.support.annotation.Nullable)

Aggregations

CompletableOnSubscribe (com.anthonycr.bonsai.CompletableOnSubscribe)4 HistoryItem (acr.browser.lightning.database.HistoryItem)3 Dialog (android.app.Dialog)3 DialogInterface (android.content.DialogInterface)3 AlertDialog (android.support.v7.app.AlertDialog)3 List (java.util.List)3 BrowserDialog (acr.browser.lightning.dialog.BrowserDialog)2 Activity (android.app.Activity)2 Nullable (android.support.annotation.Nullable)2 SingleOnSubscribe (com.anthonycr.bonsai.SingleOnSubscribe)2 ArrayList (java.util.ArrayList)2 Source (acr.browser.lightning.database.bookmark.BookmarkLocalSync.Source)1 NonNull (android.support.annotation.NonNull)1 View (android.view.View)1 ArrayAdapter (android.widget.ArrayAdapter)1 AutoCompleteTextView (android.widget.AutoCompleteTextView)1 EditText (android.widget.EditText)1 PermissionsResultAction (com.anthonycr.grant.PermissionsResultAction)1 File (java.io.File)1