Search in sources :

Example 1 with BaseActivity

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

the class CommentAdapter method setCommentStateHighlighted.

public void setCommentStateHighlighted(final CommentViewHolder holder, final Comment n, final CommentNode baseNode, boolean isReplying, boolean animate) {
    if (currentlySelected != null && currentlySelected != holder) {
        setCommentStateUnhighlighted(currentlySelected, currentBaseNode, true);
    }
    if (mContext instanceof BaseActivity) {
        ((BaseActivity) mContext).setShareUrl("https://reddit.com" + submission.getPermalink() + n.getFullName() + "?context=3");
    }
    // and expand to show all children comments
    if (SettingValues.swap && holder.firstTextView.getVisibility() == View.GONE && !isReplying) {
        hiddenPersons.remove(n.getFullName());
        unhideAll(baseNode, holder.getAdapterPosition() + 1);
        if (toCollapse.contains(n.getFullName()) && SettingValues.collapseComments) {
            setViews(n.getDataNode().get("body_html").asText(), submission.getSubredditName(), holder);
        }
        CommentAdapterHelper.hideChildrenObject(holder.childrenNumber);
        holder.commentOverflow.setVisibility(View.VISIBLE);
        toCollapse.remove(n.getFullName());
    } else {
        currentlySelected = holder;
        currentBaseNode = baseNode;
        int color = Palette.getColor(n.getSubredditName());
        currentSelectedItem = n.getFullName();
        currentNode = baseNode;
        LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
        resetMenu(holder.menuArea, false);
        final View baseView = (SettingValues.rightHandedCommentMenu) ? inflater.inflate(R.layout.comment_menu_right_handed, holder.menuArea) : inflater.inflate(R.layout.comment_menu, holder.menuArea);
        if (!isReplying) {
            baseView.setVisibility(View.GONE);
            if (animate) {
                expand(baseView);
            } else {
                baseView.setVisibility(View.VISIBLE);
                final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
                final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
                baseView.measure(widthSpec, heightSpec);
                View l2 = baseView.findViewById(R.id.replyArea) == null ? baseView.findViewById(R.id.innerSend) : baseView.findViewById(R.id.replyArea);
                final int widthSpec2 = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
                final int heightSpec2 = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
                l2.measure(widthSpec2, heightSpec2);
                ViewGroup.LayoutParams layoutParams = baseView.getLayoutParams();
                layoutParams.height = baseView.getMeasuredHeight() - l2.getMeasuredHeight();
                baseView.setLayoutParams(layoutParams);
            }
        }
        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
        params.setMargins(0, 0, 0, 0);
        holder.itemView.setLayoutParams(params);
        View reply = baseView.findViewById(R.id.reply);
        View send = baseView.findViewById(R.id.send);
        final View menu = baseView.findViewById(R.id.menu);
        final View replyArea = baseView.findViewById(R.id.replyArea);
        final View more = baseView.findViewById(R.id.more);
        final ImageView upvote = (ImageView) baseView.findViewById(R.id.upvote);
        final ImageView downvote = (ImageView) baseView.findViewById(R.id.downvote);
        View discard = baseView.findViewById(R.id.discard);
        final EditText replyLine = (EditText) baseView.findViewById(R.id.replyLine);
        final Comment comment = baseNode.getComment();
        if (ActionStates.getVoteDirection(comment) == VoteDirection.UPVOTE) {
            upvote.setColorFilter(holder.textColorUp, PorterDuff.Mode.MULTIPLY);
        } else if (ActionStates.getVoteDirection(comment) == VoteDirection.DOWNVOTE) {
            downvote.setColorFilter(holder.textColorDown, PorterDuff.Mode.MULTIPLY);
        } else {
            downvote.clearColorFilter();
            upvote.clearColorFilter();
        }
        {
            final ImageView mod = (ImageView) baseView.findViewById(R.id.mod);
            try {
                if (UserSubscriptions.modOf.contains(submission.getSubredditName())) {
                    // todo
                    mod.setVisibility(View.GONE);
                } else {
                    mod.setVisibility(View.GONE);
                }
            } catch (Exception e) {
                Log.d(LogUtil.getTag(), "Error loading mod " + e.toString());
            }
        }
        if (UserSubscriptions.modOf != null && UserSubscriptions.modOf.contains(submission.getSubredditName().toLowerCase(Locale.ENGLISH))) {
            baseView.findViewById(R.id.mod).setVisibility(View.VISIBLE);
            final Map<String, Integer> reports = comment.getUserReports();
            final Map<String, String> reports2 = comment.getModeratorReports();
            if (reports.size() + reports2.size() > 0) {
                ((ImageView) baseView.findViewById(R.id.mod)).setColorFilter(ContextCompat.getColor(mContext, R.color.md_red_300), PorterDuff.Mode.SRC_ATOP);
            } else {
                ((ImageView) baseView.findViewById(R.id.mod)).setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
            }
            baseView.findViewById(R.id.mod).setOnClickListener(new OnSingleClickListener() {

                @Override
                public void onSingleClick(View v) {
                    CommentAdapterHelper.showModBottomSheet(CommentAdapter.this, mContext, baseNode, comment, holder, reports, reports2);
                }
            });
        } else {
            baseView.findViewById(R.id.mod).setVisibility(View.GONE);
        }
        final ImageView edit = (ImageView) baseView.findViewById(R.id.edit);
        if (Authentication.name != null && Authentication.name.toLowerCase(Locale.ENGLISH).equals(comment.getAuthor().toLowerCase(Locale.ENGLISH)) && Authentication.didOnline) {
            edit.setOnClickListener(new OnSingleClickListener() {

                @Override
                public void onSingleClick(View v) {
                    CommentAdapterHelper.doCommentEdit(CommentAdapter.this, mContext, fm, baseNode, baseNode.isTopLevel() ? submission.getSelftext() : baseNode.getParent().getComment().getBody(), holder);
                }
            });
        } else {
            edit.setVisibility(View.GONE);
        }
        final ImageView delete = (ImageView) baseView.findViewById(R.id.delete);
        if (Authentication.name != null && Authentication.name.toLowerCase(Locale.ENGLISH).equals(comment.getAuthor().toLowerCase(Locale.ENGLISH)) && Authentication.didOnline) {
            delete.setOnClickListener(new OnSingleClickListener() {

                @Override
                public void onSingleClick(View v) {
                    CommentAdapterHelper.deleteComment(CommentAdapter.this, mContext, baseNode, holder);
                }
            });
        } else {
            delete.setVisibility(View.GONE);
        }
        if (Authentication.isLoggedIn && !submission.isArchived() && !submission.isLocked() && !deleted.contains(n.getFullName()) && !comment.getAuthor().equals("[deleted]") && Authentication.didOnline) {
            if (isReplying) {
                baseView.setVisibility(View.VISIBLE);
                final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
                final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
                baseView.measure(widthSpec, heightSpec);
                View l2 = baseView.findViewById(R.id.replyArea) == null ? baseView.findViewById(R.id.innerSend) : baseView.findViewById(R.id.replyArea);
                final int widthSpec2 = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
                final int heightSpec2 = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
                l2.measure(widthSpec2, heightSpec2);
                RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) baseView.getLayoutParams();
                params2.height = RelativeLayout.LayoutParams.WRAP_CONTENT;
                params2.addRule(RelativeLayout.BELOW, R.id.commentOverflow);
                baseView.setLayoutParams(params2);
                replyArea.setVisibility(View.VISIBLE);
                menu.setVisibility(View.GONE);
                currentlyEditing = replyLine;
                currentlyEditing.setOnFocusChangeListener(new View.OnFocusChangeListener() {

                    @Override
                    public void onFocusChange(View v, boolean hasFocus) {
                        if (hasFocus) {
                            mPage.fastScroll.setVisibility(View.GONE);
                            if (mPage.fab != null) {
                                mPage.fab.setVisibility(View.GONE);
                            }
                            mPage.overrideFab = true;
                        } else if (SettingValues.fastscroll) {
                            mPage.fastScroll.setVisibility(View.VISIBLE);
                            if (mPage.fab != null) {
                                mPage.fab.setVisibility(View.VISIBLE);
                            }
                            mPage.overrideFab = false;
                        }
                    }
                });
                final TextView profile = (TextView) baseView.findViewById(R.id.profile);
                changedProfile = Authentication.name;
                profile.setText("/u/" + changedProfile);
                profile.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        final HashMap<String, String> accounts = new HashMap<>();
                        for (String s : Authentication.authentication.getStringSet("accounts", new HashSet<String>())) {
                            if (s.contains(":")) {
                                accounts.put(s.split(":")[0], s.split(":")[1]);
                            } else {
                                accounts.put(s, "");
                            }
                        }
                        final ArrayList<String> keys = new ArrayList<>(accounts.keySet());
                        final int i = keys.indexOf(changedProfile);
                        AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext);
                        builder.setTitle(R.string.sorting_choose);
                        builder.setSingleChoiceItems(keys.toArray(new String[keys.size()]), i, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                changedProfile = keys.get(which);
                                profile.setText("/u/" + changedProfile);
                            }
                        });
                        builder.alwaysCallSingleChoiceCallback();
                        builder.setNegativeButton(R.string.btn_cancel, null);
                        builder.show();
                    }
                });
                replyLine.requestFocus();
                InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
                currentlyEditingId = n.getFullName();
                replyLine.setText(backedText);
                replyLine.addTextChangedListener(new TextWatcher() {

                    @Override
                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                    }

                    @Override
                    public void onTextChanged(CharSequence s, int start, int before, int count) {
                        backedText = s.toString();
                    }

                    @Override
                    public void afterTextChanged(Editable s) {
                    }
                });
                editingPosition = holder.getAdapterPosition();
            }
            reply.setOnClickListener(new OnSingleClickListener() {

                @Override
                public void onSingleClick(View v) {
                    expandAndSetParams(baseView);
                    // If the base theme is Light or Sepia, tint the Editor actions to be white
                    if (SettingValues.currentTheme == 1 || SettingValues.currentTheme == 5) {
                        ((ImageView) replyArea.findViewById(R.id.savedraft)).setColorFilter(Color.WHITE);
                        ((ImageView) replyArea.findViewById(R.id.draft)).setColorFilter(Color.WHITE);
                        ((ImageView) replyArea.findViewById(R.id.imagerep)).setColorFilter(Color.WHITE);
                        ((ImageView) replyArea.findViewById(R.id.link)).setColorFilter(Color.WHITE);
                        ((ImageView) replyArea.findViewById(R.id.bold)).setColorFilter(Color.WHITE);
                        ((ImageView) replyArea.findViewById(R.id.italics)).setColorFilter(Color.WHITE);
                        ((ImageView) replyArea.findViewById(R.id.bulletlist)).setColorFilter(Color.WHITE);
                        ((ImageView) replyArea.findViewById(R.id.numlist)).setColorFilter(Color.WHITE);
                        ((ImageView) replyArea.findViewById(R.id.draw)).setColorFilter(Color.WHITE);
                        ((ImageView) replyArea.findViewById(R.id.quote)).setColorFilter(Color.WHITE);
                        ((ImageView) replyArea.findViewById(R.id.size)).setColorFilter(Color.WHITE);
                        ((ImageView) replyArea.findViewById(R.id.strike)).setColorFilter(Color.WHITE);
                        ((TextView) replyArea.findViewById(R.id.author)).setTextColor(Color.WHITE);
                        replyLine.getBackground().setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN);
                    }
                    replyArea.setVisibility(View.VISIBLE);
                    menu.setVisibility(View.GONE);
                    currentlyEditing = replyLine;
                    DoEditorActions.doActions(currentlyEditing, replyArea, fm, (Activity) mContext, comment.getBody(), getParents(baseNode));
                    currentlyEditing.setOnFocusChangeListener(new View.OnFocusChangeListener() {

                        @Override
                        public void onFocusChange(View v, boolean hasFocus) {
                            if (hasFocus) {
                                mPage.fastScroll.setVisibility(View.GONE);
                                if (mPage.fab != null)
                                    mPage.fab.setVisibility(View.GONE);
                                mPage.overrideFab = true;
                            } else if (SettingValues.fastscroll) {
                                mPage.fastScroll.setVisibility(View.VISIBLE);
                                if (mPage.fab != null)
                                    mPage.fab.setVisibility(View.VISIBLE);
                                mPage.overrideFab = false;
                            }
                        }
                    });
                    final TextView profile = (TextView) baseView.findViewById(R.id.profile);
                    changedProfile = Authentication.name;
                    profile.setText("/u/" + changedProfile);
                    profile.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            final HashMap<String, String> accounts = new HashMap<>();
                            for (String s : Authentication.authentication.getStringSet("accounts", new HashSet<String>())) {
                                if (s.contains(":")) {
                                    accounts.put(s.split(":")[0], s.split(":")[1]);
                                } else {
                                    accounts.put(s, "");
                                }
                            }
                            final ArrayList<String> keys = new ArrayList<>(accounts.keySet());
                            final int i = keys.indexOf(changedProfile);
                            AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext);
                            builder.setTitle(R.string.sorting_choose);
                            builder.setSingleChoiceItems(keys.toArray(new String[keys.size()]), i, new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    changedProfile = keys.get(which);
                                    profile.setText("/u/" + changedProfile);
                                }
                            });
                            builder.alwaysCallSingleChoiceCallback();
                            builder.setNegativeButton(R.string.btn_cancel, null);
                            builder.show();
                        }
                    });
                    replyLine.requestFocus();
                    InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
                    currentlyEditingId = n.getFullName();
                    replyLine.addTextChangedListener(new TextWatcher() {

                        @Override
                        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                        }

                        @Override
                        public void onTextChanged(CharSequence s, int start, int before, int count) {
                            backedText = s.toString();
                        }

                        @Override
                        public void afterTextChanged(Editable s) {
                        }
                    });
                    editingPosition = holder.getAdapterPosition();
                }
            });
            send.setOnClickListener(new OnSingleClickListener() {

                @Override
                public void onSingleClick(View v) {
                    currentlyEditingId = "";
                    backedText = "";
                    doShowMenu(baseView);
                    if (SettingValues.fastscroll) {
                        mPage.fastScroll.setVisibility(View.VISIBLE);
                        if (mPage.fab != null)
                            mPage.fab.setVisibility(View.VISIBLE);
                        mPage.overrideFab = false;
                    }
                    dataSet.refreshLayout.setRefreshing(true);
                    if (currentlyEditing != null) {
                        String text = currentlyEditing.getText().toString();
                        new ReplyTaskComment(n, baseNode, holder, changedProfile).execute(text);
                        currentlyEditing = null;
                        editingPosition = -1;
                    }
                    // Hide soft keyboard
                    View view = ((Activity) mContext).getCurrentFocus();
                    if (view != null) {
                        InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
                    }
                }
            });
            discard.setOnClickListener(new OnSingleClickListener() {

                @Override
                public void onSingleClick(View v) {
                    currentlyEditing = null;
                    editingPosition = -1;
                    currentlyEditingId = "";
                    backedText = "";
                    mPage.overrideFab = false;
                    View view = ((Activity) mContext).getCurrentFocus();
                    if (view != null) {
                        InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
                    }
                    doShowMenu(baseView);
                }
            });
        } else {
            if (reply.getVisibility() == View.VISIBLE) {
                reply.setVisibility(View.GONE);
            }
            if ((submission.isArchived() || deleted.contains(n.getFullName()) || comment.getAuthor().equals("[deleted]")) && Authentication.isLoggedIn && Authentication.didOnline && upvote.getVisibility() == View.VISIBLE) {
                upvote.setVisibility(View.GONE);
            }
            if ((submission.isArchived() || deleted.contains(n.getFullName()) || comment.getAuthor().equals("[deleted]")) && Authentication.isLoggedIn && Authentication.didOnline && downvote.getVisibility() == View.VISIBLE) {
                downvote.setVisibility(View.GONE);
            }
        }
        more.setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View v) {
                CommentAdapterHelper.showOverflowBottomSheet(CommentAdapter.this, mContext, holder, baseNode);
            }
        });
        upvote.setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View v) {
                setCommentStateUnhighlighted(holder, comment, baseNode, true);
                if (ActionStates.getVoteDirection(comment) == VoteDirection.UPVOTE) {
                    new Vote(v, mContext).execute(n);
                    ActionStates.setVoteDirection(comment, VoteDirection.NO_VOTE);
                    doScoreText(holder, n, CommentAdapter.this);
                    upvote.clearColorFilter();
                } else {
                    new Vote(true, v, mContext).execute(n);
                    ActionStates.setVoteDirection(comment, VoteDirection.UPVOTE);
                    // reset colour
                    downvote.clearColorFilter();
                    doScoreText(holder, n, CommentAdapter.this);
                    upvote.setColorFilter(holder.textColorUp, PorterDuff.Mode.MULTIPLY);
                }
            }
        });
        downvote.setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View v) {
                setCommentStateUnhighlighted(holder, comment, baseNode, true);
                if (ActionStates.getVoteDirection(comment) == VoteDirection.DOWNVOTE) {
                    new Vote(v, mContext).execute(n);
                    ActionStates.setVoteDirection(comment, VoteDirection.NO_VOTE);
                    doScoreText(holder, n, CommentAdapter.this);
                    downvote.clearColorFilter();
                } else {
                    new Vote(false, v, mContext).execute(n);
                    ActionStates.setVoteDirection(comment, VoteDirection.DOWNVOTE);
                    // reset colour
                    upvote.clearColorFilter();
                    doScoreText(holder, n, CommentAdapter.this);
                    downvote.setColorFilter(holder.textColorDown, PorterDuff.Mode.MULTIPLY);
                }
            }
        });
        menu.setBackgroundColor(color);
        replyArea.setBackgroundColor(color);
        if (!isReplying) {
            menu.setVisibility(View.VISIBLE);
            replyArea.setVisibility(View.GONE);
        }
        holder.itemView.findViewById(R.id.background).setBackgroundColor(Color.argb(50, Color.red(color), Color.green(color), Color.blue(color)));
    }
}
Also used : HashMap(java.util.HashMap) DialogInterface(android.content.DialogInterface) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) ArrayList(java.util.ArrayList) BaseActivity(me.ccrama.redditslide.Activities.BaseActivity) Activity(android.app.Activity) InputMethodManager(android.view.inputmethod.InputMethodManager) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) TextView(android.widget.TextView) ImageView(android.widget.ImageView) HashSet(java.util.HashSet) EditText(android.widget.EditText) Comment(net.dean.jraw.models.Comment) Vote(me.ccrama.redditslide.Vote) ViewGroup(android.view.ViewGroup) ImageView(android.widget.ImageView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) ApiException(net.dean.jraw.ApiException) LayoutInflater(android.view.LayoutInflater) BaseActivity(me.ccrama.redditslide.Activities.BaseActivity) RelativeLayout(android.widget.RelativeLayout) RecyclerView(android.support.v7.widget.RecyclerView)

