Search in sources :

Example 6 with ClaimSearchResultHandler

use of com.odysee.app.tasks.claim.ClaimSearchResultHandler 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 7 with ClaimSearchResultHandler

use of com.odysee.app.tasks.claim.ClaimSearchResultHandler 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 8 with ClaimSearchResultHandler

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

the class FollowingFragment method fetchSuggestedChannels.

private void fetchSuggestedChannels() {
    if (suggestedClaimSearchLoading) {
        return;
    }
    suggestedClaimSearchLoading = true;
    if (discoverDialog != null) {
        discoverDialog.setLoading(true);
    }
    Helper.setViewVisibility(noContentView, View.GONE);
    suggestedChannelClaimSearchTask = new ClaimSearchTask(buildSuggestedOptions(), Lbry.API_CONNECTION_STRING, suggestedChannelAdapter == null || suggestedChannelAdapter.getItemCount() == 0 ? bigContentLoading : contentLoading, new ClaimSearchResultHandler() {

        @Override
        public void onSuccess(List<Claim> claims, boolean hasReachedEnd) {
            suggestedHasReachedEnd = hasReachedEnd;
            suggestedClaimSearchLoading = false;
            if (discoverDialog != null) {
                discoverDialog.setLoading(false);
            }
            if (suggestedChannelAdapter == null) {
                suggestedChannelAdapter = new SuggestedChannelGridAdapter(claims, getContext());
                suggestedChannelAdapter.setListener(FollowingFragment.this);
                if (suggestedChannelGrid != null) {
                    suggestedChannelGrid.setAdapter(suggestedChannelAdapter);
                }
                if (discoverDialog != null) {
                    discoverDialog.setAdapter(suggestedChannelAdapter);
                }
            } else {
                suggestedChannelAdapter.addClaims(claims);
            }
            if (discoverDialog == null || !discoverDialog.isVisible()) {
                checkNoContent(true);
            }
        }

        @Override
        public void onError(Exception error) {
            suggestedClaimSearchLoading = false;
            if (discoverDialog != null) {
                discoverDialog.setLoading(false);
            }
            if (discoverDialog == null || !discoverDialog.isVisible()) {
                checkNoContent(true);
            }
        }
    });
    suggestedChannelClaimSearchTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : ClaimSearchTask(com.odysee.app.tasks.claim.ClaimSearchTask) ClaimSearchResultHandler(com.odysee.app.tasks.claim.ClaimSearchResultHandler) SuggestedChannelGridAdapter(com.odysee.app.adapter.SuggestedChannelGridAdapter) List(java.util.List) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) LbryUriException(com.odysee.app.exceptions.LbryUriException)

Aggregations

ClaimSearchResultHandler (com.odysee.app.tasks.claim.ClaimSearchResultHandler)8 Claim (com.odysee.app.model.Claim)7 JSONException (org.json.JSONException)7 ClaimSearchTask (com.odysee.app.tasks.claim.ClaimSearchTask)6 ClaimListAdapter (com.odysee.app.adapter.ClaimListAdapter)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Context (android.content.Context)4 MainActivity (com.odysee.app.MainActivity)4 LbryUriException (com.odysee.app.exceptions.LbryUriException)4 JSONObject (org.json.JSONObject)4 ApiCallException (com.odysee.app.exceptions.ApiCallException)3 TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)2 LbryRequestException (com.odysee.app.exceptions.LbryRequestException)2 LbryResponseException (com.odysee.app.exceptions.LbryResponseException)2 LbryioRequestException (com.odysee.app.exceptions.LbryioRequestException)2 LbryioResponseException (com.odysee.app.exceptions.LbryioResponseException)2 PurchaseListTask (com.odysee.app.tasks.claim.PurchaseListTask)2 IOException (java.io.IOException)2 ExecutionException (java.util.concurrent.ExecutionException)2