use of com.foobnix.pdf.info.presentation.PathAdapter in project LibreraReader by foobnix.
the class PrefDialogs method chooseFolderDialog.
public static void chooseFolderDialog(final FragmentActivity a, final Runnable onChanges, final Runnable onScan) {
final PathAdapter recentAdapter = new PathAdapter();
recentAdapter.setPaths(AppState.get().searchPaths);
final AlertDialog.Builder builder = new AlertDialog.Builder(a);
builder.setTitle(R.string.scan_device_for_new_books);
final ListView list = new ListView(a);
list.setAdapter(recentAdapter);
builder.setView(list);
builder.setPositiveButton(R.string.search, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
onScan.run();
}
});
builder.setNeutralButton(R.string.add, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
ChooserDialogFragment.chooseFolder(a, AppState.get().dirLastPath).setOnSelectListener(new ResultResponse2<String, Dialog>() {
@Override
public boolean onResultRecive(String nPath, Dialog dialog) {
boolean isExists = false;
String existPath = "";
for (String str : AppState.get().searchPaths.split(",")) {
if (str != null && str.trim().length() != 0 && nPath.equals(str)) {
isExists = true;
existPath = str;
break;
}
}
if (ExtUtils.isExteralSD(nPath)) {
Toast.makeText(a, R.string.incorrect_value, Toast.LENGTH_SHORT).show();
} else if (isExists) {
Toast.makeText(a, String.format("[ %s == %s ] %s", nPath, existPath, a.getString(R.string.this_directory_is_already_in_the_list)), Toast.LENGTH_LONG).show();
} else {
if (AppState.get().searchPaths.endsWith(",")) {
AppState.get().searchPaths = AppState.get().searchPaths + "" + nPath;
} else {
AppState.get().searchPaths = AppState.get().searchPaths + "," + nPath;
}
}
dialog.dismiss();
onChanges.run();
chooseFolderDialog(a, onChanges, onScan);
return false;
}
});
}
});
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
recentAdapter.setOnDeleClick(new ResultResponse<Uri>() {
@Override
public boolean onResultRecive(Uri result) {
String path = result.getPath();
LOG.d("TEST", "Remove " + AppState.get().searchPaths);
LOG.d("TEST", "Remove " + path);
StringBuilder builder = new StringBuilder();
for (String str : AppState.get().searchPaths.split(",")) {
if (str != null && str.trim().length() > 0 && !str.equals(path)) {
builder.append(str);
builder.append(",");
}
}
AppState.get().searchPaths = builder.toString();
LOG.d("TEST", "Remove " + AppState.get().searchPaths);
recentAdapter.setPaths(AppState.get().searchPaths);
onChanges.run();
return false;
}
});
AlertDialog create = builder.create();
create.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
Keyboards.hideNavigation(a);
}
});
create.show();
}
Aggregations