Search in sources :

Example 6 with ResolveTask

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

the class MainActivity method resolveUrlSuggestions.

private void resolveUrlSuggestions(List<String> urls) {
    ResolveTask task = new ResolveTask(urls, Lbry.API_CONNECTION_STRING, null, new ClaimListResultHandler() {

        @Override
        public void onSuccess(List<Claim> claims) {
            if (findViewById(R.id.url_suggestions_container).getVisibility() == View.VISIBLE) {
                for (int i = 0; i < claims.size(); i++) {
                    // build a simple url from the claim for matching
                    Claim claim = claims.get(i);
                    Claim actualClaim = claim;
                    boolean isRepost = false;
                    if (Claim.TYPE_REPOST.equalsIgnoreCase(claim.getValueType())) {
                        actualClaim = claim.getRepostedClaim();
                        isRepost = true;
                    }
                    if (Helper.isNullOrEmpty(claim.getName())) {
                        continue;
                    }
                    LbryUri simpleUrl = new LbryUri();
                    if (actualClaim.getName().startsWith("@") && !isRepost) {
                        // channel
                        simpleUrl.setChannelName(actualClaim.getName());
                    } else {
                        simpleUrl.setStreamName(claim.getName());
                    }
                    urlSuggestionListAdapter.setClaimForUrl(simpleUrl, actualClaim);
                }
                urlSuggestionListAdapter.notifyDataSetChanged();
            }
        }

        @Override
        public void onError(Exception error) {
        }
    });
    task.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}
Also used : ClaimListResultHandler(com.odysee.app.tasks.claim.ClaimListResultHandler) LbryUri(com.odysee.app.utils.LbryUri) Claim(com.odysee.app.model.Claim) JSONException(org.json.JSONException) LbryUriException(com.odysee.app.exceptions.LbryUriException) ExecutionException(java.util.concurrent.ExecutionException) SQLiteException(android.database.sqlite.SQLiteException) LbryioRequestException(com.odysee.app.exceptions.LbryioRequestException) LbryioResponseException(com.odysee.app.exceptions.LbryioResponseException) ApiCallException(com.odysee.app.exceptions.ApiCallException) AuthTokenInvalidatedException(com.odysee.app.exceptions.AuthTokenInvalidatedException) ParseException(java.text.ParseException) ResolveTask(com.odysee.app.tasks.claim.ResolveTask)

Example 7 with ResolveTask

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

the class MainActivity method resolveCommentAuthors.

private void resolveCommentAuthors(List<String> urls) {
    if (urls != null && !urls.isEmpty()) {
        ResolveTask task = new ResolveTask(urls, Lbry.API_CONNECTION_STRING, null, new ClaimListResultHandler() {

            @Override
            public void onSuccess(List<Claim> claims) {
                if (notificationListAdapter != null) {
                    notificationListAdapter.updateAuthorClaims(claims);
                }
            }

            @Override
            public void onError(Exception error) {
            // pass
            }
        });
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }
}
Also used : ClaimListResultHandler(com.odysee.app.tasks.claim.ClaimListResultHandler) Claim(com.odysee.app.model.Claim) JSONException(org.json.JSONException) LbryUriException(com.odysee.app.exceptions.LbryUriException) ExecutionException(java.util.concurrent.ExecutionException) SQLiteException(android.database.sqlite.SQLiteException) LbryioRequestException(com.odysee.app.exceptions.LbryioRequestException) LbryioResponseException(com.odysee.app.exceptions.LbryioResponseException) ApiCallException(com.odysee.app.exceptions.ApiCallException) AuthTokenInvalidatedException(com.odysee.app.exceptions.AuthTokenInvalidatedException) ParseException(java.text.ParseException) ResolveTask(com.odysee.app.tasks.claim.ResolveTask)

Example 8 with ResolveTask

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

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

Aggregations

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