use of com.odysee.app.tasks.file.BulkDeleteFilesTask in project odysee-android by OdyseeTeam.
the class LibraryFragment method handleDeleteSelectedClaims.
private void handleDeleteSelectedClaims(List<Claim> selectedClaims) {
List<String> claimIds = new ArrayList<>();
for (Claim claim : selectedClaims) {
claimIds.add(claim.getClaimId());
}
if (currentFilter == FILTER_DOWNLOADS) {
new BulkDeleteFilesTask(claimIds).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
Lbry.unsetFilesForCachedClaims(claimIds);
contentListAdapter.removeItems(selectedClaims);
if (actionMode != null) {
actionMode.finish();
}
View root = getView();
if (root != null) {
String message = getResources().getQuantityString(R.plurals.files_deleted, claimIds.size());
Snackbar.make(root, message, Snackbar.LENGTH_LONG).show();
}
} else if (currentFilter == FILTER_HISTORY) {
ExecutorService executorService = Executors.newSingleThreadExecutor();
Activity a = getActivity();
String message = getResources().getQuantityString(R.plurals.confirm_delete_files, selectedClaims.size());
AlertDialog.Builder builder;
if (a != null) {
builder = new AlertDialog.Builder(a);
builder.setTitle(R.string.delete_selection).setMessage(message).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
for (Claim c : selectedClaims) {
try {
Runnable r = new DeleteViewHistoryItem(c.getPermanentUrl());
Future<?> f = executorService.submit(r);
f.get();
a.runOnUiThread(new Runnable() {
@Override
public void run() {
contentListAdapter.removeItem(c);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
a.runOnUiThread(new Runnable() {
@Override
public void run() {
if (actionMode != null) {
actionMode.finish();
}
if (executorService != null && !executorService.isShutdown()) {
executorService.shutdown();
}
}
});
}
});
t.start();
}
}).setNegativeButton(R.string.no, null);
builder.show();
}
}
}
Aggregations