Search in sources :

Example 51 with Claim

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

the class ChannelCommentsFragment method validateAndCheckPostComment.

private void validateAndCheckPostComment() {
    String comment = Helper.getValue(inputComment.getText());
    Claim channel = (Claim) commentChannelSpinner.getSelectedItem();
    if (Helper.isNullOrEmpty(comment)) {
        showError(getString(R.string.please_enter_comment));
        return;
    }
    if (channel == null || Helper.isNullOrEmpty(channel.getClaimId())) {
        showError(getString(R.string.please_select_channel));
        return;
    }
    postComment();
}
Also used : Claim(com.odysee.app.model.Claim)

Example 52 with Claim

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

the class ChannelCreateDialogFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.channel_form_bottom_sheet, container, false);
    View balanceView = v.findViewById(R.id.channel_form_balanceview);
    TextInputEditText inputDeposit = v.findViewById(R.id.inline_channel_form_input_deposit);
    inputDeposit.setOnFocusChangeListener(new View.OnFocusChangeListener() {

        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            Helper.setViewVisibility(balanceView, hasFocus ? View.VISIBLE : View.INVISIBLE);
        }
    });
    TextInputEditText inputChannelName = v.findViewById(R.id.inline_channel_form_input_name);
    TextView linkCancel = v.findViewById(R.id.inline_channel_form_cancel_link);
    linkCancel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            inputChannelName.setText("");
            inputDeposit.setText(R.string.min_deposit);
            dismiss();
        }
    });
    View progressView = v.findViewById(R.id.inline_channel_form_create_progress);
    Button createButton = v.findViewById(R.id.inline_channel_form_create_button);
    createButton.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;
            try {
                depositAmount = Double.parseDouble(depositString);
            } catch (NumberFormatException ex) {
                // pass
                showError(getString(R.string.please_enter_valid_deposit));
                return;
            }
            if (depositAmount == 0) {
                String error = getResources().getQuantityString(R.plurals.min_deposit_required, depositAmount == 1 ? 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;
            }
            AccountManager am = AccountManager.get(getContext());
            String authToken = am.peekAuthToken(Helper.getOdyseeAccount(am.getAccounts()), "auth_token_type");
            MainActivity activity = (MainActivity) getActivity();
            enableViews(inputChannelName, inputDeposit, createButton, linkCancel, false);
            Helper.setViewVisibility(progressView, View.VISIBLE);
            Callable<Claim> c = new ChannelCreateUpdate(claimToSave, new BigDecimal(depositString), false, authToken);
            ExecutorService executor = Executors.newSingleThreadExecutor();
            Future<Claim> future = executor.submit(c);
            Thread t = new Thread(new Runnable() {

                @Override
                public void run() {
                    try {
                        Claim result = future.get();
                        if (result != null) {
                            if (!BuildConfig.DEBUG) {
                                LogPublishTask logPublishTask = new LogPublishTask(result);
                                logPublishTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                            }
                            // channel created
                            Bundle bundle = new Bundle();
                            bundle.putString("claim_id", result.getClaimId());
                            bundle.putString("claim_name", result.getName());
                            LbryAnalytics.logEvent(LbryAnalytics.EVENT_CHANNEL_CREATE, bundle);
                            if (activity != null) {
                                activity.runOnUiThread(new Runnable() {

                                    @Override
                                    public void run() {
                                        if (listener != null) {
                                            listener.onChannelCreated(result);
                                        }
                                    }
                                });
                            }
                        }
                    } catch (ExecutionException ex) {
                        Throwable cause = ex.getCause();
                        if (cause instanceof ApiCallException) {
                            showError(cause.getMessage());
                        }
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    } finally {
                        if (activity != null) {
                            activity.runOnUiThread(new Runnable() {

                                @Override
                                public void run() {
                                    Helper.setViewVisibility(progressView, View.GONE);
                                    enableViews(inputChannelName, inputDeposit, createButton, linkCancel, true);
                                    dismiss();
                                }
                            });
                        }
                    }
                }
            });
            t.start();
        }
    });
    Helper.setViewText((TextView) balanceView, Helper.shortCurrencyFormat(Lbry.getAvailableBalance()));
    return v;
}
Also used : MainActivity(com.odysee.app.MainActivity) Callable(java.util.concurrent.Callable) Button(android.widget.Button) LogPublishTask(com.odysee.app.tasks.lbryinc.LogPublishTask) TextView(android.widget.TextView) ExecutionException(java.util.concurrent.ExecutionException) ChannelCreateUpdate(com.odysee.app.callable.ChannelCreateUpdate) ApiCallException(com.odysee.app.exceptions.ApiCallException) Bundle(android.os.Bundle) View(android.view.View) TextView(android.widget.TextView) BigDecimal(java.math.BigDecimal) ApiCallException(com.odysee.app.exceptions.ApiCallException) ExecutionException(java.util.concurrent.ExecutionException) ExecutorService(java.util.concurrent.ExecutorService) TextInputEditText(com.google.android.material.textfield.TextInputEditText) Future(java.util.concurrent.Future) AccountManager(android.accounts.AccountManager) Claim(com.odysee.app.model.Claim)

Example 53 with Claim

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

