Search in sources :

Example 1 with CreateSupportDialogFragment

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

the class FileViewFragment method initUi.

@SuppressWarnings("ClickableViewAccessibility")
private void initUi(View root) {
    buttonPublishSomething.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Context context = getContext();
            if (!Helper.isNullOrEmpty(currentUrl) && context instanceof MainActivity) {
                LbryUri uri = LbryUri.tryParse(currentUrl);
                if (uri != null) {
                    Map<String, Object> params = new HashMap<>();
                    params.put("suggestedUrl", uri.getStreamName());
                // ((MainActivity) context).openFragment(PublishFragment.class, true, NavMenuItem.ID_ITEM_NEW_PUBLISH, params);
                }
            }
        }
    });
    root.findViewById(R.id.file_view_title_area).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            ImageView descIndicator = root.findViewById(R.id.file_view_desc_toggle_arrow);
            View descriptionArea = root.findViewById(R.id.file_view_description_area);
            Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
            boolean hasDescription = actualClaim != null && !Helper.isNullOrEmpty(actualClaim.getDescription());
            boolean hasTags = actualClaim != null && actualClaim.getTags() != null && actualClaim.getTags().size() > 0;
            if (descriptionArea.getVisibility() != View.VISIBLE) {
                if (hasDescription || hasTags) {
                    descriptionArea.setVisibility(View.VISIBLE);
                }
                descIndicator.setImageResource(R.drawable.ic_arrow_dropup);
            } else {
                descriptionArea.setVisibility(View.GONE);
                descIndicator.setImageResource(R.drawable.ic_arrow_dropdown);
            }
        }
    });
    root.findViewById(R.id.file_view_action_like).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            AccountManager am = AccountManager.get(root.getContext());
            Account odyseeAccount = Helper.getOdyseeAccount(am.getAccounts());
            Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
            if (actualClaim != null && odyseeAccount != null) {
                react(actualClaim, true);
            }
        }
    });
    root.findViewById(R.id.file_view_action_dislike).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            AccountManager am = AccountManager.get(root.getContext());
            Account odyseeAccount = Helper.getOdyseeAccount(am.getAccounts());
            Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
            if (actualClaim != null && odyseeAccount != null) {
                react(actualClaim, false);
            }
        }
    });
    root.findViewById(R.id.file_view_action_share).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
            if (actualClaim != null) {
                try {
                    String shareUrl = LbryUri.parse(!Helper.isNullOrEmpty(actualClaim.getCanonicalUrl()) ? actualClaim.getCanonicalUrl() : (!Helper.isNullOrEmpty(actualClaim.getShortUrl()) ? actualClaim.getShortUrl() : actualClaim.getPermanentUrl())).toOdyseeString();
                    Intent shareIntent = new Intent();
                    shareIntent.setAction(Intent.ACTION_SEND);
                    shareIntent.setType("text/plain");
                    shareIntent.putExtra(Intent.EXTRA_TEXT, shareUrl);
                    MainActivity.startingShareActivity = true;
                    Intent shareUrlIntent = Intent.createChooser(shareIntent, getString(R.string.share_lbry_content));
                    shareUrlIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(shareUrlIntent);
                } catch (LbryUriException ex) {
                // pass
                }
            }
        }
    });
    root.findViewById(R.id.file_view_action_tip).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            MainActivity activity = (MainActivity) getActivity();
            if (activity != null && activity.isSignedIn()) {
                Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
                if (actualClaim != null) {
                    CreateSupportDialogFragment dialog = CreateSupportDialogFragment.newInstance(actualClaim, (amount, isTip) -> {
                        double sentAmount = amount.doubleValue();
                        String message = getResources().getQuantityString(isTip ? R.plurals.you_sent_a_tip : R.plurals.you_sent_a_support, sentAmount == 1.0 ? 1 : 2, new DecimalFormat("#,###.##").format(sentAmount));
                        Snackbar.make(root.findViewById(R.id.file_view_claim_display_area), message, Snackbar.LENGTH_LONG).show();
                    });
                    Context context = getContext();
                    if (context instanceof MainActivity) {
                        dialog.show(((MainActivity) context).getSupportFragmentManager(), CreateSupportDialogFragment.TAG);
                    }
                }
            } else {
                if (activity != null) {
                    activity.simpleSignIn(0);
                }
            }
        }
    });
    root.findViewById(R.id.file_view_action_repost).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
            if (actualClaim != null) {
                RepostClaimDialogFragment dialog = RepostClaimDialogFragment.newInstance(actualClaim, claim -> {
                    Context context = getContext();
                    if (context instanceof MainActivity) {
                        ((MainActivity) context).showMessage(R.string.content_successfully_reposted);
                    }
                });
                Context context = getContext();
                if (context instanceof MainActivity) {
                    dialog.show(((MainActivity) context).getSupportFragmentManager(), RepostClaimDialogFragment.TAG);
                }
            }
        }
    });
    root.findViewById(R.id.file_view_action_edit).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Context context = getContext();
            Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
            if (actualClaim != null && context instanceof MainActivity) {
                ((MainActivity) context).openPublishForm(actualClaim);
            }
        }
    });
    root.findViewById(R.id.file_view_action_delete).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
            if (actualClaim != null) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getContext()).setTitle(R.string.delete_file).setMessage(R.string.confirm_delete_file_message).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        deleteClaimFile();
                    }
                }).setNegativeButton(R.string.no, null);
                builder.show();
            }
        }
    });
    root.findViewById(R.id.file_view_action_unpublish).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
            if (actualClaim != null) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getContext()).setTitle(R.string.delete_content).setMessage(R.string.confirm_delete_content_message).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        deleteCurrentClaim();
                    }
                }).setNegativeButton(R.string.no, null);
                builder.show();
            }
        }
    });
    root.findViewById(R.id.file_view_action_download).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
            if (actualClaim != null) {
                if (downloadInProgress) {
                    onDownloadAborted();
                } else {
                    checkStoragePermissionAndStartDownload();
                }
            }
        }
    });
    root.findViewById(R.id.file_view_action_report).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
            if (actualClaim != null) {
                Context context = getContext();
                CustomTabColorSchemeParams.Builder ctcspb = new CustomTabColorSchemeParams.Builder();
                ctcspb.setToolbarColor(ContextCompat.getColor(context, R.color.colorPrimary));
                CustomTabColorSchemeParams ctcsp = ctcspb.build();
                CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder().setDefaultColorSchemeParams(ctcsp);
                CustomTabsIntent intent = builder.build();
                intent.launchUrl(context, Uri.parse(String.format("https://odysee.com/$/report_content?claimId=%s", actualClaim.getClaimId())));
            }
        }
    });
    root.findViewById(R.id.player_toggle_cast).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            toggleCast();
        }
    });
    PlayerView playerView = root.findViewById(R.id.file_view_exoplayer_view);
    View playbackSpeedContainer = playerView.findViewById(R.id.player_playback_speed);
    TextView textPlaybackSpeed = playerView.findViewById(R.id.player_playback_speed_label);
    View qualityContainer = playerView.findViewById(R.id.player_quality);
    TextView textQuality = playerView.findViewById(R.id.player_quality_label);
    textPlaybackSpeed.setText(DEFAULT_PLAYBACK_SPEED);
    textQuality.setText(AUTO_QUALITY_STRING);
    playbackSpeedContainer.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {

        @Override
        public void onCreateContextMenu(ContextMenu contextMenu, View view, ContextMenu.ContextMenuInfo contextMenuInfo) {
            Helper.buildPlaybackSpeedMenu(contextMenu);
        }
    });
    playbackSpeedContainer.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Context context = getContext();
            if (context instanceof MainActivity) {
                ((MainActivity) context).openContextMenu(playbackSpeedContainer);
            }
        }
    });
    qualityContainer.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {

        @Override
        public void onCreateContextMenu(ContextMenu contextMenu, View view, ContextMenu.ContextMenuInfo contextMenuInfo) {
            if (MainActivity.appPlayer != null) {
                Helper.buildQualityMenu(contextMenu, MainActivity.appPlayer, MainActivity.videoIsTranscoded);
            }
        }
    });
    qualityContainer.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Context context = getContext();
            if (context instanceof MainActivity) {
                ((MainActivity) context).openContextMenu(qualityContainer);
            }
        }
    });
    playerView.findViewById(R.id.player_toggle_fullscreen).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            // check full screen mode
            if (isInFullscreenMode()) {
                disableFullScreenMode();
            } else {
                enableFullScreenMode();
            }
        }
    });
    playerView.findViewById(R.id.player_skip_back_10).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (MainActivity.appPlayer != null) {
                MainActivity.appPlayer.seekTo(Math.max(0, MainActivity.appPlayer.getCurrentPosition() - 10000));
            }
        }
    });
    playerView.findViewById(R.id.player_skip_forward_10).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (MainActivity.appPlayer != null) {
                MainActivity.appPlayer.seekTo(MainActivity.appPlayer.getCurrentPosition() + 10000);
            }
        }
    });
    root.findViewById(R.id.file_view_publisher_info_area).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
            if (actualClaim != null && actualClaim.getSigningChannel() != null) {
                removeNotificationAsSource();
                Claim publisher = actualClaim.getSigningChannel();
                Context context = getContext();
                if (context instanceof MainActivity) {
                    ((MainActivity) context).openChannelClaim(publisher);
                }
            }
        }
    });
    View buttonFollow = root.findViewById(R.id.file_view_icon_follow);
    View buttonUnfollow = root.findViewById(R.id.file_view_icon_unfollow);
    View buttonBell = root.findViewById(R.id.file_view_icon_bell);
    buttonFollow.setOnClickListener(followUnfollowListener);
    buttonUnfollow.setOnClickListener(followUnfollowListener);
    buttonBell.setOnClickListener(bellIconListener);
    commentChannelSpinnerAdapter = new InlineChannelSpinnerAdapter(getContext(), R.layout.spinner_item_channel, new ArrayList<>());
    commentChannelSpinnerAdapter.addPlaceholder(false);
    initCommentForm(root);
    expandButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            // Prevents crash for when comment list isn't loaded yet but user tries to expand.
            if (commentListAdapter != null) {
                switchCommentListVisibility(commentListAdapter.isCollapsed());
                commentListAdapter.switchExpandedState();
            }
        }
    });
    singleCommentRoot.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            expandButton.performClick();
        }
    });
    RecyclerView relatedContentList = root.findViewById(R.id.file_view_related_content_list);
    RecyclerView commentsList = root.findViewById(R.id.file_view_comments_list);
    relatedContentList.setNestedScrollingEnabled(false);
    commentsList.setNestedScrollingEnabled(false);
    LinearLayoutManager relatedContentListLLM = new LinearLayoutManager(getContext());
    LinearLayoutManager commentsListLLM = new LinearLayoutManager(getContext());
    relatedContentList.setLayoutManager(relatedContentListLLM);
    commentsList.setLayoutManager(commentsListLLM);
    GestureDetector.SimpleOnGestureListener gestureListener = new GestureDetector.SimpleOnGestureListener() {

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            ImageView seekOverlay = root.findViewById(R.id.seek_overlay);
            int width = playerView.getWidth();
            float eventX = e.getX();
            if (eventX < width / 3.0) {
                if (MainActivity.appPlayer != null) {
                    MainActivity.appPlayer.seekTo(Math.max(0, MainActivity.appPlayer.getCurrentPosition() - 10000));
                    seekOverlay.setVisibility(View.VISIBLE);
                    seekOverlay.setImageResource(R.drawable.ic_rewind);
                }
            } else if (eventX > width * 2.0 / 3.0) {
                if (MainActivity.appPlayer != null) {
                    MainActivity.appPlayer.seekTo(MainActivity.appPlayer.getCurrentPosition() + 10000);
                    seekOverlay.setVisibility(View.VISIBLE);
                    seekOverlay.setImageResource(R.drawable.ic_forward);
                }
            } else {
                return true;
            }
            if (seekOverlayHandler == null) {
                seekOverlayHandler = new Handler();
            } else {
                // Clear pending messages
                seekOverlayHandler.removeCallbacksAndMessages(null);
            }
            seekOverlayHandler.postDelayed(() -> {
                seekOverlay.setVisibility(View.GONE);
            }, 500);
            return true;
        }

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (playerView.isControllerVisible()) {
                playerView.hideController();
            } else {
                playerView.showController();
            }
            return true;
        }
    };
    GestureDetector detector = new GestureDetector(getContext(), gestureListener);
    playerView.setOnTouchListener((view, motionEvent) -> {
        detector.onTouchEvent(motionEvent);
        return true;
    });
}
Also used : Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) NonNull(androidx.annotation.NonNull) LbryRequestException(com.odysee.app.exceptions.LbryRequestException) ChannelCreateDialogFragment(com.odysee.app.ui.channel.ChannelCreateDialogFragment) JSONException(org.json.JSONException) Future(java.util.concurrent.Future) Handler(android.os.Handler) Map(java.util.Map) Search(com.odysee.app.callable.Search) CreateSupportDialogFragment(com.odysee.app.dialog.CreateSupportDialogFragment) SimpleCache(com.google.android.exoplayer2.upstream.cache.SimpleCache) ContextCompat(androidx.core.content.ContextCompat) Log(android.util.Log) C(com.google.android.exoplayer2.C) ConnectivityManager(android.net.ConnectivityManager) Request(okhttp3.Request) Account(android.accounts.Account) AbandonHandler(com.odysee.app.tasks.claim.AbandonHandler) Helper(com.odysee.app.utils.Helper) Lbryio(com.odysee.app.utils.Lbryio) CommentListHandler(com.odysee.app.tasks.CommentListHandler) CommentItemDecoration(com.odysee.app.adapter.CommentItemDecoration) UrlSuggestion(com.odysee.app.model.UrlSuggestion) SolidIconView(com.odysee.app.ui.controls.SolidIconView) ClaimRewardTask(com.odysee.app.tasks.lbryinc.ClaimRewardTask) PlaybackParameters(com.google.android.exoplayer2.PlaybackParameters) ReadTextFileTask(com.odysee.app.tasks.ReadTextFileTask) PlayerView(com.google.android.exoplayer2.ui.PlayerView) LbryUriException(com.odysee.app.exceptions.LbryUriException) Supplier(java.util.function.Supplier) LinkedHashMap(java.util.LinkedHashMap) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) WebSettings(android.webkit.WebSettings) WebResourceRequest(android.webkit.WebResourceRequest) Comment(com.odysee.app.model.Comment) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) LbryUri(com.odysee.app.utils.LbryUri) Response(okhttp3.Response) InlineChannelSpinnerAdapter(com.odysee.app.adapter.InlineChannelSpinnerAdapter) ClaimSearchResultHandler(com.odysee.app.tasks.claim.ClaimSearchResultHandler) Predefined(com.odysee.app.utils.Predefined) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) OkHttpClient(okhttp3.OkHttpClient) SharedPreferences(android.content.SharedPreferences) PreferenceManager(androidx.preference.PreferenceManager) TagListAdapter(com.odysee.app.adapter.TagListAdapter) ImageButton(android.widget.ImageButton) LinearLayout(android.widget.LinearLayout) NestedScrollView(androidx.core.widget.NestedScrollView) FileListTask(com.odysee.app.tasks.file.FileListTask) ChannelSubscribeTask(com.odysee.app.tasks.lbryinc.ChannelSubscribeTask) WindowManager(android.view.WindowManager) Player(com.google.android.exoplayer2.Player) CustomTabsIntent(androidx.browser.customtabs.CustomTabsIntent) JSONObject(org.json.JSONObject) ActivityInfo(android.content.pm.ActivityInfo) WebViewClient(android.webkit.WebViewClient) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) Reactions(com.odysee.app.model.Reactions) MediaSource(com.google.android.exoplayer2.source.MediaSource) BufferEventTask(com.odysee.app.tasks.BufferEventTask) MediaItem(com.google.android.exoplayer2.MediaItem) AsyncTask(android.os.AsyncTask) DeleteFileTask(com.odysee.app.tasks.file.DeleteFileTask) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) LbryResponseException(com.odysee.app.exceptions.LbryResponseException) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) GenericTaskHandler(com.odysee.app.tasks.GenericTaskHandler) TrackSelectionOverrides(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides) Claim(com.odysee.app.model.Claim) PorterDuff(android.graphics.PorterDuff) DisplayMetrics(android.util.DisplayMetrics) WebViewFeature(androidx.webkit.WebViewFeature) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) CommentListTask(com.odysee.app.tasks.CommentListTask) DefaultHttpDataSource(com.google.android.exoplayer2.upstream.DefaultHttpDataSource) LeastRecentlyUsedCacheEvictor(com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor) TextInputEditText(com.google.android.material.textfield.TextInputEditText) AlertDialog(androidx.appcompat.app.AlertDialog) AbandonStreamTask(com.odysee.app.tasks.claim.AbandonStreamTask) ResolveTask(com.odysee.app.tasks.claim.ResolveTask) ProgressiveMediaSource(com.google.android.exoplayer2.source.ProgressiveMediaSource) ClaimListResultHandler(com.odysee.app.tasks.claim.ClaimListResultHandler) Lbry(com.odysee.app.utils.Lbry) CompletableFuture(java.util.concurrent.CompletableFuture) MenuItem(android.view.MenuItem) InputMethodManager(android.view.inputmethod.InputMethodManager) LighthouseSearch(com.odysee.app.callable.LighthouseSearch) MaterialButton(com.google.android.material.button.MaterialButton) LbryioRequestException(com.odysee.app.exceptions.LbryioRequestException) Build(android.os.Build) ExecutorService(java.util.concurrent.ExecutorService) LbryioResponseException(com.odysee.app.exceptions.LbryioResponseException) CustomTabColorSchemeParams(androidx.browser.customtabs.CustomTabColorSchemeParams) ApiCallException(com.odysee.app.exceptions.ApiCallException) LayoutInflater(android.view.LayoutInflater) PhotoView(com.github.chrisbanes.photoview.PhotoView) Tag(com.odysee.app.model.Tag) DecimalFormat(java.text.DecimalFormat) ClaimListAdapter(com.odysee.app.adapter.ClaimListAdapter) Color(android.graphics.Color) Fee(com.odysee.app.model.Fee) Base64(android.util.Base64) LbryAnalytics(com.odysee.app.utils.LbryAnalytics) Comparator(java.util.Comparator) Activity(android.app.Activity) AttributeProviderFactory(org.commonmark.renderer.html.AttributeProviderFactory) R(com.odysee.app.R) ClaimSearchTask(com.odysee.app.tasks.claim.ClaimSearchTask) Arrays(java.util.Arrays) Uri(android.net.Uri) ImageView(android.widget.ImageView) AppCompatSpinner(androidx.appcompat.widget.AppCompatSpinner) Parser(org.commonmark.parser.Parser) Manifest(android.Manifest) Looper(android.os.Looper) WebSettingsCompat(androidx.webkit.WebSettingsCompat) AccountManager(android.accounts.AccountManager) DefaultLoadErrorHandlingPolicy(com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy) TrackGroupInfo(com.google.android.exoplayer2.TracksInfo.TrackGroupInfo) Executors(java.util.concurrent.Executors) ReactToComment(com.odysee.app.runnable.ReactToComment) StringRes(androidx.annotation.StringRes) ClaimCacheKey(com.odysee.app.model.ClaimCacheKey) PurchaseListTask(com.odysee.app.tasks.claim.PurchaseListTask) ConstraintLayout(androidx.constraintlayout.widget.ConstraintLayout) Subscription(com.odysee.app.model.lbryinc.Subscription) DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) StoragePermissionListener(com.odysee.app.listener.StoragePermissionListener) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TextWatcher(android.text.TextWatcher) HlsMediaSource(com.google.android.exoplayer2.source.hls.HlsMediaSource) GestureDetector(android.view.GestureDetector) FetchClaimsListener(com.odysee.app.listener.FetchClaimsListener) FlexboxLayoutManager(com.google.android.flexbox.FlexboxLayoutManager) Callable(java.util.concurrent.Callable) GetFileTask(com.odysee.app.tasks.file.GetFileTask) Editable(android.text.Editable) NumberFormat(java.text.NumberFormat) ScreenOrientationListener(com.odysee.app.listener.ScreenOrientationListener) ArrayList(java.util.ArrayList) Node(org.commonmark.node.Node) PIPModeListener(com.odysee.app.listener.PIPModeListener) Code(org.commonmark.node.Code) RequestOptions(com.bumptech.glide.request.RequestOptions) CommentListAdapter(com.odysee.app.adapter.CommentListAdapter) TextUtils(android.text.TextUtils) AnyThread(androidx.annotation.AnyThread) AttributeProviderContext(org.commonmark.renderer.html.AttributeProviderContext) File(java.io.File) TracksInfo(com.google.android.exoplayer2.TracksInfo) DownloadActionListener(com.odysee.app.listener.DownloadActionListener) HtmlRenderer(org.commonmark.renderer.html.HtmlRenderer) Configuration(android.content.res.Configuration) Util(com.google.android.exoplayer2.util.Util) DateUtils(android.text.format.DateUtils) ScheduledFuture(java.util.concurrent.ScheduledFuture) ClaimListTask(com.odysee.app.tasks.claim.ClaimListTask) LinkMovementMethod(android.text.method.LinkMovementMethod) CommentCreateTask(com.odysee.app.tasks.CommentCreateTask) Comments(com.odysee.app.utils.Comments) CommentEnabledCheck(com.odysee.app.checkers.CommentEnabledCheck) View(android.view.View) WebView(android.webkit.WebView) OdyseeCollection(com.odysee.app.model.OdyseeCollection) HtmlCompat(androidx.core.text.HtmlCompat) ViewGroup(android.view.ViewGroup) List(java.util.List) TextView(android.widget.TextView) Reward(com.odysee.app.model.lbryinc.Reward) BaseFragment(com.odysee.app.ui.BaseFragment) RelativeLayout(android.widget.RelativeLayout) NotNull(org.jetbrains.annotations.NotNull) AudioAttributes(com.google.android.exoplayer2.audio.AudioAttributes) Snackbar(com.google.android.material.snackbar.Snackbar) Typeface(android.graphics.Typeface) Context(android.content.Context) ContextMenu(android.view.ContextMenu) ExoDatabaseProvider(com.google.android.exoplayer2.database.ExoDatabaseProvider) Intent(android.content.Intent) HashMap(java.util.HashMap) SuppressLint(android.annotation.SuppressLint) MainActivity(com.odysee.app.MainActivity) MotionEvent(android.view.MotionEvent) LbryFile(com.odysee.app.model.LbryFile) DialogInterface(android.content.DialogInterface) BuildCommentReactOptions(com.odysee.app.callable.BuildCommentReactOptions) CacheDataSource(com.google.android.exoplayer2.upstream.cache.CacheDataSource) AttributeProvider(org.commonmark.renderer.html.AttributeProvider) Iterator(java.util.Iterator) FetchStatCountTask(com.odysee.app.tasks.lbryinc.FetchStatCountTask) TimeUnit(java.util.concurrent.TimeUnit) Glide(com.bumptech.glide.Glide) TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) Collections(java.util.Collections) RepostClaimDialogFragment(com.odysee.app.dialog.RepostClaimDialogFragment) RepostClaimDialogFragment(com.odysee.app.dialog.RepostClaimDialogFragment) AlertDialog(androidx.appcompat.app.AlertDialog) Account(android.accounts.Account) DialogInterface(android.content.DialogInterface) CustomTabColorSchemeParams(androidx.browser.customtabs.CustomTabColorSchemeParams) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) ContextMenu(android.view.ContextMenu) GestureDetector(android.view.GestureDetector) MainActivity(com.odysee.app.MainActivity) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) CreateSupportDialogFragment(com.odysee.app.dialog.CreateSupportDialogFragment) TextView(android.widget.TextView) ImageView(android.widget.ImageView) LbryUri(com.odysee.app.utils.LbryUri) TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) AttributeProviderContext(org.commonmark.renderer.html.AttributeProviderContext) Context(android.content.Context) Handler(android.os.Handler) AbandonHandler(com.odysee.app.tasks.claim.AbandonHandler) CommentListHandler(com.odysee.app.tasks.CommentListHandler) ClaimSearchResultHandler(com.odysee.app.tasks.claim.ClaimSearchResultHandler) GenericTaskHandler(com.odysee.app.tasks.GenericTaskHandler) ClaimListResultHandler(com.odysee.app.tasks.claim.ClaimListResultHandler) CustomTabsIntent(androidx.browser.customtabs.CustomTabsIntent) Intent(android.content.Intent) InlineChannelSpinnerAdapter(com.odysee.app.adapter.InlineChannelSpinnerAdapter) 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) MotionEvent(android.view.MotionEvent) CustomTabsIntent(androidx.browser.customtabs.CustomTabsIntent) LbryUriException(com.odysee.app.exceptions.LbryUriException) PlayerView(com.google.android.exoplayer2.ui.PlayerView) AccountManager(android.accounts.AccountManager) RecyclerView(androidx.recyclerview.widget.RecyclerView) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Claim(com.odysee.app.model.Claim)

