Search in sources :

Example 1 with EXTRA_SUBMISSION_TITLE

use of me.ccrama.redditslide.Notifications.ImageDownloadNotificationService.EXTRA_SUBMISSION_TITLE in project Slide by ccrama.

the class CommentPage method onMenuItemClick.

public boolean onMenuItemClick(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.search:
            {
                if (comments.comments != null && comments.submission != null) {
                    DataShare.sharedComments = comments.comments;
                    DataShare.subAuthor = comments.submission.getAuthor();
                    Intent i = new Intent(getActivity(), CommentSearch.class);
                    if (getActivity() instanceof MainActivity) {
                        getActivity().startActivityForResult(i, 423);
                    } else {
                        startActivityForResult(i, 423);
                    }
                }
            }
            return true;
        case R.id.sidebar:
            doSidebarOpen();
            return true;
        case R.id.related:
            if (adapter.submission.isSelfPost()) {
                new AlertDialog.Builder(getActivity()).setTitle("Selftext posts have no related submissions").setPositiveButton(R.string.btn_ok, null).show();
            } else {
                Intent i = new Intent(getActivity(), Related.class);
                i.putExtra(Related.EXTRA_URL, adapter.submission.getUrl());
                startActivity(i);
            }
            return true;
        case R.id.shadowbox:
            if (SettingValues.isPro) {
                if (comments.comments != null && comments.submission != null) {
                    ShadowboxComments.comments = new ArrayList<>();
                    for (CommentObject c : comments.comments) {
                        if (c instanceof CommentItem) {
                            if (c.comment.getComment().getDataNode().get("body_html").asText().contains("&lt;/a")) {
                                String body = c.comment.getComment().getDataNode().get("body_html").asText();
                                String url;
                                String[] split = body.split("&lt;a href=\"");
                                if (split.length > 1) {
                                    for (String chunk : split) {
                                        url = chunk.substring(0, chunk.indexOf("\"", 1));
                                        ContentType.Type t = ContentType.getContentType(url);
                                        if (ContentType.mediaType(t)) {
                                            ShadowboxComments.comments.add(new CommentUrlObject(c.comment, url, subreddit));
                                        }
                                    }
                                } else {
                                    int start = body.indexOf("&lt;a href=\"");
                                    url = body.substring(start, body.indexOf("\"", start + 1));
                                    ContentType.Type t = ContentType.getContentType(url);
                                    if (ContentType.mediaType(t)) {
                                        ShadowboxComments.comments.add(new CommentUrlObject(c.comment, url, subreddit));
                                    }
                                }
                            }
                        }
                    }
                    if (!ShadowboxComments.comments.isEmpty()) {
                        Intent i = new Intent(getActivity(), ShadowboxComments.class);
                        startActivity(i);
                    } else {
                        Snackbar.make(mSwipeRefreshLayout, R.string.shadowbox_comments_nolinks, Snackbar.LENGTH_SHORT).show();
                    }
                }
            } else {
                ProUtil.proUpgradeMsg(getContext(), R.string.general_shadowbox_comments_ispro).setNegativeButton(R.string.btn_no_thanks, (dialog, whichButton) -> dialog.dismiss()).show();
            }
            return true;
        case R.id.sort:
            {
                openPopup(toolbar);
                return true;
            }
        case R.id.content:
            {
                if (adapter != null && adapter.submission != null) {
                    if (!PostMatch.openExternal(adapter.submission.getUrl())) {
                        ContentType.Type type = ContentType.getContentType(adapter.submission);
                        switch(type) {
                            case STREAMABLE:
                                if (SettingValues.video) {
                                    Intent myIntent = new Intent(getActivity(), MediaView.class);
                                    myIntent.putExtra(MediaView.SUBREDDIT, subreddit);
                                    myIntent.putExtra(MediaView.EXTRA_URL, adapter.submission.getUrl());
                                    myIntent.putExtra(EXTRA_SUBMISSION_TITLE, adapter.submission.getTitle());
                                    getActivity().startActivity(myIntent);
                                } else {
                                    LinkUtil.openExternally(adapter.submission.getUrl());
                                }
                                break;
                            case IMGUR:
                            case XKCD:
                                Intent i2 = new Intent(getActivity(), MediaView.class);
                                i2.putExtra(MediaView.SUBREDDIT, subreddit);
                                i2.putExtra(EXTRA_SUBMISSION_TITLE, adapter.submission.getTitle());
                                if (adapter.submission.getDataNode().has("preview") && adapter.submission.getDataNode().get("preview").get("images").get(0).get("source").has("height") && type != ContentType.Type.XKCD) {
                                    // Load the preview image which has probably already been cached in memory instead of the direct link
                                    String previewUrl = adapter.submission.getDataNode().get("preview").get("images").get(0).get("source").get("url").asText();
                                    i2.putExtra(MediaView.EXTRA_DISPLAY_URL, previewUrl);
                                }
                                i2.putExtra(MediaView.EXTRA_URL, adapter.submission.getUrl());
                                getActivity().startActivity(i2);
                                break;
                            case EMBEDDED:
                                if (SettingValues.video) {
                                    String data = adapter.submission.getDataNode().get("media_embed").get("content").asText();
                                    {
                                        Intent i = new Intent(getActivity(), FullscreenVideo.class);
                                        i.putExtra(FullscreenVideo.EXTRA_HTML, data);
                                        getActivity().startActivity(i);
                                    }
                                } else {
                                    LinkUtil.openExternally(adapter.submission.getUrl());
                                }
                                break;
                            case REDDIT:
                                PopulateSubmissionViewHolder.openRedditContent(adapter.submission.getUrl(), getActivity());
                                break;
                            case LINK:
                                LinkUtil.openUrl(adapter.submission.getUrl(), Palette.getColor(adapter.submission.getSubredditName()), getActivity());
                                break;
                            case NONE:
                            case SELF:
                                if (adapter.submission.getSelftext().isEmpty()) {
                                    Snackbar s = Snackbar.make(rv, R.string.submission_nocontent, Snackbar.LENGTH_SHORT);
                                    LayoutUtils.showSnackbar(s);
                                } else {
                                    LayoutInflater inflater = getActivity().getLayoutInflater();
                                    final View dialoglayout = inflater.inflate(R.layout.parent_comment_dialog, null);
                                    adapter.setViews(adapter.submission.getDataNode().get("selftext_html").asText(), adapter.submission.getSubredditName(), dialoglayout.findViewById(R.id.firstTextView), dialoglayout.findViewById(R.id.commentOverflow));
                                    new AlertDialog.Builder(getActivity()).setView(dialoglayout).show();
                                }
                                break;
                            case ALBUM:
                                if (SettingValues.album) {
                                    Intent i;
                                    if (SettingValues.albumSwipe) {
                                        i = new Intent(getActivity(), AlbumPager.class);
                                        i.putExtra(Album.EXTRA_URL, adapter.submission.getUrl());
                                        i.putExtra(AlbumPager.SUBREDDIT, subreddit);
                                    } else {
                                        i = new Intent(getActivity(), Album.class);
                                        i.putExtra(Album.EXTRA_URL, adapter.submission.getUrl());
                                        i.putExtra(Album.SUBREDDIT, subreddit);
                                    }
                                    i.putExtra(EXTRA_SUBMISSION_TITLE, adapter.submission.getTitle());
                                    getActivity().startActivity(i);
                                    getActivity().overridePendingTransition(R.anim.slideright, R.anim.fade_out);
                                } else {
                                    LinkUtil.openExternally(adapter.submission.getUrl());
                                }
                                break;
                            case TUMBLR:
                                if (SettingValues.image) {
                                    Intent i;
                                    if (SettingValues.albumSwipe) {
                                        i = new Intent(getActivity(), TumblrPager.class);
                                        i.putExtra(Album.EXTRA_URL, adapter.submission.getUrl());
                                        i.putExtra(TumblrPager.SUBREDDIT, subreddit);
                                    } else {
                                        i = new Intent(getActivity(), Tumblr.class);
                                        i.putExtra(Tumblr.SUBREDDIT, subreddit);
                                        i.putExtra(Album.EXTRA_URL, adapter.submission.getUrl());
                                    }
                                    getActivity().startActivity(i);
                                    getActivity().overridePendingTransition(R.anim.slideright, R.anim.fade_out);
                                } else {
                                    LinkUtil.openExternally(adapter.submission.getUrl());
                                }
                                break;
                            case IMAGE:
                                PopulateSubmissionViewHolder.openImage(type, getActivity(), adapter.submission, null, -1);
                                break;
                            case VREDDIT_REDIRECT:
                            case VREDDIT_DIRECT:
                            case GIF:
                                PopulateSubmissionViewHolder.openGif(getActivity(), adapter.submission, -1);
                                break;
                            case VIDEO:
                                if (!LinkUtil.tryOpenWithVideoPlugin(adapter.submission.getUrl())) {
                                    LinkUtil.openUrl(adapter.submission.getUrl(), Palette.getStatusBarColor(), getActivity());
                                }
                        }
                    } else {
                        LinkUtil.openExternally(adapter.submission.getUrl());
                    }
                }
            }
            return true;
        case R.id.reload:
            if (comments != null) {
                mSwipeRefreshLayout.setRefreshing(true);
                comments.loadMore(adapter, subreddit);
            }
            return true;
        case R.id.collapse:
            {
                if (adapter != null) {
                    adapter.collapseAll();
                }
            }
            return true;
        case android.R.id.home:
            getActivity().onBackPressed();
            return true;
    }
    return false;
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Bundle(android.os.Bundle) R(me.ccrama.redditslide.R) NonNull(androidx.annotation.NonNull) MainActivity(me.ccrama.redditslide.Activities.MainActivity) MediaView(me.ccrama.redditslide.Activities.MediaView) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) PostMatch(me.ccrama.redditslide.PostMatch) ContentType(me.ccrama.redditslide.ContentType) UserRecordPaginator(net.dean.jraw.paginators.UserRecordPaginator) DataShare(me.ccrama.redditslide.DataShare) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) Fragment(androidx.fragment.app.Fragment) Drafts(me.ccrama.redditslide.Drafts) CommentSort(net.dean.jraw.models.CommentSort) ContextCompat(androidx.core.content.ContextCompat) ProUtil(me.ccrama.redditslide.util.ProUtil) Slider(com.rey.material.widget.Slider) Palette(me.ccrama.redditslide.Visuals.Palette) BlendModeUtil(me.ccrama.redditslide.util.BlendModeUtil) Profile(me.ccrama.redditslide.Activities.Profile) PopulateSubmissionViewHolder(me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder) Layout(android.text.Layout) TextPaint(android.text.TextPaint) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) Related(me.ccrama.redditslide.Activities.Related) SubmissionParser(me.ccrama.redditslide.util.SubmissionParser) DoEditorActions(me.ccrama.redditslide.Views.DoEditorActions) Dialog(android.app.Dialog) CommentItem(me.ccrama.redditslide.Adapters.CommentItem) AccountManager(net.dean.jraw.managers.AccountManager) ArrayList(java.util.ArrayList) Calendar(java.util.Calendar) TumblrPager(me.ccrama.redditslide.Activities.TumblrPager) MiscUtil(me.ccrama.redditslide.util.MiscUtil) Toast(android.widget.Toast) UserSubscriptions(me.ccrama.redditslide.UserSubscriptions) ContextWrapper(android.content.ContextWrapper) SubmissionComments(me.ccrama.redditslide.Adapters.SubmissionComments) MultiRedditUpdateRequest(net.dean.jraw.http.MultiRedditUpdateRequest) CommentsScreen(me.ccrama.redditslide.Activities.CommentsScreen) TimePeriod(net.dean.jraw.paginators.TimePeriod) StringUtil(me.ccrama.redditslide.util.StringUtil) SettingsSubAdapter(me.ccrama.redditslide.ui.settings.SettingsSubAdapter) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) Reddit(me.ccrama.redditslide.Reddit) IOException(java.io.IOException) Submit(me.ccrama.redditslide.Activities.Submit) ColorPreferences(me.ccrama.redditslide.Visuals.ColorPreferences) ToolbarScrollHideHandler(me.ccrama.redditslide.handler.ToolbarScrollHideHandler) MultiRedditManager(net.dean.jraw.managers.MultiRedditManager) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) CommentSearch(me.ccrama.redditslide.Activities.CommentSearch) EditText(android.widget.EditText) LinkUtil(me.ccrama.redditslide.util.LinkUtil) EXTRA_SUBMISSION_TITLE(me.ccrama.redditslide.Notifications.ImageDownloadNotificationService.EXTRA_SUBMISSION_TITLE) MultiSubreddit(net.dean.jraw.models.MultiSubreddit) TimeUtils(me.ccrama.redditslide.util.TimeUtils) WindowManager(android.view.WindowManager) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) Tumblr(me.ccrama.redditslide.Activities.Tumblr) Wiki(me.ccrama.redditslide.Activities.Wiki) CommentObject(me.ccrama.redditslide.Adapters.CommentObject) Locale(java.util.Locale) ShadowboxComments(me.ccrama.redditslide.Activities.ShadowboxComments) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) View(android.view.View) Sorting(net.dean.jraw.paginators.Sorting) CommentNavType(me.ccrama.redditslide.Adapters.CommentNavType) PreCachingLayoutManagerComments(me.ccrama.redditslide.Views.PreCachingLayoutManagerComments) RecyclerView(androidx.recyclerview.widget.RecyclerView) SendMessage(me.ccrama.redditslide.Activities.SendMessage) CommentUrlObject(me.ccrama.redditslide.Adapters.CommentUrlObject) AsyncTask(android.os.AsyncTask) FullscreenVideo(me.ccrama.redditslide.Activities.FullscreenVideo) Album(me.ccrama.redditslide.Activities.Album) Authentication(me.ccrama.redditslide.Authentication) ApiException(net.dean.jraw.ApiException) ViewGroup(android.view.ViewGroup) AlbumPager(me.ccrama.redditslide.Activities.AlbumPager) OfflineSubreddit(me.ccrama.redditslide.OfflineSubreddit) List(java.util.List) NetworkUtil(me.ccrama.redditslide.util.NetworkUtil) TextView(android.widget.TextView) Toolbar(androidx.appcompat.widget.Toolbar) CommentOverflow(me.ccrama.redditslide.Views.CommentOverflow) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Snackbar(com.google.android.material.snackbar.Snackbar) LayoutUtils(me.ccrama.redditslide.util.LayoutUtils) Context(android.content.Context) StaticLayout(android.text.StaticLayout) SettingValues(me.ccrama.redditslide.SettingValues) KeyEvent(android.view.KeyEvent) AlertDialog(androidx.appcompat.app.AlertDialog) Submission(net.dean.jraw.models.Submission) Intent(android.content.Intent) HashMap(java.util.HashMap) Constants(me.ccrama.redditslide.Constants) MenuItem(android.view.MenuItem) HashSet(java.util.HashSet) UserRecord(net.dean.jraw.models.UserRecord) SubredditView(me.ccrama.redditslide.Activities.SubredditView) DialogInterface(android.content.DialogInterface) MultiReddit(net.dean.jraw.models.MultiReddit) LayoutInflater(android.view.LayoutInflater) ImageFlairs(me.ccrama.redditslide.ImageFlairs) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MoreChildItem(me.ccrama.redditslide.Adapters.MoreChildItem) DialogAction(com.afollestad.materialdialogs.DialogAction) Subreddit(net.dean.jraw.models.Subreddit) CommentAdapter(me.ccrama.redditslide.Adapters.CommentAdapter) Activity(android.app.Activity) NetworkException(net.dean.jraw.http.NetworkException) Resources(android.content.res.Resources) ContentType(me.ccrama.redditslide.ContentType) Intent(android.content.Intent) MainActivity(me.ccrama.redditslide.Activities.MainActivity) MediaView(me.ccrama.redditslide.Activities.MediaView) ImageView(android.widget.ImageView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) CommentSearch(me.ccrama.redditslide.Activities.CommentSearch) CommentObject(me.ccrama.redditslide.Adapters.CommentObject) TextPaint(android.text.TextPaint) MediaView(me.ccrama.redditslide.Activities.MediaView) ContentType(me.ccrama.redditslide.ContentType) CommentNavType(me.ccrama.redditslide.Adapters.CommentNavType) CommentItem(me.ccrama.redditslide.Adapters.CommentItem) LayoutInflater(android.view.LayoutInflater) CommentUrlObject(me.ccrama.redditslide.Adapters.CommentUrlObject) Snackbar(com.google.android.material.snackbar.Snackbar)

Aggregations

Activity (android.app.Activity)1 Dialog (android.app.Dialog)1 Context (android.content.Context)1 ContextWrapper (android.content.ContextWrapper)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 Resources (android.content.res.Resources)1 AsyncTask (android.os.AsyncTask)1 Bundle (android.os.Bundle)1 Layout (android.text.Layout)1 StaticLayout (android.text.StaticLayout)1 TextPaint (android.text.TextPaint)1 KeyEvent (android.view.KeyEvent)1 LayoutInflater (android.view.LayoutInflater)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 WindowManager (android.view.WindowManager)1 EditText (android.widget.EditText)1 FrameLayout (android.widget.FrameLayout)1