Skip to content

Instantly share code, notes, and snippets.

@john-lorrenz
Created November 19, 2019 00:13
Show Gist options
  • Save john-lorrenz/1083743c3183b078591a30702156278e to your computer and use it in GitHub Desktop.
Save john-lorrenz/1083743c3183b078591a30702156278e to your computer and use it in GitHub Desktop.
Basic Chat Kotlin Template
androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view_chat"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
implementation 'com.google.android.material:material:1.0.0'
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_chat)
val adapter = GroupAdapter<ViewHolder>()
adapter.add(ChatFromItem())
adapter.add(ChatFromItem())
adapter.add(ChatToItem())
adapter.add(ChatFromItem())
recycler_view_chat.adapter = adapter
}
inner class ChatFromItem(): Item<ViewHolder>(){
override fun getLayout(): Int {
return R.layout.row_chat_from
}
override fun bind(viewHolder: ViewHolder, position: Int) {
}
}
inner class ChatToItem(): Item<ViewHolder>(){
override fun getLayout(): Int {
return R.layout.row_chat_to
}
override fun bind(viewHolder: ViewHolder, position: Int) {
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--
// Right side alignment attribute
android:layout_alignParentRight="true"
-->
<com.google.android.material.card.MaterialCardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardElevation="0dp"
app:cardBackgroundColor="@color/colorPrimaryDark"
app:cardCornerRadius="10dp"
app:contentPadding="15dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hi man what's up?"
android:textColor="@android:color/white"/>
</com.google.android.material.card.MaterialCardView>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--
// Right side alignment attribute
android:layout_alignParentRight="true"
-->
<com.google.android.material.card.MaterialCardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardElevation="0dp"
app:cardBackgroundColor="@android:color/darker_gray"
app:cardCornerRadius="10dp"
app:contentPadding="15dp"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hi man what's up?"
android:textColor="@android:color/black"/>
</com.google.android.material.card.MaterialCardView>
</RelativeLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment