Search in sources :

Example 86 with Snackbar

use of com.google.android.material.snackbar.Snackbar in project Slide by ccrama.

the class CommentPage method changeSubscription.

private void changeSubscription(Subreddit subreddit, boolean isChecked) {
    UserSubscriptions.addSubreddit(subreddit.getDisplayName().toLowerCase(Locale.ENGLISH), getContext());
    Snackbar s = Snackbar.make(toolbar, isChecked ? getString(R.string.misc_subscribed) : getString(R.string.misc_unsubscribed), Snackbar.LENGTH_SHORT);
    LayoutUtils.showSnackbar(s);
}
Also used : Snackbar(com.google.android.material.snackbar.Snackbar)

Example 87 with Snackbar

use of com.google.android.material.snackbar.Snackbar 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)

Example 88 with Snackbar

use of com.google.android.material.snackbar.Snackbar in project Slide by ccrama.

the class NewsView method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context contextThemeWrapper = new ContextThemeWrapper(getActivity(), new ColorPreferences(inflater.getContext()).getThemeSubreddit(id));
    final View v = LayoutInflater.from(contextThemeWrapper).inflate(R.layout.fragment_verticalcontent, container, false);
    if (getActivity() instanceof MainActivity) {
        v.findViewById(R.id.back).setBackgroundResource(0);
    }
    rv = v.findViewById(R.id.vertical_content);
    rv.setHasFixedSize(true);
    final RecyclerView.LayoutManager mLayoutManager = createLayoutManager(LayoutUtils.getNumColumns(getResources().getConfiguration().orientation, getActivity()));
    if (!(getActivity() instanceof SubredditView)) {
        v.findViewById(R.id.back).setBackground(null);
    }
    rv.setLayoutManager(mLayoutManager);
    rv.setItemAnimator(new SlideUpAlphaAnimator().withInterpolator(new LinearOutSlowInInterpolator()));
    rv.getLayoutManager().scrollToPosition(0);
    mSwipeRefreshLayout = v.findViewById(R.id.activity_main_swipe_refresh_layout);
    mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors(id, getContext()));
    /**
     * If using List view mode, we need to remove the start margin from the SwipeRefreshLayout.
     * The scrollbar style of "outsideInset" creates a 4dp padding around it. To counter this,
     * change the scrollbar style to "insideOverlay" when list view is enabled.
     * To recap: this removes the margins from the start/end so list view is full-width.
     */
    if (SettingValues.defaultCardView == CreateCardView.CardEnum.LIST) {
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        MarginLayoutParamsCompat.setMarginStart(params, 0);
        rv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        mSwipeRefreshLayout.setLayoutParams(params);
    }
    /**
     * If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
     * So, we estimate the height of the header in dp.
     * If the view type is "single" (and therefore "commentPager"), we need a different offset
     */
    final int HEADER_OFFSET = (SettingValues.single || getActivity() instanceof SubredditView) ? Constants.SINGLE_HEADER_VIEW_OFFSET : Constants.TAB_HEADER_VIEW_OFFSET;
    mSwipeRefreshLayout.setProgressViewOffset(false, HEADER_OFFSET - Constants.PTR_OFFSET_TOP, HEADER_OFFSET + Constants.PTR_OFFSET_BOTTOM);
    if (SettingValues.fab) {
        fab = v.findViewById(R.id.post_floating_action_button);
        if (SettingValues.fabType == Constants.FAB_POST) {
            fab.setImageResource(R.drawable.ic_add);
            fab.setContentDescription(getString(R.string.btn_fab_post));
            fab.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Intent inte = new Intent(getActivity(), Submit.class);
                    inte.putExtra(Submit.EXTRA_SUBREDDIT, id);
                    getActivity().startActivity(inte);
                }
            });
        } else {
            fab.setImageResource(R.drawable.ic_visibility_off);
            fab.setContentDescription(getString(R.string.btn_fab_hide));
            fab.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (!Reddit.fabClear) {
                        new AlertDialog.Builder(getActivity()).setTitle(R.string.settings_fabclear).setMessage(R.string.settings_fabclear_msg).setPositiveButton(R.string.btn_ok, (dialog, which) -> {
                            Reddit.colors.edit().putBoolean(SettingValues.PREF_FAB_CLEAR, true).apply();
                            Reddit.fabClear = true;
                            clearSeenPosts(false);
                        }).show();
                    } else {
                        clearSeenPosts(false);
                    }
                }
            });
            final Handler handler = new Handler();
            fab.setOnTouchListener(new View.OnTouchListener() {

                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    detector.onTouchEvent(event);
                    if (event.getAction() == MotionEvent.ACTION_DOWN) {
                        origY = event.getY();
                        handler.postDelayed(mLongPressRunnable, android.view.ViewConfiguration.getLongPressTimeout());
                    }
                    if (((event.getAction() == MotionEvent.ACTION_MOVE) && Math.abs(event.getY() - origY) > fab.getHeight() / 2.0f) || (event.getAction() == MotionEvent.ACTION_UP)) {
                        handler.removeCallbacks(mLongPressRunnable);
                    }
                    return false;
                }
            });
            mLongPressRunnable = new Runnable() {

                public void run() {
                    fab.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                    if (!Reddit.fabClear) {
                        new AlertDialog.Builder(getActivity()).setTitle(R.string.settings_fabclear).setMessage(R.string.settings_fabclear_msg).setPositiveButton(R.string.btn_ok, (dialog, which) -> {
                            Reddit.colors.edit().putBoolean(SettingValues.PREF_FAB_CLEAR, true).apply();
                            Reddit.fabClear = true;
                            clearSeenPosts(true);
                        }).show();
                    } else {
                        clearSeenPosts(true);
                    }
                    Snackbar s = Snackbar.make(rv, getResources().getString(R.string.posts_hidden_forever), Snackbar.LENGTH_LONG);
                    /*Todo a way to unhide
                        s.setAction(R.string.btn_undo, new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {

                            }
                        });*/
                    LayoutUtils.showSnackbar(s);
                }
            };
        }
    } else {
        v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE);
    }
    if (fab != null)
        fab.show();
    header = getActivity().findViewById(R.id.header);
    // TODO, have it so that if the user clicks anywhere in the rv to hide and cancel GoToSubreddit?
    // final TextInputEditText GO_TO_SUB_FIELD = (TextInputEditText) getActivity().findViewById(R.id.toolbar_search);
    // final Toolbar TOOLBAR = ((Toolbar) getActivity().findViewById(R.id.toolbar));
    // final String PREV_TITLE = TOOLBAR.getTitle().toString();
    // final ImageView CLOSE_BUTTON = (ImageView) getActivity().findViewById(R.id.close);
    // 
    // rv.setOnTouchListener(new View.OnTouchListener() {
    // @Override
    // public boolean onTouch(View v, MotionEvent event) {
    // System.out.println("touched");
    // KeyboardUtil.hideKeyboard(getActivity(), v.getWindowToken(), 0);
    // 
    // GO_TO_SUB_FIELD.setText("");
    // GO_TO_SUB_FIELD.setVisibility(View.GONE);
    // CLOSE_BUTTON.setVisibility(View.GONE);
    // TOOLBAR.setTitle(PREV_TITLE);
    // 
    // return false;
    // }
    // });
    resetScroll();
    Reddit.isLoading = false;
    if (MainActivity.shouldLoad == null || id == null || (MainActivity.shouldLoad != null && MainActivity.shouldLoad.equals(id)) || !(getActivity() instanceof MainActivity)) {
        doAdapter();
    }
    return v;
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) SubredditView(me.ccrama.redditslide.Activities.SubredditView) MainActivity(me.ccrama.redditslide.Activities.MainActivity) SlideUpAlphaAnimator(com.mikepenz.itemanimators.SlideUpAlphaAnimator) LinearOutSlowInInterpolator(androidx.interpolator.view.animation.LinearOutSlowInInterpolator) Context(android.content.Context) ColorPreferences(me.ccrama.redditslide.Visuals.ColorPreferences) Handler(android.os.Handler) ToolbarScrollHideHandler(me.ccrama.redditslide.handler.ToolbarScrollHideHandler) Intent(android.content.Intent) SubredditView(me.ccrama.redditslide.Activities.SubredditView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) MotionEvent(android.view.MotionEvent) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) RelativeLayout(android.widget.RelativeLayout) Submit(me.ccrama.redditslide.Activities.Submit) RecyclerView(androidx.recyclerview.widget.RecyclerView) Snackbar(com.google.android.material.snackbar.Snackbar)

