Search in sources :

Example 1 with ClaimResultHandler

use of com.odysee.app.tasks.claim.ClaimResultHandler in project odysee-android by OdyseeTeam.

the class PublishFormFragment method publishClaim.

private void publishClaim(Claim claim) {
    String finalFilePath = transcodedFilePath;
    if (Helper.isNullOrEmpty(finalFilePath)) {
        finalFilePath = currentGalleryItem != null ? currentGalleryItem.getFilePath() : currentFilePath;
    }
    saveInProgress = true;
    PublishClaimTask task = new PublishClaimTask(claim, finalFilePath, progressPublish, new ClaimResultHandler() {

        @Override
        public void beforeStart() {
            preSave();
        }

        @Override
        public void onSuccess(Claim claimResult) {
            postSave();
            // Run the logPublish task
            if (!BuildConfig.DEBUG) {
                claimResult.setSigningChannel(claim.getSigningChannel());
                LogPublishTask logPublish = new LogPublishTask(claimResult);
                logPublish.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            }
            // publish done
            Bundle bundle = new Bundle();
            bundle.putString("claim_id", claimResult.getClaimId());
            bundle.putString("claim_name", claimResult.getName());
            LbryAnalytics.logEvent(editMode ? LbryAnalytics.EVENT_PUBLISH_UPDATE : LbryAnalytics.EVENT_PUBLISH, bundle);
            Context context = getContext();
            if (context instanceof MainActivity) {
                MainActivity activity = (MainActivity) context;
                activity.showMessage(R.string.publish_successful);
                activity.sendBroadcast(new Intent(MainActivity.ACTION_PUBLISH_SUCCESSFUL));
            }
        }

        @Override
        public void onError(Exception error) {
            showError(error.getMessage());
            postSave();
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : PublishClaimTask(com.odysee.app.tasks.claim.PublishClaimTask) Context(android.content.Context) ClaimResultHandler(com.odysee.app.tasks.claim.ClaimResultHandler) Bundle(android.os.Bundle) LogPublishTask(com.odysee.app.tasks.lbryinc.LogPublishTask) Intent(android.content.Intent) MainActivity(com.odysee.app.MainActivity) Claim(com.odysee.app.model.Claim) JSONException(org.json.JSONException)

Example 2 with ClaimResultHandler

use of com.odysee.app.tasks.claim.ClaimResultHandler in project odysee-android by OdyseeTeam.

the class RepostClaimDialogFragment method validateAndRepostClaim.

private void validateAndRepostClaim() {
    String name = Helper.getValue(inputName.getText());
    if (Helper.isNullOrEmpty(name) || !LbryUri.isNameValid(name)) {
        showError(getString(R.string.repost_name_invalid_characters));
        return;
    }
    String depositString = Helper.getValue(inputDeposit.getText());
    if (Helper.isNullOrEmpty(depositString)) {
        showError(getString(R.string.invalid_amount));
        return;
    }
    BigDecimal bid = new BigDecimal(depositString);
    if (bid.doubleValue() > Lbry.getAvailableBalance()) {
        showError(getString(R.string.insufficient_balance));
        return;
    }
    if (bid.doubleValue() < Helper.MIN_DEPOSIT) {
        String message = getResources().getQuantityString(R.plurals.min_deposit_required, 2, String.valueOf(Helper.MIN_DEPOSIT));
        showError(message);
        return;
    }
    Claim channel = (Claim) channelSpinner.getSelectedItem();
    if (channel == null) {
        showError(getString(R.string.please_select_repost_channel));
        return;
    }
    StreamRepostTask task = new StreamRepostTask(name, bid, claim.getClaimId(), channel.getClaimId(), repostProgress, new ClaimResultHandler() {

        @Override
        public void beforeStart() {
            startLoading();
        }

        @Override
        public void onSuccess(Claim claimResult) {
            if (listener != null) {
                listener.onClaimReposted(claimResult);
            }
            finishLoading();
            dismiss();
        }

        @Override
        public void onError(Exception error) {
            showError(error.getMessage());
            finishLoading();
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : ClaimResultHandler(com.odysee.app.tasks.claim.ClaimResultHandler) StreamRepostTask(com.odysee.app.tasks.claim.StreamRepostTask) BigDecimal(java.math.BigDecimal) Claim(com.odysee.app.model.Claim)

Example 3 with ClaimResultHandler

use of com.odysee.app.tasks.claim.ClaimResultHandler in project odysee-android by OdyseeTeam.

the class ChannelFormFragment method validateAndSaveClaim.

private void validateAndSaveClaim(Claim claim) {
    if (!editMode && Helper.isNullOrEmpty(claim.getName())) {
        showError(getString(R.string.please_enter_channel_name));
        return;
    }
    String channelName = claim.getName().startsWith("@") ? claim.getName().substring(1) : claim.getName();
    if (!LbryUri.isNameValid(channelName)) {
        showError(getString(R.string.channel_name_invalid_characters));
        return;
    }
    if (!editMode) {
        if (Helper.channelExists(channelName)) {
            showError(getString(R.string.channel_name_already_created));
            return;
        }
    }
    String depositString = Helper.getValue(inputDeposit.getText());
    double depositAmount = 0;
    try {
        depositAmount = Double.parseDouble(depositString);
    } catch (NumberFormatException ex) {
        // pass
        showError(getString(R.string.please_enter_valid_deposit));
        return;
    }
    if (depositAmount < Helper.MIN_DEPOSIT) {
        String error = getResources().getQuantityString(R.plurals.min_deposit_required, depositAmount == 1 ? 1 : 2, String.valueOf(Helper.MIN_DEPOSIT));
        showError(error);
        return;
    }
    if (Lbry.getAvailableBalance() < depositAmount) {
        showError(getString(R.string.deposit_more_than_balance));
        return;
    }
    AccountManager am = AccountManager.get(getContext());
    String authToken = am.peekAuthToken(Helper.getOdyseeAccount(am.getAccounts()), "auth_token_type");
    ChannelCreateUpdateTask task = new ChannelCreateUpdateTask(claim, new BigDecimal(depositString), editMode, channelSaveProgress, authToken, new ClaimResultHandler() {

        @Override
        public void beforeStart() {
            preSave();
        }

        @Override
        public void onSuccess(Claim claimResult) {
            postSave();
            // Run the logPublish task
            if (!BuildConfig.DEBUG) {
                LogPublishTask logPublish = new LogPublishTask(claimResult);
                logPublish.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            }
            if (!editMode) {
                // channel created
                Bundle bundle = new Bundle();
                bundle.putString("claim_id", claimResult.getClaimId());
                bundle.putString("claim_name", claimResult.getName());
                LbryAnalytics.logEvent(LbryAnalytics.EVENT_CHANNEL_CREATE, bundle);
            }
            Context context = getContext();
            if (context instanceof MainActivity) {
                MainActivity activity = (MainActivity) context;
                activity.showMessage(R.string.channel_save_successful);
                activity.onBackPressed();
            }
        }

        @Override
        public void onError(Exception error) {
            showError(error != null ? error.getMessage() : getString(R.string.channel_save_failed));
            postSave();
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : Context(android.content.Context) ClaimResultHandler(com.odysee.app.tasks.claim.ClaimResultHandler) ChannelCreateUpdateTask(com.odysee.app.tasks.claim.ChannelCreateUpdateTask) Bundle(android.os.Bundle) MainActivity(com.odysee.app.MainActivity) BigDecimal(java.math.BigDecimal) LogPublishTask(com.odysee.app.tasks.lbryinc.LogPublishTask) AccountManager(android.accounts.AccountManager) Claim(com.odysee.app.model.Claim)

Aggregations

Claim (com.odysee.app.model.Claim)3 ClaimResultHandler (com.odysee.app.tasks.claim.ClaimResultHandler)3 Context (android.content.Context)2 Bundle (android.os.Bundle)2 MainActivity (com.odysee.app.MainActivity)2 LogPublishTask (com.odysee.app.tasks.lbryinc.LogPublishTask)2 BigDecimal (java.math.BigDecimal)2 AccountManager (android.accounts.AccountManager)1 Intent (android.content.Intent)1 ChannelCreateUpdateTask (com.odysee.app.tasks.claim.ChannelCreateUpdateTask)1 PublishClaimTask (com.odysee.app.tasks.claim.PublishClaimTask)1 StreamRepostTask (com.odysee.app.tasks.claim.StreamRepostTask)1 JSONException (org.json.JSONException)1