Search in sources :

Example 11 with Snackbar

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

the class CommentAdapterHelper method showModBottomSheet.

public static void showModBottomSheet(final CommentAdapter adapter, final Context mContext, final CommentNode baseNode, final Comment comment, final CommentViewHolder holder, final Map<String, Integer> reports, final Map<String, String> reports2) {
    int[] attrs = new int[] { R.attr.tintColor };
    TypedArray ta = mContext.obtainStyledAttributes(attrs);
    // Initialize drawables
    int color = ta.getColor(0, Color.WHITE);
    Drawable profile = mContext.getResources().getDrawable(R.drawable.ic_account_circle);
    final Drawable report = mContext.getResources().getDrawable(R.drawable.ic_report);
    final Drawable approve = mContext.getResources().getDrawable(R.drawable.ic_thumb_up);
    final Drawable nsfw = mContext.getResources().getDrawable(R.drawable.ic_visibility_off);
    final Drawable pin = mContext.getResources().getDrawable(R.drawable.ic_bookmark_border);
    final Drawable distinguish = mContext.getResources().getDrawable(R.drawable.ic_star);
    final Drawable remove = mContext.getResources().getDrawable(R.drawable.ic_close);
    final Drawable ban = mContext.getResources().getDrawable(R.drawable.ic_gavel);
    final Drawable spam = mContext.getResources().getDrawable(R.drawable.ic_flag);
    final Drawable note = mContext.getResources().getDrawable(R.drawable.ic_note);
    final Drawable removeReason = mContext.getResources().getDrawable(R.drawable.ic_announcement);
    final Drawable lock = mContext.getResources().getDrawable(R.drawable.ic_lock);
    // Tint drawables
    final List<Drawable> drawableSet = Arrays.asList(profile, report, approve, nsfw, distinguish, remove, pin, ban, spam, note, removeReason, lock);
    BlendModeUtil.tintDrawablesAsSrcAtop(drawableSet, color);
    ta.recycle();
    // Bottom sheet builder
    BottomSheet.Builder b = new BottomSheet.Builder((Activity) mContext).title(CompatUtil.fromHtml(comment.getBody()));
    int reportCount = reports.size() + reports2.size();
    if (reportCount == 0) {
        b.sheet(0, report, mContext.getString(R.string.mod_no_reports));
    } else {
        b.sheet(0, report, mContext.getResources().getQuantityString(R.plurals.mod_btn_reports, reportCount, reportCount));
    }
    if (SettingValues.toolboxEnabled) {
        b.sheet(24, note, mContext.getString(R.string.mod_usernotes_view));
    }
    b.sheet(1, approve, mContext.getString(R.string.mod_btn_approve));
    b.sheet(6, remove, mContext.getString(R.string.btn_remove));
    b.sheet(7, removeReason, mContext.getString(R.string.mod_btn_remove_reason));
    b.sheet(10, spam, mContext.getString(R.string.mod_btn_spam));
    final boolean locked = comment.getDataNode().has("locked") && comment.getDataNode().get("locked").asBoolean();
    if (locked) {
        b.sheet(25, lock, mContext.getString(R.string.mod_btn_unlock_comment));
    } else {
        b.sheet(25, lock, mContext.getString(R.string.mod_btn_lock_comment));
    }
    final boolean stickied = comment.getDataNode().has("stickied") && comment.getDataNode().get("stickied").asBoolean();
    if (baseNode.isTopLevel() && comment.getAuthor().equalsIgnoreCase(Authentication.name)) {
        if (!stickied) {
            b.sheet(4, pin, mContext.getString(R.string.mod_sticky));
        } else {
            b.sheet(4, pin, mContext.getString(R.string.mod_unsticky));
        }
    }
    final boolean distinguished = !comment.getDataNode().get("distinguished").isNull();
    if (comment.getAuthor().equalsIgnoreCase(Authentication.name)) {
        if (!distinguished) {
            b.sheet(9, distinguish, mContext.getString(R.string.mod_distinguish));
        } else {
            b.sheet(9, distinguish, mContext.getString(R.string.mod_undistinguish));
        }
    }
    b.sheet(8, profile, mContext.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:
                    viewReports(mContext, reports, reports2);
                    break;
                case 1:
                    doApproval(mContext, holder, comment, adapter);
                    break;
                case 4:
                    if (stickied) {
                        unStickyComment(mContext, holder, comment);
                    } else {
                        stickyComment(mContext, holder, comment);
                    }
                    break;
                case 9:
                    if (distinguished) {
                        unDistinguishComment(mContext, holder, comment);
                    } else {
                        distinguishComment(mContext, holder, comment);
                    }
                    break;
                case 6:
                    removeComment(mContext, holder, comment, adapter, false);
                    break;
                case 7:
                    if (SettingValues.removalReasonType == SettingValues.RemovalReasonType.TOOLBOX.ordinal() && ToolboxUI.canShowRemoval(comment.getSubredditName())) {
                        ToolboxUI.showRemoval(mContext, comment, new ToolboxUI.CompletedRemovalCallback() {

                            @Override
                            public void onComplete(boolean success) {
                                if (success) {
                                    Snackbar s = Snackbar.make(holder.itemView, R.string.comment_removed, Snackbar.LENGTH_LONG);
                                    LayoutUtils.showSnackbar(s);
                                    adapter.removed.add(comment.getFullName());
                                    adapter.approved.remove(comment.getFullName());
                                    holder.content.setText(CommentAdapterHelper.getScoreString(comment, mContext, holder, adapter.submission, adapter));
                                } 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
                        doRemoveCommentReason(mContext, holder, comment, adapter);
                    }
                    break;
                case 10:
                    removeComment(mContext, holder, comment, adapter, true);
                    break;
                case 8:
                    Intent i = new Intent(mContext, Profile.class);
                    i.putExtra(Profile.EXTRA_PROFILE, comment.getAuthor());
                    mContext.startActivity(i);
                    break;
                case 23:
                    showBan(mContext, adapter.listView, comment, "", "", "", "");
                    break;
                case 24:
                    ToolboxUI.showUsernotes(mContext, comment.getAuthor(), comment.getSubredditName(), "l," + comment.getParentId() + "," + comment.getId());
                    break;
                case 25:
                    lockUnlockComment(mContext, holder, comment, !locked);
                    break;
            }
        }
    });
    b.show();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) DialogInterface(android.content.DialogInterface) Drawable(android.graphics.drawable.Drawable) Activity(android.app.Activity) Intent(android.content.Intent) Profile(me.ccrama.redditslide.Activities.Profile) TypedArray(android.content.res.TypedArray) BottomSheet(com.cocosw.bottomsheet.BottomSheet) Snackbar(com.google.android.material.snackbar.Snackbar)

