-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Abandon channels and bulk delete files tasks. Some visual tweaks.
- Loading branch information
Showing
17 changed files
with
380 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
app/src/main/java/io/lbry/browser/tasks/claim/AbandonChannelTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package io.lbry.browser.tasks.claim; | ||
|
||
import android.os.AsyncTask; | ||
import android.view.View; | ||
|
||
import org.json.JSONObject; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import io.lbry.browser.exceptions.ApiCallException; | ||
import io.lbry.browser.tasks.GenericTaskHandler; | ||
import io.lbry.browser.utils.Helper; | ||
import io.lbry.browser.utils.Lbry; | ||
|
||
public class AbandonChannelTask extends AsyncTask<Void, Void, Boolean> { | ||
private List<String> claimIds; | ||
private List<String> successfulClaimIds; | ||
private List<String> failedClaimIds; | ||
private List<Exception> failedExceptions; | ||
private View progressView; | ||
private AbandonHandler handler; | ||
|
||
public AbandonChannelTask(List<String> claimIds, View progressView, AbandonHandler handler) { | ||
this.claimIds = claimIds; | ||
this.progressView = progressView; | ||
this.handler = handler; | ||
} | ||
|
||
protected void onPreExecute() { | ||
Helper.setViewVisibility(progressView, View.VISIBLE); | ||
} | ||
|
||
public Boolean doInBackground(Void... params) { | ||
successfulClaimIds = new ArrayList<>(); | ||
failedClaimIds = new ArrayList<>(); | ||
failedExceptions = new ArrayList<>(); | ||
|
||
for (String claimId : claimIds) { | ||
try { | ||
Map<String, Object> options = new HashMap<>(); | ||
options.put("claim_id", claimId); | ||
options.put("blocking", false); | ||
JSONObject result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_CHANNEL_ABANDON, options); | ||
successfulClaimIds.add(claimId); | ||
} catch (ApiCallException ex) { | ||
failedClaimIds.add(claimId); | ||
failedExceptions.add(ex); | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
protected void onPostExecute(Boolean result) { | ||
Helper.setViewVisibility(progressView, View.GONE); | ||
if (handler != null) { | ||
handler.onComplete(successfulClaimIds, failedClaimIds, failedExceptions); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/io/lbry/browser/tasks/claim/AbandonHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.lbry.browser.tasks.claim; | ||
|
||
import java.util.List; | ||
|
||
public interface AbandonHandler { | ||
void onComplete(List<String> successfulClaimIds, List<String> failedClaimIds, List<Exception> errors); | ||
} |
32 changes: 32 additions & 0 deletions
32
app/src/main/java/io/lbry/browser/tasks/file/BulkDeleteFilesTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.lbry.browser.tasks.file; | ||
|
||
import android.os.AsyncTask; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import io.lbry.browser.exceptions.ApiCallException; | ||
import io.lbry.browser.tasks.GenericTaskHandler; | ||
import io.lbry.browser.utils.Lbry; | ||
|
||
// Just run delete on the specified claim IDs (no need for a handler) | ||
public class BulkDeleteFilesTask extends AsyncTask<Void, Void, Boolean> { | ||
private List<String> claimIds; | ||
public BulkDeleteFilesTask(List<String> claimIds) { | ||
this.claimIds = claimIds; | ||
} | ||
protected Boolean doInBackground(Void... params) { | ||
for (String claimId : claimIds) { | ||
try { | ||
Map<String, Object> options = new HashMap<>(); | ||
options.put("claim_id", claimId); | ||
options.put("delete_from_download_dir", true); | ||
Lbry.genericApiCall(Lbry.METHOD_FILE_DELETE, options); | ||
} catch (ApiCallException ex) { | ||
// pass | ||
} | ||
} | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.