Search in sources :

Example 16 with Snackbar

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

the class PopulateSubmissionViewHolder method hideSubmission.

public <T extends Contribution> void hideSubmission(final Submission submission, final List<T> posts, final String baseSub, final RecyclerView recyclerview, Context c) {
    final int pos = posts.indexOf(submission);
    if (pos != -1) {
        if (submission.isHidden()) {
            posts.remove(pos);
            Hidden.undoHidden(submission);
            recyclerview.getAdapter().notifyItemRemoved(pos + 1);
            Snackbar snack = Snackbar.make(recyclerview, R.string.submission_info_unhidden, Snackbar.LENGTH_LONG);
            LayoutUtils.showSnackbar(snack);
        } else {
            final T t = posts.get(pos);
            posts.remove(pos);
            Hidden.setHidden(t);
            final OfflineSubreddit s;
            boolean success = false;
            if (baseSub != null) {
                s = OfflineSubreddit.getSubreddit(baseSub, false, c);
                try {
                    s.hide(pos);
                    success = true;
                } catch (Exception e) {
                }
            } else {
                success = false;
                s = null;
            }
            recyclerview.getAdapter().notifyItemRemoved(pos + 1);
            final boolean finalSuccess = success;
            Snackbar snack = Snackbar.make(recyclerview, R.string.submission_info_hidden, Snackbar.LENGTH_LONG).setAction(R.string.btn_undo, new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (baseSub != null && s != null && finalSuccess) {
                        s.unhideLast();
                    }
                    posts.add(pos, t);
                    recyclerview.getAdapter().notifyItemInserted(pos + 1);
                    Hidden.undoHidden(t);
                }
            });
            LayoutUtils.showSnackbar(snack);
        }
    }
}
Also used : OfflineSubreddit(me.ccrama.redditslide.OfflineSubreddit) MediaView(me.ccrama.redditslide.Activities.MediaView) ImageView(android.widget.ImageView) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) InvalidScopeException(net.dean.jraw.http.oauth.InvalidScopeException) ApiException(net.dean.jraw.ApiException) NetworkException(net.dean.jraw.http.NetworkException) Snackbar(com.google.android.material.snackbar.Snackbar)

Example 17 with Snackbar

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

the class PopulateSubmissionViewHolder method showModBottomSheet.