Example 12 with Snackbar

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

the class SubmissionAdapter 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, subreddit, (subreddit.equals("frontpage") || subreddit.equals("mod") || subreddit.equals("friends") || (subreddit.equals("all")) || subreddit.contains(".") || subreddit.contains("+")));
        holder.itemView.setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View v) {
                if (Authentication.didOnline || submission.getComments() != null) {
                    holder.title.setAlpha(0.54f);
                    holder.body.setAlpha(0.54f);
                    if (context instanceof MainActivity) {
                        final MainActivity a = (MainActivity) context;
                        if (a.singleMode && a.commentPager && a.adapter instanceof MainActivity.MainPagerAdapterComment) {
                            if (a.openingComments != submission) {
                                clicked = holder2.getBindingAdapterPosition();
                                a.openingComments = submission;
                                a.toOpenComments = a.pager.getCurrentItem() + 1;
                                a.currentComment = holder.getBindingAdapterPosition() - 1;
                                ((MainActivity.MainPagerAdapterComment) (a).adapter).storedFragment = (a).adapter.getCurrentFragment();
                                ((MainActivity.MainPagerAdapterComment) (a).adapter).size = a.toOpenComments + 1;
                                try {
                                    a.adapter.notifyDataSetChanged();
                                } catch (Exception ignored) {
                                }
                            }
                            a.pager.postDelayed(new Runnable() {

                                @Override
                                public void run() {
                                    a.pager.setCurrentItem(a.pager.getCurrentItem() + 1, true);
                                }
                            }, 400);
                        } else {
                            Intent i2 = new Intent(context, CommentsScreen.class);
                            i2.putExtra(CommentsScreen.EXTRA_PAGE, holder2.getBindingAdapterPosition() - 1);
                            i2.putExtra(CommentsScreen.EXTRA_SUBREDDIT, subreddit);
                            i2.putExtra("fullname", submission.getFullName());
                            context.startActivityForResult(i2, 940);
                            clicked = holder2.getBindingAdapterPosition();
                        }
                    } else if (context instanceof SubredditView) {
                        final SubredditView a = (SubredditView) context;
                        if (a.singleMode && a.commentPager) {
                            if (a.openingComments != submission) {
                                clicked = holder2.getBindingAdapterPosition();
                                a.openingComments = submission;
                                a.currentComment = holder.getBindingAdapterPosition() - 1;
                                ((SubredditView.SubredditPagerAdapterComment) (a).adapter).storedFragment = (a).adapter.getCurrentFragment();
                                ((SubredditView.SubredditPagerAdapterComment) a.adapter).size = 3;
                                a.adapter.notifyDataSetChanged();
                            }
                            a.pager.postDelayed(new Runnable() {

                                @Override
                                public void run() {
                                    a.pager.setCurrentItem(a.pager.getCurrentItem() + 1, true);
                                }
                            }, 400);
                        } else {
                            Intent i2 = new Intent(context, CommentsScreen.class);
                            i2.putExtra(CommentsScreen.EXTRA_PAGE, holder2.getBindingAdapterPosition() - 1);
                            i2.putExtra(CommentsScreen.EXTRA_SUBREDDIT, subreddit);
                            i2.putExtra("fullname", submission.getFullName());
                            context.startActivityForResult(i2, 940);
                            clicked = holder2.getBindingAdapterPosition();
                        }
                    }
                } else {
                    if (!Reddit.appRestart.contains("offlinepopup")) {
                        new AlertDialog.Builder(context).setTitle(R.string.cache_no_comments_found).setMessage(R.string.cache_no_comments_found_message).setCancelable(false).setPositiveButton(R.string.btn_ok, (dialog, which) -> Reddit.appRestart.edit().putString("offlinepopup", "").apply()).show();
                    } else {
                        Snackbar s = Snackbar.make(holder.itemView, R.string.cache_no_comments_found_snackbar, Snackbar.LENGTH_SHORT);
                        s.setAction(R.string.misc_more_info, new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                new AlertDialog.Builder(context).setTitle(R.string.cache_no_comments_found).setMessage(R.string.cache_no_comments_found_message).setCancelable(false).setPositiveButton(R.string.btn_ok, (dialog, which) -> Reddit.appRestart.edit().putString("offlinepopup", "").apply()).show();
                            }
                        });
                        LayoutUtils.showSnackbar(s);
                    }
                }
            }
        });
        new PopulateSubmissionViewHolder().populateSubmissionViewHolder(holder, submission, context, false, false, dataSet.posts, listView, custom, dataSet.offline, dataSet.subreddit.toLowerCase(Locale.ENGLISH), null);
    }
    if (holder2 instanceof SubmissionFooterViewHolder) {
        Handler handler = new Handler();
        final Runnable r = new Runnable() {

            public void run() {
                notifyItemChanged(dataSet.posts.size() + // the loading spinner to replaced by nomoreposts.xml
                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) {
                    ((SubmissionsView) displayer).forceRefresh();
                }
            });
        }
    }
    if (holder2 instanceof SpacerViewHolder) {
        View header = (context).findViewById(R.id.header);
        int height = header.getHeight();
        if (height == 0) {
            header.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
            height = header.getMeasuredHeight();
            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);
            }
        } else {
            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 : AlertDialog(androidx.appcompat.app.AlertDialog) LayoutUtils(me.ccrama.redditslide.util.LayoutUtils) LinearLayout(android.widget.LinearLayout) SettingValues(me.ccrama.redditslide.SettingValues) AlertDialog(androidx.appcompat.app.AlertDialog) R(me.ccrama.redditslide.R) Submission(net.dean.jraw.models.Submission) MainActivity(me.ccrama.redditslide.Activities.MainActivity) Intent(android.content.Intent) ArrayList(java.util.ArrayList) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) Locale(java.util.Locale) Handler(android.os.Handler) SubredditView(me.ccrama.redditslide.Activities.SubredditView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) CommentsScreen(me.ccrama.redditslide.Activities.CommentsScreen) LayoutInflater(android.view.LayoutInflater) Reddit(me.ccrama.redditslide.Reddit) Authentication(me.ccrama.redditslide.Authentication) ViewGroup(android.view.ViewGroup) PopulateSubmissionViewHolder(me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder) CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) List(java.util.List) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) Activity(android.app.Activity) Snackbar(com.google.android.material.snackbar.Snackbar) CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) SubredditView(me.ccrama.redditslide.Activities.SubredditView) MainActivity(me.ccrama.redditslide.Activities.MainActivity) PopulateSubmissionViewHolder(me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder) CommentsScreen(me.ccrama.redditslide.Activities.CommentsScreen) Submission(net.dean.jraw.models.Submission) PopulateSubmissionViewHolder(me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder) Handler(android.os.Handler) Intent(android.content.Intent) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) LinearLayout(android.widget.LinearLayout) Snackbar(com.google.android.material.snackbar.Snackbar)

