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);
}
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;
}
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;
}
}
Aggregations