Search in sources :

Example 41 with Claim

use of com.odysee.app.model.Claim 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 42 with Claim

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

the class FileViewFragment method loadLastPlaybackPosition.

private long loadLastPlaybackPosition() {
    long position = -1;
    Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
    if (actualClaim != null) {
        String key = String.format("PlayPos_%s", !Helper.isNullOrEmpty(actualClaim.getShortUrl()) ? actualClaim.getShortUrl() : actualClaim.getPermanentUrl());
        Context context = getContext();
        if (context != null) {
            SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
            position = sp.getLong(key, -1);
        }
    }
    return position;
}
Also used : AttributeProviderContext(org.commonmark.renderer.html.AttributeProviderContext) Context(android.content.Context) SharedPreferences(android.content.SharedPreferences) Claim(com.odysee.app.model.Claim)

Example 43 with Claim

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

the class FileViewFragment method checkOwnClaim.

private void checkOwnClaim() {
    Claim claimToCheck = collectionClaimItem != null ? collectionClaimItem : fileClaim;
    if (claimToCheck != null) {
        boolean isOwnClaim = Lbry.ownClaims.contains(claimToCheck);
        View root = getView();
        if (root != null) {
            Helper.setViewVisibility(root.findViewById(R.id.file_view_action_report), isOwnClaim ? View.GONE : View.VISIBLE);
            // TODO Re-enable this when implemented
            // Helper.setViewVisibility(root.findViewById(R.id.file_view_action_edit), isOwnClaim ? View.VISIBLE : View.GONE);
            // Helper.setViewVisibility(root.findViewById(R.id.file_view_action_unpublish), isOwnClaim ? View.VISIBLE : View.GONE);
            LinearLayout fileViewActionsArea = root.findViewById(R.id.file_view_actions_area);
            fileViewActionsArea.setWeightSum(isOwnClaim ? 6 : 5);
        }
    }
}
Also used : 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) Claim(com.odysee.app.model.Claim) LinearLayout(android.widget.LinearLayout)

Example 44 with Claim

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

the class FileViewFragment method playOrViewMedia.

private void playOrViewMedia() {
    boolean handled = false;
    Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
    String mediaType = actualClaim.getMediaType();
    if (!Helper.isNullOrEmpty(mediaType)) {
        if (actualClaim.isPlayable()) {
            startTimeMillis = System.currentTimeMillis();
            showExoplayerView();
            playMedia();
            handled = true;
        } else if (actualClaim.isViewable()) {
            // check type and display
            boolean fileExists = false;
            LbryFile claimFile = actualClaim.getFile();
            Uri fileUri = null;
            if (claimFile != null && !Helper.isNullOrEmpty(claimFile.getDownloadPath())) {
                File file = new File(claimFile.getDownloadPath());
                fileUri = Uri.fromFile(file);
                fileExists = file.exists();
            }
            if (!fileExists) {
                showError(getString(R.string.claim_file_not_found, claimFile != null ? claimFile.getDownloadPath() : ""));
            } else if (fileUri != null) {
                View root = getView();
                Context context = getContext();
                if (root != null) {
                    if (mediaType.startsWith("image")) {
                        // display the image
                        View container = root.findViewById(R.id.file_view_imageviewer_container);
                        PhotoView photoView = root.findViewById(R.id.file_view_imageviewer);
                        if (context != null) {
                            Glide.with(context.getApplicationContext()).load(fileUri).centerInside().into(photoView);
                        }
                        container.setVisibility(View.VISIBLE);
                    } else if (mediaType.startsWith("text")) {
                        // show web view (and parse markdown too)
                        View container = root.findViewById(R.id.file_view_webview_container);
                        initWebView(root);
                        applyThemeToWebView();
                        if (Arrays.asList("text/markdown", "text/md").contains(mediaType.toLowerCase())) {
                            loadMarkdownFromFile(claimFile.getDownloadPath());
                        } else {
                            webView.loadUrl(fileUri.toString());
                        }
                        container.setVisibility(View.VISIBLE);
                    }
                }
                handled = true;
            }
        } else {
            openClaimExternally(actualClaim, mediaType);
        }
    }
    if (!handled) {
        showUnsupportedView();
    }
}
Also used : AttributeProviderContext(org.commonmark.renderer.html.AttributeProviderContext) Context(android.content.Context) PhotoView(com.github.chrisbanes.photoview.PhotoView) LbryFile(com.odysee.app.model.LbryFile) LbryUri(com.odysee.app.utils.LbryUri) Uri(android.net.Uri) File(java.io.File) LbryFile(com.odysee.app.model.LbryFile) 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) Claim(com.odysee.app.model.Claim)

Example 45 with Claim

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

the class ChannelFormFragment method buildChannelClaimToSave.

private Claim buildChannelClaimToSave() {
    Claim claim = new Claim();
    String name = Helper.getValue(inputChannelName.getText());
    if (!name.startsWith("@")) {
        name = String.format("@%s", name);
    }
    claim.setName(name);
    if (currentClaim != null) {
        claim.setClaimId(currentClaim.getClaimId());
    }
    Claim.ChannelMetadata metadata = new Claim.ChannelMetadata();
    metadata.setTitle(Helper.getValue(inputTitle.getText()));
    metadata.setDescription(Helper.getValue(inputDescription.getText()));
    metadata.setWebsiteUrl(Helper.getValue(inputWebsite.getText()));
    metadata.setEmail(Helper.getValue(inputEmail.getText()));
    Claim.Resource cover = new Claim.Resource();
    cover.setUrl(coverUrl == null ? "" : coverUrl);
    Claim.Resource thumbnail = new Claim.Resource();
    thumbnail.setUrl(thumbnailUrl == null ? "" : thumbnailUrl);
    metadata.setThumbnail(thumbnail);
    metadata.setCover(cover);
    List<Tag> addedTags = addedTagsAdapter != null ? new ArrayList<>(addedTagsAdapter.getTags()) : new ArrayList<>();
    metadata.setTags(Helper.getTagsForTagObjects(addedTags));
    claim.setValue(metadata);
    return claim;
}
Also used : Tag(com.odysee.app.model.Tag) 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