Search in sources :

Example 16 with Claim

use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.

the class ClaimListAdapter method getItemViewType.

@Override
public int getItemViewType(int position) {
    if (items.get(position).isFeatured()) {
        return VIEW_TYPE_FEATURED;
    }
    Claim claim = items.get(position);
    String valueType = items.get(position).getValueType();
    Claim actualClaim = Claim.TYPE_REPOST.equalsIgnoreCase(valueType) ? claim.getRepostedClaim() : claim;
    return Claim.TYPE_CHANNEL.equalsIgnoreCase(actualClaim.getValueType()) ? VIEW_TYPE_CHANNEL : VIEW_TYPE_STREAM;
}
Also used : Claim(com.odysee.app.model.Claim)

Example 17 with Claim

use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.

the class ChannelCommentsFragment method buildPostComment.

private Comment buildPostComment() {
    Comment comment = new Comment();
    Claim channel = (Claim) commentChannelSpinner.getSelectedItem();
    comment.setClaimId(claim.getClaimId());
    comment.setChannelId(channel.getClaimId());
    comment.setChannelName(channel.getName());
    comment.setText(Helper.getValue(inputComment.getText()));
    comment.setPoster(channel);
    if (replyToComment != null) {
        comment.setParentId(replyToComment.getId());
    }
    return comment;
}
Also used : Comment(com.odysee.app.model.Comment) Claim(com.odysee.app.model.Claim)

Example 18 with Claim

use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.

the class ChannelCommentsFragment method setupInlineChannelCreator.

private void setupInlineChannelCreator(View container, TextInputEditText inputChannelName, TextInputEditText inputDeposit, View inlineBalanceView, TextView inlineBalanceValue, View linkCancel, MaterialButton buttonCreate, View progressView, AppCompatSpinner channelSpinner, InlineChannelSpinnerAdapter channelSpinnerAdapter) {
    inputDeposit.setOnFocusChangeListener(new View.OnFocusChangeListener() {

        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            Helper.setViewVisibility(inlineBalanceView, hasFocus ? View.VISIBLE : View.INVISIBLE);
        }
    });
    linkCancel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Helper.setViewText(inputChannelName, null);
            Helper.setViewText(inputDeposit, null);
            Helper.setViewVisibility(container, View.GONE);
        }
    });
    buttonCreate.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            // validate deposit and channel name
            String channelNameString = Helper.normalizeChannelName(Helper.getValue(inputChannelName.getText()));
            Claim claimToSave = new Claim();
            claimToSave.setName(channelNameString);
            String channelName = claimToSave.getName().startsWith("@") ? claimToSave.getName().substring(1) : claimToSave.getName();
            String depositString = Helper.getValue(inputDeposit.getText());
            if ("@".equals(channelName) || Helper.isNullOrEmpty(channelName)) {
                showError(getString(R.string.please_enter_channel_name));
                return;
            }
            if (!LbryUri.isNameValid(channelName)) {
                showError(getString(R.string.channel_name_invalid_characters));
                return;
            }
            if (Helper.channelExists(channelName)) {
                showError(getString(R.string.channel_name_already_created));
                return;
            }
            double depositAmount = 0;
            try {
                depositAmount = Double.valueOf(depositString);
            } catch (NumberFormatException ex) {
                // pass
                showError(getString(R.string.please_enter_valid_deposit));
                return;
            }
            if (depositAmount <= 0.000001) {
                String error = getResources().getQuantityString(R.plurals.min_deposit_required, Math.abs(depositAmount - 1.0) <= 0.000001 ? 1 : 2, String.valueOf(Helper.MIN_DEPOSIT));
                showError(error);
                return;
            }
            if (Lbry.walletBalance == null || Lbry.getAvailableBalance() < depositAmount) {
                showError(getString(R.string.deposit_more_than_balance));
                return;
            }
            ChannelCreateUpdateTask task = new ChannelCreateUpdateTask(claimToSave, new BigDecimal(depositString), false, progressView, Lbryio.AUTH_TOKEN, new ClaimResultHandler() {

                @Override
                public void beforeStart() {
                    Helper.setViewEnabled(inputChannelName, false);
                    Helper.setViewEnabled(inputDeposit, false);
                    Helper.setViewEnabled(buttonCreate, false);
                    Helper.setViewEnabled(linkCancel, false);
                }

                @Override
                public void onSuccess(Claim claimResult) {
                    if (!BuildConfig.DEBUG) {
                        LogPublishTask logPublishTask = new LogPublishTask(claimResult);
                        logPublishTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                    }
                    // 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);
                    // add the claim to the channel list and set it as the selected item
                    if (channelSpinnerAdapter != null) {
                        channelSpinnerAdapter.add(claimResult);
                    }
                    if (channelSpinner != null && channelSpinnerAdapter != null) {
                        channelSpinner.setSelection(channelSpinnerAdapter.getCount() - 1);
                    }
                    Helper.setViewEnabled(inputChannelName, true);
                    Helper.setViewEnabled(inputDeposit, true);
                    Helper.setViewEnabled(buttonCreate, true);
                    Helper.setViewEnabled(linkCancel, true);
                }

                @Override
                public void onError(Exception error) {
                    Helper.setViewEnabled(inputChannelName, true);
                    Helper.setViewEnabled(inputDeposit, true);
                    Helper.setViewEnabled(buttonCreate, true);
                    Helper.setViewEnabled(linkCancel, true);
                    showError(error.getMessage());
                }
            });
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    });
    Helper.setViewText(inlineBalanceValue, Helper.shortCurrencyFormat(Lbry.getAvailableBalance()));
}
Also used : Bundle(android.os.Bundle) NestedScrollView(androidx.core.widget.NestedScrollView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) BigDecimal(java.math.BigDecimal) LogPublishTask(com.odysee.app.tasks.lbryinc.LogPublishTask) Claim(com.odysee.app.model.Claim)

