Search in sources :

Example 1 with ClaimSearchResultHandler

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

the class FileViewFragment method checkAndConfirmPurchaseUrl.

private void checkAndConfirmPurchaseUrl() {
    Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
    if (actualClaim != null) {
        PurchaseListTask task = new PurchaseListTask(actualClaim.getClaimId(), null, new ClaimSearchResultHandler() {

            @Override
            public void onSuccess(List<Claim> claims, boolean hasReachedEnd) {
                boolean purchased = false;
                if (claims.size() == 1) {
                    Claim purchasedClaim = claims.get(0);
                    if (actualClaim.getClaimId().equalsIgnoreCase(purchasedClaim.getClaimId())) {
                        // already purchased
                        purchased = true;
                    }
                }
                if (purchased) {
                    handleMainActionForClaim();
                } else {
                    restoreMainActionButton();
                    confirmPurchaseUrl();
                }
            }

            @Override
            public void onError(Exception error) {
                // pass
                restoreMainActionButton();
            }
        });
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }
}
Also used : ClaimSearchResultHandler(com.odysee.app.tasks.claim.ClaimSearchResultHandler) TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) Claim(com.odysee.app.model.Claim) 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) PurchaseListTask(com.odysee.app.tasks.claim.PurchaseListTask)

Example 2 with ClaimSearchResultHandler

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

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

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

the class LibraryFragment method fetchPurchases.

private void fetchPurchases() {
    contentListLoading = true;
    Helper.setViewVisibility(linkStats, View.GONE);
    Helper.setViewVisibility(layoutListEmpty, View.GONE);
    PurchaseListTask task = new PurchaseListTask(currentPage, PAGE_SIZE, listLoading, new ClaimSearchResultHandler() {

        @Override
        public void onSuccess(List<Claim> claims, boolean hasReachedEnd) {
            listReachedEnd = hasReachedEnd;
            if (contentListAdapter == null) {
                initContentListAdapter(claims);
            } else {
                contentListAdapter.addItems(claims);
            }
            if (contentListAdapter != null && contentList.getAdapter() == null) {
                contentList.setAdapter(contentListAdapter);
            }
            checkListEmpty();
            contentListLoading = false;
        }

        @Override
        public void onError(Exception error) {
            checkStatsLink();
            checkListEmpty();
            contentListLoading = false;
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : ClaimSearchResultHandler(com.odysee.app.tasks.claim.ClaimSearchResultHandler) Claim(com.odysee.app.model.Claim) JSONException(org.json.JSONException) ApiCallException(com.odysee.app.exceptions.ApiCallException) PurchaseListTask(com.odysee.app.tasks.claim.PurchaseListTask)

Example 5 with ClaimSearchResultHandler

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

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