Example 13 with Snackbar

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

the class SettingsBackup method backupToDir.

public void backupToDir(final boolean personal) {
    new AsyncTask<Void, Void, Void>() {

        @Override
        protected void onPreExecute() {
            progress = new MaterialDialog.Builder(SettingsBackup.this).cancelable(false).title(R.string.backup_backing_up).progress(false, 40).cancelable(false).build();
            progress.show();
        }

        @Override
        protected Void doInBackground(Void... params) {
            File prefsdir = new File(getApplicationInfo().dataDir, "shared_prefs");
            if (prefsdir.exists() && prefsdir.isDirectory()) {
                String[] list = prefsdir.list();
                Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).mkdirs();
                File backedup = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + File.separator + "Slide" + new SimpleDateFormat("-yyyy-MM-dd-HH-mm-ss").format(Calendar.getInstance().getTime()) + (!personal ? "-personal" : "") + ".txt");
                file = backedup;
                FileWriter fw = null;
                try {
                    backedup.createNewFile();
                    fw = new FileWriter(backedup);
                    fw.write("Slide_backupEND>");
                    for (String s : list) {
                        if (!s.contains("cache") && !s.contains("ion-cookies") && !s.contains("albums") && !s.contains("STACKTRACE") && !s.contains("com.google") && (!personal || (!s.contains("SUBSNEW") && !s.contains("appRestart") && !s.contains("AUTH") && !s.contains("TAGS") && !s.contains("SEEN") && !s.contains("HIDDEN") && !s.contains("HIDDEN_POSTS")))) {
                            FileReader fr = null;
                            try {
                                fr = new FileReader(new File(prefsdir + File.separator + s));
                                int c = fr.read();
                                fw.write("<START" + new File(s).getName() + ">");
                                while (c != -1) {
                                    fw.write(c);
                                    c = fr.read();
                                }
                                fw.write("END>");
                            } catch (IOException e) {
                                e.printStackTrace();
                            } finally {
                                close(fr);
                            }
                        }
                    }
                    return null;
                } catch (Exception e) {
                    e.printStackTrace();
                // todo error
                } finally {
                    close(fw);
                }
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            progress.dismiss();
            new AlertDialog.Builder(SettingsBackup.this).setTitle(R.string.backup_complete).setMessage(R.string.backup_saved_downloads).setPositiveButton(R.string.btn_view, (dialog, which) -> {
                Intent intent = FileUtil.getFileIntent(file, new Intent(Intent.ACTION_VIEW), SettingsBackup.this);
                if (intent.resolveActivityInfo(getPackageManager(), 0) != null) {
                    startActivity(Intent.createChooser(intent, getString(R.string.settings_backup_view)));
                } else {
                    Snackbar s = Snackbar.make(findViewById(R.id.restorefile), R.string.settings_backup_err_no_explorer + file.getAbsolutePath(), Snackbar.LENGTH_INDEFINITE);
                    LayoutUtils.showSnackbar(s);
                }
            }).setNegativeButton(R.string.btn_close, null).setCancelable(false).show();
        }
    }.execute();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) FileWriter(java.io.FileWriter) Intent(android.content.Intent) IOException(java.io.IOException) IOException(java.io.IOException) FileReader(java.io.FileReader) File(java.io.File) DriveFile(com.google.android.gms.drive.DriveFile) SimpleDateFormat(java.text.SimpleDateFormat) Snackbar(com.google.android.material.snackbar.Snackbar)

