allow selecting only 1 contact at the selection activity
This commit is contained in:
parent
a19bf32b3c
commit
8e3eee5106
|
@ -65,7 +65,6 @@
|
|||
|
||||
<activity
|
||||
android:name=".activities.ContactActivity"
|
||||
android:label="@string/new_contact"
|
||||
android:parentActivityName=".activities.MainActivity">
|
||||
|
||||
<intent-filter>
|
||||
|
@ -77,7 +76,7 @@
|
|||
<data android:mimeType="vnd.android.cursor.item/raw_contact"/>
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter android:label="@string/edit_contact">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.EDIT"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
|
||||
|
@ -92,7 +91,7 @@
|
|||
android:mimeType="vnd.android.cursor.item/raw_contact"/>
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter android:label="@string/new_contact">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.INSERT"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
|
||||
|
@ -101,7 +100,7 @@
|
|||
<data android:mimeType="vnd.android.cursor.dir/raw_contact"/>
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter android:label="@string/edit_contact">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
|
||||
|
@ -110,7 +109,7 @@
|
|||
<data android:mimeType="vnd.android.cursor.item/group"/>
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter android:label="@string/edit_contact">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
|
||||
|
|
|
@ -4,8 +4,6 @@ import android.content.Intent
|
|||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.provider.ContactsContract
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import com.simplemobiletools.commons.extensions.appLaunched
|
||||
import com.simplemobiletools.commons.extensions.baseConfig
|
||||
import com.simplemobiletools.commons.extensions.isActivityDestroyed
|
||||
|
@ -20,9 +18,6 @@ import com.simplemobiletools.contacts.models.Contact
|
|||
import kotlinx.android.synthetic.main.layout_select_contact.*
|
||||
|
||||
class SelectContactActivity : SimpleActivity() {
|
||||
private var skipFavorites = false
|
||||
private var allowMultiple = false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.layout_select_contact)
|
||||
|
@ -45,28 +40,7 @@ class SelectContactActivity : SimpleActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_select_contact, menu)
|
||||
menu.findItem(R.id.confirm).isVisible = allowMultiple
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.confirm -> confirmSelection()
|
||||
else -> return super.onOptionsItemSelected(item)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun initContacts() {
|
||||
skipFavorites = intent.getBooleanExtra("extraSkipFavorites", false)
|
||||
allowMultiple = intent.getBooleanExtra("isPickMultiContactsWithoutProfile", false)
|
||||
if (allowMultiple) {
|
||||
title = getString(R.string.select_contacts)
|
||||
invalidateOptionsMenu()
|
||||
}
|
||||
|
||||
ContactsHelper(this).getContacts {
|
||||
var contacts = it
|
||||
if (isActivityDestroyed()) {
|
||||
|
@ -78,16 +52,13 @@ class SelectContactActivity : SimpleActivity() {
|
|||
contacts = contacts.filter { contactSources.contains(it.source) } as ArrayList<Contact>
|
||||
}
|
||||
|
||||
if (skipFavorites) {
|
||||
val favorites = config.favorites
|
||||
contacts = contacts.filter { !favorites.contains(it.id.toString()) } as ArrayList<Contact>
|
||||
}
|
||||
|
||||
Contact.sorting = config.sorting
|
||||
contacts.sort()
|
||||
|
||||
runOnUiThread {
|
||||
select_contact_list.adapter = SelectContactsAdapter(this, contacts, HashSet())
|
||||
select_contact_list.adapter = SelectContactsAdapter(this, contacts, HashSet(), false) {
|
||||
confirmSelection(it)
|
||||
}
|
||||
select_contact_fastscroller.allowBubbleDisplay = baseConfig.showInfoBubble
|
||||
select_contact_fastscroller.setViews(select_contact_list) {
|
||||
select_contact_fastscroller.updateBubbleText(contacts[it].getBubbleText())
|
||||
|
@ -96,9 +67,8 @@ class SelectContactActivity : SimpleActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun confirmSelection() {
|
||||
val selectedItems = (select_contact_list.adapter as SelectContactsAdapter).getSelectedItemsSet()
|
||||
val lookupKey = ContactsHelper(this).getContactLookupKey(selectedItems.first())
|
||||
private fun confirmSelection(contact: Contact) {
|
||||
val lookupKey = ContactsHelper(this).getContactLookupKey(contact.id.toString())
|
||||
val lookupUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey)
|
||||
|
||||
Intent().apply {
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy
|
|||
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
import com.bumptech.glide.signature.ObjectKey
|
||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||
import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
|
||||
import com.simplemobiletools.commons.interfaces.MyAdapterListener
|
||||
import com.simplemobiletools.contacts.R
|
||||
|
@ -20,8 +21,8 @@ import com.simplemobiletools.contacts.models.Contact
|
|||
import kotlinx.android.synthetic.main.item_add_favorite_with_number.view.*
|
||||
import java.util.*
|
||||
|
||||
class SelectContactsAdapter(val activity: SimpleActivity, val contacts: List<Contact>, val selectedContacts: Set<String>)
|
||||
: RecyclerView.Adapter<SelectContactsAdapter.ViewHolder>() {
|
||||
class SelectContactsAdapter(val activity: SimpleActivity, val contacts: List<Contact>, val selectedContacts: Set<String>, val allowPickMultiple: Boolean,
|
||||
val itemClick: ((Contact) -> Unit)? = null) : RecyclerView.Adapter<SelectContactsAdapter.ViewHolder>() {
|
||||
private val itemViews = SparseArray<View>()
|
||||
private val selectedPositions = HashSet<Int>()
|
||||
private val config = activity.config
|
||||
|
@ -68,7 +69,7 @@ class SelectContactsAdapter(val activity: SimpleActivity, val contacts: List<Con
|
|||
|
||||
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
|
||||
val view = activity.layoutInflater.inflate(itemLayout, parent, false)
|
||||
return ViewHolder(view, adapterListener, activity)
|
||||
return ViewHolder(view, adapterListener, activity, allowPickMultiple, itemClick)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
|
@ -79,9 +80,11 @@ class SelectContactsAdapter(val activity: SimpleActivity, val contacts: List<Con
|
|||
|
||||
override fun getItemCount() = contacts.size
|
||||
|
||||
class ViewHolder(view: View, val adapterListener: MyAdapterListener, val activity: SimpleActivity) : RecyclerView.ViewHolder(view) {
|
||||
class ViewHolder(view: View, val adapterListener: MyAdapterListener, val activity: SimpleActivity, val showCheckbox: Boolean,
|
||||
val itemClick: ((Contact) -> Unit)?) : RecyclerView.ViewHolder(view) {
|
||||
fun bindView(contact: Contact, startNameWithSurname: Boolean, contactDrawable: Drawable, config: Config): View {
|
||||
itemView.apply {
|
||||
contact_checkbox.beVisibleIf(showCheckbox)
|
||||
contact_checkbox.setColors(config.textColor, config.primaryColor, config.backgroundColor)
|
||||
val textColor = config.textColor
|
||||
|
||||
|
@ -89,7 +92,13 @@ class SelectContactsAdapter(val activity: SimpleActivity, val contacts: List<Con
|
|||
contact_name.setTextColor(textColor)
|
||||
contact_number?.text = contact.phoneNumbers.firstOrNull()?.value ?: ""
|
||||
contact_number?.setTextColor(textColor)
|
||||
contact_frame.setOnClickListener { viewClicked(!contact_checkbox.isChecked) }
|
||||
contact_frame.setOnClickListener {
|
||||
if (itemClick != null) {
|
||||
itemClick.invoke(contact)
|
||||
} else {
|
||||
viewClicked(!contact_checkbox.isChecked)
|
||||
}
|
||||
}
|
||||
|
||||
if (contact.photoUri.isNotEmpty()) {
|
||||
val options = RequestOptions()
|
||||
|
|
|
@ -33,7 +33,7 @@ class AddFavoritesDialog(val activity: SimpleActivity, val callback: () -> Unit)
|
|||
|
||||
activity.runOnUiThread {
|
||||
view.apply {
|
||||
select_contact_list.adapter = SelectContactsAdapter(activity, allContacts, config.favorites)
|
||||
select_contact_list.adapter = SelectContactsAdapter(activity, allContacts, config.favorites, true)
|
||||
select_contact_fastscroller.allowBubbleDisplay = activity.baseConfig.showInfoBubble
|
||||
select_contact_fastscroller.setViews(select_contact_list) {
|
||||
select_contact_fastscroller.updateBubbleText(allContacts[it].getBubbleText())
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/confirm"
|
||||
android:icon="@drawable/ic_check"
|
||||
android:title="@string/confirm_selection"
|
||||
app:showAsAction="ifRoom"/>
|
||||
</menu>
|
Loading…
Reference in New Issue