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

The following examples show how to use androidx.recyclerview.widget.LinearLayoutManager#setStackFromEnd() . 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: 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 2
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 3
Source File: FormBuildHelper.java    From SSForms with GNU General Public License v3.0 5 votes vote down vote up
public FormBuildHelper(Context context, Activity activity, RecyclerView recyclerView, FragmentManager fragmentManager) {
    // initialize form adapter
    this.mFormAdapter = new FormAdapter(context, activity, fragmentManager);

    // set up the recyclerview with adapter
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
    linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    linearLayoutManager.setStackFromEnd(false);

    recyclerView.setLayoutManager(linearLayoutManager);
    recyclerView.setAdapter(mFormAdapter);
    recyclerView.setItemAnimator(new DefaultItemAnimator());

}
 
Example 4
Source File: ChatFragment.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.fragment_chat, container, false);
    this.rmv = layout.findViewById(R.id.chatFragment_recyclerViewLayout);
    this.rmv.disableSwipeRefresh();
    LinearLayoutManager llm = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
    llm.setStackFromEnd(true);
    rmv.setLayoutManager(llm);

    Bundle args = getArguments();
    if (args == null) gid = -1;
    else gid = args.getInt("gid", -1);

    adapter = new ChatAdapter(requireContext(), this);
    this.rmv.loadListData(adapter);
    onItemCountChanged(0);

    try {
        pyx = RegisteredPyx.get();
    } catch (LevelMismatchException ex) {
        this.rmv.showError(R.string.failedLoading);
        return layout;
    }

    message = layout.findViewById(R.id.chatFragment_message);
    send = layout.findViewById(R.id.chatFragment_send);
    send.setOnClickListener(v -> {
        String msg = message.getText().toString();
        if (msg.isEmpty()) return;
        sendMessage(msg);
    });

    pyx.polling().addListener(this);

    return layout;
}
 
Example 5
Source File: RecyclerBinderAsyncInitRangeIteratorTest.java    From litho with Apache License 2.0 5 votes vote down vote up
private RecyclerBinder getStackedEndRecyclerBinder() {
  final LinearLayoutManager layoutManager =
      new LinearLayoutManager(
          mComponentContext.getAndroidContext(), OrientationHelper.VERTICAL, false);
  layoutManager.setStackFromEnd(true);
  when(mLayoutInfo.getLayoutManager()).thenReturn(layoutManager);
  return mRecyclerBinderBuilder.build(mComponentContext);
}
 
Example 6
Source File: DebugFragment.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    registerEventBus();

    v = inflater.inflate(R.layout.debug_fragment, container, false);

    mListView = v.findViewById(R.id.logwrapper);

    mArrayAdapter = new MyAdapter();
    mListView.setAdapter(mArrayAdapter);
    mListView.setItemAnimator(null);
    mListView.setOnTouchListener((v, event) -> false);

    ToggleButton toggleLock = v.findViewById(R.id.toogleLockList);
    toggleLock.setOnCheckedChangeListener((buttonView, isChecked) -> isLockPosition = isChecked);

    Button close = v.findViewById(R.id.close);
    close.setOnClickListener(v -> getActivity().getSupportFragmentManager().beginTransaction().remove(DebugFragment.this).commit());

    mLayoutManager = new LinearLayoutManager(getActivity());
    mLayoutManager.setStackFromEnd(true);

    mListView.setLayoutManager(mLayoutManager);

    return v;
}
 
Example 7
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 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: ChatFragment.java    From Twire with GNU General Public License v3.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    final View mRootView = inflater.inflate(R.layout.fragment_chat, container, false);
    LinearLayoutManager llm = new LinearLayoutManager(getContext());
    llm.setStackFromEnd(true);
    settings = new Settings(getContext());

    mSendText = mRootView.findViewById(R.id.send_message_textview);
    mSendButton = mRootView.findViewById(R.id.chat_send_ic);
    mSlowmodeIcon = mRootView.findViewById(R.id.slowmode_ic);
    mSubonlyIcon = mRootView.findViewById(R.id.subsonly_ic);
    mR9KIcon = mRootView.findViewById(R.id.r9k_ic);
    mRecyclerView = mRootView.findViewById(R.id.ChatRecyclerView);
    chatInputDivider = mRootView.findViewById(R.id.chat_input_divider);
    mChatInputLayout = mRootView.findViewById(R.id.chat_input);
    mChatInputLayout.bringToFront();
    mChatStatus = mRootView.findViewById(R.id.chat_status_text);
    mChatAdapter = new ChatAdapter(mRecyclerView, getActivity(), this);
    mChatStatusBar = mRootView.findViewById(R.id.chat_status_bar);

    mEmoteKeyboardButton = mRootView.findViewById(R.id.chat_emote_keyboard_ic);
    mEmoteChatBackspace = mRootView.findViewById(R.id.emote_backspace);
    emoteKeyboardContainer = mRootView.findViewById(R.id.emote_keyboard_container);
    mEmoteTabs = mRootView.findViewById(R.id.tabs);
    mEmoteViewPager = mRootView.findViewById(R.id.tabs_viewpager);
    selectedTabColorRes = Service.getColorAttribute(R.attr.textColor, R.color.black_text, getContext());
    unselectedTabColorRes = Service.getColorAttribute(R.attr.disabledTextColor, R.color.black_text_disabled, getContext());
    vibe = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);

    defaultBackgroundColor = mSendButton.getColorFilter();
    mRecyclerView.setAdapter(mChatAdapter);
    mRecyclerView.setLayoutManager(llm);
    mRecyclerView.setItemAnimator(null);

    mChannelInfo = getArguments().getParcelable(getString(R.string.stream_fragment_streamerInfo));// intent.getParcelableExtra(getResources().getString(R.string.intent_key_streamer_info));
    vodID = getArguments().getString(getString(R.string.stream_fragment_vod_id));

    if (!settings.isLoggedIn() || vodID != null) {
        userNotLoggedIn();
    } else {
        setupChatInput();
        loadRecentEmotes();
        setupEmoteViews();
    }

    setupKeyboardShowListener();

    setupTransition();
    return mRootView;
}
 
