Search in sources :

Example 66 with Claim

use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.

the class FileViewFragment method ensureCommentListAdapterCreated.

private void ensureCommentListAdapterCreated(final List<Comment> comments) {
    Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
    if (commentListAdapter == null) {
        final Context androidContext = getContext();
        final View root = getView();
        commentListAdapter = new CommentListAdapter(comments, getContext(), actualClaim, new CommentListAdapter.CommentListListener() {

            @Override
            public void onListChanged() {
                checkNoComments();
            }

            @Override
            public void onCommentReactClicked(Comment c, boolean liked) {
                react(c, liked);
            }

            @Override
            public void onReplyClicked(Comment comment) {
                setReplyToComment(comment);
            }
        });
        commentListAdapter.setListener(new ClaimListAdapter.ClaimListItemListener() {

            @Override
            public void onClaimClicked(Claim claim, int position) {
                if (!Helper.isNullOrEmpty(claim.getName()) && claim.getName().startsWith("@") && androidContext instanceof MainActivity) {
                    removeNotificationAsSource();
                    ((MainActivity) androidContext).openChannelClaim(claim);
                }
            }
        });
        RecyclerView commentsList = root.findViewById(R.id.file_view_comments_list);
        // Indent reply-type items
        int marginInPx = Math.round(40 * ((float) androidContext.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT));
        commentsList.addItemDecoration(new CommentItemDecoration(marginInPx));
        commentsList.setAdapter(commentListAdapter);
        commentListAdapter.notifyItemRangeInserted(0, comments.size());
        scrollToCommentHash();
        checkNoComments();
        resolveCommentPosters();
    }
}
Also used : AttributeProviderContext(org.commonmark.renderer.html.AttributeProviderContext) Context(android.content.Context) Comment(com.odysee.app.model.Comment) ReactToComment(com.odysee.app.runnable.ReactToComment) CommentListAdapter(com.odysee.app.adapter.CommentListAdapter) MainActivity(com.odysee.app.MainActivity) CommentItemDecoration(com.odysee.app.adapter.CommentItemDecoration) 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) ClaimListAdapter(com.odysee.app.adapter.ClaimListAdapter) SuppressLint(android.annotation.SuppressLint) RecyclerView(androidx.recyclerview.widget.RecyclerView) TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) Claim(com.odysee.app.model.Claim)

Example 67 with Claim

use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.

the class FileViewFragment method handleMainActionForClaim.

private void handleMainActionForClaim() {
    Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
    if (actualClaim.isPlayable()) {
        startTimeMillis = System.currentTimeMillis();
        showExoplayerView();
        playMedia();
    }
}
Also used : Claim(com.odysee.app.model.Claim)

Example 68 with Claim

use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.

the class FileViewFragment method resolveCommentPosters.

private void resolveCommentPosters() {
    if (commentListAdapter != null) {
        long st = System.currentTimeMillis();
        List<String> urlsToResolve = new ArrayList<>(commentListAdapter.getClaimUrlsToResolve());
        if (urlsToResolve.size() > 0) {
            ResolveTask task = new ResolveTask(urlsToResolve, Lbry.API_CONNECTION_STRING, null, new ClaimListResultHandler() {

                @Override
                public void onSuccess(List<Claim> claims) {
                    if (commentListAdapter != null) {
                        for (Claim claim : claims) {
                            if (claim.getClaimId() != null) {
                                commentListAdapter.updatePosterForComment(claim.getClaimId(), claim);
                            }
                        }
                        // filter for blocked comments
                        commentListAdapter.filterBlockedChannels(Lbryio.blockedChannels);
                        commentListAdapter.notifyDataSetChanged();
                    }
                }

                @Override
                public void onError(Exception error) {
                // pass
                }
            });
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }
}
Also used : ClaimListResultHandler(com.odysee.app.tasks.claim.ClaimListResultHandler) ArrayList(java.util.ArrayList) 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) ResolveTask(com.odysee.app.tasks.claim.ResolveTask)

Example 69 with Claim

use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.

the class FileViewFragment method checkParams.