Example 2 with BaseActivity

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

the class NewsView method resetScroll.

public void resetScroll() {
    if (toolbarScroll == null) {
        toolbarScroll = new ToolbarScrollHideHandler(((BaseActivity) getActivity()).mToolbar, header) {

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                if (!posts.loading && !posts.nomore && !posts.offline && !adapter.isError) {
                    visibleItemCount = rv.getLayoutManager().getChildCount();
                    totalItemCount = rv.getLayoutManager().getItemCount();
                    int[] firstVisibleItems;
                    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 ((visibleItemCount + pastVisiblesItems) + 5 >= totalItemCount) {
                        posts.loading = true;
                        posts.loadMore(mSwipeRefreshLayout.getContext(), NewsView.this, false, posts.subreddit);
                    }
                }
                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();
                    }
                }
            }

            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                // switch (newState) {
                // case RecyclerView.SCROLL_STATE_IDLE:
                // ((Reddit)getActivity().getApplicationContext()).getImageLoader().resume();
                // break;
                // case RecyclerView.SCROLL_STATE_DRAGGING:
                // ((Reddit)getActivity().getApplicationContext()).getImageLoader().resume();
                // break;
                // case RecyclerView.SCROLL_STATE_SETTLING:
                // ((Reddit)getActivity().getApplicationContext()).getImageLoader().pause();
                // break;
                // }
                super.onScrollStateChanged(recyclerView, newState);
                // If the toolbar search is open, and the user scrolls in the Main view--close the search UI
                if (getActivity() instanceof MainActivity && (SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_TOOLBAR || SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_BOTH) && ((MainActivity) getContext()).findViewById(R.id.toolbar_search).getVisibility() == View.VISIBLE) {
                    ((MainActivity) getContext()).findViewById(R.id.close_search_toolbar).performClick();
                }
            }
        };
        rv.addOnScrollListener(toolbarScroll);
    } else {
        toolbarScroll.reset = true;
    }
}
Also used : CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) BaseActivity(me.ccrama.redditslide.Activities.BaseActivity) RecyclerView(android.support.v7.widget.RecyclerView) MainActivity(me.ccrama.redditslide.Activities.MainActivity) ToolbarScrollHideHandler(me.ccrama.redditslide.handler.ToolbarScrollHideHandler)

