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;
|
import io.lbry.browser.utils.Lbry;
|
||||||
|
|
||||||
public class PurchaseListTask extends AsyncTask<Void, Void, List<Claim>> {
|
public class PurchaseListTask extends AsyncTask<Void, Void, List<Claim>> {
|
||||||
|
private String claimId;
|
||||||
private int page;
|
private int page;
|
||||||
private int pageSize;
|
private int pageSize;
|
||||||
private ClaimSearchResultHandler handler;
|
private ClaimSearchResultHandler handler;
|
||||||
private View progressView;
|
private View progressView;
|
||||||
private Exception error;
|
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) {
|
public PurchaseListTask(int page, int pageSize, View progressView, ClaimSearchResultHandler handler) {
|
||||||
this.page = page;
|
this.page = page;
|
||||||
this.pageSize = pageSize;
|
this.pageSize = pageSize;
|
||||||
|
@ -38,8 +45,15 @@ public class PurchaseListTask extends AsyncTask<Void, Void, List<Claim>> {
|
||||||
List<Claim> claims = null;
|
List<Claim> claims = null;
|
||||||
try {
|
try {
|
||||||
Map<String, Object> options = new HashMap<>();
|
Map<String, Object> options = new HashMap<>();
|
||||||
options.put("page", page);
|
if (!Helper.isNullOrEmpty(claimId)) {
|
||||||
options.put("page_size", pageSize);
|
options.put("claim_id", claimId);
|
||||||
|
}
|
||||||
|
if (page > 0) {
|
||||||
|
options.put("page", page);
|
||||||
|
}
|
||||||
|
if (pageSize > 0) {
|
||||||
|
options.put("page_size", pageSize);
|
||||||
|
}
|
||||||
options.put("resolve", true);
|
options.put("resolve", true);
|
||||||
|
|
||||||
JSONObject result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_PURCHASE_LIST, options);
|
JSONObject result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_PURCHASE_LIST, options);
|
||||||
|
@ -47,9 +61,10 @@ public class PurchaseListTask extends AsyncTask<Void, Void, List<Claim>> {
|
||||||
claims = new ArrayList<>();
|
claims = new ArrayList<>();
|
||||||
for (int i = 0; i < items.length(); i++) {
|
for (int i = 0; i < items.length(); i++) {
|
||||||
Claim claim = Claim.fromJSONObject(items.getJSONObject(i).getJSONObject("claim"));
|
Claim claim = Claim.fromJSONObject(items.getJSONObject(i).getJSONObject("claim"));
|
||||||
claims.add(claim);
|
if (!Helper.isNullOrEmpty(claim.getClaimId())) {
|
||||||
|
claims.add(claim);
|
||||||
Lbry.addClaimToCache(claim);
|
Lbry.addClaimToCache(claim);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (ApiCallException | JSONException | ClassCastException ex) {
|
} catch (ApiCallException | JSONException | ClassCastException ex) {
|
||||||
error = 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.ClaimListResultHandler;
|
||||||
import io.lbry.browser.tasks.claim.ClaimListTask;
|
import io.lbry.browser.tasks.claim.ClaimListTask;
|
||||||
import io.lbry.browser.tasks.claim.ClaimSearchResultHandler;
|
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.claim.ResolveTask;
|
||||||
import io.lbry.browser.tasks.file.DeleteFileTask;
|
import io.lbry.browser.tasks.file.DeleteFileTask;
|
||||||
import io.lbry.browser.tasks.file.FileListTask;
|
import io.lbry.browser.tasks.file.FileListTask;
|
||||||
|
@ -1624,29 +1625,65 @@ public class FileViewFragment extends BaseFragment implements
|
||||||
// Check if the claim is free
|
// Check if the claim is free
|
||||||
Claim.GenericMetadata metadata = claim.getValue();
|
Claim.GenericMetadata metadata = claim.getValue();
|
||||||
if (metadata instanceof Claim.StreamMetadata) {
|
if (metadata instanceof Claim.StreamMetadata) {
|
||||||
Claim.StreamMetadata streamMetadata = (Claim.StreamMetadata) metadata;
|
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);
|
||||||
|
}
|
||||||
if (claim.getFile() == null && !claim.isFree()) {
|
if (claim.getFile() == null && !claim.isFree()) {
|
||||||
// TODO: also check ownership from purchase_list
|
if (!Lbry.SDK_READY) {
|
||||||
// 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();
|
Snackbar.make(getView().findViewById(R.id.file_view_global_layout), R.string.sdk_initializing_functionality, Snackbar.LENGTH_LONG).show();
|
||||||
|
restoreMainActionButton();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
View root = getView();
|
checkAndConfirmPurchaseUrl();
|
||||||
if (root != null) {
|
} else {
|
||||||
root.findViewById(R.id.file_view_main_action_button).setVisibility(View.INVISIBLE);
|
if (!claim.isPlayable() && !Lbry.SDK_READY) {
|
||||||
root.findViewById(R.id.file_view_main_action_loading).setVisibility(View.VISIBLE);
|
Snackbar.make(getView().findViewById(R.id.file_view_global_layout), R.string.sdk_initializing_functionality, Snackbar.LENGTH_LONG).show();
|
||||||
handleMainActionForClaim();
|
restoreMainActionButton();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleMainActionForClaim();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
showError(getString(R.string.cannot_view_claim));
|
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() {
|
private void confirmPurchaseUrl() {
|
||||||
if (claim != null) {
|
if (claim != null) {
|
||||||
Fee fee = ((Claim.StreamMetadata) claim.getValue()).getFee();
|
Fee fee = ((Claim.StreamMetadata) claim.getValue()).getFee();
|
||||||
|
|
Loading…
Reference in a new issue