Example 14 with Snackbar

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

the class MultiredditView method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_verticalcontent, container, false);
    rv = v.findViewById(R.id.vertical_content);
    final RecyclerView.LayoutManager mLayoutManager = createLayoutManager(LayoutUtils.getNumColumns(getResources().getConfiguration().orientation, getActivity()));
    rv.setLayoutManager(mLayoutManager);
    if (SettingValues.fab) {
        fab = v.findViewById(R.id.post_floating_action_button);
        if (SettingValues.fabType == Constants.FAB_POST) {
            fab.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    final ArrayList<String> subs = new ArrayList<>();
                    for (MultiSubreddit s : posts.multiReddit.getSubreddits()) {
                        subs.add(s.getDisplayName());
                    }
                    new MaterialDialog.Builder(getActivity()).title(R.string.multi_submit_which_sub).items(subs).itemsCallback(new MaterialDialog.ListCallback() {

                        @Override
                        public void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
                            Intent i = new Intent(getActivity(), Submit.class);
                            i.putExtra(Submit.EXTRA_SUBREDDIT, subs.get(which));
                            startActivity(i);
                        }
                    }).show();
                }
            });
        } else if (SettingValues.fabType == Constants.FAB_SEARCH) {
            fab.setImageResource(R.drawable.ic_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();
                        }
                    });
                    builder.positiveText(getString(R.string.search_subreddit, "/m/" + posts.multiReddit.getDisplayName())).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_MULTIREDDIT, posts.multiReddit.getDisplayName());
                            startActivity(i);
                        }
                    });
                    builder.show();
                }
            });
        } else {
            fab.setImageResource(R.drawable.ic_visibility_off);
            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);
                    }
                }
            });
            fab.setOnLongClickListener(new View.OnLongClickListener() {

                @Override
                public boolean onLongClick(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(true);
                        }).show();
                    } else {
                        clearSeenPosts(true);
                    }
                    /*
                        ToDo Make a sncakbar with an undo option of the clear all
                        View.OnClickListener undoAction = new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                adapter.dataSet.posts = original;
                                for(Submission post : adapter.dataSet.posts){
                                    if(HasSeen.getSeen(post.getFullName()))
                                        Hidden.undoHidden(post);
                                }
                            }
                        };*/
                    Snackbar s = Snackbar.make(rv, getResources().getString(R.string.posts_hidden_forever), Snackbar.LENGTH_LONG);
                    LayoutUtils.showSnackbar(s);
                    return false;
                }
            });
        }
    } else {
        v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE);
    }
    refreshLayout = v.findViewById(R.id.activity_main_swipe_refresh_layout);
    /**
     * 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);
        refreshLayout.setLayoutParams(params);
    }
    List<MultiReddit> multireddits;
    if (profile.isEmpty()) {
        multireddits = UserSubscriptions.multireddits;
    } else {
        multireddits = UserSubscriptions.public_multireddits.get(profile);
    }
    if ((multireddits != null) && !multireddits.isEmpty()) {
        refreshLayout.setColorSchemeColors(Palette.getColors(multireddits.get(id).getDisplayName(), getActivity()));
    }
    // If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
    // So, we estimate the height of the header in dp
    refreshLayout.setProgressViewOffset(false, Constants.TAB_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP, Constants.TAB_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM);
    refreshLayout.post(new Runnable() {

        @Override
        public void run() {
            refreshLayout.setRefreshing(true);
        }
    });
    if ((multireddits != null) && !multireddits.isEmpty()) {
        posts = new MultiredditPosts(multireddits.get(id).getDisplayName(), profile);
        adapter = new MultiredditAdapter(getActivity(), posts, rv, refreshLayout, this);
        rv.setAdapter(adapter);
        rv.setItemAnimator(new SlideUpAlphaAnimator().withInterpolator(new LinearOutSlowInInterpolator()));
        posts.loadMore(getActivity(), this, true, adapter);
        refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

            @Override
            public void onRefresh() {
                posts.loadMore(getActivity(), MultiredditView.this, true, adapter);
            // TODO catch errors
            }
        });
        if (fab != null) {
            fab.show();
        }
        rv.addOnScrollListener(new ToolbarScrollHideHandler((getActivity()).findViewById(R.id.toolbar), getActivity().findViewById(R.id.header)) {

            @Override
            public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                visibleItemCount = rv.getLayoutManager().getChildCount();
                totalItemCount = rv.getLayoutManager().getItemCount();
                int[] firstVisibleItems = ((CatchStaggeredGridLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPositions(null);
                if (firstVisibleItems != null && firstVisibleItems.length > 0) {
                    for (int firstVisibleItem : firstVisibleItems) {
                        pastVisiblesItems = firstVisibleItem;
                        if (SettingValues.scrollSeen && pastVisiblesItems > 0 && SettingValues.storeHistory) {
                            HasSeen.addSeenScrolling(posts.posts.get(pastVisiblesItems - 1).getFullName());
                        }
                    }
                }
                if (!posts.loading) {
                    if ((visibleItemCount + pastVisiblesItems) + 5 >= totalItemCount && !posts.nomore) {
                        posts.loading = true;
                        posts.loadMore(getActivity(), MultiredditView.this, false, adapter);
                    }
                }
                if (recyclerView.getScrollState() == RecyclerView.SCROLL_STATE_DRAGGING) {
                    diff += dy;
                } else {
                    diff = 0;
                }
                if (fab != null) {
                    if (dy <= 0 && fab.getId() != 0 && SettingValues.fab) {
                        if (recyclerView.getScrollState() != RecyclerView.SCROLL_STATE_DRAGGING || diff < -fab.getHeight() * 2)
                            fab.show();
                    } else {
                        fab.hide();
                    }
                }
            }
        });
    }
    return v;
}
Also used : LayoutUtils(me.ccrama.redditslide.util.LayoutUtils) LinearOutSlowInInterpolator(androidx.interpolator.view.animation.LinearOutSlowInInterpolator) SettingValues(me.ccrama.redditslide.SettingValues) Bundle(android.os.Bundle) AlertDialog(androidx.appcompat.app.AlertDialog) MultiSubreddit(net.dean.jraw.models.MultiSubreddit) R(me.ccrama.redditslide.R) HasSeen(me.ccrama.redditslide.HasSeen) NonNull(androidx.annotation.NonNull) Submission(net.dean.jraw.models.Submission) Intent(android.content.Intent) Constants(me.ccrama.redditslide.Constants) Hidden(me.ccrama.redditslide.Hidden) ArrayList(java.util.ArrayList) Locale(java.util.Locale) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) Fragment(androidx.fragment.app.Fragment) Search(me.ccrama.redditslide.Activities.Search) View(android.view.View) UserSubscriptions(me.ccrama.redditslide.UserSubscriptions) RecyclerView(androidx.recyclerview.widget.RecyclerView) AlphaInAnimator(com.mikepenz.itemanimators.AlphaInAnimator) MultiReddit(net.dean.jraw.models.MultiReddit) LayoutInflater(android.view.LayoutInflater) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) MarginLayoutParamsCompat(androidx.core.view.MarginLayoutParamsCompat) Reddit(me.ccrama.redditslide.Reddit) MultiredditAdapter(me.ccrama.redditslide.Adapters.MultiredditAdapter) DialogAction(com.afollestad.materialdialogs.DialogAction) Submit(me.ccrama.redditslide.Activities.Submit) Palette(me.ccrama.redditslide.Visuals.Palette) ToolbarScrollHideHandler(me.ccrama.redditslide.handler.ToolbarScrollHideHandler) ViewGroup(android.view.ViewGroup) CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) SubmissionDisplay(me.ccrama.redditslide.Adapters.SubmissionDisplay) OfflineSubreddit(me.ccrama.redditslide.OfflineSubreddit) SlideUpAlphaAnimator(com.mikepenz.itemanimators.SlideUpAlphaAnimator) List(java.util.List) Configuration(android.content.res.Configuration) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) RelativeLayout(android.widget.RelativeLayout) MultiredditPosts(me.ccrama.redditslide.Adapters.MultiredditPosts) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Snackbar(com.google.android.material.snackbar.Snackbar) ArrayList(java.util.ArrayList) MultiSubreddit(net.dean.jraw.models.MultiSubreddit) MultiReddit(net.dean.jraw.models.MultiReddit) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) SlideUpAlphaAnimator(com.mikepenz.itemanimators.SlideUpAlphaAnimator) LinearOutSlowInInterpolator(androidx.interpolator.view.animation.LinearOutSlowInInterpolator) Search(me.ccrama.redditslide.Activities.Search) ToolbarScrollHideHandler(me.ccrama.redditslide.handler.ToolbarScrollHideHandler) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Intent(android.content.Intent) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) MultiredditPosts(me.ccrama.redditslide.Adapters.MultiredditPosts) DialogAction(com.afollestad.materialdialogs.DialogAction) RelativeLayout(android.widget.RelativeLayout) Submit(me.ccrama.redditslide.Activities.Submit) RecyclerView(androidx.recyclerview.widget.RecyclerView) MultiredditAdapter(me.ccrama.redditslide.Adapters.MultiredditAdapter) Snackbar(com.google.android.material.snackbar.Snackbar)

Example 15 with Snackbar

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

the class PopulateSubmissionViewHolder method showBan.

public void showBan(final Context mContext, final View mToolbar, final Submission submission, String rs, String nt, String msg, String t) {
    LinearLayout l = new LinearLayout(mContext);
    l.setOrientation(LinearLayout.VERTICAL);
    int sixteen = DisplayUtil.dpToPxVertical(16);
    l.setPadding(sixteen, 0, sixteen, 0);
    final EditText reason = new EditText(mContext);
    reason.setHint(R.string.mod_ban_reason);
    reason.setText(rs);
    reason.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
    l.addView(reason);
    final EditText note = new EditText(mContext);
    note.setHint(R.string.mod_ban_note_mod);
    note.setText(nt);
    note.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
    l.addView(note);
    final EditText message = new EditText(mContext);
    message.setHint(R.string.mod_ban_note_user);
    message.setText(msg);
    message.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
    l.addView(message);
    final EditText time = new EditText(mContext);
    time.setHint(R.string.mod_ban_time);
    time.setText(t);
    time.setInputType(InputType.TYPE_CLASS_NUMBER);
    l.addView(time);
    new AlertDialog.Builder(mContext).setView(l).setTitle(mContext.getString(R.string.mod_ban_title, submission.getAuthor())).setCancelable(true).setPositiveButton(R.string.mod_btn_ban, (dialog, which) -> {
        // to ban
        if (reason.getText().toString().isEmpty()) {
            new AlertDialog.Builder(mContext).setTitle(R.string.mod_ban_reason_required).setMessage(R.string.misc_please_try_again).setPositiveButton(R.string.btn_ok, (dialog1, which1) -> showBan(mContext, mToolbar, submission, reason.getText().toString(), note.getText().toString(), message.getText().toString(), time.getText().toString())).setCancelable(false).show();
        } else {
            new AsyncTask<Void, Void, Boolean>() {

                @Override
                protected Boolean doInBackground(Void... params) {
                    try {
                        String n = note.getText().toString();
                        String m = message.getText().toString();
                        if (n.isEmpty()) {
                            n = null;
                        }
                        if (m.isEmpty()) {
                            m = null;
                        }
                        if (time.getText().toString().isEmpty()) {
                            new ModerationManager(Authentication.reddit).banUserPermanently(submission.getSubredditName(), submission.getAuthor(), reason.getText().toString(), n, m);
                        } else {
                            new ModerationManager(Authentication.reddit).banUser(submission.getSubredditName(), submission.getAuthor(), reason.getText().toString(), n, m, Integer.parseInt(time.getText().toString()));
                        }
                        return true;
                    } catch (Exception e) {
                        if (e instanceof InvalidScopeException) {
                            scope = true;
                        }
                        e.printStackTrace();
                        return false;
                    }
                }

                boolean scope;

                @Override
                protected void onPostExecute(Boolean done) {
                    Snackbar s;
                    if (done) {
                        s = Snackbar.make(mToolbar, R.string.mod_ban_success, Snackbar.LENGTH_SHORT);
                    } else {
                        if (scope) {
                            new AlertDialog.Builder(mContext).setTitle(R.string.mod_ban_reauth).setMessage(R.string.mod_ban_reauth_question).setPositiveButton(R.string.btn_ok, (dialog12, which12) -> {
                                Intent i = new Intent(mContext, Reauthenticate.class);
                                mContext.startActivity(i);
                            }).setNegativeButton(R.string.misc_maybe_later, null).setCancelable(false).show();
                        }
                        s = Snackbar.make(mToolbar, R.string.mod_ban_fail, Snackbar.LENGTH_INDEFINITE).setAction(R.string.misc_try_again, new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                showBan(mContext, mToolbar, submission, reason.getText().toString(), note.getText().toString(), message.getText().toString(), time.getText().toString());
                            }
                        });
                    }
                    if (s != null) {
                        LayoutUtils.showSnackbar(s);
                    }
                }
            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }).setNegativeButton(R.string.btn_cancel, null).show();
}
Also used : EditText(android.widget.EditText) AlertDialog(androidx.appcompat.app.AlertDialog) ModerationManager(net.dean.jraw.managers.ModerationManager) SpannableStringBuilder(android.text.SpannableStringBuilder) Intent(android.content.Intent) 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) InvalidScopeException(net.dean.jraw.http.oauth.InvalidScopeException) 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