This repository was archived by the owner on Jun 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 544
Expand file tree
/
Copy pathContactRecyclerViewAdapter.kt
More file actions
78 lines (68 loc) · 2.79 KB
/
ContactRecyclerViewAdapter.kt
File metadata and controls
78 lines (68 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package chat.rocket.android.contacts
import android.content.Context
import timber.log.Timber
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import android.widget.Toast
import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.RecyclerView
import chat.rocket.android.R
import chat.rocket.android.contacts.models.Contact
import chat.rocket.android.main.ui.MainActivity
import java.util.*
import kotlin.collections.HashMap
import chat.rocket.android.util.extensions.showToast
class ContactRecyclerViewAdapter(
private val context: MainActivity,
private val contactArrayList: ArrayList<Contact?>,
private val contactHashMap: HashMap<String, String>
) : RecyclerView.Adapter<ContactRecyclerViewAdapter.ViewHolder>() {
override fun getItemCount(): Int {
return contactArrayList.size
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater
.from(parent.context)
.inflate(R.layout.item_contact, parent, false)
return ViewHolder(view)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.contact = contactArrayList[position]
holder.status = contactHashMap.get(holder.contact!!.getPhoneNumber())
try {
holder.contactName.text = holder.contact!!.getName()
if (holder.contact!!.isPhone()) {
holder.contactDetail.text = holder.contact!!.getPhoneNumber()
} else {
holder.contactDetail.text = holder.contact!!.getEmailAddress()
}
} catch (exception: NullPointerException) {
Timber.e("Failed to send resolution. Exception is: $exception")
}
}
inner class ViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
var contact: Contact? = null
var status: String? = null
var contactName: TextView
var contactDetail: TextView
var inviteButton: Button
init {
this.contactName = view.findViewById(R.id.contact_name) as TextView
this.contactDetail = view.findViewById(R.id.contact_detail) as TextView
this.inviteButton = view.findViewById(R.id.invite_contact) as Button
this.inviteButton.setOnClickListener { view ->
run {
// Make API call using context.presenter
if(contact!!.isPhone()){
context.presenter.inviteViaSMS(contact!!.getPhoneNumber()!!);
}else{
context.presenter.inviteViaEmail(contact!!.getEmailAddress()!!);
}
}
}
}
}
}