Search in sources :

Example 76 with Claim

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

the class FileViewFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_file_view, container, false);
    layoutLoadingState = root.findViewById(R.id.file_view_loading_state);
    layoutNothingAtLocation = root.findViewById(R.id.container_nothing_at_location);
    layoutResolving = root.findViewById(R.id.file_view_loading_container);
    layoutDisplayArea = root.findViewById(R.id.file_view_claim_display_area);
    buttonPublishSomething = root.findViewById(R.id.nothing_at_location_publish_button);
    tipButton = root.findViewById(R.id.file_view_action_tip);
    expandButton = root.findViewById(R.id.expand_commentarea_button);
    singleCommentRoot = root.findViewById(R.id.collapsed_comment);
    relatedContentTitle = root.findViewById(R.id.related_or_playlist);
    containerCommentForm = root.findViewById(R.id.container_comment_form);
    containerReplyToComment = root.findViewById(R.id.comment_form_reply_to_container);
    textReplyingTo = root.findViewById(R.id.comment_form_replying_to_text);
    textReplyToBody = root.findViewById(R.id.comment_form_reply_to_body);
    buttonClearReplyToComment = root.findViewById(R.id.comment_form_clear_reply_to);
    commentChannelSpinner = root.findViewById(R.id.comment_form_channel_spinner);
    progressLoadingChannels = root.findViewById(R.id.comment_form_channels_loading);
    progressPostComment = root.findViewById(R.id.comment_form_post_progress);
    inputComment = root.findViewById(R.id.comment_form_body);
    textCommentLimit = root.findViewById(R.id.comment_form_text_limit);
    buttonPostComment = root.findViewById(R.id.comment_form_post);
    buttonCreateChannel = root.findViewById(R.id.create_channel_button);
    commentPostAsThumbnail = root.findViewById(R.id.comment_form_thumbnail);
    commentPostAsNoThumbnail = root.findViewById(R.id.comment_form_no_thumbnail);
    commentPostAsAlpha = root.findViewById(R.id.comment_form_thumbnail_alpha);
    buttonCommentSignedInUserRequired = root.findViewById(R.id.sign_in_user_button);
    textNothingAtLocation = root.findViewById(R.id.nothing_at_location_text);
    commentLoadingArea = root.findViewById(R.id.file_comments_loading);
    likeReactionAmount = root.findViewById(R.id.likes_amount);
    dislikeReactionAmount = root.findViewById(R.id.dislikes_amount);
    likeReactionIcon = root.findViewById(R.id.like_icon);
    dislikeReactionIcon = root.findViewById(R.id.dislike_icon);
    initUi(root);
    fileViewPlayerListener = new Player.Listener() {

        @Override
        public void onPlaybackStateChanged(@Player.State int playbackState) {
            if (playbackState == Player.STATE_READY) {
                elapsedDuration = MainActivity.appPlayer.getCurrentPosition();
                totalDuration = MainActivity.appPlayer.getDuration() < 0 ? 0 : MainActivity.appPlayer.getDuration();
                if (!playbackStarted) {
                    logPlay(currentUrl, startTimeMillis);
                    playbackStarted = true;
                    long lastPosition = loadLastPlaybackPosition();
                    if (lastPosition > -1) {
                        MainActivity.appPlayer.seekTo(lastPosition);
                    }
                }
                renderTotalDuration();
                scheduleElapsedPlayback();
                hideBuffering();
                if (loadingNewClaim) {
                    setPlaybackSpeedToDefault();
                    setPlayerQualityToDefault();
                    MainActivity.appPlayer.setPlayWhenReady(true);
                    loadingNewClaim = false;
                }
            } else if (playbackState == Player.STATE_BUFFERING) {
                if (!loadingQualityChanged) {
                    Context ctx = getContext();
                    boolean sendBufferingEvents = true;
                    if (ctx != null) {
                        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(ctx);
                        sendBufferingEvents = sp.getBoolean(MainActivity.PREFERENCE_KEY_SEND_BUFFERING_EVENTS, true);
                    }
                    if (MainActivity.appPlayer != null && MainActivity.appPlayer.getCurrentPosition() > 0 && sendBufferingEvents) {
                        // we only want to log a buffer event after the media has already started playing
                        if (!Helper.isNullOrEmpty(currentMediaSourceUrl)) {
                            long duration = MainActivity.appPlayer.getDuration();
                            long position = MainActivity.appPlayer.getCurrentPosition();
                            String userIdHash = Lbryio.currentUser != null ? String.valueOf(Lbryio.currentUser.getId()) : "0";
                            Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
                            BufferEventTask bufferEvent = new BufferEventTask(actualClaim.getPermanentUrl(), duration, position, 1, userIdHash);
                            bufferEvent.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
                        }
                    }
                }
                loadingQualityChanged = false;
                showBuffering();
            } else if (playbackState == Player.STATE_ENDED) {
                playNextItemInPlaylist();
            } else {
                hideBuffering();
            }
        }

        @Override
        public void onIsPlayingChanged(boolean isPlayng) {
            isPlaying = isPlayng;
        }
    };
    scrollView = root.findViewById(R.id.file_view_scroll_view);
    return root;
}
Also used : AttributeProviderContext(org.commonmark.renderer.html.AttributeProviderContext) Context(android.content.Context) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) Player(com.google.android.exoplayer2.Player) BufferEventTask(com.odysee.app.tasks.BufferEventTask) 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) TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) SuppressLint(android.annotation.SuppressLint) Claim(com.odysee.app.model.Claim) TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)