Example 3 with BaseActivity

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

the class SubmissionsView method resetScroll.

public void resetScroll() {
    if (toolbarScroll == null) {
        toolbarScroll = new ToolbarScrollHideHandler(((BaseActivity) getActivity()).mToolbar, header) {

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                if (!posts.loading && !posts.nomore && !posts.offline && !adapter.isError) {
                    visibleItemCount = rv.getLayoutManager().getChildCount();
                    totalItemCount = rv.getLayoutManager().getItemCount();
                    int[] firstVisibleItems;
                    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 ((visibleItemCount + pastVisiblesItems) + 5 >= totalItemCount) {
                        posts.loading = true;
                        posts.loadMore(mSwipeRefreshLayout.getContext(), SubmissionsView.this, false, posts.subreddit);
                    }
                }
                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();
                    }
                }
            }

            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                // switch (newState) {
                // case RecyclerView.SCROLL_STATE_IDLE:
                // ((Reddit)getActivity().getApplicationContext()).getImageLoader().resume();
                // break;
                // case RecyclerView.SCROLL_STATE_DRAGGING:
                // ((Reddit)getActivity().getApplicationContext()).getImageLoader().resume();
                // break;
                // case RecyclerView.SCROLL_STATE_SETTLING:
                // ((Reddit)getActivity().getApplicationContext()).getImageLoader().pause();
                // break;
                // }
                super.onScrollStateChanged(recyclerView, newState);
                // If the toolbar search is open, and the user scrolls in the Main view--close the search UI
                if (getActivity() instanceof MainActivity && (SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_TOOLBAR || SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_BOTH) && ((MainActivity) getContext()).findViewById(R.id.toolbar_search).getVisibility() == View.VISIBLE) {
                    ((MainActivity) getContext()).findViewById(R.id.close_search_toolbar).performClick();
                }
            }
        };
        rv.addOnScrollListener(toolbarScroll);
    } else {
        toolbarScroll.reset = true;
    }
}
Also used : CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) BaseActivity(me.ccrama.redditslide.Activities.BaseActivity) RecyclerView(android.support.v7.widget.RecyclerView) MainActivity(me.ccrama.redditslide.Activities.MainActivity) ToolbarScrollHideHandler(me.ccrama.redditslide.handler.ToolbarScrollHideHandler)

