Search in sources :

Example 31 with Claim

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

the class FileViewFragment method checkAndConfirmPurchaseUrl.

private void checkAndConfirmPurchaseUrl() {
    Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
    if (actualClaim != null) {
        PurchaseListTask task = new PurchaseListTask(actualClaim.getClaimId(), null, new ClaimSearchResultHandler() {

            @Override
            public void onSuccess(List<Claim> claims, boolean hasReachedEnd) {
                boolean purchased = false;
                if (claims.size() == 1) {
                    Claim purchasedClaim = claims.get(0);
                    if (actualClaim.getClaimId().equalsIgnoreCase(purchasedClaim.getClaimId())) {
                        // already purchased
                        purchased = true;
                    }
                }
                if (purchased) {
                    handleMainActionForClaim();
                } else {
                    restoreMainActionButton();
                    confirmPurchaseUrl();
                }
            }

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

Example 32 with Claim

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

the class FileViewFragment method loadRelatedContent.

private void loadRelatedContent() {
    // reset the list view
    View root = getView();
    if (fileClaim != null && root != null) {
        Context context = getContext();
        List<Claim> loadingPlaceholders = new ArrayList<>();
        int loadingPlaceholdersLength = Claim.TYPE_COLLECTION.equalsIgnoreCase(fileClaim.getValueType()) ? fileClaim.getClaimIds().size() : 15;
        for (int i = 0; i < loadingPlaceholdersLength; i++) {
            Claim placeholder = new Claim();
            placeholder.setLoadingPlaceholder(true);
            loadingPlaceholders.add(placeholder);
        }
        relatedContentAdapter = new ClaimListAdapter(loadingPlaceholders, context);
        relatedContentAdapter.setContextGroupId(FILE_CONTEXT_GROUP_ID);
        RecyclerView relatedContentList = root.findViewById(R.id.file_view_related_content_list);
        relatedContentList.setAdapter(relatedContentAdapter);
        ProgressBar relatedLoading = root.findViewById(R.id.file_view_related_content_progress);
        boolean canShowMatureContent = false;
        if (context != null) {
            SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
            canShowMatureContent = sp.getBoolean(MainActivity.PREFERENCE_KEY_SHOW_MATURE_CONTENT, false);
        }
        if (!Claim.TYPE_COLLECTION.equalsIgnoreCase(fileClaim.getValueType())) {
            String title = fileClaim.getTitle();
            String claimId = fileClaim.getClaimId();
            final boolean nsfw = canShowMatureContent;
            relatedLoading.setVisibility(View.VISIBLE);
            // Making a request which explicitly uses a certain value form the amount of results needed
            // and no processing any possible exception, so using a callable instead of an AsyncTask
            // makes sense for all Android API Levels
            Thread t = new Thread(new Runnable() {

                @Override
                public void run() {
                    ExecutorService executor = Executors.newSingleThreadExecutor();
                    LighthouseSearch callable = new LighthouseSearch(title, RELATED_CONTENT_SIZE, 0, nsfw, claimId);
                    Future<List<Claim>> future = executor.submit(callable);
                    try {
                        List<Claim> result = future.get();
                        if (executor != null && !executor.isShutdown()) {
                            executor.shutdown();
                        }
                        MainActivity a = (MainActivity) getActivity();
                        if (a != null) {
                            a.runOnUiThread(new Runnable() {

                                @Override
                                public void run() {
                                    relatedContentRequestSuccedded(result);
                                    relatedLoading.setVisibility(View.GONE);
                                }
                            });
                        }
                    } catch (InterruptedException | ExecutionException e) {
                        if (executor != null && !executor.isShutdown()) {
                            executor.shutdown();
                        }
                        e.printStackTrace();
                    }
                }
            });
            t.start();
        } else {
            TextView relatedOrPlayList = root.findViewById(R.id.related_or_playlist);
            relatedOrPlayList.setText(fileClaim.getTitle());
            relatedOrPlayList.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.ic_cast_connected, 0, 0, 0);
            relatedOrPlayList.setPadding(0, 0, 0, 16);
            relatedOrPlayList.setTypeface(null, Typeface.BOLD);
            Map<String, Object> claimSearchOptions = new HashMap<>(3);
            claimSearchOptions.put("claim_ids", fileClaim.getClaimIds());
            claimSearchOptions.put("not_tags", canShowMatureContent ? null : new ArrayList<>(Predefined.MATURE_TAGS));
            claimSearchOptions.put("page_size", fileClaim.getClaimIds().size());
            ExecutorService executor = Executors.newSingleThreadExecutor();
            Future<List<Claim>> future = executor.submit(new Search(claimSearchOptions));
            try {
                List<Claim> playlistClaimItems = future.get();
                if (playlistClaimItems != null) {
                    relatedContentAdapter.setItems(playlistClaimItems);
                    relatedContentAdapter.setListener(FileViewFragment.this);
                    View v = getView();
                    if (v != null) {
                        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);
                    }
                    scrollToCommentHash();
                }
            } catch (InterruptedException | ExecutionException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MainActivity(com.odysee.app.MainActivity) ClaimListAdapter(com.odysee.app.adapter.ClaimListAdapter) LighthouseSearch(com.odysee.app.callable.LighthouseSearch) Search(com.odysee.app.callable.Search) LighthouseSearch(com.odysee.app.callable.LighthouseSearch) ArrayList(java.util.ArrayList) List(java.util.List) TextView(android.widget.TextView) ExecutionException(java.util.concurrent.ExecutionException) ProgressBar(android.widget.ProgressBar) TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) AttributeProviderContext(org.commonmark.renderer.html.AttributeProviderContext) Context(android.content.Context) SharedPreferences(android.content.SharedPreferences) 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) AnyThread(androidx.annotation.AnyThread) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) CompletableFuture(java.util.concurrent.CompletableFuture) ScheduledFuture(java.util.concurrent.ScheduledFuture) RecyclerView(androidx.recyclerview.widget.RecyclerView) JSONObject(org.json.JSONObject) Claim(com.odysee.app.model.Claim)

Example 33 with Claim

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

the class FileViewFragment method resolveUrl.

private void resolveUrl(String url) {
    // resolving = true;
    Helper.setViewVisibility(layoutDisplayArea, View.INVISIBLE);
    Helper.setViewVisibility(layoutLoadingState, View.VISIBLE);
    Helper.setViewVisibility(layoutNothingAtLocation, View.GONE);
    ResolveTask task = new ResolveTask(url, Lbry.API_CONNECTION_STRING, layoutResolving, new ClaimListResultHandler() {

        @Override
        public void onSuccess(List<Claim> claims) {
            if (!claims.isEmpty() && !Helper.isNullOrEmpty(claims.get(0).getClaimId())) {
                fileClaim = claims.get(0);
                if (Claim.TYPE_REPOST.equalsIgnoreCase(fileClaim.getValueType())) {
                    fileClaim = fileClaim.getRepostedClaim();
                    // cache the reposted claim too for subsequent loads
                    Lbry.addClaimToCache(fileClaim);
                    if (fileClaim.getName().startsWith("@")) {
                        // this is a reposted channel, so finish this activity and launch the channel url
                        Context context = getContext();
                        if (context instanceof MainActivity) {
                            MainActivity activity = (MainActivity) context;
                            activity.getSupportFragmentManager().popBackStack();
                            activity.openChannelUrl(!Helper.isNullOrEmpty(fileClaim.getShortUrl()) ? fileClaim.getShortUrl() : fileClaim.getPermanentUrl());
                        }
                        return;
                    }
                } else {
                    Lbry.addClaimToCache(fileClaim);
                }
                if (Claim.TYPE_COLLECTION.equalsIgnoreCase(fileClaim.getValueType()) && fileClaim.getClaimIds() != null && fileClaim.getClaimIds().size() > 0) {
                    collectionClaimItem = null;
                }
                Helper.saveUrlHistory(url, fileClaim.getTitle(), UrlSuggestion.TYPE_FILE);
                // do not save collections to view history
                if (!Claim.TYPE_COLLECTION.equalsIgnoreCase(fileClaim.getType())) {
                    // also save view history
                    Helper.saveViewHistory(url, fileClaim);
                }
                checkAndResetNowPlayingClaim();
                if (Helper.isClaimBlocked(fileClaim)) {
                    renderClaimBlocked();
                } else {
                    loadFile();
                    checkAndLoadRelatedContent();
                    checkAndLoadComments();
                    renderClaim();
                }
            } else {
                // render nothing at location
                renderNothingAtLocation();
            }
        }

        @Override
        public void onError(Exception error) {
        // resolving = false;
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : AttributeProviderContext(org.commonmark.renderer.html.AttributeProviderContext) Context(android.content.Context) ClaimListResultHandler(com.odysee.app.tasks.claim.ClaimListResultHandler) MainActivity(com.odysee.app.MainActivity) 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 34 with Claim

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

the class FileViewFragment method onMainActionButtonClicked.

private void onMainActionButtonClicked() {
    Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
    // Check if the claim is free
    Claim.GenericMetadata metadata = actualClaim.getValue();
    if (metadata instanceof Claim.StreamMetadata) {
        View root = getView();
        if (root != null) {
            root.findViewById(R.id.file_view_main_action_button).setVisibility(View.INVISIBLE);
            root.findViewById(R.id.file_view_main_action_loading).setVisibility(View.VISIBLE);
        }
        if (actualClaim.getFile() == null && !actualClaim.isFree()) {
            checkAndConfirmPurchaseUrl();
        } else {
            handleMainActionForClaim();
        }
    } else {
        showError(getString(R.string.cannot_view_claim));
    }
}
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)

Example 35 with Claim

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

the class FileViewFragment method onDownloadAborted.

private void onDownloadAborted() {
    downloadInProgress = false;
    Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
    if (actualClaim != null) {
        actualClaim.setFile(null);
    }
    View root = getView();
    if (root != null) {
        ((ImageView) root.findViewById(R.id.file_view_action_download_icon)).setImageResource(R.drawable.ic_download);
        Helper.setViewVisibility(root.findViewById(R.id.file_view_download_progress), View.GONE);
        Helper.setViewVisibility(root.findViewById(R.id.file_view_unsupported_container), View.GONE);
    }
    checkIsFileComplete();
    restoreMainActionButton();
}
Also used : ImageView(android.widget.ImageView) 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)

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