private void checkParams() {
    boolean updateRequired = false;
    Context context = getContext();
    // claim.setClaimId(FileViewFragmentArgs.fromBundle(getArguments()).getClaimId());
    try {
        Map<String, Object> params = getParams();
        Claim newClaim = null;
        String newUrl = null;
        if (params != null) {
            if (params.containsKey("collection")) {
                handlePlayCollection(params);
                return;
            }
            if (params.containsKey("claim")) {
                newClaim = (Claim) params.get("claim");
                // Only update fragment if new claim is different than currently being played
                if (newClaim != null && !newClaim.equals(this.fileClaim)) {
                    updateRequired = true;
                }
            }
            if (params.containsKey("url")) {
                LbryUri newLbryUri = LbryUri.tryParse(params.get("url").toString());
                if (newLbryUri != null) {
                    newUrl = newLbryUri.toString();
                    String qs = newLbryUri.getQueryString();
                    if (!Helper.isNullOrEmpty(qs)) {
                        String[] qsPairs = qs.split("&");
                        for (String pair : qsPairs) {
                            String[] parts = pair.split("=");
                            if (parts.length < 2) {
                                continue;
                            }
                            if ("comment_hash".equalsIgnoreCase(parts[0])) {
                                commentHash = parts[1];
                                break;
                            }
                        }
                    }
                    if (fileClaim == null || !newUrl.equalsIgnoreCase(currentUrl)) {
                        updateRequired = true;
                    }
                }
            }
        } else if (currentUrl != null) {
            updateRequired = true;
        } else if (context instanceof MainActivity) {
            ((MainActivity) context).onBackPressed();
        }
        boolean invalidRepost = false;
        if (updateRequired) {
            resetViewCount();
            resetFee();
            checkNewClaimAndUrl(newClaim, newUrl);
            // This is required to recycle current fragment with new claim from related content
            fileClaim = null;
            if (newClaim != null) {
                fileClaim = newClaim;
            }
            if (fileClaim == null && !Helper.isNullOrEmpty(newUrl)) {
                // check if the claim is already cached
                currentUrl = newUrl;
                ClaimCacheKey key = new ClaimCacheKey();
                key.setUrl(currentUrl);
                onNewClaim(currentUrl);
                if (Lbry.claimCache.containsKey(key)) {
                    fileClaim = Lbry.claimCache.get(key);
                }
            }
            if (fileClaim != null && Claim.TYPE_REPOST.equalsIgnoreCase(fileClaim.getValueType())) {
                fileClaim = fileClaim.getRepostedClaim();
                if (fileClaim == null || Helper.isNullOrEmpty(fileClaim.getClaimId())) {
                    // Invalid repost, probably
                    invalidRepost = true;
                    renderNothingAtLocation();
                } else if (fileClaim.getName().startsWith("@")) {
                    // this is a reposted channel, so launch the channel url
                    if (context instanceof MainActivity) {
                        MainActivity activity = (MainActivity) context;
                        // activity.onBackPressed(); // remove the reposted url page from the back stack
                        activity.getSupportFragmentManager().popBackStack();
                        activity.openChannelUrl(!Helper.isNullOrEmpty(fileClaim.getShortUrl()) ? fileClaim.getShortUrl() : fileClaim.getPermanentUrl());
                    }
                    return;
                }
            }
            if (fileClaim == null) {
                resolveUrl(currentUrl);
            }
        } else {
            checkAndResetNowPlayingClaim();
        }
        if (!Helper.isNullOrEmpty(currentUrl)) {
            Helper.saveUrlHistory(currentUrl, fileClaim != null ? fileClaim.getTitle() : null, UrlSuggestion.TYPE_FILE);
        }
        if (fileClaim != null && !invalidRepost) {
            if (Claim.TYPE_COLLECTION.equalsIgnoreCase(fileClaim.getValueType()) && fileClaim.getClaimIds() != null && fileClaim.getClaimIds().size() > 0) {
                resolvePlaylistClaimsAndPlayFirst();
                return;
            }
            Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
            if (!Claim.TYPE_COLLECTION.equalsIgnoreCase(actualClaim.getType())) {
                // We don't want to save actual collections to the view history
                Helper.saveViewHistory(currentUrl, actualClaim);
            }
            if (Helper.isClaimBlocked(actualClaim)) {
                renderClaimBlocked();
            } else {
                checkAndLoadRelatedContent();
                checkAndLoadComments();
                renderClaim();
                if (actualClaim.getFile() == null) {
                    loadFile();
                } else {
                // initialFileLoadDone = true;
                }
            }
        }
        checkIsFileComplete();
    } catch (Exception ex) {
        android.util.Log.e(TAG, ex.getMessage(), ex);
    }
}
Also used : AttributeProviderContext(org.commonmark.renderer.html.AttributeProviderContext) Context(android.content.Context) ClaimCacheKey(com.odysee.app.model.ClaimCacheKey) JSONObject(org.json.JSONObject) MainActivity(com.odysee.app.MainActivity) LbryUri(com.odysee.app.utils.LbryUri) 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)

