Search in sources :

Example 76 with MainActivity

use of com.odysee.app.MainActivity 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 77 with MainActivity

use of com.odysee.app.MainActivity 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 78 with MainActivity

use of com.odysee.app.MainActivity 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)

Example 79 with MainActivity

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

the class TransactionHistoryFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    MainActivity activity = (MainActivity) getContext();
    if (activity != null) {
        activity.hideSearchBar();
        activity.setActionBarTitle(R.string.transaction_history);
    }
}
Also used : MainActivity(com.odysee.app.MainActivity)

Example 80 with MainActivity

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

the class TransactionHistoryFragment method onResume.

@Override
public void onResume() {
    super.onResume();
    Context context = getContext();
    if (context instanceof MainActivity) {
        MainActivity activity = (MainActivity) context;
        LbryAnalytics.setCurrentScreen(activity, "Transaction History", "TransactionHistory");
    }
    if (adapter != null && adapter.getItemCount() > 0 && transactionList != null) {
        transactionList.setAdapter(adapter);
    }
    loadTransactions();
}
Also used : Context(android.content.Context) MainActivity(com.odysee.app.MainActivity)

Aggregations

MainActivity (com.odysee.app.MainActivity)138 Context (android.content.Context)119 Claim (com.odysee.app.model.Claim)39 View (android.view.View)31 TextView (android.widget.TextView)30 RecyclerView (androidx.recyclerview.widget.RecyclerView)26 AttributeProviderContext (org.commonmark.renderer.html.AttributeProviderContext)25 ArrayList (java.util.ArrayList)21 TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)19 ImageView (android.widget.ImageView)18 SuppressLint (android.annotation.SuppressLint)15 AdapterView (android.widget.AdapterView)14 NestedScrollView (androidx.core.widget.NestedScrollView)14 JSONException (org.json.JSONException)13 JSONObject (org.json.JSONObject)13 SolidIconView (com.odysee.app.ui.controls.SolidIconView)12 HashMap (java.util.HashMap)12 ClaimListAdapter (com.odysee.app.adapter.ClaimListAdapter)11 ApiCallException (com.odysee.app.exceptions.ApiCallException)11 WebView (android.webkit.WebView)10