Java Code Examples for androidx.recyclerview.widget.LinearLayoutManager#setReverseLayout()

The following examples show how to use androidx.recyclerview.widget.LinearLayoutManager#setReverseLayout() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GroupChatFragment.java    From SendBird-Android with MIT License 6 votes vote down vote up
private void setUpRecyclerView() {
    mLayoutManager = new LinearLayoutManager(getActivity());
    mLayoutManager.setReverseLayout(true);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setAdapter(mChatAdapter);
    mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (newState == RecyclerView.SCROLL_STATE_IDLE) {
                if (mLayoutManager.findFirstVisibleItemPosition() == 0) {
                    mMessageCollection.fetchSucceededMessages(MessageCollection.Direction.NEXT, null);
                    mNewMessageText.setVisibility(View.GONE);
                }

                if (mLayoutManager.findLastVisibleItemPosition() == mChatAdapter.getItemCount() - 1) {
                    mMessageCollection.fetchSucceededMessages(MessageCollection.Direction.PREVIOUS, null);
                }

            }
        }
    });
}
 
Example 2
Source File: OpenChatFragment.java    From SendBird-Android with MIT License 6 votes vote down vote up
private void setUpRecyclerView() {
    mLayoutManager = new LinearLayoutManager(getActivity());
    mLayoutManager.setReverseLayout(true);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setAdapter(mChatAdapter);

    // Load more messages when user reaches the top of the current message list.
    mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {

            if (mLayoutManager.findLastVisibleItemPosition() == mChatAdapter.getItemCount() - 1) {
                loadNextMessageList(CHANNEL_LIST_LIMIT);
            }
            Log.v(LOG_TAG, "onScrollStateChanged");
        }
    });
}
 
Example 3
Source File: FilePickerActivity.java    From SimplicityBrowser with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    if (UserPreferences.getBoolean("dark_mode", false)) {
        setTheme(R.style.SettingsThemeDark);
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_file_picker);
    recyclerView = findViewById(R.id.recycler_view);
    mToolbar = findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
    }
    LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
    mLayoutManager.setReverseLayout(true);
    mLayoutManager.setStackFromEnd(true);
    recyclerView.setLayoutManager(mLayoutManager);
    recyclerViewAdapter = new AdapterDownloads(FilePickerActivity.this, getUserDownloads());
    recyclerView.setAdapter(recyclerViewAdapter);
    recyclerViewAdapter.notifyDataSetChanged();
}
 
Example 4
Source File: ViewPrivateMessagesActivity.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 5 votes vote down vote up
private void bindView() {
    mAdapter = new PrivateMessagesDetailRecyclerViewAdapter(this, privateMessage, mCustomThemeWrapper);
    mLinearLayoutManager = new LinearLayoutManager(this);
    mLinearLayoutManager.setReverseLayout(true);
    mLinearLayoutManager.setStackFromEnd(true);
    mRecyclerView.setLayoutManager(mLinearLayoutManager);
    mRecyclerView.setAdapter(mAdapter);
}
 
Example 5
Source File: GroupChatFragment.java    From SendBird-Android with MIT License 5 votes vote down vote up
private void setUpRecyclerView() {
    mLayoutManager = new LinearLayoutManager(getActivity());
    mLayoutManager.setReverseLayout(true);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setAdapter(mChatAdapter);
    mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (mLayoutManager.findLastVisibleItemPosition() == mChatAdapter.getItemCount() - 1) {
                mChatAdapter.loadPreviousMessages(CHANNEL_LIST_LIMIT, null);
            }
        }
    });
}
 
Example 6
Source File: HistoryActivity.java    From SimplicityBrowser with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    if(UserPreferences.getBoolean("dark_mode", false)){
        setTheme(R.style.BookMarksThemeDark);
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_history);
    preferences = PreferenceManager.getDefaultSharedPreferences(this);
    mToolbar = findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);

    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
    }
    listHistory = UserPreferences.getHistory();
    recyclerBookmarks = findViewById(R.id.recycler_history);
    LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
    mLayoutManager.setReverseLayout(true);
    mLayoutManager.setStackFromEnd(true);
    recyclerBookmarks.setLayoutManager(mLayoutManager);
    adapterBookmarks = new AdapterHistory(this, listHistory, this);
    recyclerBookmarks.setAdapter(adapterBookmarks);
    //show long click hint
    if (preferences.getBoolean("first_history", true) && !listHistory.isEmpty()) {
        Cardbar.snackBar(getApplicationContext(), "Long click to copy link", true).show();

        preferences.edit().putBoolean("first_history", false).apply();
    }


}
 