Example 89 with Snackbar

use of com.google.android.material.snackbar.Snackbar in project Slide by ccrama.

the class SubmissionsView method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context contextThemeWrapper = new ContextThemeWrapper(getActivity(), new ColorPreferences(inflater.getContext()).getThemeSubreddit(id));
    final View v = LayoutInflater.from(contextThemeWrapper).inflate(R.layout.fragment_verticalcontent, container, false);
    if (getActivity() instanceof MainActivity) {
        v.findViewById(R.id.back).setBackgroundResource(0);
    }
    rv = v.findViewById(R.id.vertical_content);
    rv.setHasFixedSize(true);
    final RecyclerView.LayoutManager mLayoutManager = createLayoutManager(LayoutUtils.getNumColumns(getResources().getConfiguration().orientation, getActivity()));
    if (!(getActivity() instanceof SubredditView)) {
        v.findViewById(R.id.back).setBackground(null);
    }
    rv.setLayoutManager(mLayoutManager);
    rv.setItemAnimator(new SlideUpAlphaAnimator().withInterpolator(new LinearOutSlowInInterpolator()));
    rv.getLayoutManager().scrollToPosition(0);
    mSwipeRefreshLayout = v.findViewById(R.id.activity_main_swipe_refresh_layout);
    mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors(id, getContext()));
    /**
     * If using List view mode, we need to remove the start margin from the SwipeRefreshLayout.
     * The scrollbar style of "outsideInset" creates a 4dp padding around it. To counter this,
     * change the scrollbar style to "insideOverlay" when list view is enabled.
     * To recap: this removes the margins from the start/end so list view is full-width.
     */
    if (SettingValues.defaultCardView == CreateCardView.CardEnum.LIST) {
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        MarginLayoutParamsCompat.setMarginStart(params, 0);
        rv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        mSwipeRefreshLayout.setLayoutParams(params);
    }
    /**
     * If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
     * So, we estimate the height of the header in dp.
     * If the view type is "single" (and therefore "commentPager"), we need a different offset
     */
    final int HEADER_OFFSET = (SettingValues.single || getActivity() instanceof SubredditView) ? Constants.SINGLE_HEADER_VIEW_OFFSET : Constants.TAB_HEADER_VIEW_OFFSET;
    mSwipeRefreshLayout.setProgressViewOffset(false, HEADER_OFFSET - Constants.PTR_OFFSET_TOP, HEADER_OFFSET + Constants.PTR_OFFSET_BOTTOM);
    if (SettingValues.fab) {
        fab = v.findViewById(R.id.post_floating_action_button);
        if (SettingValues.fabType == Constants.FAB_POST) {
            fab.setImageResource(R.drawable.ic_add);
            fab.setContentDescription(getString(R.string.btn_fab_post));
            fab.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Intent inte = new Intent(getActivity(), Submit.class);
                    inte.putExtra(Submit.EXTRA_SUBREDDIT, id);
                    getActivity().startActivity(inte);
                }
            });
        } else if (SettingValues.fabType == Constants.FAB_SEARCH) {
            fab.setImageResource(R.drawable.ic_search);
            fab.setContentDescription(getString(R.string.btn_fab_search));
            fab.setOnClickListener(new View.OnClickListener() {

                String term;

                @Override
                public void onClick(View v) {
                    MaterialDialog.Builder builder = new MaterialDialog.Builder(getActivity()).title(R.string.search_title).alwaysCallInputCallback().input(getString(R.string.search_msg), "", new MaterialDialog.InputCallback() {

                        @Override
                        public void onInput(MaterialDialog materialDialog, CharSequence charSequence) {
                            term = charSequence.toString();
                        }
                    });
                    // Add "search current sub" if it is not frontpage/all/random
                    if (!id.equalsIgnoreCase("frontpage") && !id.equalsIgnoreCase("all") && !id.contains(".") && !id.contains("/m/") && !id.equalsIgnoreCase("friends") && !id.equalsIgnoreCase("random") && !id.equalsIgnoreCase("popular") && !id.equalsIgnoreCase("myrandom") && !id.equalsIgnoreCase("randnsfw")) {
                        builder.positiveText(getString(R.string.search_subreddit, id)).onPositive(new MaterialDialog.SingleButtonCallback() {

                            @Override
                            public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
                                Intent i = new Intent(getActivity(), Search.class);
                                i.putExtra(Search.EXTRA_TERM, term);
                                i.putExtra(Search.EXTRA_SUBREDDIT, id);
                                startActivity(i);
                            }
                        });
                        builder.neutralText(R.string.search_all).onNeutral(new MaterialDialog.SingleButtonCallback() {

                            @Override
                            public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
                                Intent i = new Intent(getActivity(), Search.class);
                                i.putExtra(Search.EXTRA_TERM, term);
                                startActivity(i);
                            }
                        });
                    } else {
                        builder.positiveText(R.string.search_all).onPositive(new MaterialDialog.SingleButtonCallback() {

                            @Override
                            public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
                                Intent i = new Intent(getActivity(), Search.class);
                                i.putExtra(Search.EXTRA_TERM, term);
                                startActivity(i);
                            }
                        });
                    }
                    builder.show();
                }
            });
        } else {
            fab.setImageResource(R.drawable.ic_visibility_off);
            fab.setContentDescription(getString(R.string.btn_fab_hide));
            fab.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (!Reddit.fabClear) {
                        new AlertDialog.Builder(getActivity()).setTitle(R.string.settings_fabclear).setMessage(R.string.settings_fabclear_msg).setPositiveButton(R.string.btn_ok, (dialog, which) -> {
                            Reddit.colors.edit().putBoolean(SettingValues.PREF_FAB_CLEAR, true).apply();
                            Reddit.fabClear = true;
                            clearSeenPosts(false);
                        }).show();
                    } else {
                        clearSeenPosts(false);
                    }
                }
            });
            final Handler handler = new Handler();
            fab.setOnTouchListener(new View.OnTouchListener() {

                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    detector.onTouchEvent(event);
                    if (event.getAction() == MotionEvent.ACTION_DOWN) {
                        origY = event.getY();
                        handler.postDelayed(mLongPressRunnable, android.view.ViewConfiguration.getLongPressTimeout());
                    }
                    if (((event.getAction() == MotionEvent.ACTION_MOVE) && Math.abs(event.getY() - origY) > fab.getHeight() / 2.0f) || (event.getAction() == MotionEvent.ACTION_UP)) {
                        handler.removeCallbacks(mLongPressRunnable);
                    }
                    return false;
                }
            });
            mLongPressRunnable = new Runnable() {

                public void run() {
                    fab.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                    if (!Reddit.fabClear) {
                        new AlertDialog.Builder(getActivity()).setTitle(R.string.settings_fabclear).setMessage(R.string.settings_fabclear_msg).setPositiveButton(R.string.btn_ok, (dialog, which) -> {
                            Reddit.colors.edit().putBoolean(SettingValues.PREF_FAB_CLEAR, true).apply();
                            Reddit.fabClear = true;
                            clearSeenPosts(true);
                        }).show();
                    } else {
                        clearSeenPosts(true);
                    }
                    Snackbar s = Snackbar.make(rv, getResources().getString(R.string.posts_hidden_forever), Snackbar.LENGTH_LONG);
                    /*Todo a way to unhide
                        s.setAction(R.string.btn_undo, new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {

                            }
                        });*/
                    LayoutUtils.showSnackbar(s);
                }
            };
        }
    } else {
        v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE);
    }
    if (fab != null)
        fab.show();
    header = getActivity().findViewById(R.id.header);
    // TODO, have it so that if the user clicks anywhere in the rv to hide and cancel GoToSubreddit?
    // final TextInputEditText GO_TO_SUB_FIELD = (TextInputEditText) getActivity().findViewById(R.id.toolbar_search);
    // final Toolbar TOOLBAR = ((Toolbar) getActivity().findViewById(R.id.toolbar));
    // final String PREV_TITLE = TOOLBAR.getTitle().toString();
    // final ImageView CLOSE_BUTTON = (ImageView) getActivity().findViewById(R.id.close);
    // 
    // rv.setOnTouchListener(new View.OnTouchListener() {
    // @Override
    // public boolean onTouch(View v, MotionEvent event) {
    // System.out.println("touched");
    // KeyboardUtil.hideKeyboard(getActivity(), v.getWindowToken(), 0);
    // 
    // GO_TO_SUB_FIELD.setText("");
    // GO_TO_SUB_FIELD.setVisibility(View.GONE);
    // CLOSE_BUTTON.setVisibility(View.GONE);
    // TOOLBAR.setTitle(PREV_TITLE);
    // 
    // return false;
    // }
    // });
    resetScroll();
    Reddit.isLoading = false;
    if (MainActivity.shouldLoad == null || id == null || (MainActivity.shouldLoad != null && MainActivity.shouldLoad.equals(id)) || !(getActivity() instanceof MainActivity)) {
        doAdapter();
    }
    return v;
}
Also used : Bundle(android.os.Bundle) R(me.ccrama.redditslide.R) NonNull(androidx.annotation.NonNull) MainActivity(me.ccrama.redditslide.Activities.MainActivity) Locale(java.util.Locale) Handler(android.os.Handler) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) Fragment(androidx.fragment.app.Fragment) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) SubredditPosts(me.ccrama.redditslide.Adapters.SubredditPosts) MarginLayoutParamsCompat(androidx.core.view.MarginLayoutParamsCompat) Palette(me.ccrama.redditslide.Visuals.Palette) ViewGroup(android.view.ViewGroup) CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) HapticFeedbackConstants(android.view.HapticFeedbackConstants) OfflineSubreddit(me.ccrama.redditslide.OfflineSubreddit) List(java.util.List) RelativeLayout(android.widget.RelativeLayout) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Snackbar(com.google.android.material.snackbar.Snackbar) LayoutUtils(me.ccrama.redditslide.util.LayoutUtils) Context(android.content.Context) LinearOutSlowInInterpolator(androidx.interpolator.view.animation.LinearOutSlowInInterpolator) GestureDetector(android.view.GestureDetector) BaseActivity(me.ccrama.redditslide.Activities.BaseActivity) SettingValues(me.ccrama.redditslide.SettingValues) AlertDialog(androidx.appcompat.app.AlertDialog) HasSeen(me.ccrama.redditslide.HasSeen) Submission(net.dean.jraw.models.Submission) Intent(android.content.Intent) Constants(me.ccrama.redditslide.Constants) Hidden(me.ccrama.redditslide.Hidden) MotionEvent(android.view.MotionEvent) Search(me.ccrama.redditslide.Activities.Search) SubredditView(me.ccrama.redditslide.Activities.SubredditView) SubmissionAdapter(me.ccrama.redditslide.Adapters.SubmissionAdapter) AlphaInAnimator(com.mikepenz.itemanimators.AlphaInAnimator) LayoutInflater(android.view.LayoutInflater) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) Reddit(me.ccrama.redditslide.Reddit) DialogAction(com.afollestad.materialdialogs.DialogAction) Submit(me.ccrama.redditslide.Activities.Submit) ColorPreferences(me.ccrama.redditslide.Visuals.ColorPreferences) ToolbarScrollHideHandler(me.ccrama.redditslide.handler.ToolbarScrollHideHandler) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) SubmissionDisplay(me.ccrama.redditslide.Adapters.SubmissionDisplay) SlideUpAlphaAnimator(com.mikepenz.itemanimators.SlideUpAlphaAnimator) Configuration(android.content.res.Configuration) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) MainActivity(me.ccrama.redditslide.Activities.MainActivity) SlideUpAlphaAnimator(com.mikepenz.itemanimators.SlideUpAlphaAnimator) LinearOutSlowInInterpolator(androidx.interpolator.view.animation.LinearOutSlowInInterpolator) Search(me.ccrama.redditslide.Activities.Search) Context(android.content.Context) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ColorPreferences(me.ccrama.redditslide.Visuals.ColorPreferences) Handler(android.os.Handler) ToolbarScrollHideHandler(me.ccrama.redditslide.handler.ToolbarScrollHideHandler) Intent(android.content.Intent) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) MotionEvent(android.view.MotionEvent) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) DialogAction(com.afollestad.materialdialogs.DialogAction) RelativeLayout(android.widget.RelativeLayout) Submit(me.ccrama.redditslide.Activities.Submit) RecyclerView(androidx.recyclerview.widget.RecyclerView) Snackbar(com.google.android.material.snackbar.Snackbar)