public <T extends Contribution> void showModBottomSheet(final Activity mContext, final Submission submission, final List<T> posts, final SubmissionViewHolder holder, final RecyclerView recyclerview, final Map<String, Integer> reports, final Map<String, String> reports2) {
    final Resources res = mContext.getResources();
    int[] attrs = new int[] { R.attr.tintColor };
    TypedArray ta = mContext.obtainStyledAttributes(attrs);
    int color = ta.getColor(0, Color.WHITE);
    Drawable profile = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_account_circle, null);
    final Drawable report = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_report, null);
    final Drawable approve = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_thumb_up, null);
    final Drawable nsfw = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_visibility_off, null);
    final Drawable spoiler = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_remove_circle, null);
    final Drawable pin = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_bookmark_border, null);
    final Drawable lock = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_lock, null);
    final Drawable flair = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_format_quote, null);
    final Drawable remove = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_close, null);
    final Drawable remove_reason = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_announcement, null);
    final Drawable ban = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_gavel, null);
    final Drawable spam = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_flag, null);
    final Drawable distinguish = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_star, null);
    final Drawable note = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_note, null);
    final List<Drawable> drawableSet = Arrays.asList(profile, report, approve, spam, nsfw, pin, flair, remove, spoiler, remove_reason, ban, spam, distinguish, lock, note);
    BlendModeUtil.tintDrawablesAsSrcAtop(drawableSet, color);
    ta.recycle();
    BottomSheet.Builder b = new BottomSheet.Builder(mContext).title(CompatUtil.fromHtml(submission.getTitle()));
    int reportCount = reports.size() + reports2.size();
    b.sheet(0, report, res.getQuantityString(R.plurals.mod_btn_reports, reportCount, reportCount));
    if (SettingValues.toolboxEnabled) {
        b.sheet(24, note, res.getString(R.string.mod_usernotes_view));
    }
    boolean approved = false;
    String whoApproved = "";
    b.sheet(1, approve, res.getString(R.string.mod_btn_approve));
    b.sheet(6, remove, mContext.getString(R.string.mod_btn_remove)).sheet(7, remove_reason, res.getString(R.string.mod_btn_remove_reason)).sheet(30, spam, res.getString(R.string.mod_btn_spam));
    // b.sheet(2, spam, mContext.getString(R.string.mod_btn_spam)) todo this
    b.sheet(20, flair, res.getString(R.string.mod_btn_submission_flair));
    final boolean isNsfw = submission.isNsfw();
    if (isNsfw) {
        b.sheet(3, nsfw, res.getString(R.string.mod_btn_unmark_nsfw));
    } else {
        b.sheet(3, nsfw, res.getString(R.string.mod_btn_mark_nsfw));
    }
    final boolean isSpoiler = submission.getDataNode().get("spoiler").asBoolean();
    if (isSpoiler) {
        b.sheet(12, nsfw, res.getString(R.string.mod_btn_unmark_spoiler));
    } else {
        b.sheet(12, nsfw, res.getString(R.string.mod_btn_mark_spoiler));
    }
    final boolean locked = submission.isLocked();
    if (locked) {
        b.sheet(9, lock, res.getString(R.string.mod_btn_unlock_thread));
    } else {
        b.sheet(9, lock, res.getString(R.string.mod_btn_lock_thread));
    }
    final boolean stickied = submission.isStickied();
    if (!SubmissionCache.removed.contains(submission.getFullName())) {
        if (stickied) {
            b.sheet(4, pin, res.getString(R.string.mod_btn_unpin));
        } else {
            b.sheet(4, pin, res.getString(R.string.mod_btn_pin));
        }
    }
    final boolean distinguished = submission.getDistinguishedStatus() == DistinguishedStatus.MODERATOR || submission.getDistinguishedStatus() == DistinguishedStatus.ADMIN;
    if (submission.getAuthor().equalsIgnoreCase(Authentication.name)) {
        if (distinguished) {
            b.sheet(5, distinguish, "Undistingiush");
        } else {
            b.sheet(5, distinguish, "Distinguish");
        }
    }
    final String finalWhoApproved = whoApproved;
    final boolean finalApproved = approved;
    b.sheet(8, profile, res.getString(R.string.mod_btn_author));
    b.sheet(23, ban, mContext.getString(R.string.mod_ban_user));
    b.listener(new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            switch(which) {
                case 0:
                    new AsyncTask<Void, Void, ArrayList<String>>() {

                        @Override
                        protected ArrayList<String> doInBackground(Void... params) {
                            ArrayList<String> finalReports = new ArrayList<>();
                            for (Map.Entry<String, Integer> entry : reports.entrySet()) {
                                finalReports.add(entry.getValue() + "× " + entry.getKey());
                            }
                            for (Map.Entry<String, String> entry : reports2.entrySet()) {
                                finalReports.add(entry.getKey() + ": " + entry.getValue());
                            }
                            if (finalReports.isEmpty()) {
                                finalReports.add(mContext.getString(R.string.mod_no_reports));
                            }
                            return finalReports;
                        }

                        @Override
                        public void onPostExecute(ArrayList<String> data) {
                            new AlertDialog.Builder(mContext).setTitle(R.string.mod_reports).setItems(data.toArray(new CharSequence[0]), null).show();
                        }
                    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                    break;
                case 1:
                    if (finalApproved) {
                        Intent i = new Intent(mContext, Profile.class);
                        i.putExtra(Profile.EXTRA_PROFILE, finalWhoApproved);
                        mContext.startActivity(i);
                    } else {
                        approveSubmission(mContext, posts, submission, recyclerview, holder);
                    }
                    break;
                case 2:
                    // todo this
                    break;
                case 3:
                    if (isNsfw) {
                        unNsfwSubmission(mContext, submission, holder);
                    } else {
                        setPostNsfw(mContext, submission, holder);
                    }
                    break;
                case 12:
                    if (isSpoiler) {
                        unSpoiler(mContext, submission, holder);
                    } else {
                        setSpoiler(mContext, submission, holder);
                    }
                    break;
                case 9:
                    if (locked) {
                        unLockSubmission(mContext, submission, holder);
                    } else {
                        lockSubmission(mContext, submission, holder);
                    }
                    break;
                case 4:
                    if (stickied) {
                        unStickySubmission(mContext, submission, holder);
                    } else {
                        stickySubmission(mContext, submission, holder);
                    }
                    break;
                case 5:
                    if (distinguished) {
                        unDistinguishSubmission(mContext, submission, holder);
                    } else {
                        distinguishSubmission(mContext, submission, holder);
                    }
                    break;
                case 6:
                    removeSubmission(mContext, submission, posts, recyclerview, holder, false);
                    break;
                case 7:
                    if (SettingValues.removalReasonType == SettingValues.RemovalReasonType.TOOLBOX.ordinal() && ToolboxUI.canShowRemoval(submission.getSubredditName())) {
                        ToolboxUI.showRemoval(mContext, submission, new ToolboxUI.CompletedRemovalCallback() {

                            @Override
                            public void onComplete(boolean success) {
                                if (success) {
                                    SubmissionCache.removed.add(submission.getFullName());
                                    SubmissionCache.approved.remove(submission.getFullName());
                                    SubmissionCache.updateInfoSpannable(submission, mContext, submission.getSubredditName());
                                    if (mContext instanceof ModQueue) {
                                        final int pos = posts.indexOf(submission);
                                        posts.remove(submission);
                                        if (pos == 0) {
                                            recyclerview.getAdapter().notifyDataSetChanged();
                                        } else {
                                            recyclerview.getAdapter().notifyItemRemoved(pos + 1);
                                        }
                                    } else {
                                        recyclerview.getAdapter().notifyItemChanged(holder.getBindingAdapterPosition());
                                    }
                                    Snackbar s = Snackbar.make(holder.itemView, R.string.submission_removed, Snackbar.LENGTH_LONG);
                                    LayoutUtils.showSnackbar(s);
                                } else {
                                    new AlertDialog.Builder(mContext).setTitle(R.string.err_general).setMessage(R.string.err_retry_later).show();
                                }
                            }
                        });
                    } else {
                        // Show a Slide reason dialog if we can't show a toolbox or reddit one
                        doRemoveSubmissionReason(mContext, submission, posts, recyclerview, holder);
                    }
                    break;
                case 30:
                    removeSubmission(mContext, submission, posts, recyclerview, holder, true);
                    break;
                case 8:
                    Intent i = new Intent(mContext, Profile.class);
                    i.putExtra(Profile.EXTRA_PROFILE, submission.getAuthor());
                    mContext.startActivity(i);
                    break;
                case 20:
                    doSetFlair(mContext, submission, holder);
                    break;
                case 23:
                    // ban a user
                    showBan(mContext, holder.itemView, submission, "", "", "", "");
                    break;
                case 24:
                    ToolboxUI.showUsernotes(mContext, submission.getAuthor(), submission.getSubredditName(), "l," + submission.getId());
                    break;
            }
        }
    });
    b.show();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) Profile(me.ccrama.redditslide.Activities.Profile) ModQueue(me.ccrama.redditslide.Activities.ModQueue) TypedArray(android.content.res.TypedArray) Drawable(android.graphics.drawable.Drawable) AsyncTask(android.os.AsyncTask) Intent(android.content.Intent) Resources(android.content.res.Resources) BottomSheet(com.cocosw.bottomsheet.BottomSheet) Map(java.util.Map) Snackbar(com.google.android.material.snackbar.Snackbar)