Example 10
Source File: ChatChannel.java    From Shipr-Community-Android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    //Init RecyclerView
    mLinearLayoutManager = new LinearLayoutManager(getActivity());
    mLinearLayoutManager.setStackFromEnd(true);
    mMessageRecycler.setLayoutManager(mLinearLayoutManager);
    mMessageRecycler.setHasFixedSize(true);

    //Clear Notification
    NotificationManager notificationManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
    int channel_id = NotificationService.getIntId("general");
    if (channel_id != -1) notificationManager.cancel(channel_id);

    //Emoji
    mEmojicon.ShowEmojIcon();
    mEmojicon.setUseSystemEmoji(true);

    mEmojicon.setKeyboardListener(new EmojIconActions.KeyboardListener() {
        @Override
        public void onKeyboardOpen() {
            Log.e("Keyboard", "open");
        }

        @Override
        public void onKeyboardClose() {
            Log.e("Keyboard", "close");
        }
    });

    mEmojicon.addEmojiconEditTextList(mEmojiconEditText);
    disableAutoOpenEmoji(mEmojicon);

    setUpAdapter();

    //disable send button (will be enabled when text is present)
    mSendButton.setEnabled(false);

    // Enable Send button when there's text to send
    editTextWatcher();

    FirebaseMessaging.getInstance().subscribeToTopic(mChannel);

    // Send button sends a message and clears the EditText
    mSendButton.setOnClickListener(view -> {
        sendMessage();
        mEmojiconEditText.setText("");
    });


    authStateCheck();

    //Keep the keyboard closed on start
    //      ((Activity) getContext()).getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
 
Example 11
Source File: ChatFragment.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
						 Bundle savedInstanceState) {
	final View mRootView = inflater.inflate(R.layout.fragment_chat, container, false);
	LinearLayoutManager llm = new LinearLayoutManager(getContext());
	llm.setStackFromEnd(true);
	settings = new Settings(getContext());

	mSendText = mRootView.findViewById(R.id.send_message_textview);
	mSendButton = mRootView.findViewById(R.id.chat_send_ic);
	mSlowmodeIcon = mRootView.findViewById(R.id.slowmode_ic);
	mSubonlyIcon = mRootView.findViewById(R.id.subsonly_ic);
	mR9KIcon = mRootView.findViewById(R.id.r9k_ic);
	mRecyclerView = mRootView.findViewById(R.id.ChatRecyclerView);
	chatInputDivider = mRootView.findViewById(R.id.chat_input_divider);
	mChatInputLayout = mRootView.findViewById(R.id.chat_input); mChatInputLayout.bringToFront();
	mChatStatus = mRootView.findViewById(R.id.chat_status_text);
	mChatAdapter = new ChatAdapter(mRecyclerView, getActivity(), this);
	mChatStatusBar = mRootView.findViewById(R.id.chat_status_bar);

	mEmoteKeyboardButton = mRootView.findViewById(R.id.chat_emote_keyboard_ic);
	mEmoteChatBackspace = mRootView.findViewById(R.id.emote_backspace);
	emoteKeyboardContainer = mRootView.findViewById(R.id.emote_keyboard_container);
	mEmoteTabs = mRootView.findViewById(R.id.tabs);
	mEmoteViewPager = mRootView.findViewById(R.id.tabs_viewpager);
	selectedTabColorRes = Service.getColorAttribute(R.attr.textColor, R.color.black_text, getContext());
	unselectedTabColorRes = Service.getColorAttribute(R.attr.disabledTextColor, R.color.black_text_disabled, getContext());
	vibe = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);

	defaultBackgroundColor = mSendButton.getColorFilter();
	mRecyclerView.setAdapter(mChatAdapter);
	mRecyclerView.setLayoutManager(llm);
	mRecyclerView.setItemAnimator(null);

	mChannelInfo = getArguments().getParcelable(getString(R.string.stream_fragment_streamerInfo));// intent.getParcelableExtra(getResources().getString(R.string.intent_key_streamer_info));

	if (!settings.isLoggedIn()) {
		userNotLoggedIn();
	} else {
		setupChatInput();
		loadRecentEmotes();
		setupEmoteViews();
	}

	setupKeyboardShowListener();

	setupTransition();
	return mRootView;
}
 
Example 12
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);
}