use of com.moez.QKSMS.ui.view.MessageListRecyclerView in project qksms by moezbhatti.
the class MessageListFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_conversation, container, false);
mRecyclerView = (MessageListRecyclerView) view.findViewById(R.id.conversation);
mAdapter = new MessageListAdapter(mContext);
mAdapter.setItemClickListener(this);
mAdapter.setMultiSelectListener(this);
mAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
private long mLastMessageId = -1;
@Override
public void onChanged() {
LinearLayoutManager manager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
int position;
if (mRowId != -1 && mCursor != null) {
// Scroll to the position in the conversation for that message.
position = SmsHelper.getPositionForMessageId(mCursor, "sms", mRowId, mAdapter.getColumnsMap());
// Be sure to reset the row ID here---we only want to scroll to the message
// the first time the cursor is loaded after the row ID is set.
mRowId = -1;
} else {
position = mAdapter.getItemCount() - 1;
}
if (mAdapter.getCount() > 0) {
MessageItem lastMessage = mAdapter.getItem(mAdapter.getCount() - 1);
if (mLastMessageId >= 0 && mLastMessageId != lastMessage.getMessageId()) {
// Scroll to bottom only if a new message was inserted in this conversation
if (position != -1) {
manager.smoothScrollToPosition(mRecyclerView, null, position);
}
}
mLastMessageId = lastMessage.getMessageId();
}
}
});
mRecyclerView.setAdapter(mAdapter);
mLayoutManager = new SmoothLinearLayoutManager(mContext);
mLayoutManager.setStackFromEnd(true);
mRecyclerView.setLayoutManager(mLayoutManager);
mComposeView = (ComposeView) view.findViewById(R.id.compose_view);
mComposeView.setActivityLauncher(this);
mComposeView.setLabel("MessageList");
mRecyclerView.setComposeView(mComposeView);
return view;
}
use of com.moez.QKSMS.ui.view.MessageListRecyclerView in project qksms by moezbhatti.
the class SearchFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_search, container, false);
mQuery = (QKEditText) view.findViewById(R.id.search_query);
mQuery.setTextChangedListener(s -> {
mSearchString = s.toString();
query();
});
mQuery.setOnEditorActionListener((v, actionId, event) -> {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
mSearchString = mQuery.getText().toString();
query();
// Hide the keyboard when the user makes a query
mQuery.clearFocus();
KeyboardUtils.hide(mContext, mQuery);
return true;
}
return false;
});
mLayoutManager = new LinearLayoutManager(mContext);
mAdapter = new SearchAdapter(mContext);
mAdapter.setItemClickListener(this);
mRecyclerView = (MessageListRecyclerView) view.findViewById(R.id.search_list);
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setAdapter(mAdapter);
new Handler().postDelayed(() -> KeyboardUtils.showAndFocus(mContext, mQuery), 50);
return view;
}
Aggregations