do not prompt again for content that is already purchased
This commit is contained in:
parent
f03d58d648
commit
f9de0d7937
2 changed files with 68 additions and 16 deletions
|
@ -18,12 +18,19 @@ import io.lbry.browser.utils.Helper;
|
|||
import io.lbry.browser.utils.Lbry;
|
||||
|
||||
public class PurchaseListTask extends AsyncTask<Void, Void, List<Claim>> {
|
||||
private String claimId;
|
||||
private int page;
|
||||
private int pageSize;
|
||||
private ClaimSearchResultHandler handler;
|
||||
private View progressView;
|
||||
private Exception error;
|
||||
|
||||
public PurchaseListTask(String claimId, View progressView, ClaimSearchResultHandler handler) {
|
||||
this.claimId = claimId;
|
||||
this.progressView = progressView;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public PurchaseListTask(int page, int pageSize, View progressView, ClaimSearchResultHandler handler) {
|
||||
this.page = page;
|
||||
this.pageSize = pageSize;
|
||||
|
@ -38,8 +45,15 @@ public class PurchaseListTask extends AsyncTask<Void, Void, List<Claim>> {
|
|||
List<Claim> claims = null;
|
||||
try {
|
||||
Map<String, Object> options = new HashMap<>();
|
||||
if (!Helper.isNullOrEmpty(claimId)) {
|
||||
options.put("claim_id", claimId);
|
||||
}
|
||||
if (page > 0) {
|
||||
options.put("page", page);
|
||||
}
|
||||
if (pageSize > 0) {
|
||||
options.put("page_size", pageSize);
|
||||
}
|
||||
options.put("resolve", true);
|
||||
|
||||
JSONObject result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_PURCHASE_LIST, options);
|
||||
|
@ -47,10 +61,11 @@ public class PurchaseListTask extends AsyncTask<Void, Void, List<Claim>> {
|
|||
claims = new ArrayList<>();
|
||||
for (int i = 0; i < items.length(); i++) {
|
||||
Claim claim = Claim.fromJSONObject(items.getJSONObject(i).getJSONObject("claim"));
|
||||
if (!Helper.isNullOrEmpty(claim.getClaimId())) {
|
||||
claims.add(claim);
|
||||
|
||||
Lbry.addClaimToCache(claim);
|
||||
}
|
||||
}
|
||||
} catch (ApiCallException | JSONException | ClassCastException ex) {
|
||||
error = ex;
|
||||
}
|
||||
|
|
|
@ -131,6 +131,7 @@ import io.lbry.browser.tasks.claim.AbandonStreamTask;
|
|||
import io.lbry.browser.tasks.claim.ClaimListResultHandler;
|
||||
import io.lbry.browser.tasks.claim.ClaimListTask;
|
||||
import io.lbry.browser.tasks.claim.ClaimSearchResultHandler;
|
||||
import io.lbry.browser.tasks.claim.PurchaseListTask;
|
||||
import io.lbry.browser.tasks.claim.ResolveTask;
|
||||
import io.lbry.browser.tasks.file.DeleteFileTask;
|
||||
import io.lbry.browser.tasks.file.FileListTask;
|
||||
|
@ -1624,29 +1625,65 @@ public class FileViewFragment extends BaseFragment implements
|
|||
// Check if the claim is free
|
||||
Claim.GenericMetadata metadata = claim.getValue();
|
||||
if (metadata instanceof Claim.StreamMetadata) {
|
||||
Claim.StreamMetadata streamMetadata = (Claim.StreamMetadata) metadata;
|
||||
if (claim.getFile() == null && !claim.isFree()) {
|
||||
// TODO: also check ownership from purchase_list
|
||||
// not free (and the user does not own the claim yet), perform a purchase
|
||||
confirmPurchaseUrl();
|
||||
} else {
|
||||
if (!claim.isPlayable() && !Lbry.SDK_READY) {
|
||||
Snackbar.make(getView().findViewById(R.id.file_view_global_layout), R.string.sdk_initializing_functionality, Snackbar.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
View root = getView();
|
||||
if (root != null) {
|
||||
root.findViewById(R.id.file_view_main_action_button).setVisibility(View.INVISIBLE);
|
||||
root.findViewById(R.id.file_view_main_action_loading).setVisibility(View.VISIBLE);
|
||||
handleMainActionForClaim();
|
||||
}
|
||||
if (claim.getFile() == null && !claim.isFree()) {
|
||||
if (!Lbry.SDK_READY) {
|
||||
Snackbar.make(getView().findViewById(R.id.file_view_global_layout), R.string.sdk_initializing_functionality, Snackbar.LENGTH_LONG).show();
|
||||
restoreMainActionButton();
|
||||
return;
|
||||
}
|
||||
|
||||
checkAndConfirmPurchaseUrl();
|
||||
} else {
|
||||
if (!claim.isPlayable() && !Lbry.SDK_READY) {
|
||||
Snackbar.make(getView().findViewById(R.id.file_view_global_layout), R.string.sdk_initializing_functionality, Snackbar.LENGTH_LONG).show();
|
||||
restoreMainActionButton();
|
||||
return;
|
||||
}
|
||||
|
||||
handleMainActionForClaim();
|
||||
}
|
||||
} else {
|
||||
showError(getString(R.string.cannot_view_claim));
|
||||
}
|
||||
}
|
||||
|
||||
private void checkAndConfirmPurchaseUrl() {
|
||||
if (claim != null) {
|
||||
PurchaseListTask task = new PurchaseListTask(claim.getClaimId(), null, new ClaimSearchResultHandler() {
|
||||
@Override
|
||||
public void onSuccess(List<Claim> claims, boolean hasReachedEnd) {
|
||||
boolean purchased = false;
|
||||
if (claims.size() == 1) {
|
||||
Claim purchasedClaim = claims.get(0);
|
||||
if (claim.getClaimId().equalsIgnoreCase(purchasedClaim.getClaimId())) {
|
||||
// already purchased
|
||||
purchased = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (purchased) {
|
||||
handleMainActionForClaim();
|
||||
} else {
|
||||
restoreMainActionButton();
|
||||
confirmPurchaseUrl();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
// pass
|
||||
restoreMainActionButton();
|
||||
}
|
||||
});
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
}
|
||||
|
||||
private void confirmPurchaseUrl() {
|
||||
if (claim != null) {
|
||||
Fee fee = ((Claim.StreamMetadata) claim.getValue()).getFee();
|
||||
|
|
Loading…
Reference in a new issue