Search in sources :

Example 1 with ClaimSearchTask

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

the class FileViewFragment method resolvePlaylistClaimsAndPlayFirst.

private void resolvePlaylistClaimsAndPlayFirst() {
    if (playlistResolved) {
        return;
    }
    Helper.setViewVisibility(layoutLoadingState, View.VISIBLE);
    Helper.setViewVisibility(layoutResolving, View.VISIBLE);
    Helper.setViewVisibility(layoutNothingAtLocation, View.GONE);
    Helper.setViewVisibility(layoutDisplayArea, View.GONE);
    Map<String, Object> options = new HashMap<>();
    options.put("claim_type", "stream");
    options.put("page", 1);
    options.put("page_size", 999);
    options.put("claim_ids", fileClaim.getClaimIds());
    ClaimSearchTask task = new ClaimSearchTask(options, Lbry.API_CONNECTION_STRING, null, new ClaimSearchResultHandler() {

        @Override
        public void onSuccess(List<Claim> claims, boolean hasReachedEnd) {
            playlistResolved = true;
            // reorder the claims based on the order in the list, TODO: find a more efficient way to do this
            Map<String, Claim> playlistClaimMap = new LinkedHashMap<>();
            List<String> claimIds = fileClaim.getClaimIds();
            for (String id : claimIds) {
                for (Claim claim : claims) {
                    if (id.equalsIgnoreCase(claim.getClaimId())) {
                        playlistClaimMap.put(id, claim);
                        break;
                    }
                }
            }
            playlistClaims = new ArrayList<>(playlistClaimMap.values());
            if (playlistClaims.size() > 0) {
                playClaimFromCollection(playlistClaims.get(0), 0);
            }
            relatedContentAdapter = new ClaimListAdapter(playlistClaims, getContext());
            relatedContentAdapter.setListener(FileViewFragment.this);
            View root = getView();
            if (root != null) {
                RecyclerView relatedContentList = root.findViewById(R.id.file_view_related_content_list);
                relatedContentList.setAdapter(relatedContentAdapter);
            }
        }

        @Override
        public void onError(Exception error) {
            showError(getString(R.string.comment_error));
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ClaimListAdapter(com.odysee.app.adapter.ClaimListAdapter) SolidIconView(com.odysee.app.ui.controls.SolidIconView) PlayerView(com.google.android.exoplayer2.ui.PlayerView) NestedScrollView(androidx.core.widget.NestedScrollView) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) PhotoView(com.github.chrisbanes.photoview.PhotoView) ImageView(android.widget.ImageView) View(android.view.View) WebView(android.webkit.WebView) TextView(android.widget.TextView) LbryRequestException(com.odysee.app.exceptions.LbryRequestException) JSONException(org.json.JSONException) LbryUriException(com.odysee.app.exceptions.LbryUriException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) LbryResponseException(com.odysee.app.exceptions.LbryResponseException) LbryioRequestException(com.odysee.app.exceptions.LbryioRequestException) LbryioResponseException(com.odysee.app.exceptions.LbryioResponseException) ApiCallException(com.odysee.app.exceptions.ApiCallException) 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) RecyclerView(androidx.recyclerview.widget.RecyclerView) TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Claim(com.odysee.app.model.Claim)

Example 2 with ClaimSearchTask

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

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

the class ChannelContentFragment 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);
            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();
        }

        @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 4 with ClaimSearchTask

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

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

Aggregations

ClaimSearchResultHandler (com.odysee.app.tasks.claim.ClaimSearchResultHandler)6 ClaimSearchTask (com.odysee.app.tasks.claim.ClaimSearchTask)6 ClaimListAdapter (com.odysee.app.adapter.ClaimListAdapter)5 Claim (com.odysee.app.model.Claim)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 JSONException (org.json.JSONException)5 Context (android.content.Context)4 MainActivity (com.odysee.app.MainActivity)4 JSONObject (org.json.JSONObject)4 LbryUriException (com.odysee.app.exceptions.LbryUriException)3 View (android.view.View)1 WebView (android.webkit.WebView)1 AdapterView (android.widget.AdapterView)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 NestedScrollView (androidx.core.widget.NestedScrollView)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 PhotoView (com.github.chrisbanes.photoview.PhotoView)1 TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)1