Example 4 with BaseActivity

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

the class SubredditListView method doAdapter.

public void doAdapter() {
    mSwipeRefreshLayout.post(new Runnable() {

        @Override
        public void run() {
            mSwipeRefreshLayout.setRefreshing(true);
        }
    });
    posts = new SubredditNames(where, getContext(), SubredditListView.this);
    adapter = new SubredditAdapter(getActivity(), posts, rv, where, this);
    rv.setAdapter(adapter);
    posts.loadMore(mSwipeRefreshLayout.getContext(), true, where);
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            refresh();
        }
    });
    rv.addOnScrollListener(new ToolbarScrollHideHandler(((BaseActivity) getActivity()).mToolbar, getActivity().findViewById(R.id.header)) {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            if (!posts.loading && !posts.nomore) {
                visibleItemCount = rv.getLayoutManager().getChildCount();
                totalItemCount = rv.getLayoutManager().getItemCount();
                pastVisiblesItems = ((LinearLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPosition();
                if ((visibleItemCount + pastVisiblesItems) >= totalItemCount) {
                    posts.loading = true;
                    LogUtil.v("Loading more");
                    posts.loadMore(mSwipeRefreshLayout.getContext(), false, where);
                }
            }
        }
    });
}
Also used : BaseActivity(me.ccrama.redditslide.Activities.BaseActivity) RecyclerView(android.support.v7.widget.RecyclerView) SubredditAdapter(me.ccrama.redditslide.Adapters.SubredditAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SubredditNames(me.ccrama.redditslide.Adapters.SubredditNames) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) ToolbarScrollHideHandler(me.ccrama.redditslide.handler.ToolbarScrollHideHandler)

