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