Jude95 / EasyRecyclerView

ArrayAdapter,pull to refresh,auto load more,Header/Footer,EmptyView,ProgressView,ErrorView
2.03k stars 458 forks source link

Add new item to top/bottom of RecyclerView #161

Open IRMobydick opened 7 years ago

IRMobydick commented 7 years ago

Hi there, I want to add arrived message to top of my recyclerview, and as you provided in "insert" demo, I'm using .insert(object, position) By this way Item added, but! we should scroll down to reach to position 0! means item added but still is invisible to user.

mCommentsList.add(0, comment);  // Add arrived item to data list
mAdapter.insert(comment, 0);    // insert arrived item to adapter

my trick is this:

mRecyclerView.getRecyclerView().smoothScrollToPosition(0);

But I want user see the insert animation ( I applied DefaultItemAnimation to recyclerview ), by this trick, user can't see that animation!


In second try, I've set .setReverseLayout and setStackFromEnd to true in my linear layout, everything work okay, and like messenger I've add new arrived item to end of list, but the issue is in adapter load more.

( -> of course first item divider decoration draw and it's not so nice, but its not my issue now)

For this I've set .setMore methos to my adaptor and in onMoreClick i call my load more method.

my more data loading method:

private void moreData(){

    final List<Comment> mMoreList = new ArrayList<>();
    Utilities.runOnUIThread(new Runnable() {
        @Override
        public void run() {

            NetworkRequestsManager.getInstance().getNotifications(NextURL, new GeneralNetworkListener<String>() {
                @Override
                public void getResult(String response, boolean error) {

                    if (error){

                        TopToast.make(mRecyclerView, mContext, Utilities.getTypeface(Constants.fontLight), response, TopToast.LENGTH_SHORT).show();
                        mAdapter.pauseMore();

                    } else {

                        if (!response.isEmpty()){

                            ApiCommentsObject apiresponse   = gson.fromJson(response, ApiCommentsObject.class);
                            NextURL = apiresponse.Meta.NextPage;

                            if (apiresponse.Comments.isEmpty()){
                                mAdapter.pauseMore();
                            } else {

                                for (Comment comment : apiresponse.Comments){
                                    mMoreList.add(comment);
                                }

                                mCommentsList.addAll(mMoreList);
                                mAdapter.addAll(mMoreList);

                            }

                        } else {
                            mAdapter.pauseMore();
                        }

                    }

                }
            });

        }
    });

but when adapter get update, recyclerview goes to latest item in list and load more view show again, and user missed loaded items. How can resolve the problem? :'(

draw decorating for first item

when user click on plus, after load new item, see a view like this, and loaded items goes down

mostifa commented 5 years ago

سلام چه خبر