Example 19 with Claim

use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.

the class ClaimListTask method doInBackground.

protected List<Claim> doInBackground(Void... params) {
    List<Claim> claims = null;
    try {
        Map<String, Object> options = new HashMap<>();
        if (types != null && types.size() > 0) {
            options.put("claim_type", types);
        }
        options.put("page", 1);
        options.put("page_size", 999);
        options.put("resolve", true);
        JSONObject result;
        if (!Helper.isNullOrEmpty(authToken)) {
            result = (JSONObject) Lbry.authenticatedGenericApiCall(Lbry.METHOD_CLAIM_LIST, options, authToken);
        } else {
            result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_CLAIM_LIST, options);
        }
        JSONArray items = result.getJSONArray("items");
        claims = new ArrayList<>();
        for (int i = 0; i < items.length(); i++) {
            claims.add(Claim.fromJSONObject(items.getJSONObject(i)));
        }
    } catch (ApiCallException | JSONException ex) {
        error = ex;
    }
    return claims;
}
Also used : HashMap(java.util.HashMap) ApiCallException(com.odysee.app.exceptions.ApiCallException) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) Claim(com.odysee.app.model.Claim)

Example 20 with Claim

use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.

the class ClaimRewardTask method fetchSingleClaimTxid.

private String fetchSingleClaimTxid(String claimType) throws ApiCallException, JSONException {
    Map<String, Object> options = new HashMap<>();
    options.put("claim_type", claimType);
    options.put("page", 1);
    options.put("page_size", 1);
    options.put("resolve", true);
    JSONObject result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_CLAIM_LIST, options);
    JSONArray items = result.getJSONArray("items");
    if (items.length() > 0) {
        Claim claim = Claim.fromJSONObject(items.getJSONObject(0));
        return claim.getTxid();
    }
    return null;
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) JSONArray(org.json.JSONArray) JSONObject(org.json.JSONObject) Claim(com.odysee.app.model.Claim)

Aggregations

Claim (com.odysee.app.model.Claim)133 Context (android.content.Context)51 MainActivity (com.odysee.app.MainActivity)44 JSONException (org.json.JSONException)42 View (android.view.View)41 TextView (android.widget.TextView)37 RecyclerView (androidx.recyclerview.widget.RecyclerView)36 ApiCallException (com.odysee.app.exceptions.ApiCallException)36 ArrayList (java.util.ArrayList)32 ImageView (android.widget.ImageView)31 AdapterView (android.widget.AdapterView)29 NestedScrollView (androidx.core.widget.NestedScrollView)28 ClaimListResultHandler (com.odysee.app.tasks.claim.ClaimListResultHandler)26 JSONObject (org.json.JSONObject)26 ExecutionException (java.util.concurrent.ExecutionException)25 TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)24 LbryUriException (com.odysee.app.exceptions.LbryUriException)24 SolidIconView (com.odysee.app.ui.controls.SolidIconView)24 WebView (android.webkit.WebView)23 PhotoView (com.github.chrisbanes.photoview.PhotoView)23