the class FileViewFragment method checkRewardsDriver.

private void checkRewardsDriver() {
    Context ctx = getContext();
    Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
    if (ctx != null && actualClaim != null && !actualClaim.isFree() && actualClaim.getFile() == null) {
        String rewardsDriverText = getString(R.string.earn_some_credits_to_access);
        checkRewardsDriverCard(rewardsDriverText, actualClaim.getActualCost(Lbryio.LBCUSDRate).doubleValue());
    }
}
Also used : AttributeProviderContext(org.commonmark.renderer.html.AttributeProviderContext) Context(android.content.Context) Claim(com.odysee.app.model.Claim)

Example 54 with Claim

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

the class FollowingFragment method fetchClaimSearchContent.

private void fetchClaimSearchContent(boolean reset) {
    if (reset && contentListAdapter != null) {
        contentListAdapter.clearItems();
        currentClaimSearchPage = 1;
    }
    contentClaimSearchLoading = true;
    Helper.setViewVisibility(noContentView, View.GONE);
    Map<String, Object> claimSearchOptions = buildContentOptions();
    contentClaimSearchTask = new ClaimSearchTask(claimSearchOptions, Lbry.API_CONNECTION_STRING, getLoadingView(), new ClaimSearchResultHandler() {

        @Override
        public void onSuccess(List<Claim> claims, boolean hasReachedEnd) {
            claims = Helper.filterClaimsByOutpoint(claims);
            claims = Helper.filterClaimsByBlockedChannels(claims, Lbryio.blockedChannels);
            Date d = new Date();
            Calendar cal = new GregorianCalendar();
            cal.setTime(d);
            // Remove claims with a release time in the future
            claims.removeIf(e -> {
                Claim.GenericMetadata metadata = e.getValue();
                return metadata instanceof Claim.StreamMetadata && (((Claim.StreamMetadata) metadata).getReleaseTime()) > (cal.getTimeInMillis() / 1000L);
            });
            // Sort claims so those which are livestreaming now are shwon on the top of the list
            Collections.sort(claims, new Comparator<Claim>() {

                @Override
                public int compare(Claim claim, Claim t1) {
                    if (claim.isLive() && !t1.isLive())
                        return -1;
                    else if (!claim.isLive() && t1.isLive())
                        return 1;
                    else
                        return 0;
                }
            });
            if (contentListAdapter == null) {
                Context context = getContext();
                if (context != null) {
                    contentListAdapter = new ClaimListAdapter(claims, context);
                    contentListAdapter.setListener(new ClaimListAdapter.ClaimListItemListener() {

                        @Override
                        public void onClaimClicked(Claim claim, int position) {
                            Context context = getContext();
                            if (context instanceof MainActivity) {
                                MainActivity activity = (MainActivity) context;
                                if (claim.getName().startsWith("@")) {
                                    // channel claim
                                    activity.openChannelClaim(claim);
                                } else {
                                    activity.openFileClaim(claim);
                                }
                            }
                        }
                    });
                }
            } else {
                contentListAdapter.addItems(claims);
            }
            if (contentList != null && contentList.getAdapter() == null) {
                contentList.setAdapter(contentListAdapter);
            }
            contentHasReachedEnd = hasReachedEnd;
            contentClaimSearchLoading = false;
            checkNoContent(false);
        }

        @Override
        public void onError(Exception error) {
            contentClaimSearchLoading = false;
            checkNoContent(false);
        }
    });
    contentClaimSearchTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : Context(android.content.Context) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) MainActivity(com.odysee.app.MainActivity) ClaimListAdapter(com.odysee.app.adapter.ClaimListAdapter) Date(java.util.Date) JSONException(org.json.JSONException) LbryUriException(com.odysee.app.exceptions.LbryUriException) ClaimSearchTask(com.odysee.app.tasks.claim.ClaimSearchTask) ClaimSearchResultHandler(com.odysee.app.tasks.claim.ClaimSearchResultHandler) JSONObject(org.json.JSONObject) List(java.util.List) ArrayList(java.util.ArrayList) Claim(com.odysee.app.model.Claim)

Example 55 with Claim

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

the class FollowingFragment method fetchAndResolveChannelList.

private void fetchAndResolveChannelList() {
    buildChannelIdsAndUrls();
    if (!channelIds.isEmpty()) {
        ResolveTask resolveSubscribedTask = new ResolveTask(channelUrls, Lbry.API_CONNECTION_STRING, channelListLoading, new ClaimListResultHandler() {

            @Override
            public void onSuccess(List<Claim> claims) {
                updateChannelFilterListAdapter(claims, true);
                Lbryio.cacheResolvedSubscriptions = claims;
            }

            @Override
            public void onError(Exception error) {
                handler.postDelayed(FollowingFragment.this::fetchAndResolveChannelList, 5_000);
            }
        });
        resolveSubscribedTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        fetchClaimSearchContent();
    }
}
Also used : ClaimListResultHandler(com.odysee.app.tasks.claim.ClaimListResultHandler) Claim(com.odysee.app.model.Claim) JSONException(org.json.JSONException) LbryUriException(com.odysee.app.exceptions.LbryUriException) ResolveTask(com.odysee.app.tasks.claim.ResolveTask)

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