Example 77 with Claim

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

the class FileViewFragment method getLivestreamUrl.

/**
 * @return The URL to connect to get the video stream, usually a .M3U8
 */
@AnyThread
private String getLivestreamUrl() {
    Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
        Supplier<JSONObject> task = new Supplier<JSONObject>() {

            @Override
            public JSONObject get() {
                return getLivestreamData(actualClaim);
            }
        };
        CompletableFuture<JSONObject> completableFuture = CompletableFuture.supplyAsync(task);
        CompletableFuture<String> cf = completableFuture.thenApply(jsonData -> getLivestreamUrl(jsonData));
        try {
            return cf.get();
        } catch (ExecutionException | InterruptedException e) {
            e.printStackTrace();
        }
    } else {
        ExecutorService executor = Executors.newSingleThreadExecutor();
        Callable<JSONObject> callable = () -> getLivestreamData(actualClaim);
        Future<JSONObject> future = executor.submit(callable);
        for (; ; ) {
            if (future.isDone()) {
                try {
                    JSONObject jsonData = future.get();
                    return getLivestreamUrl(jsonData);
                } catch (InterruptedException | ExecutionException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    return null;
}
Also used : JSONObject(org.json.JSONObject) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) Supplier(java.util.function.Supplier) ExecutionException(java.util.concurrent.ExecutionException) Claim(com.odysee.app.model.Claim) AnyThread(androidx.annotation.AnyThread)

Example 78 with Claim

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

the class FileViewFragment method checkIsFileComplete.

private void checkIsFileComplete() {
    Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
    if (actualClaim == null) {
        return;
    }
    View root = getView();
    if (root != null) {
        if (actualClaim.getFile() != null && actualClaim.getFile().isCompleted()) {
            Helper.setViewVisibility(root.findViewById(R.id.file_view_action_delete), View.VISIBLE);
            Helper.setViewVisibility(root.findViewById(R.id.file_view_action_download), View.GONE);
        } else {
            Helper.setViewVisibility(root.findViewById(R.id.file_view_action_delete), View.GONE);
        // Helper.setViewVisibility(root.findViewById(R.id.file_view_action_download), View.VISIBLE);
        }
    }
}
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 79 with Claim

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

the class FileViewFragment method loadFile.

private void loadFile() {
    Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
    String claimId = actualClaim.getClaimId();
    FileListTask task = new FileListTask(claimId, null, new FileListTask.FileListResultHandler() {

        @Override
        public void onSuccess(List<LbryFile> files, boolean hasReachedEnd) {
            if (files.size() > 0) {
                actualClaim.setFile(files.get(0));
                checkIsFileComplete();
                if (!actualClaim.isPlayable() && !actualClaim.isViewable()) {
                    showUnsupportedView();
                }
            } else {
                if (!actualClaim.isPlayable() && !actualClaim.isViewable()) {
                    restoreMainActionButton();
                }
            }
        // initialFileLoadDone = true;
        }

        @Override
        public void onError(Exception error) {
        // initialFileLoadDone = true;
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : FileListTask(com.odysee.app.tasks.file.FileListTask) LbryFile(com.odysee.app.model.LbryFile) 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)

Example 80 with Claim

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

the class ChannelFormFragment method validateAndSaveClaim.

private void validateAndSaveClaim(Claim claim) {
    if (!editMode && Helper.isNullOrEmpty(claim.getName())) {
        showError(getString(R.string.please_enter_channel_name));
        return;
    }
    String channelName = claim.getName().startsWith("@") ? claim.getName().substring(1) : claim.getName();
    if (!LbryUri.isNameValid(channelName)) {
        showError(getString(R.string.channel_name_invalid_characters));
        return;
    }
    if (!editMode) {
        if (Helper.channelExists(channelName)) {
            showError(getString(R.string.channel_name_already_created));
            return;
        }
    }
    String depositString = Helper.getValue(inputDeposit.getText());
    double depositAmount = 0;
    try {
        depositAmount = Double.parseDouble(depositString);
    } catch (NumberFormatException ex) {
        // pass
        showError(getString(R.string.please_enter_valid_deposit));
        return;
    }
    if (depositAmount < Helper.MIN_DEPOSIT) {
        String error = getResources().getQuantityString(R.plurals.min_deposit_required, depositAmount == 1 ? 1 : 2, String.valueOf(Helper.MIN_DEPOSIT));
        showError(error);
        return;
    }
    if (Lbry.getAvailableBalance() < depositAmount) {
        showError(getString(R.string.deposit_more_than_balance));
        return;
    }
    AccountManager am = AccountManager.get(getContext());
    String authToken = am.peekAuthToken(Helper.getOdyseeAccount(am.getAccounts()), "auth_token_type");
    ChannelCreateUpdateTask task = new ChannelCreateUpdateTask(claim, new BigDecimal(depositString), editMode, channelSaveProgress, authToken, new ClaimResultHandler() {

        @Override
        public void beforeStart() {
            preSave();
        }

        @Override
        public void onSuccess(Claim claimResult) {
            postSave();
            // Run the logPublish task
            if (!BuildConfig.DEBUG) {
                LogPublishTask logPublish = new LogPublishTask(claimResult);
                logPublish.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            }
            if (!editMode) {
                // channel created
                Bundle bundle = new Bundle();
                bundle.putString("claim_id", claimResult.getClaimId());
                bundle.putString("claim_name", claimResult.getName());
                LbryAnalytics.logEvent(LbryAnalytics.EVENT_CHANNEL_CREATE, bundle);
            }
            Context context = getContext();
            if (context instanceof MainActivity) {
                MainActivity activity = (MainActivity) context;
                activity.showMessage(R.string.channel_save_successful);
                activity.onBackPressed();
            }
        }

        @Override
        public void onError(Exception error) {
            showError(error != null ? error.getMessage() : getString(R.string.channel_save_failed));
            postSave();
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : Context(android.content.Context) ClaimResultHandler(com.odysee.app.tasks.claim.ClaimResultHandler) ChannelCreateUpdateTask(com.odysee.app.tasks.claim.ChannelCreateUpdateTask) Bundle(android.os.Bundle) MainActivity(com.odysee.app.MainActivity) BigDecimal(java.math.BigDecimal) LogPublishTask(com.odysee.app.tasks.lbryinc.LogPublishTask) AccountManager(android.accounts.AccountManager) 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