Example 18 with Snackbar

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

the class PopulateNewsViewHolder method addClickFunctions.

private static void addClickFunctions(final View base, final ContentType.Type type, final Activity contextActivity, final Submission submission, final NewsViewHolder holder, final boolean full) {
    base.setOnClickListener(new OnSingleClickListener() {

        @Override
        public void onSingleClick(View v) {
            if (NetworkUtil.isConnected(contextActivity) || (!NetworkUtil.isConnected(contextActivity) && ContentType.fullImage(type))) {
                if (SettingValues.storeHistory && !full) {
                    if (!submission.isNsfw() || SettingValues.storeNSFWHistory) {
                        HasSeen.addSeen(submission.getFullName());
                        if (contextActivity instanceof MainActivity || contextActivity instanceof MultiredditOverview || contextActivity instanceof SubredditView || contextActivity instanceof Search || contextActivity instanceof Profile) {
                            holder.title.setAlpha(0.54f);
                        }
                    }
                }
                if (!(contextActivity instanceof PeekViewActivity) || !((PeekViewActivity) contextActivity).isPeeking() || (base instanceof HeaderImageLinkView && ((HeaderImageLinkView) base).popped)) {
                    if (!PostMatch.openExternal(submission.getUrl()) || type == ContentType.Type.VIDEO) {
                        switch(type) {
                            case STREAMABLE:
                                if (SettingValues.video) {
                                    Intent myIntent = new Intent(contextActivity, MediaView.class);
                                    myIntent.putExtra(MediaView.SUBREDDIT, submission.getSubredditName());
                                    myIntent.putExtra(MediaView.EXTRA_URL, submission.getUrl());
                                    myIntent.putExtra(EXTRA_SUBMISSION_TITLE, submission.getTitle());
                                    contextActivity.startActivity(myIntent);
                                } else {
                                    LinkUtil.openExternally(submission.getUrl());
                                }
                                break;
                            case IMGUR:
                            case DEVIANTART:
                            case XKCD:
                            case IMAGE:
                                openImage(type, contextActivity, submission, holder.leadImage, holder.getBindingAdapterPosition());
                                break;
                            case EMBEDDED:
                                if (SettingValues.video) {
                                    String data = CompatUtil.fromHtml(submission.getDataNode().get("media_embed").get("content").asText()).toString();
                                    {
                                        Intent i = new Intent(contextActivity, FullscreenVideo.class);
                                        i.putExtra(FullscreenVideo.EXTRA_HTML, data);
                                        contextActivity.startActivity(i);
                                    }
                                } else {
                                    LinkUtil.openExternally(submission.getUrl());
                                }
                                break;
                            case REDDIT:
                                openRedditContent(submission.getUrl(), contextActivity);
                                break;
                            case LINK:
                                LinkUtil.openUrl(submission.getUrl(), Palette.getColor(submission.getSubredditName()), contextActivity, holder.getBindingAdapterPosition(), submission);
                                break;
                            case SELF:
                                if (holder != null) {
                                    OnSingleClickListener.override = true;
                                    holder.itemView.performClick();
                                }
                                break;
                            case ALBUM:
                                if (SettingValues.album) {
                                    Intent i;
                                    if (SettingValues.albumSwipe) {
                                        i = new Intent(contextActivity, AlbumPager.class);
                                        i.putExtra(AlbumPager.SUBREDDIT, submission.getSubredditName());
                                    } else {
                                        i = new Intent(contextActivity, Album.class);
                                        i.putExtra(Album.SUBREDDIT, submission.getSubredditName());
                                    }
                                    i.putExtra(EXTRA_SUBMISSION_TITLE, submission.getTitle());
                                    i.putExtra(Album.EXTRA_URL, submission.getUrl());
                                    PopulateBase.addAdaptorPosition(i, submission, holder.getBindingAdapterPosition());
                                    contextActivity.startActivity(i);
                                    contextActivity.overridePendingTransition(R.anim.slideright, R.anim.fade_out);
                                } else {
                                    LinkUtil.openExternally(submission.getUrl());
                                }
                                break;
                            case TUMBLR:
                                if (SettingValues.album) {
                                    Intent i;
                                    if (SettingValues.albumSwipe) {
                                        i = new Intent(contextActivity, TumblrPager.class);
                                        i.putExtra(TumblrPager.SUBREDDIT, submission.getSubredditName());
                                    } else {
                                        i = new Intent(contextActivity, Tumblr.class);
                                        i.putExtra(Tumblr.SUBREDDIT, submission.getSubredditName());
                                    }
                                    i.putExtra(Album.EXTRA_URL, submission.getUrl());
                                    PopulateBase.addAdaptorPosition(i, submission, holder.getBindingAdapterPosition());
                                    contextActivity.startActivity(i);
                                    contextActivity.overridePendingTransition(R.anim.slideright, R.anim.fade_out);
                                } else {
                                    LinkUtil.openExternally(submission.getUrl());
                                }
                                break;
                            case GIF:
                                openGif(contextActivity, submission, holder.getBindingAdapterPosition());
                                break;
                            case NONE:
                                if (holder != null) {
                                    holder.itemView.performClick();
                                }
                                break;
                            case VIDEO:
                                if (!LinkUtil.tryOpenWithVideoPlugin(submission.getUrl())) {
                                    LinkUtil.openUrl(submission.getUrl(), Palette.getStatusBarColor(), contextActivity);
                                }
                                break;
                        }
                    } else {
                        LinkUtil.openExternally(submission.getUrl());
                    }
                }
            } else {
                if (!(contextActivity instanceof PeekViewActivity) || !((PeekViewActivity) contextActivity).isPeeking()) {
                    Snackbar s = Snackbar.make(holder.itemView, R.string.go_online_view_content, Snackbar.LENGTH_SHORT);
                    LayoutUtils.showSnackbar(s);
                }
            }
        }
    });
}
Also used : MultiredditOverview(me.ccrama.redditslide.Activities.MultiredditOverview) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) SubredditView(me.ccrama.redditslide.Activities.SubredditView) Intent(android.content.Intent) MainActivity(me.ccrama.redditslide.Activities.MainActivity) MediaView(me.ccrama.redditslide.Activities.MediaView) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) Profile(me.ccrama.redditslide.Activities.Profile) MediaView(me.ccrama.redditslide.Activities.MediaView) Search(me.ccrama.redditslide.Activities.Search) PeekViewActivity(me.ccrama.redditslide.ForceTouch.PeekViewActivity) Snackbar(com.google.android.material.snackbar.Snackbar)

