Search in sources :

Example 86 with Claim

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

the class ChannelPlaylistsFragment method fetchClaimSearchPlaylists.

private void fetchClaimSearchPlaylists(boolean reset) {
    if (reset && playlistsListAdapter != null) {
        playlistsListAdapter.clearItems();
        currentClaimSearchPage = 1;
    }
    playlistsClaimSearchLoading = true;
    Helper.setViewVisibility(noPlaylistsView, View.GONE);
    Map<String, Object> claimSearchOptions = buildPlaylistsOptions();
    // channel claim
    ClaimSearchTask playlistsClaimSearchTask = new ClaimSearchTask(claimSearchOptions, Lbry.API_CONNECTION_STRING, getLoadingView(), new ClaimSearchResultHandler() {

        @Override
        public void onSuccess(List<Claim> claims, boolean hasReachedEnd) {
            claims = Helper.filterClaimsByOutpoint(claims);
            if (playlistsListAdapter == null) {
                Context context = getContext();
                if (context != null) {
                    playlistsListAdapter = new ClaimListAdapter(claims, context);
                    playlistsListAdapter.setListener(new ClaimListAdapter.ClaimListItemListener() {

                        @Override
                        public void onClaimClicked(Claim claim, int position) {
                            Context context = getContext();
                            if (context instanceof MainActivity) {
                                MainActivity activity = (MainActivity) context;
                                activity.openFileClaim(claim);
                            }
                        }
                    });
                }
            } else {
                playlistsListAdapter.addItems(claims);
            }
            if (playlistsList != null && playlistsList.getAdapter() == null) {
                playlistsList.setAdapter(playlistsListAdapter);
            }
            playlistsHasReachedEnd = hasReachedEnd;
            playlistsClaimSearchLoading = false;
            checkNoPlaylists();
        }

        @Override
        public void onError(Exception error) {
            playlistsClaimSearchLoading = false;
            checkNoPlaylists();
        }
    });
    playlistsClaimSearchTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : Context(android.content.Context) MainActivity(com.odysee.app.MainActivity) ClaimListAdapter(com.odysee.app.adapter.ClaimListAdapter) ClaimSearchTask(com.odysee.app.tasks.claim.ClaimSearchTask) ClaimSearchResultHandler(com.odysee.app.tasks.claim.ClaimSearchResultHandler) Claim(com.odysee.app.model.Claim)

Example 87 with Claim

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

the class AllContentFragment method fetchClaimSearchContent.

public 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);
            if (contentListAdapter == null) {
                Context context = getContext();
                if (context != null) {
                    contentListAdapter = new ClaimListAdapter(claims, context);
                    contentListAdapter.setContextGroupId(ALL_CONTENT_CONTEXT_GROUP_ID);
                    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();
        }

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

Example 88 with Claim

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

the class AllContentFragment method onContextItemSelected.

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (item.getGroupId() == ALL_CONTENT_CONTEXT_GROUP_ID && item.getItemId() == R.id.action_block) {
        if (contentListAdapter != null) {
            int position = contentListAdapter.getPosition();
            Claim claim = contentListAdapter.getItems().get(position);
            if (claim != null && claim.getSigningChannel() != null) {
                Claim channel = claim.getSigningChannel();
                Context context = getContext();
                if (context instanceof MainActivity) {
                    ((MainActivity) context).handleBlockChannel(channel);
                }
            }
        }
        return true;
    }
    if (item.getGroupId() == ALL_CONTENT_CONTEXT_GROUP_ID) {
        if (contentListAdapter != null) {
            int position = contentListAdapter.getPosition();
            Claim claim = contentListAdapter.getItems().get(position);
            String url = claim.getPermanentUrl();
            Context context = getContext();
            if (context instanceof MainActivity) {
                MainActivity activity = (MainActivity) context;
                if (item.getItemId() == R.id.action_add_to_watch_later) {
                    activity.handleAddUrlToList(url, OdyseeCollection.BUILT_IN_ID_WATCHLATER);
                } else if (item.getItemId() == R.id.action_add_to_favorites) {
                    activity.handleAddUrlToList(url, OdyseeCollection.BUILT_IN_ID_FAVORITES);
                } else if (item.getItemId() == R.id.action_add_to_lists) {
                    activity.handleAddUrlToList(url, null);
                }
            }
        }
    }
    return super.onContextItemSelected(item);
}
Also used : Context(android.content.Context) MainActivity(com.odysee.app.MainActivity) Claim(com.odysee.app.model.Claim)

Example 89 with Claim

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

the class PurchaseListTask method doInBackground.

protected List<Claim> doInBackground(Void... params) {
    List<Claim> claims = null;
    try {
        Map<String, Object> options = new HashMap<>();
        if (!Helper.isNullOrEmpty(claimId)) {
            options.put("claim_id", claimId);
        }
        if (page > 0) {
            options.put("page", page);
        }
        if (pageSize > 0) {
            options.put("page_size", pageSize);
        }
        options.put("resolve", true);
        JSONObject result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_PURCHASE_LIST, options);
        JSONArray items = result.getJSONArray("items");
        claims = new ArrayList<>();
        for (int i = 0; i < items.length(); i++) {
            Claim claim = Claim.fromJSONObject(items.getJSONObject(i).getJSONObject("claim"));
            if (!Helper.isNullOrEmpty(claim.getClaimId())) {
                claims.add(claim);
                Lbry.addClaimToCache(claim);
            }
        }
    } catch (ApiCallException | JSONException | ClassCastException 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 90 with Claim

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

the class StreamRepostTask method doInBackground.

protected Claim doInBackground(Void... params) {
    Claim claimResult = null;
    try {
        Map<String, Object> options = new HashMap<>();
        options.put("name", name);
        options.put("bid", new DecimalFormat(Helper.SDK_AMOUNT_FORMAT, new DecimalFormatSymbols(Locale.US)).format(bid.doubleValue()));
        options.put("claim_id", claimId);
        options.put("channel_id", channelId);
        JSONObject result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_STREAM_REPOST, options);
        if (result.has("outputs")) {
            JSONArray outputs = result.getJSONArray("outputs");
            for (int i = 0; i < outputs.length(); i++) {
                JSONObject output = outputs.getJSONObject(i);
                if (output.has("claim_id") && output.has("claim_op")) {
                    claimResult = Claim.claimFromOutput(output);
                    break;
                }
            }
        }
    } catch (ApiCallException | ClassCastException | JSONException ex) {
        error = ex;
    }
    return claimResult;
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) HashMap(java.util.HashMap) ApiCallException(com.odysee.app.exceptions.ApiCallException) DecimalFormat(java.text.DecimalFormat) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) 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