feat: Cleaner adapter/detail

parent acacc970
......@@ -2,6 +2,8 @@
- List friends
- Remind daily
- Select best friend to remind of
- Keep track of reminded?
- Stats
- Quick increment
......
......@@ -37,37 +37,60 @@ class FriendsAdapter(
class FriendsViewHolder(private val view: View) : RecyclerView.ViewHolder(view) {
private val name = view.contactName
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
fun bind(friend: Friend) {
name.text = friend.name
data.text = buildString {
if (friend.lastDate != null ) {
data.text = buildDataString(friend)
bindPhone(friend)
bindPic(friend)
bindClick(friend)
}
private fun buildDataString(friend: Friend): String {
return buildString {
if (friend.lastDate != null) {
append(friend.timesContacted)
append(" interactions, last ")
append(DateUtils.getRelativeTimeSpanString(friend.lastTimeStamp))
} else {
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")
private fun bindClick(friend: Friend) {
view.setOnClickListener {
Toast.makeText(view.context, friend.mapString(), Toast.LENGTH_LONG).show()
println(friend.mapString())
}
}
private fun bindPic(friend: Friend) {
friend.photo?.let {
pic.setImageBitmap(it)
}
}
view.setOnClickListener {
Toast.makeText(view.context, friend.mapString(), Toast.LENGTH_LONG).show()
println(friend.mapString())
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 @@
android:elevation="2dp"
android:src="@drawable/user"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="@id/contactName"
app:layout_constraintEnd_toStartOf="@id/contactName"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
......@@ -40,8 +40,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Title"
app:layout_constraintBottom_toTopOf="@id/contactData"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toRightOf="@id/pic"
app:layout_constraintRight_toLeftOf="@id/contactName"
app:layout_constraintStart_toEndOf="@id/pic"
app:layout_constraintTop_toTopOf="parent"
tools:text="@tools:sample/full_names" />
......@@ -50,6 +49,21 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
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:focusable="false"
android:focusableInTouchMode="false"
......@@ -57,27 +71,27 @@
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
app:layout_constraintBottom_toTopOf="@id/contactCall"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toRightOf="@id/contactText"
app:layout_constraintRight_toLeftOf="@id/contactName"
app:layout_constraintTop_toBottomOf="@id/contactName"
tools:text="2 interactions, last 1 hour ago" />
app:layout_constraintStart_toEndOf="@+id/pic"
app:layout_constraintTop_toBottomOf="@id/contactData"
tools:text="0213 456" />
<com.google.android.material.button.MaterialButton
android:id="@+id/contactText"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:text="Text"
android:visibility="invisible"
tools:visibility="visible"
app:icon="@android:drawable/ic_menu_send"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toRightOf="@id/pic"
app:layout_constraintRight_toLeftOf="@id/contactCall"
app:layout_constraintTop_toBottomOf="@id/contactData" />
app:layout_constraintEnd_toStartOf="@id/contactCall"
app:layout_constraintStart_toEndOf="@id/pic"
app:layout_constraintTop_toBottomOf="@id/contactPhone"
tools:visibility="visible" />
<com.google.android.material.button.MaterialButton
android:id="@+id/contactCall"
......@@ -86,14 +100,14 @@
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:text="Call"
app:icon="@android:drawable/ic_menu_call"
android:visibility="invisible"
tools:visibility="visible"
app:icon="@android:drawable/ic_menu_call"
app:layout_constraintBottom_toBottomOf="@id/contactText"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toRightOf="@id/contactText"
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.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