use of com.odysee.app.tasks.lbryinc.ClaimRewardTask in project odysee-android by OdyseeTeam.
the class RewardsFragment method claimReward.
private void claimReward(String type, String code, EditText inputClaimCode, MaterialButton buttonClaim, View loadingView) {
rewardClaimInProgress = true;
Helper.setViewEnabled(buttonClaim, false);
Helper.setViewEnabled(inputClaimCode, false);
Activity activity = getActivity();
if (activity != null) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
loadingView.setVisibility(View.VISIBLE);
}
});
}
final AccountManager am = AccountManager.get(getContext());
final String authToken = am.peekAuthToken(Helper.getOdyseeAccount(am.getAccounts()), "auth_token_type");
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
Supplier<JSONObject> s = new ClaimRewardSupplier(type, code, authToken);
CompletableFuture<JSONObject> cf = CompletableFuture.supplyAsync(s);
cf.whenComplete((result, e) -> {
afterClaimingReward(inputClaimCode, buttonClaim, loadingView, activity, result, e);
});
} else {
ClaimRewardTask task = new ClaimRewardTask(type, code, authToken, new ClaimRewardTask.ClaimRewardHandler() {
@Override
public void onSuccess(double amountClaimed, String message) {
loadingView.setVisibility(View.INVISIBLE);
if (Helper.isNullOrEmpty(message)) {
message = getResources().getQuantityString(R.plurals.claim_reward_message, amountClaimed == 1 ? 1 : 2, new DecimalFormat(Helper.LBC_CURRENCY_FORMAT_PATTERN).format(amountClaimed));
}
View view = getView();
if (view != null) {
Snackbar.make(view, message, Snackbar.LENGTH_LONG).show();
}
Helper.setViewEnabled(buttonClaim, true);
Helper.setViewEnabled(inputClaimCode, true);
rewardClaimInProgress = false;
fetchRewards();
}
@Override
public void onError(Exception error) {
loadingView.setVisibility(View.INVISIBLE);
View view = getView();
if (view != null && error != null && !Helper.isNullOrEmpty(error.getMessage())) {
Snackbar.make(view, error.getMessage(), Snackbar.LENGTH_LONG).setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
}
Helper.setViewEnabled(buttonClaim, true);
Helper.setViewEnabled(inputClaimCode, true);
rewardClaimInProgress = false;
}
});
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
use of com.odysee.app.tasks.lbryinc.ClaimRewardTask in project odysee-android by OdyseeTeam.
the class MainActivity method checkAndClaimNewAndroidReward.
public void checkAndClaimNewAndroidReward() {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
boolean rewardClaimed = sp.getBoolean(PREFERENCE_KEY_INTERNAL_NEW_ANDROID_REWARD_CLAIMED, false);
if (!rewardClaimed) {
ClaimRewardTask task = new ClaimRewardTask(Reward.TYPE_NEW_ANDROID, null, null, new ClaimRewardTask.ClaimRewardHandler() {
@Override
public void onSuccess(double amountClaimed, String message) {
if (Helper.isNullOrEmpty(message)) {
message = getResources().getQuantityString(R.plurals.claim_reward_message, amountClaimed == 1 ? 1 : 2, new DecimalFormat(Helper.LBC_CURRENCY_FORMAT_PATTERN).format(amountClaimed));
}
Snackbar.make(findViewById(R.id.content_main), message, Snackbar.LENGTH_LONG).show();
sp.edit().putBoolean(PREFERENCE_KEY_INTERNAL_NEW_ANDROID_REWARD_CLAIMED, true).apply();
}
@Override
public void onError(Exception error) {
// pass. fail silently
sp.edit().putBoolean(PREFERENCE_KEY_INTERNAL_NEW_ANDROID_REWARD_CLAIMED, true).apply();
}
});
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
use of com.odysee.app.tasks.lbryinc.ClaimRewardTask in project odysee-android by OdyseeTeam.
the class FileViewFragment method claimEligibleRewards.
private void claimEligibleRewards() {
// attempt to claim eligible rewards after viewing or playing a file (fail silently)
final String authToken = Lbryio.AUTH_TOKEN;
ClaimRewardTask firstStreamTask = new ClaimRewardTask(Reward.TYPE_FIRST_STREAM, null, authToken, eligibleRewardHandler);
ClaimRewardTask dailyViewTask = new ClaimRewardTask(Reward.TYPE_DAILY_VIEW, null, authToken, eligibleRewardHandler);
firstStreamTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
dailyViewTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Aggregations