Search in sources :

Example 16 with ClaimListResultHandler

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

the class FirstRunActivity method checkChannelStep.

private void checkChannelStep() {
    ClaimListTask task = new ClaimListTask(Claim.TYPE_CHANNEL, null, Lbryio.AUTH_TOKEN, new ClaimListResultHandler() {

        @Override
        public void onSuccess(List<Claim> claims) {
            onRequestInProgress(false);
            if (claims.size() == 0) {
                // no channels, move to first run step: channel
                checkEmailVerifiedRewardForChannelStep();
            } else {
                // this user already has a channel, move to the final step: rewards verification
                proceedToRewardsStep();
            }
        }

        @Override
        public void onError(Exception error) {
            checkEmailVerifiedRewardForChannelStep();
        // onRequestCompleted(FIRST_RUN_STEP_CHANNEL);
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : ClaimListResultHandler(com.odysee.app.tasks.claim.ClaimListResultHandler) ClaimListTask(com.odysee.app.tasks.claim.ClaimListTask) Claim(com.odysee.app.model.Claim) LbryioRequestException(com.odysee.app.exceptions.LbryioRequestException) LbryioResponseException(com.odysee.app.exceptions.LbryioResponseException) ApiCallException(com.odysee.app.exceptions.ApiCallException) IOException(java.io.IOException)

Example 17 with ClaimListResultHandler

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

the class SearchFragment method resolveFeaturedItem.

private void resolveFeaturedItem(String vanityUrl) {
    final ClaimCacheKey key = new ClaimCacheKey();
    key.setUrl(vanityUrl);
    if (Lbry.claimCache.containsKey(key)) {
        Claim cachedClaim = Lbry.claimCache.get(key);
        updateFeaturedItemFromResolvedClaim(cachedClaim);
        return;
    }
    ResolveTask task = new ResolveTask(vanityUrl, Lbry.API_CONNECTION_STRING, null, new ClaimListResultHandler() {

        @Override
        public void onSuccess(List<Claim> claims) {
            if (claims.size() > 0 && !Helper.isNullOrEmpty(claims.get(0).getClaimId())) {
                Claim resolved = claims.get(0);
                Lbry.claimCache.put(key, resolved);
                updateFeaturedItemFromResolvedClaim(resolved);
            }
        }

        @Override
        public void onError(Exception error) {
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : ClaimListResultHandler(com.odysee.app.tasks.claim.ClaimListResultHandler) ClaimCacheKey(com.odysee.app.model.ClaimCacheKey) Claim(com.odysee.app.model.Claim) JSONException(org.json.JSONException) ResolveTask(com.odysee.app.tasks.claim.ResolveTask)

Example 18 with ClaimListResultHandler

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

the class LibraryFragment method fetchOwnClaimsAndShowDownloads.

private void fetchOwnClaimsAndShowDownloads() {
    if (Lbry.ownClaims != null && Lbry.ownClaims.size() > 0) {
        initialOwnClaimsFetched = true;
        fetchDownloads();
        return;
    }
    linkStats.setVisibility(View.INVISIBLE);
    ClaimListTask task = new ClaimListTask(Arrays.asList(Claim.TYPE_STREAM, Claim.TYPE_REPOST), listLoading, new ClaimListResultHandler() {

        @Override
        public void onSuccess(List<Claim> claims) {
            Lbry.ownClaims = Helper.filterDeletedClaims(new ArrayList<>(claims));
            initialOwnClaimsFetched = true;
            if (currentFilter == FILTER_DOWNLOADS) {
                fetchDownloads();
            }
            checkStatsLink();
        }

        @Override
        public void onError(Exception error) {
            initialOwnClaimsFetched = true;
            checkStatsLink();
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : ClaimListResultHandler(com.odysee.app.tasks.claim.ClaimListResultHandler) ClaimListTask(com.odysee.app.tasks.claim.ClaimListTask) Claim(com.odysee.app.model.Claim) JSONException(org.json.JSONException) ApiCallException(com.odysee.app.exceptions.ApiCallException)

Example 19 with ClaimListResultHandler

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

the class PlaylistFragment method onPlaylistLoaded.

private void onPlaylistLoaded(OdyseeCollection collection) {
    currentCollection = collection;
    if (visibilityIcon != null) {
        visibilityIcon.setImageResource(collection.getVisibility() == OdyseeCollection.VISIBILITY_PRIVATE ? R.drawable.ic_private : R.drawable.ic_public);
    }
    Helper.setViewText(textTitle, collection.getName());
    Helper.setViewText(textVideoCount, getResources().getQuantityString(R.plurals.video_count, collection.getItems().size(), collection.getItems().size()));
    // load the claims
    ResolveTask task = new ResolveTask(collection.getItems(), Lbry.API_CONNECTION_STRING, playlistItemsLoading, new ClaimListResultHandler() {

        @Override
        public void onSuccess(List<Claim> claims) {
            // reorder the claims based on the order in the playlist collection, TODO: find a more efficient way to do this
            Map<String, Claim> playlistClaimMap = new LinkedHashMap<>();
            List<String> claimIds = new ArrayList<>();
            List<String> collectionItems = collection.getItems();
            for (int i = 0; i < collectionItems.size(); i++) {
                LbryUri url = LbryUri.tryParse(collectionItems.get(i));
                if (url != null) {
                    claimIds.add(url.getClaimId());
                }
            }
            for (String id : claimIds) {
                for (Claim claim : claims) {
                    if (id.equalsIgnoreCase(claim.getClaimId())) {
                        playlistClaimMap.put(id, claim);
                        break;
                    }
                }
            }
            collection.setClaims(new ArrayList<>(playlistClaimMap.values()));
            adapter = new ClaimListAdapter(collection.getClaims(), ClaimListAdapter.STYLE_SMALL_LIST, getContext());
            adapter.setListener(new ClaimListAdapter.ClaimListItemListener() {

                @Override
                public void onClaimClicked(Claim claim, int position) {
                    Context context = getContext();
                    if (context instanceof MainActivity) {
                        ((MainActivity) context).openPrivatePlaylist(collection, claim, position);
                    }
                }
            });
            if (playlistList != null) {
                playlistList.setAdapter(adapter);
            }
        }

        @Override
        public void onError(Exception error) {
            // pass
            Context context = getContext();
            if (context instanceof MainActivity) {
                ((MainActivity) context).showError(getString(R.string.could_not_load_playlist));
            }
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : Context(android.content.Context) ClaimListResultHandler(com.odysee.app.tasks.claim.ClaimListResultHandler) ArrayList(java.util.ArrayList) MainActivity(com.odysee.app.MainActivity) ClaimListAdapter(com.odysee.app.adapter.ClaimListAdapter) SQLiteException(android.database.sqlite.SQLiteException) ArrayList(java.util.ArrayList) List(java.util.List) LbryUri(com.odysee.app.utils.LbryUri) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Claim(com.odysee.app.model.Claim) ResolveTask(com.odysee.app.tasks.claim.ResolveTask)

Example 20 with ClaimListResultHandler

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

the class PublishFormFragment method fetchChannels.

private void fetchChannels() {
    if (Lbry.ownChannels != null && Lbry.ownChannels.size() > 0) {
        updateChannelList(Lbry.ownChannels);
        return;
    }
    fetchingChannels = true;
    disableChannelSpinner();
    ClaimListTask task = new ClaimListTask(Claim.TYPE_CHANNEL, progressLoadingChannels, new ClaimListResultHandler() {

        @Override
        public void onSuccess(List<Claim> claims) {
            Lbry.ownChannels = new ArrayList<>(claims);
            updateChannelList(Lbry.ownChannels);
            enableChannelSpinner();
            fetchingChannels = false;
        }

        @Override
        public void onError(Exception error) {
            enableChannelSpinner();
            fetchingChannels = false;
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : ClaimListResultHandler(com.odysee.app.tasks.claim.ClaimListResultHandler) ClaimListTask(com.odysee.app.tasks.claim.ClaimListTask) Claim(com.odysee.app.model.Claim) JSONException(org.json.JSONException)

Aggregations

Claim (com.odysee.app.model.Claim)20 ClaimListResultHandler (com.odysee.app.tasks.claim.ClaimListResultHandler)20 JSONException (org.json.JSONException)12 ApiCallException (com.odysee.app.exceptions.ApiCallException)11 ClaimListTask (com.odysee.app.tasks.claim.ClaimListTask)11 LbryUriException (com.odysee.app.exceptions.LbryUriException)9 ResolveTask (com.odysee.app.tasks.claim.ResolveTask)9 LbryioRequestException (com.odysee.app.exceptions.LbryioRequestException)8 LbryioResponseException (com.odysee.app.exceptions.LbryioResponseException)8 ExecutionException (java.util.concurrent.ExecutionException)8 ArrayList (java.util.ArrayList)7 Context (android.content.Context)5 SQLiteException (android.database.sqlite.SQLiteException)5 MainActivity (com.odysee.app.MainActivity)5 AuthTokenInvalidatedException (com.odysee.app.exceptions.AuthTokenInvalidatedException)4 IOException (java.io.IOException)4 ParseException (java.text.ParseException)4 TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)3 ClaimListAdapter (com.odysee.app.adapter.ClaimListAdapter)3 LbryRequestException (com.odysee.app.exceptions.LbryRequestException)3