Example 90 with Snackbar

use of com.google.android.material.snackbar.Snackbar in project Slide by ccrama.

the class MultiredditAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder2, final int pos) {
    int i = (pos != 0) ? (pos - 1) : pos;
    if (holder2 instanceof SubmissionViewHolder) {
        final SubmissionViewHolder holder = (SubmissionViewHolder) holder2;
        final Submission submission = dataSet.posts.get(i);
        CreateCardView.colorCard(submission.getSubredditName().toLowerCase(Locale.ENGLISH), holder.itemView, "multi" + dataSet.multiReddit.getDisplayName(), true);
        holder.itemView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                if (Authentication.didOnline || submission.getComments() != null) {
                    holder.title.setAlpha(0.65f);
                    holder.leadImage.setAlpha(0.65f);
                    holder.thumbimage.setAlpha(0.65f);
                    Intent i2 = new Intent(context, CommentsScreen.class);
                    i2.putExtra(CommentsScreen.EXTRA_PAGE, holder2.getBindingAdapterPosition() - 1);
                    i2.putExtra(CommentsScreen.EXTRA_MULTIREDDIT, dataSet.multiReddit.getDisplayName());
                    context.startActivityForResult(i2, 940);
                    i2.putExtra("fullname", submission.getFullName());
                    clicked = holder2.getBindingAdapterPosition();
                } else {
                    Snackbar s = Snackbar.make(holder.itemView, R.string.offline_comments_not_loaded, Snackbar.LENGTH_SHORT);
                    LayoutUtils.showSnackbar(s);
                }
            }
        });
        new PopulateSubmissionViewHolder().populateSubmissionViewHolder(holder, submission, context, false, false, dataSet.posts, listView, true, false, "multi" + dataSet.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH), null);
    }
    if (holder2 instanceof SubmissionFooterViewHolder) {
        Handler handler = new Handler();
        final Runnable r = new Runnable() {

            public void run() {
                // the loading spinner to replaced by nomoreposts.xml
                notifyItemChanged(dataSet.posts.size() + 1);
            }
        };
        handler.post(r);
        if (holder2.itemView.findViewById(R.id.reload) != null) {
            holder2.itemView.findViewById(R.id.reload).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    dataSet.loadMore(context, baseView, true, MultiredditAdapter.this);
                }
            });
        }
    }
    if (holder2 instanceof SpacerViewHolder) {
        final int height = (context).findViewById(R.id.header).getHeight();
        holder2.itemView.findViewById(R.id.height).setLayoutParams(new LinearLayout.LayoutParams(holder2.itemView.getWidth(), height));
        if (listView.getLayoutManager() instanceof CatchStaggeredGridLayoutManager) {
            CatchStaggeredGridLayoutManager.LayoutParams layoutParams = new CatchStaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height);
            layoutParams.setFullSpan(true);
            holder2.itemView.setLayoutParams(layoutParams);
        }
    }
}
Also used : CommentsScreen(me.ccrama.redditslide.Activities.CommentsScreen) CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) Submission(net.dean.jraw.models.Submission) PopulateSubmissionViewHolder(me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder) Handler(android.os.Handler) Intent(android.content.Intent) MultiredditView(me.ccrama.redditslide.Fragments.MultiredditView) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) PopulateSubmissionViewHolder(me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder) LinearLayout(android.widget.LinearLayout) Snackbar(com.google.android.material.snackbar.Snackbar)

Aggregations

Snackbar (com.google.android.material.snackbar.Snackbar)110 View (android.view.View)61 Intent (android.content.Intent)46 TextView (android.widget.TextView)41 AlertDialog (androidx.appcompat.app.AlertDialog)29 Context (android.content.Context)28 ImageView (android.widget.ImageView)28 LayoutInflater (android.view.LayoutInflater)24 ArrayList (java.util.ArrayList)23 RecyclerView (androidx.recyclerview.widget.RecyclerView)22 Bundle (android.os.Bundle)20 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)20 DialogInterface (android.content.DialogInterface)19 List (java.util.List)19 CreateCardView (me.ccrama.redditslide.Views.CreateCardView)18 Submission (net.dean.jraw.models.Submission)18 SubredditView (me.ccrama.redditslide.Activities.SubredditView)17 ApiException (net.dean.jraw.ApiException)17 Activity (android.app.Activity)16 OnSingleClickListener (me.ccrama.redditslide.util.OnSingleClickListener)16