Search in sources :

Example 1 with Source

use of acr.browser.lightning.database.bookmark.BookmarkLocalSync.Source in project Lightning-Browser by anthonycr.

the class BookmarkSettingsFragment method showChooserDialog.

private void showChooserDialog(final Activity activity, List<String> list) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    final ArrayAdapter<String> adapter = new ArrayAdapter<>(activity, android.R.layout.simple_list_item_1);
    for (String title : list) {
        adapter.add(title);
    }
    builder.setTitle(R.string.supported_browsers_title);
    builder.setAdapter(adapter, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            String title = adapter.getItem(which);
            Preconditions.checkNonNull(title);
            Source source = null;
            if (title.equals(getString(R.string.stock_browser))) {
                source = Source.STOCK;
            } else if (title.equals(getTitle(activity, "com.android.chrome"))) {
                source = Source.CHROME_STABLE;
            } else if (title.equals(getTitle(activity, "com.android.beta"))) {
                source = Source.CHROME_BETA;
            } else if (title.equals(getTitle(activity, "com.android.dev"))) {
                source = Source.CHROME_DEV;
            }
            if (source != null) {
                new ImportBookmarksTask(activity, source).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            }
        }
    });
    Dialog dialog = builder.show();
    BrowserDialog.setDialogSize(activity, dialog);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) Source(acr.browser.lightning.database.bookmark.BookmarkLocalSync.Source) Dialog(android.app.Dialog) BrowserDialog(acr.browser.lightning.dialog.BrowserDialog) AlertDialog(android.support.v7.app.AlertDialog) ArrayAdapter(android.widget.ArrayAdapter)

Example 2 with Source

use of acr.browser.lightning.database.bookmark.BookmarkLocalSync.Source in project Lightning-Browser by anthonycr.

the class BookmarkSettingsFragment method buildTitleList.

@NonNull
private List<String> buildTitleList(@NonNull Activity activity, @NonNull List<Source> items) {
    List<String> titles = new ArrayList<>();
    String title;
    for (Source source : items) {
        switch(source) {
            case STOCK:
                titles.add(getString(R.string.stock_browser));
                break;
            case CHROME_STABLE:
                title = getTitle(activity, "com.android.chrome");
                if (title != null) {
                    titles.add(title);
                }
                break;
            case CHROME_BETA:
                title = getTitle(activity, "com.chrome.beta");
                if (title != null) {
                    titles.add(title);
                }
                break;
            case CHROME_DEV:
                title = getTitle(activity, "com.chrome.beta");
                if (title != null) {
                    titles.add(title);
                }
                break;
            default:
                break;
        }
    }
    return titles;
}
Also used : ArrayList(java.util.ArrayList) Source(acr.browser.lightning.database.bookmark.BookmarkLocalSync.Source) NonNull(android.support.annotation.NonNull)

Example 3 with Source

use of acr.browser.lightning.database.bookmark.BookmarkLocalSync.Source 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

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