Example 19 with Snackbar

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

the class PopulateNewsViewHolder method hideSubmission.

public <T extends Contribution> void hideSubmission(final Submission submission, final List<T> posts, final String baseSub, final RecyclerView recyclerview, Context c) {
    final int pos = posts.indexOf(submission);
    if (pos != -1) {
        if (submission.isHidden()) {
            posts.remove(pos);
            Hidden.undoHidden(submission);
            recyclerview.getAdapter().notifyItemRemoved(pos + 1);
            Snackbar snack = Snackbar.make(recyclerview, R.string.submission_info_unhidden, Snackbar.LENGTH_LONG);
            LayoutUtils.showSnackbar(snack);
        } else {
            final T t = posts.get(pos);
            posts.remove(pos);
            Hidden.setHidden(t);
            final OfflineSubreddit s;
            boolean success = false;
            if (baseSub != null) {
                s = OfflineSubreddit.getSubreddit(baseSub, false, c);
                try {
                    s.hide(pos);
                    success = true;
                } catch (Exception e) {
                }
            } else {
                success = false;
                s = null;
            }
            recyclerview.getAdapter().notifyItemRemoved(pos + 1);
            final boolean finalSuccess = success;
            Snackbar snack = Snackbar.make(recyclerview, R.string.submission_info_hidden, Snackbar.LENGTH_LONG).setAction(R.string.btn_undo, new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (baseSub != null && s != null && finalSuccess) {
                        s.unhideLast();
                    }
                    posts.add(pos, t);
                    recyclerview.getAdapter().notifyItemInserted(pos + 1);
                    Hidden.undoHidden(t);
                }
            });
            LayoutUtils.showSnackbar(snack);
        }
    }
}
Also used : OfflineSubreddit(me.ccrama.redditslide.OfflineSubreddit) MediaView(me.ccrama.redditslide.Activities.MediaView) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) Snackbar(com.google.android.material.snackbar.Snackbar)

Example 20 with Snackbar

use of com.google.android.material.snackbar.Snackbar in project android-client by GenesisVision.

the class BaseSwipeBackActivity method showSnackbar.

protected void showSnackbar(String message, View view) {
    Snackbar snack = Snackbar.make(view, message, Snackbar.LENGTH_LONG);
    ((TextView) snack.getView().findViewById(com.google.android.material.R.id.snackbar_text)).setTextColor(ThemeUtil.getColorByAttrId(this, R.attr.colorTextPrimary));
    snack.getView().setBackgroundColor(ThemeUtil.getColorByAttrId(this, R.attr.colorCard));
    snack.show();
}
Also used : TextView(android.widget.TextView) 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