Search in sources :

Example 1 with DeleteViewHistoryItem

use of com.odysee.app.runnable.DeleteViewHistoryItem 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();
        }
    }
}
Also used : DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) MainActivity(com.odysee.app.MainActivity) Activity(android.app.Activity) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) CardView(androidx.cardview.widget.CardView) TextView(android.widget.TextView) JSONException(org.json.JSONException) ApiCallException(com.odysee.app.exceptions.ApiCallException) MainThread(androidx.annotation.MainThread) DeleteViewHistoryItem(com.odysee.app.runnable.DeleteViewHistoryItem) ExecutorService(java.util.concurrent.ExecutorService) BulkDeleteFilesTask(com.odysee.app.tasks.file.BulkDeleteFilesTask) Claim(com.odysee.app.model.Claim)

Aggregations

Activity (android.app.Activity)1 DialogInterface (android.content.DialogInterface)1 View (android.view.View)1 TextView (android.widget.TextView)1 MainThread (androidx.annotation.MainThread)1 CardView (androidx.cardview.widget.CardView)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 MainActivity (com.odysee.app.MainActivity)1 ApiCallException (com.odysee.app.exceptions.ApiCallException)1 Claim (com.odysee.app.model.Claim)1 DeleteViewHistoryItem (com.odysee.app.runnable.DeleteViewHistoryItem)1 BulkDeleteFilesTask (com.odysee.app.tasks.file.BulkDeleteFilesTask)1 ArrayList (java.util.ArrayList)1 ExecutorService (java.util.concurrent.ExecutorService)1 JSONException (org.json.JSONException)1