Example 2 with CreateSupportDialogFragment

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

the class ChannelFragment method onCreateView.

public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_channel, container, false);
    layoutLoadingState = root.findViewById(R.id.channel_view_loading_state);
    layoutNothingAtLocation = root.findViewById(R.id.container_nothing_at_location);
    layoutDisplayArea = root.findViewById(R.id.channel_view_claim_display_area);
    layoutResolving = root.findViewById(R.id.channel_view_loading_container);
    imageCover = root.findViewById(R.id.channel_view_cover_image);
    imageThumbnail = root.findViewById(R.id.channel_view_thumbnail);
    noThumbnailView = root.findViewById(R.id.channel_view_no_thumbnail);
    textAlpha = root.findViewById(R.id.channel_view_icon_alpha);
    textTitle = root.findViewById(R.id.channel_view_title);
    textFollowerCount = root.findViewById(R.id.channel_view_follower_count);
    buttonEdit = root.findViewById(R.id.channel_view_edit);
    buttonDelete = root.findViewById(R.id.channel_view_delete);
    buttonShare = root.findViewById(R.id.channel_view_share);
    buttonTip = root.findViewById(R.id.channel_view_tip);
    buttonReport = root.findViewById(R.id.channel_view_report);
    buttonFollowUnfollow = root.findViewById(R.id.channel_view_follow_unfollow);
    textFollow = root.findViewById(R.id.channel_view_text_follow);
    iconFollow = root.findViewById(R.id.channel_view_icon_follow);
    iconUnfollow = root.findViewById(R.id.channel_view_icon_unfollow);
    buttonBell = root.findViewById(R.id.channel_view_subscribe_notify);
    iconBell = root.findViewById(R.id.channel_view_icon_bell);
    blockUnblock = root.findViewById(R.id.channel_view_block_unblock);
    blockUnblockText = root.findViewById(R.id.channel_view_block_unblock_text);
    blockUnblock.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            boolean blocked = Lbryio.isChannelBlocked(claim);
            Context context = getContext();
            if (context instanceof MainActivity) {
                if (blocked) {
                    // handle unblock
                    ((MainActivity) context).handleUnblockChannel(claim);
                } else {
                    ((MainActivity) context).handleBlockChannel(claim);
                }
            }
        }
    });
    tabPager = root.findViewById(R.id.channel_view_pager);
    tabLayout = root.findViewById(R.id.channel_view_tabs);
    tabPager.setSaveEnabled(false);
    buttonEdit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (claim != null) {
                Context context = getContext();
                if (context instanceof MainActivity) {
                    ((MainActivity) context).openChannelForm(claim);
                }
            }
        }
    });
    buttonDelete.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (claim != null) {
                Context c = getContext();
                if (c != null) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(c).setTitle(R.string.delete_channel).setMessage(R.string.confirm_delete_channel).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            deleteCurrentClaim();
                        }
                    }).setNegativeButton(R.string.no, null);
                    builder.show();
                }
            }
        }
    });
    buttonShare.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (claim != null) {
                try {
                    String shareUrl = LbryUri.parse(!Helper.isNullOrEmpty(claim.getCanonicalUrl()) ? claim.getCanonicalUrl() : (!Helper.isNullOrEmpty(claim.getShortUrl()) ? claim.getShortUrl() : claim.getPermanentUrl())).toOdyseeString();
                    Intent shareIntent = new Intent();
                    shareIntent.setAction(Intent.ACTION_SEND);
                    shareIntent.setType("text/plain");
                    shareIntent.putExtra(Intent.EXTRA_TEXT, shareUrl);
                    MainActivity.startingShareActivity = true;
                    Intent shareUrlIntent = Intent.createChooser(shareIntent, getString(R.string.share_lbry_content));
                    shareUrlIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(shareUrlIntent);
                } catch (LbryUriException ex) {
                // pass
                }
            }
        }
    });
    buttonTip.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            MainActivity activity = (MainActivity) getActivity();
            if (activity != null && activity.isSignedIn()) {
                if (claim != null) {
                    CreateSupportDialogFragment dialog = CreateSupportDialogFragment.newInstance(claim, (amount, isTip) -> {
                        double sentAmount = amount.doubleValue();
                        View view1 = getView();
                        if (view1 != null) {
                            String message = getResources().getQuantityString(isTip ? R.plurals.you_sent_a_tip : R.plurals.you_sent_a_support, sentAmount == 1.0 ? 1 : 2, new DecimalFormat("#,###.##").format(sentAmount));
                            Snackbar.make(view1, message, Snackbar.LENGTH_LONG).show();
                        }
                    });
                    Context context = getContext();
                    if (context instanceof MainActivity) {
                        dialog.show(((MainActivity) context).getSupportFragmentManager(), CreateSupportDialogFragment.TAG);
                    }
                }
            } else {
                if (activity != null) {
                    activity.simpleSignIn(0);
                }
            }
        }
    });
    buttonReport.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (claim != null) {
                Context context = getContext();
                CustomTabColorSchemeParams.Builder ctcspb = new CustomTabColorSchemeParams.Builder();
                ctcspb.setToolbarColor(ContextCompat.getColor(context, R.color.colorPrimary));
                CustomTabColorSchemeParams ctcsp = ctcspb.build();
                CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder().setDefaultColorSchemeParams(ctcsp);
                CustomTabsIntent intent = builder.build();
                intent.launchUrl(context, Uri.parse(String.format("https://odysee.com/$/report_content?claimId=%s", claim.getClaimId())));
            }
        }
    });
    buttonBell.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (claim != null) {
                boolean isNotificationsDisabled = Lbryio.isNotificationsDisabled(claim);
                final Subscription subscription = Subscription.fromClaim(claim);
                subscription.setNotificationsDisabled(!isNotificationsDisabled);
                view.setEnabled(false);
                Context context = getContext();
                new ChannelSubscribeTask(context, claim.getClaimId(), subscription, false, new ChannelSubscribeTask.ChannelSubscribeHandler() {

                    @Override
                    public void onSuccess() {
                        view.setEnabled(true);
                        Lbryio.updateSubscriptionNotificationsDisabled(subscription);
                        Context context = getContext();
                        if (context instanceof MainActivity) {
                            ((MainActivity) context).showMessage(subscription.isNotificationsDisabled() ? R.string.receive_no_notifications : R.string.receive_all_notifications);
                        }
                        checkIsFollowing();
                        if (context != null) {
                            context.sendBroadcast(new Intent(MainActivity.ACTION_SAVE_SHARED_USER_STATE));
                        }
                    }

                    @Override
                    public void onError(Exception exception) {
                        view.setEnabled(true);
                    }
                }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            }
        }
    });
    buttonFollowUnfollow.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            MainActivity activity = (MainActivity) getActivity();
            if (activity != null && activity.isSignedIn()) {
                if (claim != null) {
                    if (subscribing) {
                        return;
                    }
                    boolean isFollowing = Lbryio.isFollowing(claim);
                    if (isFollowing) {
                        Context context = getContext();
                        if (context != null) {
                            AlertDialog.Builder builder = new AlertDialog.Builder(context).setTitle(R.string.confirm_unfollow).setMessage(R.string.confirm_unfollow_message).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    doFollowUnfollow(isFollowing, view);
                                }
                            }).setNegativeButton(R.string.no, null);
                            builder.show();
                        }
                    } else {
                        doFollowUnfollow(isFollowing, view);
                    }
                }
            } else {
                if (activity != null) {
                    activity.simpleSignIn(0);
                }
            }
        }
    });
    return root;
}
Also used : Context(android.content.Context) AlertDialog(androidx.appcompat.app.AlertDialog) Bundle(android.os.Bundle) SneakyThrows(lombok.SneakyThrows) NonNull(androidx.annotation.NonNull) ChannelSubscribeTask(com.odysee.app.tasks.lbryinc.ChannelSubscribeTask) Uri(android.net.Uri) ImageView(android.widget.ImageView) CustomTabsIntent(androidx.browser.customtabs.CustomTabsIntent) FetchChannelsListener(com.odysee.app.listener.FetchChannelsListener) Handler(android.os.Handler) Map(java.util.Map) Fragment(androidx.fragment.app.Fragment) View(android.view.View) CreateSupportDialogFragment(com.odysee.app.dialog.CreateSupportDialogFragment) ContextCompat(androidx.core.content.ContextCompat) AsyncTask(android.os.AsyncTask) TabLayout(com.google.android.material.tabs.TabLayout) AbandonHandler(com.odysee.app.tasks.claim.AbandonHandler) Helper(com.odysee.app.utils.Helper) Claim(com.odysee.app.model.Claim) ViewGroup(android.view.ViewGroup) Lbryio(com.odysee.app.utils.Lbryio) List(java.util.List) ClaimCacheKey(com.odysee.app.model.ClaimCacheKey) TextView(android.widget.TextView) BaseFragment(com.odysee.app.ui.BaseFragment) Subscription(com.odysee.app.model.lbryinc.Subscription) Snackbar(com.google.android.material.snackbar.Snackbar) Context(android.content.Context) AlertDialog(androidx.appcompat.app.AlertDialog) ResolveTask(com.odysee.app.tasks.claim.ResolveTask) UrlSuggestion(com.odysee.app.model.UrlSuggestion) ClaimListResultHandler(com.odysee.app.tasks.claim.ClaimListResultHandler) Lbry(com.odysee.app.utils.Lbry) SolidIconView(com.odysee.app.ui.controls.SolidIconView) Intent(android.content.Intent) ViewPager2(androidx.viewpager2.widget.ViewPager2) LbryUriException(com.odysee.app.exceptions.LbryUriException) NumberFormat(java.text.NumberFormat) FragmentActivity(androidx.fragment.app.FragmentActivity) FragmentStateAdapter(androidx.viewpager2.adapter.FragmentStateAdapter) MainActivity(com.odysee.app.MainActivity) OutlineIconView(com.odysee.app.ui.controls.OutlineIconView) LbryUri(com.odysee.app.utils.LbryUri) FollowingFragment(com.odysee.app.ui.findcontent.FollowingFragment) DialogInterface(android.content.DialogInterface) CustomTabColorSchemeParams(androidx.browser.customtabs.CustomTabColorSchemeParams) RequestOptions(com.bumptech.glide.request.RequestOptions) LayoutInflater(android.view.LayoutInflater) DecimalFormat(java.text.DecimalFormat) FetchStatCountTask(com.odysee.app.tasks.lbryinc.FetchStatCountTask) Color(android.graphics.Color) Glide(com.bumptech.glide.Glide) LbryAnalytics(com.odysee.app.utils.LbryAnalytics) Collections(java.util.Collections) AbandonChannelTask(com.odysee.app.tasks.claim.AbandonChannelTask) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) R(com.odysee.app.R) DialogInterface(android.content.DialogInterface) CustomTabColorSchemeParams(androidx.browser.customtabs.CustomTabColorSchemeParams) DecimalFormat(java.text.DecimalFormat) CustomTabsIntent(androidx.browser.customtabs.CustomTabsIntent) Intent(android.content.Intent) MainActivity(com.odysee.app.MainActivity) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) SolidIconView(com.odysee.app.ui.controls.SolidIconView) OutlineIconView(com.odysee.app.ui.controls.OutlineIconView) LbryUriException(com.odysee.app.exceptions.LbryUriException) CreateSupportDialogFragment(com.odysee.app.dialog.CreateSupportDialogFragment) CustomTabsIntent(androidx.browser.customtabs.CustomTabsIntent) LbryUriException(com.odysee.app.exceptions.LbryUriException) ChannelSubscribeTask(com.odysee.app.tasks.lbryinc.ChannelSubscribeTask) Subscription(com.odysee.app.model.lbryinc.Subscription)

Aggregations

Context (android.content.Context)2 DialogInterface (android.content.DialogInterface)2 Intent (android.content.Intent)2 Color (android.graphics.Color)2 Uri (android.net.Uri)2 AsyncTask (android.os.AsyncTask)2 Bundle (android.os.Bundle)2 Handler (android.os.Handler)2 LayoutInflater (android.view.LayoutInflater)2 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 NonNull (androidx.annotation.NonNull)2 AlertDialog (androidx.appcompat.app.AlertDialog)2 CustomTabColorSchemeParams (androidx.browser.customtabs.CustomTabColorSchemeParams)2 CustomTabsIntent (androidx.browser.customtabs.CustomTabsIntent)2 ContextCompat (androidx.core.content.ContextCompat)2 Glide (com.bumptech.glide.Glide)2 RequestOptions (com.bumptech.glide.request.RequestOptions)2