feat: Cleaner adapter/detail

parent acacc970
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
- List friends - List friends
- Remind daily - Remind daily
- Select best friend to remind of
- Keep track of reminded?
- Stats - Stats
- Quick increment - Quick increment
......
...@@ -37,38 +37,61 @@ class FriendsAdapter( ...@@ -37,38 +37,61 @@ class FriendsAdapter(
class FriendsViewHolder(private val view: View) : RecyclerView.ViewHolder(view) { class FriendsViewHolder(private val view: View) : RecyclerView.ViewHolder(view) {
private val name = view.contactName private val name = view.contactName
private val data = view.contactData private val data = view.contactData
private val phone = view.contactPhone
private val callButton = view.contactCall
private val smsButton = view.contactText
private val pic = view.pic private val pic = view.pic
fun bind(friend: Friend) { fun bind(friend: Friend) {
name.text = friend.name name.text = friend.name
data.text = buildString { data.text = buildDataString(friend)
if (friend.lastDate != null ) { bindPhone(friend)
bindPic(friend)
bindClick(friend)
}
private fun buildDataString(friend: Friend): String {
return buildString {
if (friend.lastDate != null) {
append(friend.timesContacted) append(friend.timesContacted)
append(" interactions, last ") append(" interactions, last ")
append(DateUtils.getRelativeTimeSpanString(friend.lastTimeStamp)) append(DateUtils.getRelativeTimeSpanString(friend.lastTimeStamp))
} else { } else {
append("Never interacted") append("Never interacted")
} }
friend.phone?.let {
view.contactCall.visibility = View.VISIBLE
view.contactCall.setOnClickListener {
view.context.startActivity(friend.callIntent())
}
view.contactText.visibility = View.VISIBLE
view.contactText.setOnClickListener {
view.context.startActivity(friend.smsIntent())
}
append("\n$it")
}
friend.photo?.let {
pic.setImageBitmap(it)
}
} }
}
private fun bindClick(friend: Friend) {
view.setOnClickListener { view.setOnClickListener {
Toast.makeText(view.context, friend.mapString(), Toast.LENGTH_LONG).show() Toast.makeText(view.context, friend.mapString(), Toast.LENGTH_LONG).show()
println(friend.mapString()) println(friend.mapString())
} }
} }
private fun bindPic(friend: Friend) {
friend.photo?.let {
pic.setImageBitmap(it)
}
}
private fun bindPhone(friend: Friend) {
friend.phone?.let {
phone.text = it
mapOf(
callButton to friend.callIntent(),
smsButton to friend.smsIntent()
).entries.forEach { pair ->
pair.key.apply {
visibility = View.VISIBLE
setOnClickListener {
view.context.startActivity(pair.value)
}
}
}
}
}
} }
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
android:elevation="2dp" android:elevation="2dp"
android:src="@drawable/user" android:src="@drawable/user"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="@id/contactName" app:layout_constraintEnd_toStartOf="@id/contactName"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
...@@ -40,8 +40,7 @@ ...@@ -40,8 +40,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Title" android:textAppearance="@style/TextAppearance.AppCompat.Title"
app:layout_constraintBottom_toTopOf="@id/contactData" app:layout_constraintBottom_toTopOf="@id/contactData"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toRightOf="@id/pic" app:layout_constraintStart_toEndOf="@id/pic"
app:layout_constraintRight_toLeftOf="@id/contactName"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tools:text="@tools:sample/full_names" /> tools:text="@tools:sample/full_names" />
...@@ -50,6 +49,21 @@ ...@@ -50,6 +49,21 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="15dp" android:layout_marginEnd="15dp"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="end"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
app:layout_constraintBottom_toTopOf="@id/contactPhone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/pic"
app:layout_constraintTop_toBottomOf="@id/contactName"
tools:text="2 interactions, last 1 hour ago" />
<TextView
android:id="@+id/contactPhone"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="15dp"
android:layout_marginBottom="15dp" android:layout_marginBottom="15dp"
android:focusable="false" android:focusable="false"
android:focusableInTouchMode="false" android:focusableInTouchMode="false"
...@@ -57,27 +71,27 @@ ...@@ -57,27 +71,27 @@
android:textAppearance="@style/TextAppearance.AppCompat.Subhead" android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
app:layout_constraintBottom_toTopOf="@id/contactCall" app:layout_constraintBottom_toTopOf="@id/contactCall"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toRightOf="@id/contactText"
app:layout_constraintRight_toLeftOf="@id/contactName" app:layout_constraintRight_toLeftOf="@id/contactName"
app:layout_constraintTop_toBottomOf="@id/contactName" app:layout_constraintStart_toEndOf="@+id/pic"
tools:text="2 interactions, last 1 hour ago" /> app:layout_constraintTop_toBottomOf="@id/contactData"
tools:text="0213 456" />
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/contactText" android:id="@+id/contactText"
style="@style/Widget.MaterialComponents.Button.OutlinedButton" style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp" android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:text="Text" android:text="Text"
android:visibility="invisible" android:visibility="invisible"
tools:visibility="visible"
app:icon="@android:drawable/ic_menu_send" app:icon="@android:drawable/ic_menu_send"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="1.0" app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toRightOf="@id/pic" app:layout_constraintEnd_toStartOf="@id/contactCall"
app:layout_constraintRight_toLeftOf="@id/contactCall" app:layout_constraintStart_toEndOf="@id/pic"
app:layout_constraintTop_toBottomOf="@id/contactData" /> app:layout_constraintTop_toBottomOf="@id/contactPhone"
tools:visibility="visible" />
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/contactCall" android:id="@+id/contactCall"
...@@ -86,14 +100,14 @@ ...@@ -86,14 +100,14 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="10dp" android:layout_marginEnd="10dp"
android:text="Call" android:text="Call"
app:icon="@android:drawable/ic_menu_call"
android:visibility="invisible" android:visibility="invisible"
tools:visibility="visible" app:icon="@android:drawable/ic_menu_call"
app:layout_constraintBottom_toBottomOf="@id/contactText" app:layout_constraintBottom_toBottomOf="@id/contactText"
app:layout_constraintHorizontal_bias="1.0" app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toRightOf="@id/contactText"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/contactData" /> app:layout_constraintStart_toEndOf="@id/contactText"
app:layout_constraintTop_toBottomOf="@id/contactPhone"
tools:visibility="visible" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment