Search in sources :

Example 31 with MainActivity

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

the class FileViewFragment method logFileView.

private void logFileView(String url, long timeToStart) {
    Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
    if (actualClaim != null) {
        String authToken = Lbryio.AUTH_TOKEN;
        Map<String, String> options = new HashMap<>();
        options.put("uri", url);
        options.put("claim_id", actualClaim.getClaimId());
        options.put("outpoint", String.format("%s:%d", actualClaim.getTxid(), actualClaim.getNout()));
        if (timeToStart > 0) {
            options.put("time_to_start", String.valueOf(timeToStart));
        }
        if (!Helper.isNullOrEmpty(authToken)) {
            options.put("auth_token", authToken);
        }
        Activity activity = getActivity();
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
            Supplier<Boolean> s = new Supplier<Boolean>() {

                @Override
                public Boolean get() {
                    try {
                        Lbryio.call("file", "view", options, null).close();
                        return true;
                    } catch (LbryioRequestException | LbryioResponseException ex) {
                        return false;
                    }
                }
            };
            CompletableFuture<Boolean> cf = CompletableFuture.supplyAsync(s);
            cf.whenComplete((result, ex) -> {
                if (result) {
                    if (activity != null) {
                        activity.runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                claimEligibleRewards();
                            }
                        });
                    }
                    if (ex != null) {
                        if (activity != null) {
                            activity.runOnUiThread(new Runnable() {

                                @Override
                                public void run() {
                                    ((MainActivity) activity).showError(ex.getMessage());
                                }
                            });
                        }
                    }
                }
            });
        } else {
            Thread t = new Thread(new Runnable() {

                @Override
                public void run() {
                    try {
                        Lbryio.call("file", "view", options, null).close();
                        if (activity != null) {
                            activity.runOnUiThread(new Runnable() {

                                @Override
                                public void run() {
                                    claimEligibleRewards();
                                }
                            });
                        }
                    } catch (LbryioRequestException | LbryioResponseException ex) {
                        if (activity != null) {
                            activity.runOnUiThread(new Runnable() {

                                @Override
                                public void run() {
                                    ((MainActivity) activity).showError(ex.getMessage());
                                }
                            });
                        }
                    }
                }
            });
            t.start();
        }
    }
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) LbryioRequestException(com.odysee.app.exceptions.LbryioRequestException) Activity(android.app.Activity) MainActivity(com.odysee.app.MainActivity) AnyThread(androidx.annotation.AnyThread) Supplier(java.util.function.Supplier) TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) Claim(com.odysee.app.model.Claim) LbryioResponseException(com.odysee.app.exceptions.LbryioResponseException)

Example 32 with MainActivity

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

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

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

the class FileViewFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    Context context = getContext();
    if (context instanceof MainActivity) {
        MainActivity activity = (MainActivity) context;
        activity.hideToolbar();
        activity.setBackPressInterceptor(this);
        activity.addDownloadActionListener(this);
        activity.addFetchClaimsListener(this);
        activity.addPIPModeListener(this);
        activity.addScreenOrientationListener(this);
        if (!MainActivity.hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, context)) {
            activity.addStoragePermissionListener(this);
        }
    }
}
Also used : AttributeProviderContext(org.commonmark.renderer.html.AttributeProviderContext) Context(android.content.Context) MainActivity(com.odysee.app.MainActivity) TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)

Example 35 with MainActivity

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

the class FileViewFragment method deleteCurrentClaim.

private void deleteCurrentClaim() {
    Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
    if (actualClaim != null) {
        Helper.setViewVisibility(layoutDisplayArea, View.INVISIBLE);
        Helper.setViewVisibility(layoutLoadingState, View.VISIBLE);
        Helper.setViewVisibility(layoutNothingAtLocation, View.GONE);
        AbandonStreamTask task = new AbandonStreamTask(Arrays.asList(actualClaim.getClaimId()), layoutResolving, new AbandonHandler() {

            @Override
            public void onComplete(List<String> successfulClaimIds, List<String> failedClaimIds, List<Exception> errors) {
                Context context = getContext();
                if (context instanceof MainActivity) {
                    if (failedClaimIds.size() == 0) {
                        MainActivity activity = (MainActivity) context;
                        activity.showMessage(R.string.content_deleted);
                        activity.onBackPressed();
                    } else {
                        showError(getString(R.string.content_failed_delete));
                    }
                }
            }
        });
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }
}
Also used : AttributeProviderContext(org.commonmark.renderer.html.AttributeProviderContext) Context(android.content.Context) AbandonStreamTask(com.odysee.app.tasks.claim.AbandonStreamTask) AbandonHandler(com.odysee.app.tasks.claim.AbandonHandler) 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)

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