Search in sources :

Example 1 with Album

use of me.ccrama.redditslide.Activities.Album in project Slide by ccrama.

the class SpoilerRobotoTextView method onLinkClick.

@Override
public void onLinkClick(String url, int xOffset, String subreddit, URLSpan span) {
    if (url == null) {
        ((View) getParent()).callOnClick();
        return;
    }
    ContentType.Type type = ContentType.getContentType(url);
    Context context = getContext();
    Activity activity = null;
    if (context instanceof Activity) {
        activity = (Activity) context;
    } else if (context instanceof ContextThemeWrapper) {
        activity = (Activity) ((ContextThemeWrapper) context).getBaseContext();
    } else if (context instanceof ContextWrapper) {
        Context context1 = ((ContextWrapper) context).getBaseContext();
        if (context1 instanceof Activity) {
            activity = (Activity) context1;
        } else if (context1 instanceof ContextWrapper) {
            Context context2 = ((ContextWrapper) context1).getBaseContext();
            if (context2 instanceof Activity) {
                activity = (Activity) context2;
            } else if (context2 instanceof ContextWrapper) {
                activity = (Activity) ((ContextThemeWrapper) context2).getBaseContext();
            }
        }
    } else {
        throw new RuntimeException("Could not find activity from context:" + context);
    }
    if (!PostMatch.openExternal(url) || type == ContentType.Type.VIDEO) {
        switch(type) {
            case DEVIANTART:
            case IMGUR:
            case XKCD:
                if (SettingValues.image) {
                    Intent intent2 = new Intent(activity, MediaView.class);
                    intent2.putExtra(MediaView.EXTRA_URL, url);
                    intent2.putExtra(MediaView.SUBREDDIT, subreddit);
                    activity.startActivity(intent2);
                } else {
                    LinkUtil.openExternally(url);
                }
                break;
            case REDDIT:
                OpenRedditLink.openUrl(activity, url, true);
                break;
            case LINK:
                LogUtil.v("Opening link");
                LinkUtil.openUrl(url, Palette.getColor(subreddit), activity);
                break;
            case SELF:
            case NONE:
                break;
            case STREAMABLE:
                openStreamable(url, subreddit);
                break;
            case ALBUM:
                if (SettingValues.album) {
                    Intent i;
                    if (SettingValues.albumSwipe) {
                        i = new Intent(activity, AlbumPager.class);
                        i.putExtra(Album.EXTRA_URL, url);
                        i.putExtra(AlbumPager.SUBREDDIT, subreddit);
                    } else {
                        i = new Intent(activity, Album.class);
                        i.putExtra(Album.SUBREDDIT, subreddit);
                        i.putExtra(Album.EXTRA_URL, url);
                    }
                    activity.startActivity(i);
                } else {
                    LinkUtil.openExternally(url);
                }
                break;
            case TUMBLR:
                if (SettingValues.image) {
                    Intent i = new Intent(activity, TumblrPager.class);
                    i.putExtra(Album.EXTRA_URL, url);
                    activity.startActivity(i);
                } else {
                    LinkUtil.openExternally(url);
                }
                break;
            case IMAGE:
                openImage(url, subreddit);
                break;
            case VREDDIT_REDIRECT:
                openVReddit(url, subreddit, activity);
                break;
            case GIF:
            case VREDDIT_DIRECT:
                openGif(url, subreddit, activity);
                break;
            case VIDEO:
                if (!LinkUtil.tryOpenWithVideoPlugin(url)) {
                    LinkUtil.openUrl(url, Palette.getStatusBarColor(), activity);
                }
            case SPOILER:
                spoilerClicked = true;
                setOrRemoveSpoilerSpans(xOffset, span);
                break;
            case EXTERNAL:
                LinkUtil.openExternally(url);
                break;
        }
    } else {
        LinkUtil.openExternally(url);
    }
}
Also used : Context(android.content.Context) AlbumPager(me.ccrama.redditslide.Activities.AlbumPager) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) PeekViewActivity(me.ccrama.redditslide.ForceTouch.PeekViewActivity) Activity(android.app.Activity) Album(me.ccrama.redditslide.Activities.Album) Intent(android.content.Intent) MediaView(me.ccrama.redditslide.Activities.MediaView) PeekView(me.ccrama.redditslide.ForceTouch.PeekView) View(android.view.View) TextView(android.widget.TextView) PeekMediaView(me.ccrama.redditslide.Views.PeekMediaView) RobotoTextView(com.devspark.robototextview.widget.RobotoTextView) ContextWrapper(android.content.ContextWrapper)

Example 2 with Album

use of me.ccrama.redditslide.Activities.Album 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)2 Context (android.content.Context)2 ContextWrapper (android.content.ContextWrapper)2 Intent (android.content.Intent)2 View (android.view.View)2 TextView (android.widget.TextView)2 ContextThemeWrapper (androidx.appcompat.view.ContextThemeWrapper)2 Album (me.ccrama.redditslide.Activities.Album)2 AlbumPager (me.ccrama.redditslide.Activities.AlbumPager)2 MediaView (me.ccrama.redditslide.Activities.MediaView)2 Dialog (android.app.Dialog)1 DialogInterface (android.content.DialogInterface)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