fill the list of contacts at insert_or_edit
This commit is contained in:
parent
a7b79f89ed
commit
78240eeb2b
4 changed files with 53 additions and 1 deletions
|
@ -9,8 +9,12 @@ import com.simplemobiletools.commons.extensions.toast
|
||||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||||
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
|
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
|
||||||
import com.simplemobiletools.contacts.R
|
import com.simplemobiletools.contacts.R
|
||||||
|
import com.simplemobiletools.contacts.adapters.ContactsAdapter
|
||||||
import com.simplemobiletools.contacts.extensions.config
|
import com.simplemobiletools.contacts.extensions.config
|
||||||
|
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
||||||
import com.simplemobiletools.contacts.helpers.KEY_PHONE
|
import com.simplemobiletools.contacts.helpers.KEY_PHONE
|
||||||
|
import com.simplemobiletools.contacts.helpers.LOCATION_INSERT_OR_EDIT
|
||||||
|
import com.simplemobiletools.contacts.models.Contact
|
||||||
import kotlinx.android.synthetic.main.activity_insert_edit_contact.*
|
import kotlinx.android.synthetic.main.activity_insert_edit_contact.*
|
||||||
|
|
||||||
class InsertOrEditContactActivity : SimpleActivity() {
|
class InsertOrEditContactActivity : SimpleActivity() {
|
||||||
|
@ -22,6 +26,9 @@ class InsertOrEditContactActivity : SimpleActivity() {
|
||||||
|
|
||||||
handlePermission(PERMISSION_READ_CONTACTS) {
|
handlePermission(PERMISSION_READ_CONTACTS) {
|
||||||
// we do not really care about the permission request result. Even if it was denied, load private contacts
|
// we do not really care about the permission request result. Even if it was denied, load private contacts
|
||||||
|
ContactsHelper(this).getContacts {
|
||||||
|
gotContacts(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,4 +50,23 @@ class InsertOrEditContactActivity : SimpleActivity() {
|
||||||
|
|
||||||
existing_contact_label.setTextColor(getAdjustedPrimaryColor())
|
existing_contact_label.setTextColor(getAdjustedPrimaryColor())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun gotContacts(contacts: ArrayList<Contact>) {
|
||||||
|
Contact.sorting = config.sorting
|
||||||
|
Contact.startWithSurname = config.startNameWithSurname
|
||||||
|
contacts.sort()
|
||||||
|
|
||||||
|
ContactsAdapter(this, contacts, null, LOCATION_INSERT_OR_EDIT, null, existing_contact_list, existing_contact_fastscroller) {
|
||||||
|
|
||||||
|
}.apply {
|
||||||
|
addVerticalDividers(true)
|
||||||
|
existing_contact_list.adapter = this
|
||||||
|
}
|
||||||
|
|
||||||
|
existing_contact_fastscroller.setScrollToY(0)
|
||||||
|
existing_contact_fastscroller.setViews(existing_contact_list) {
|
||||||
|
val item = (existing_contact_list.adapter as ContactsAdapter).contactItems.getOrNull(it)
|
||||||
|
existing_contact_fastscroller.updateBubbleText(item?.getBubbleText() ?: "")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,8 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) {
|
||||||
val contact = contactItems[position]
|
val contact = contactItems[position]
|
||||||
val view = holder.bindView(contact, true, true) { itemView, layoutPosition ->
|
val allowLongClick = location != LOCATION_INSERT_OR_EDIT
|
||||||
|
val view = holder.bindView(contact, true, allowLongClick) { itemView, layoutPosition ->
|
||||||
setupView(itemView, contact)
|
setupView(itemView, contact)
|
||||||
}
|
}
|
||||||
bindViewHolder(holder, position, view)
|
bindViewHolder(holder, position, view)
|
||||||
|
|
|
@ -34,6 +34,7 @@ const val LOCATION_RECENTS_TAB = 2
|
||||||
const val LOCATION_GROUPS_TAB = 3
|
const val LOCATION_GROUPS_TAB = 3
|
||||||
const val LOCATION_GROUP_CONTACTS = 4
|
const val LOCATION_GROUP_CONTACTS = 4
|
||||||
const val LOCATION_DIALPAD = 5
|
const val LOCATION_DIALPAD = 5
|
||||||
|
const val LOCATION_INSERT_OR_EDIT = 6
|
||||||
|
|
||||||
const val CONTACTS_TAB_MASK = 1
|
const val CONTACTS_TAB_MASK = 1
|
||||||
const val FAVORITES_TAB_MASK = 2
|
const val FAVORITES_TAB_MASK = 2
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:id="@+id/insert_edit_contact_holder"
|
android:id="@+id/insert_edit_contact_holder"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
@ -41,8 +42,31 @@
|
||||||
android:layout_below="@+id/new_contact_holder"
|
android:layout_below="@+id/new_contact_holder"
|
||||||
android:layout_marginStart="@dimen/bigger_margin"
|
android:layout_marginStart="@dimen/bigger_margin"
|
||||||
android:layout_marginLeft="@dimen/bigger_margin"
|
android:layout_marginLeft="@dimen/bigger_margin"
|
||||||
|
android:layout_marginBottom="@dimen/activity_margin"
|
||||||
android:text="@string/add_to_existing_contact"
|
android:text="@string/add_to_existing_contact"
|
||||||
android:textAllCaps="true"
|
android:textAllCaps="true"
|
||||||
android:textSize="@dimen/smaller_text_size"/>
|
android:textSize="@dimen/smaller_text_size"/>
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyRecyclerView
|
||||||
|
android:id="@+id/existing_contact_list"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_below="@+id/existing_contact_label"
|
||||||
|
android:clipToPadding="false"
|
||||||
|
android:scrollbars="none"
|
||||||
|
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager"/>
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.FastScroller
|
||||||
|
android:id="@+id/existing_contact_fastscroller"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_below="@+id/existing_contact_label"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:paddingStart="@dimen/normal_margin"
|
||||||
|
android:paddingLeft="@dimen/normal_margin">
|
||||||
|
|
||||||
|
<include layout="@layout/fastscroller_handle_vertical"/>
|
||||||
|
|
||||||
|
</com.simplemobiletools.commons.views.FastScroller>
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
Loading…
Reference in a new issue