Example 7
Source File: MessageActivity.java    From toktok-android with GNU General Public License v3.0 5 votes vote down vote up
private void initRecyclerView() {
    mRecycler = this.findViewById(R.id.message_recycler);

    LinearLayoutManager mLayoutManager = new LinearLayoutManager(getBaseContext());
    mLayoutManager.setReverseLayout(true);
    mRecycler.setHasFixedSize(true);
    mRecyclerAdapter = new MessageAdapter(this, this);

    if (imgSRC == 0) {
        imgSRC = R.drawable.lorem;
        mRecyclerAdapter.addItem(new Message(MessageType.Action, "The Amazing Group was created", "", R.drawable.user));
        mRecyclerAdapter.addItem(new Message(MessageType.Received, "Awesome stuff!", "14:29 Received", R.drawable.john));
    }

    mRecyclerAdapter.addItem(new Message(MessageType.Delivered, "Welcome to TokTok " + title + ", I hope you love it, as much as I do \uD83D\uDE00", "14:30 Delivered", R.drawable.user));
    mRecyclerAdapter.addItem(new Message(MessageType.Received, "Thanks André Almeida, let's hope soo.", "14:31 Received", imgSRC));
    mRecyclerAdapter.addItem(new Message(MessageType.Action, "Smiled", "", imgSRC));
    mRecyclerAdapter.addItem(new Message(MessageType.Received, "Yooo!", "14:32 Received", imgSRC));

    mRecycler.setAdapter(mRecyclerAdapter);
    mRecycler.setLayoutManager(mLayoutManager);

    mRecycler.setItemAnimator(new MessageItemAnimator());

    ImageButton attachButton = this.findViewById(R.id.message_attachments_button);

    attachButton.setOnClickListener(v -> {
        InputMethodManager imm = (InputMethodManager) MessageActivity.this.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(mInput.getApplicationWindowToken(), 0);

        overlayAttachments.start();
    });
}
 
Example 8
Source File: FirestoreChatActivity.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_chat);
    ButterKnife.bind(this);

    LinearLayoutManager manager = new LinearLayoutManager(this);
    manager.setReverseLayout(true);
    manager.setStackFromEnd(true);

    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setLayoutManager(manager);

    mRecyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View view, int left, int top, int right, int bottom,
                                   int oldLeft, int oldTop, int oldRight, int oldBottom) {
            if (bottom < oldBottom) {
                mRecyclerView.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mRecyclerView.smoothScrollToPosition(0);
                    }
                }, 100);
            }
        }
    });

    ImeHelper.setImeOnDoneListener(mMessageEdit, new ImeHelper.DonePressedListener() {
        @Override
        public void onDonePressed() {
            onSendClick();
        }
    });
}
 
Example 9
Source File: PostListFragment.java    From quickstart-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    // Set up Layout Manager, reverse layout
    mManager = new LinearLayoutManager(getActivity());
    mManager.setReverseLayout(true);
    mManager.setStackFromEnd(true);
    mRecycler.setLayoutManager(mManager);

    // Set up FirebaseRecyclerAdapter with the Query
    Query postsQuery = getQuery(mDatabase);

    FirebaseRecyclerOptions options = new FirebaseRecyclerOptions.Builder<Post>()
            .setQuery(postsQuery, Post.class)
            .build();

    mAdapter = new FirebaseRecyclerAdapter<Post, PostViewHolder>(options) {

        @Override
        public PostViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
            LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
            return new PostViewHolder(inflater.inflate(R.layout.item_post, viewGroup, false));
        }

        @Override
        protected void onBindViewHolder(PostViewHolder viewHolder, int position, final Post model) {
            final DatabaseReference postRef = getRef(position);

            // Set click listener for the whole post view
            final String postKey = postRef.getKey();
            viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    // Launch PostDetailActivity
                    Intent intent = new Intent(getActivity(), PostDetailActivity.class);
                    intent.putExtra(PostDetailActivity.EXTRA_POST_KEY, postKey);
                    startActivity(intent);
                }
            });

            // Determine if the current user has liked this post and set UI accordingly
            if (model.stars.containsKey(getUid())) {
                viewHolder.starView.setImageResource(R.drawable.ic_toggle_star_24);
            } else {
                viewHolder.starView.setImageResource(R.drawable.ic_toggle_star_outline_24);
            }

            // Bind Post to ViewHolder, setting OnClickListener for the star button
            viewHolder.bindToPost(model, new View.OnClickListener() {
                @Override
                public void onClick(View starView) {
                    // Need to write to both places the post is stored
                    DatabaseReference globalPostRef = mDatabase.child("posts").child(postRef.getKey());
                    DatabaseReference userPostRef = mDatabase.child("user-posts").child(model.uid).child(postRef.getKey());

                    // Run two transactions
                    onStarClicked(globalPostRef);
                    onStarClicked(userPostRef);
                }
            });
        }
    };
    mRecycler.setAdapter(mAdapter);
}
 
Example 10
Source File: QiscusRecyclerView.java    From qiscus-sdk-android with Apache License 2.0 4 votes vote down vote up
public void setUpAsBottomList() {
    setHasFixedSize(true);
    LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
    layoutManager.setReverseLayout(true);
    setLayoutManager(layoutManager);
}