Search in sources :

Example 1 with ConversationListAdapter

use of drift.com.drift.adapters.ConversationListAdapter in project drift-sdk-android by Driftt.

the class ConversationListActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    StatusBarColorizer.setActivityColor(this);
    setContentView(R.layout.drift_sdk_activity_conversation_list);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle("Conversations");
    }
    conversationRecyclerView = findViewById(R.id.drift_sdk_conversation_list_recycler_view);
    progressBar = findViewById(R.id.drift_sdk_conversation_list_progress_bar);
    networkAvailabilityBar = findViewById(R.id.drift_sdk_conversation_list_load_page_text_view);
    emptyState = findViewById(R.id.drift_sdk_conversation_list_empty_linear_layout);
    emptyStateButton = findViewById(R.id.drift_sdk_conversation_list_empty_state_create_button);
    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    conversationRecyclerView.setLayoutManager(layoutManager);
    DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(conversationRecyclerView.getContext(), layoutManager.getOrientation());
    dividerItemDecoration.setDrawable(ContextCompat.getDrawable(this, R.drawable.drift_sdk_recycler_view_divider));
    conversationRecyclerView.addItemDecoration(dividerItemDecoration);
    conversationRecyclerView.addOnItemTouchListener(new RecyclerTouchListener(this, conversationRecyclerView, new ClickListener() {

        @Override
        public void onClick(View view, int position) {
            Conversation conversation = conversationListAdapter.getItemAt(position);
            if (conversation != null) {
                Intent intent = ConversationActivity.intentForConversation(ConversationListActivity.this, conversation.id);
                ConversationListActivity.this.startActivity(intent);
            }
        }
    }));
    emptyStateButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent intent = ConversationActivity.intentForCreateConversation(ConversationListActivity.this);
            ConversationListActivity.this.startActivity(intent);
        }
    });
    emptyStateButton.setTextColor(ColorHelper.getForegroundColor());
    Drawable backgroundDrawable = DrawableCompat.wrap(emptyStateButton.getBackground()).mutate();
    DrawableCompat.setTint(backgroundDrawable, ColorHelper.getBackgroundColor());
    emptyState.setVisibility(View.GONE);
    conversationListAdapter = new ConversationListAdapter(this, ConversationManager.getInstance().getConversations());
    conversationRecyclerView.setAdapter(conversationListAdapter);
    if (conversationListAdapter.getItemCount() == 0) {
        progressBar.setVisibility(View.VISIBLE);
    } else {
        progressBar.setVisibility(View.GONE);
    }
}
Also used : RecyclerTouchListener(drift.com.drift.helpers.RecyclerTouchListener) Drawable(android.graphics.drawable.Drawable) Conversation(drift.com.drift.model.Conversation) Intent(android.content.Intent) ConversationListAdapter(drift.com.drift.adapters.ConversationListAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) ActionBar(android.support.v7.app.ActionBar) ClickListener(drift.com.drift.helpers.ClickListener)

Aggregations

Intent (android.content.Intent)1 Drawable (android.graphics.drawable.Drawable)1 ActionBar (android.support.v7.app.ActionBar)1 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 TextView (android.widget.TextView)1 ConversationListAdapter (drift.com.drift.adapters.ConversationListAdapter)1 ClickListener (drift.com.drift.helpers.ClickListener)1 RecyclerTouchListener (drift.com.drift.helpers.RecyclerTouchListener)1 Conversation (drift.com.drift.model.Conversation)1