Example 5 with BaseActivity

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

the class CommentAdapter method setCommentStateUnhighlighted.

public void setCommentStateUnhighlighted(final CommentViewHolder holder, final Comment comment, final CommentNode baseNode, boolean animate) {
    if (currentlyEditing != null && !currentlyEditing.getText().toString().isEmpty() && holder.getAdapterPosition() <= editingPosition) {
        new AlertDialogWrapper.Builder(mContext).setTitle(R.string.discard_comment_title).setMessage(R.string.comment_discard_msg).setPositiveButton(R.string.btn_yes, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                currentlyEditing = null;
                editingPosition = -1;
                if (SettingValues.fastscroll) {
                    mPage.fastScroll.setVisibility(View.VISIBLE);
                }
                if (mPage.fab != null)
                    mPage.fab.setVisibility(View.VISIBLE);
                mPage.overrideFab = false;
                currentlyEditingId = "";
                backedText = "";
                View view = ((Activity) mContext).getCurrentFocus();
                if (view != null) {
                    InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
                }
                if (mContext instanceof BaseActivity) {
                    ((BaseActivity) mContext).setShareUrl("https://reddit.com" + submission.getPermalink());
                }
                setCommentStateUnhighlighted(holder, comment, baseNode, true);
            }
        }).setNegativeButton(R.string.btn_no, null).show();
    } else {
        if (mContext instanceof BaseActivity) {
            ((BaseActivity) mContext).setShareUrl("https://freddit.com" + submission.getPermalink());
        }
        currentlySelected = null;
        currentSelectedItem = "";
        if (animate) {
            collapseAndRemove(holder.menuArea);
        } else {
            resetMenu(holder.menuArea, true);
        }
        int dwidth = (int) (3 * Resources.getSystem().getDisplayMetrics().density);
        int width = 0;
        // Padding on the left, starting with the third comment
        for (int i = 2; i < baseNode.getDepth(); i++) {
            width += dwidth;
        }
        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
        params.setMargins(width, 0, 0, 0);
        holder.itemView.setLayoutParams(params);
        TypedValue typedValue = new TypedValue();
        Resources.Theme theme = mContext.getTheme();
        theme.resolveAttribute(R.attr.card_background, typedValue, true);
        int color = typedValue.data;
        holder.itemView.findViewById(R.id.background).setBackgroundColor(color);
    }
}
Also used : DialogInterface(android.content.DialogInterface) InputMethodManager(android.view.inputmethod.InputMethodManager) ImageView(android.widget.ImageView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) BaseActivity(me.ccrama.redditslide.Activities.BaseActivity) RecyclerView(android.support.v7.widget.RecyclerView) Resources(android.content.res.Resources) TypedValue(android.util.TypedValue)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)5 BaseActivity (me.ccrama.redditslide.Activities.BaseActivity)5 ToolbarScrollHideHandler (me.ccrama.redditslide.handler.ToolbarScrollHideHandler)3 DialogInterface (android.content.DialogInterface)2 View (android.view.View)2 InputMethodManager (android.view.inputmethod.InputMethodManager)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 AlertDialogWrapper (com.afollestad.materialdialogs.AlertDialogWrapper)2 MainActivity (me.ccrama.redditslide.Activities.MainActivity)2 SpoilerRobotoTextView (me.ccrama.redditslide.SpoilerRobotoTextView)2 CatchStaggeredGridLayoutManager (me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager)2 Activity (android.app.Activity)1 Resources (android.content.res.Resources)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 TypedValue (android.util.TypedValue)1 LayoutInflater (android.view.LayoutInflater)1