fix #269, add placeholders at SelectContact activity
This commit is contained in:
parent
c8bf2a496e
commit
4f130fe402
6 changed files with 82 additions and 22 deletions
|
@ -6,8 +6,7 @@ import android.os.Bundle
|
|||
import android.provider.ContactsContract
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import com.simplemobiletools.commons.extensions.baseConfig
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
|
||||
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CONTACTS
|
||||
import com.simplemobiletools.contacts.R
|
||||
|
@ -28,6 +27,7 @@ class SelectContactActivity : SimpleActivity() {
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_select_contact)
|
||||
setupPlaceholders()
|
||||
|
||||
handlePermission(PERMISSION_READ_CONTACTS) {
|
||||
if (it) {
|
||||
|
@ -104,8 +104,11 @@ class SelectContactActivity : SimpleActivity() {
|
|||
contacts.sort()
|
||||
|
||||
runOnUiThread {
|
||||
select_contact_list.adapter = SelectContactsAdapter(this, contacts, ArrayList(), false) {
|
||||
updatePlaceholderVisibility(contacts)
|
||||
SelectContactsAdapter(this, contacts, ArrayList(), false, select_contact_list) {
|
||||
confirmSelection(it)
|
||||
}.apply {
|
||||
select_contact_list.adapter = this
|
||||
}
|
||||
|
||||
select_contact_fastscroller.allowBubbleDisplay = baseConfig.showInfoBubble
|
||||
|
@ -131,9 +134,29 @@ class SelectContactActivity : SimpleActivity() {
|
|||
val contactId = ContactsHelper(this).getContactMimeTypeId(contact.id.toString(), specialMimeType!!)
|
||||
Uri.withAppendedPath(ContactsContract.Data.CONTENT_URI, contactId)
|
||||
}
|
||||
else -> {
|
||||
getContactPublicUri(contact)
|
||||
else -> getContactPublicUri(contact)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupPlaceholders() {
|
||||
select_contact_placeholder.setTextColor(config.textColor)
|
||||
select_contact_placeholder_2.setTextColor(getAdjustedPrimaryColor())
|
||||
select_contact_placeholder_2.underlineText()
|
||||
select_contact_placeholder_2.setOnClickListener {
|
||||
FilterContactSourcesDialog(this) {
|
||||
initContacts()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updatePlaceholderVisibility(contacts: ArrayList<Contact>) {
|
||||
select_contact_list.beVisibleIf(contacts.isNotEmpty())
|
||||
select_contact_placeholder_2.beVisibleIf(contacts.isEmpty())
|
||||
select_contact_placeholder.beVisibleIf(contacts.isEmpty())
|
||||
select_contact_placeholder.setText(when (specialMimeType) {
|
||||
ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE -> R.string.no_contacts_with_emails
|
||||
ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE -> R.string.no_contacts_with_phone_numbers
|
||||
else -> R.string.no_contacts_found
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.graphics.drawable.Drawable
|
|||
import android.util.SparseArray
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.DividerItemDecoration
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
|
@ -13,6 +14,7 @@ import com.bumptech.glide.signature.ObjectKey
|
|||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
|
||||
import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
|
||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import com.simplemobiletools.contacts.R
|
||||
import com.simplemobiletools.contacts.activities.SimpleActivity
|
||||
import com.simplemobiletools.contacts.extensions.config
|
||||
|
@ -22,7 +24,7 @@ import kotlinx.android.synthetic.main.item_add_favorite_with_number.view.*
|
|||
import java.util.*
|
||||
|
||||
class SelectContactsAdapter(val activity: SimpleActivity, val contacts: List<Contact>, private val selectedContacts: ArrayList<Contact>, private val allowPickMultiple: Boolean,
|
||||
private val itemClick: ((Contact) -> Unit)? = null) : RecyclerView.Adapter<SelectContactsAdapter.ViewHolder>() {
|
||||
private val recyclerView: MyRecyclerView, private val itemClick: ((Contact) -> Unit)? = null) : RecyclerView.Adapter<SelectContactsAdapter.ViewHolder>() {
|
||||
private val itemViews = SparseArray<View>()
|
||||
private val selectedPositions = HashSet<Int>()
|
||||
private val config = activity.config
|
||||
|
@ -36,10 +38,19 @@ class SelectContactsAdapter(val activity: SimpleActivity, val contacts: List<Con
|
|||
|
||||
init {
|
||||
contacts.forEachIndexed { index, contact ->
|
||||
if (selectedContacts.map { it.id }.contains(contact.id)) {
|
||||
if (selectedContacts.asSequence().map { it.id }.contains(contact.id)) {
|
||||
selectedPositions.add(index)
|
||||
}
|
||||
}
|
||||
|
||||
if (recyclerView.itemDecorationCount > 0) {
|
||||
recyclerView.removeItemDecorationAt(0)
|
||||
}
|
||||
|
||||
DividerItemDecoration(activity, DividerItemDecoration.VERTICAL).apply {
|
||||
setDrawable(activity.resources.getDrawable(R.drawable.divider))
|
||||
recyclerView.addItemDecoration(this)
|
||||
}
|
||||
}
|
||||
|
||||
private fun toggleItemSelection(select: Boolean, pos: Int) {
|
||||
|
|
|
@ -33,7 +33,7 @@ class SelectContactsDialog(val activity: SimpleActivity, initialContacts: ArrayL
|
|||
|
||||
activity.runOnUiThread {
|
||||
view.apply {
|
||||
select_contact_list.adapter = SelectContactsAdapter(activity, allContacts, initiallySelectedContacts, true)
|
||||
select_contact_list.adapter = SelectContactsAdapter(activity, allContacts, initiallySelectedContacts, true, select_contact_list)
|
||||
select_contact_fastscroller.allowBubbleDisplay = activity.baseConfig.showInfoBubble
|
||||
select_contact_fastscroller.setViews(select_contact_list) {
|
||||
select_contact_fastscroller.updateBubbleText(allContacts[it].getBubbleText())
|
||||
|
|
|
@ -26,13 +26,13 @@
|
|||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/group_contacts_placeholder_2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/group_contacts_placeholder"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:paddingBottom="@dimen/medium_margin"
|
||||
android:paddingTop="@dimen/medium_margin"
|
||||
android:padding="@dimen/activity_margin"
|
||||
android:text="@string/add_contacts"
|
||||
android:textSize="@dimen/bigger_text_size"
|
||||
android:visibility="gone"/>
|
||||
|
@ -51,8 +51,8 @@
|
|||
android:layout_height="match_parent"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:paddingLeft="@dimen/normal_margin"
|
||||
android:paddingStart="@dimen/normal_margin">
|
||||
android:paddingStart="@dimen/normal_margin"
|
||||
android:paddingLeft="@dimen/normal_margin">
|
||||
|
||||
<include layout="@layout/fastscroller_handle_vertical"/>
|
||||
|
||||
|
|
|
@ -6,6 +6,32 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/select_contact_placeholder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="@dimen/activity_margin"
|
||||
android:gravity="center"
|
||||
android:paddingLeft="@dimen/activity_margin"
|
||||
android:paddingRight="@dimen/activity_margin"
|
||||
android:text="@string/no_contacts_found"
|
||||
android:textSize="@dimen/bigger_text_size"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/select_contact_placeholder_2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/select_contact_placeholder"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:padding="@dimen/activity_margin"
|
||||
android:text="@string/change_filter"
|
||||
android:textSize="@dimen/bigger_text_size"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyRecyclerView
|
||||
android:id="@+id/select_contact_list"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -18,12 +44,12 @@
|
|||
android:id="@+id/select_contact_fastscroller"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignTop="@+id/select_contact_list"
|
||||
android:layout_alignBottom="@+id/select_contact_list"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignTop="@+id/select_contact_list"
|
||||
android:paddingLeft="@dimen/normal_margin"
|
||||
android:paddingStart="@dimen/normal_margin">
|
||||
android:paddingStart="@dimen/normal_margin"
|
||||
android:paddingLeft="@dimen/normal_margin">
|
||||
|
||||
<include layout="@layout/fastscroller_handle_vertical"/>
|
||||
|
||||
|
|
|
@ -17,19 +17,19 @@
|
|||
android:gravity="center"
|
||||
android:paddingLeft="@dimen/activity_margin"
|
||||
android:paddingRight="@dimen/activity_margin"
|
||||
android:text="@string/no_items_found"
|
||||
android:text="@string/no_contacts_found"
|
||||
android:textSize="@dimen/bigger_text_size"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/fragment_placeholder_2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/fragment_placeholder"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:paddingBottom="@dimen/medium_margin"
|
||||
android:paddingTop="@dimen/medium_margin"
|
||||
android:padding="@dimen/activity_margin"
|
||||
android:text="@string/change_filter"
|
||||
android:textSize="@dimen/bigger_text_size"
|
||||
android:visibility="gone"/>
|
||||
|
@ -48,8 +48,8 @@
|
|||
android:layout_height="match_parent"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:paddingLeft="@dimen/normal_margin"
|
||||
android:paddingStart="@dimen/normal_margin">
|
||||
android:paddingStart="@dimen/normal_margin"
|
||||
android:paddingLeft="@dimen/normal_margin">
|
||||
|
||||
<include layout="@layout/fastscroller_handle_vertical"/>
|
||||
|
||||
|
|
Loading…
Reference in a new issue