package com.lettemin import android.Manifest import android.content.pm.PackageManager import android.os.Bundle import android.provider.ContactsContract import android.text.Editable import android.text.TextWatcher import android.view.View import android.view.ViewGroup import android.widget.BaseAdapter import android.widget.Button import android.widget.CheckedTextView import android.widget.EditText import android.widget.ListView import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat /** * Multi-select contact picker. Includes two pseudo-entries (Anonymous, Likely Spam) * at the top of the list. * * Input : EXTRA_PROFILE_ID (String?, the profile being edited; used to pre-check) * EXTRA_SELECTED (String[], current selection from edit activity, used * to override repo state if the user has been editing) * Output : EXTRA_SELECTED (String[], new selection) */ class ContactPickerActivity : AppCompatActivity() { companion object { const val EXTRA_PROFILE_ID = "profile_id" const val EXTRA_SELECTED = "selected" // String[] of contact keys } private data class Row(val key: String, val label: String) private val rows = mutableListOf() private val filtered = mutableListOf() private val selected = mutableSetOf() private lateinit var adapter: Adapter private lateinit var list: ListView override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_contact_picker) list = findViewById(R.id.list) adapter = Adapter() list.adapter = adapter intent.getStringArrayExtra(EXTRA_SELECTED)?.let { selected.addAll(it) } loadAll() filter("") findViewById(R.id.search).addTextChangedListener(object : TextWatcher { override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { filter(s?.toString() ?: "") } override fun afterTextChanged(s: Editable?) {} }) list.setOnItemClickListener { _, _, pos, _ -> val row = filtered[pos] if (selected.contains(row.key)) selected.remove(row.key) else selected.add(row.key) adapter.notifyDataSetChanged() } findViewById