Example 70 with Claim

use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.

the class FileViewFragment method relatedContentRequestSuccedded.

private void relatedContentRequestSuccedded(List<Claim> claims) {
    Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
    List<Claim> filteredClaims = new ArrayList<>();
    for (Claim c : claims) {
        if (!c.getClaimId().equalsIgnoreCase(actualClaim.getClaimId())) {
            filteredClaims.add(c);
        }
    }
    filteredClaims = Helper.filterClaimsByBlockedChannels(filteredClaims, Lbryio.blockedChannels);
    Context ctx = getContext();
    if (ctx != null) {
        relatedContentAdapter.setItems(filteredClaims);
        relatedContentAdapter.setListener(new ClaimListAdapter.ClaimListItemListener() {

            @Override
            public void onClaimClicked(Claim claim, int position) {
                if (claim.isLoadingPlaceholder()) {
                    return;
                }
                if (ctx instanceof MainActivity) {
                    MainActivity activity = (MainActivity) ctx;
                    if (claim.getName().startsWith("@")) {
                        activity.openChannelClaim(claim);
                    } else {
                        Map<String, Object> params = new HashMap<>(1);
                        params.put("url", !Helper.isNullOrEmpty(claim.getShortUrl()) ? claim.getShortUrl() : claim.getPermanentUrl());
                        setParams(params);
                        checkParams();
                    }
                }
            }
        });
        View v = getView();
        if (v != null) {
            View root = getView();
            RecyclerView relatedContentList = root.findViewById(R.id.file_view_related_content_list);
            relatedContentList.setAdapter(relatedContentAdapter);
            relatedContentAdapter.notifyDataSetChanged();
            Helper.setViewVisibility(v.findViewById(R.id.file_view_no_related_content), relatedContentAdapter == null || relatedContentAdapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
        }
        // if related content loads before comment, this will affect the scroll position
        // so just ensure that we are at the correct position
        scrollToCommentHash();
    }
}
Also used : AttributeProviderContext(org.commonmark.renderer.html.AttributeProviderContext) Context(android.content.Context) ArrayList(java.util.ArrayList) MainActivity(com.odysee.app.MainActivity) 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) SuppressLint(android.annotation.SuppressLint) 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)

Aggregations

Claim (com.odysee.app.model.Claim)133 Context (android.content.Context)51 MainActivity (com.odysee.app.MainActivity)44 JSONException (org.json.JSONException)42 View (android.view.View)41 TextView (android.widget.TextView)37 RecyclerView (androidx.recyclerview.widget.RecyclerView)36 ApiCallException (com.odysee.app.exceptions.ApiCallException)36 ArrayList (java.util.ArrayList)32 ImageView (android.widget.ImageView)31 AdapterView (android.widget.AdapterView)29 NestedScrollView (androidx.core.widget.NestedScrollView)28 ClaimListResultHandler (com.odysee.app.tasks.claim.ClaimListResultHandler)26 JSONObject (org.json.JSONObject)26 ExecutionException (java.util.concurrent.ExecutionException)25 TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)24 LbryUriException (com.odysee.app.exceptions.LbryUriException)24 SolidIconView (com.odysee.app.ui.controls.SolidIconView)24 WebView (android.webkit.WebView)23 PhotoView (com.github.chrisbanes.photoview.PhotoView)23