Features: - LDAP contact management (CRUD) - Search by name, phone, company - Call/SMS integration - Android contacts sync for caller ID - Material Design 3 UI LDAP Structure: - uid-based DN for flexible cn modification - Attributes: cn, displayName, mobile, mail, o, ou, title
98 lines
3.3 KiB
Kotlin
98 lines
3.3 KiB
Kotlin
package net.ioresponse.ldapcontacts
|
|
|
|
import android.graphics.Color
|
|
import android.view.LayoutInflater
|
|
import android.view.View
|
|
import android.view.ViewGroup
|
|
import android.widget.ImageButton
|
|
import android.widget.TextView
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
|
class ContactAdapter(
|
|
private var contacts: List<Contact>,
|
|
private val onItemClick: (Contact) -> Unit,
|
|
private val onCallClick: (Contact) -> Unit
|
|
) : RecyclerView.Adapter<ContactAdapter.ViewHolder>() {
|
|
|
|
private val colors = listOf(
|
|
Color.parseColor("#F44336"),
|
|
Color.parseColor("#E91E63"),
|
|
Color.parseColor("#9C27B0"),
|
|
Color.parseColor("#673AB7"),
|
|
Color.parseColor("#3F51B5"),
|
|
Color.parseColor("#2196F3"),
|
|
Color.parseColor("#03A9F4"),
|
|
Color.parseColor("#00BCD4"),
|
|
Color.parseColor("#009688"),
|
|
Color.parseColor("#4CAF50"),
|
|
Color.parseColor("#8BC34A"),
|
|
Color.parseColor("#FF9800"),
|
|
Color.parseColor("#FF5722")
|
|
)
|
|
|
|
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
|
val initialsText: TextView = view.findViewById(R.id.initialsText)
|
|
val nameText: TextView = view.findViewById(R.id.nameText)
|
|
val phoneText: TextView = view.findViewById(R.id.phoneText)
|
|
val orgText: TextView = view.findViewById(R.id.orgText)
|
|
val callButton: ImageButton = view.findViewById(R.id.callButton)
|
|
}
|
|
|
|
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) {
|
|
val contact = contacts[position]
|
|
|
|
holder.initialsText.text = contact.initials
|
|
holder.initialsText.background.setTint(colors[position % colors.size])
|
|
|
|
// 이름 + 직급 표시
|
|
val nameWithTitle = buildString {
|
|
append(contact.name)
|
|
if (contact.title.isNotEmpty() && contact.title != "-") {
|
|
append(" ")
|
|
append(contact.title)
|
|
}
|
|
}
|
|
holder.nameText.text = nameWithTitle
|
|
holder.phoneText.text = contact.phone.ifEmpty { "-" }
|
|
|
|
// 회사 - 부서 형식으로 표시
|
|
val orgDept = buildString {
|
|
if (contact.organization.isNotEmpty() && contact.organization != "-") {
|
|
append(contact.organization)
|
|
}
|
|
if (contact.department.isNotEmpty() && contact.department != "-") {
|
|
if (isNotEmpty()) append(" - ")
|
|
append(contact.department)
|
|
}
|
|
}
|
|
if (orgDept.isNotEmpty()) {
|
|
holder.orgText.visibility = View.VISIBLE
|
|
holder.orgText.text = orgDept
|
|
} else {
|
|
holder.orgText.visibility = View.GONE
|
|
}
|
|
|
|
holder.itemView.setOnClickListener { onItemClick(contact) }
|
|
|
|
if (contact.phone.isNotEmpty()) {
|
|
holder.callButton.visibility = View.VISIBLE
|
|
holder.callButton.setOnClickListener { onCallClick(contact) }
|
|
} else {
|
|
holder.callButton.visibility = View.GONE
|
|
}
|
|
}
|
|
|
|
override fun getItemCount() = contacts.size
|
|
|
|
fun updateContacts(newContacts: List<Contact>) {
|
|
contacts = newContacts
|
|
notifyDataSetChanged()
|
|
}
|
|
}
|