add Filter and Sort menu items to the Select contact screen
This commit is contained in:
parent
2c31cf5bc9
commit
2011464acf
|
@ -4,6 +4,8 @@ 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
|
||||
|
@ -12,6 +14,8 @@ import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
|
|||
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CONTACTS
|
||||
import com.simplemobiletools.contacts.R
|
||||
import com.simplemobiletools.contacts.adapters.SelectContactsAdapter
|
||||
import com.simplemobiletools.contacts.dialogs.ChangeSortingDialog
|
||||
import com.simplemobiletools.contacts.dialogs.FilterContactSourcesDialog
|
||||
import com.simplemobiletools.contacts.extensions.config
|
||||
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
||||
import com.simplemobiletools.contacts.helpers.SMT_PRIVATE
|
||||
|
@ -30,6 +34,7 @@ class SelectContactActivity : SimpleActivity() {
|
|||
if (it) {
|
||||
handlePermission(PERMISSION_WRITE_CONTACTS) {
|
||||
if (it) {
|
||||
isGetEmailIntent = intent.data == ContactsContract.CommonDataKinds.Email.CONTENT_URI
|
||||
initContacts()
|
||||
} else {
|
||||
toast(R.string.no_contacts_permission)
|
||||
|
@ -43,8 +48,33 @@ class SelectContactActivity : SimpleActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_select_activity, menu)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.sort -> showSortingDialog()
|
||||
R.id.filter -> showFilterDialog()
|
||||
else -> return super.onOptionsItemSelected(item)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun showSortingDialog() {
|
||||
ChangeSortingDialog(this) {
|
||||
initContacts()
|
||||
}
|
||||
}
|
||||
|
||||
private fun showFilterDialog() {
|
||||
FilterContactSourcesDialog(this) {
|
||||
initContacts()
|
||||
}
|
||||
}
|
||||
|
||||
private fun initContacts() {
|
||||
isGetEmailIntent = intent.data == ContactsContract.CommonDataKinds.Email.CONTENT_URI
|
||||
ContactsHelper(this).getContacts(true) {
|
||||
if (isActivityDestroyed()) {
|
||||
return@getContacts
|
||||
|
@ -70,6 +100,7 @@ class SelectContactActivity : SimpleActivity() {
|
|||
select_contact_list.adapter = SelectContactsAdapter(this, contacts, ArrayList(), false) {
|
||||
confirmSelection(it)
|
||||
}
|
||||
|
||||
select_contact_fastscroller.allowBubbleDisplay = baseConfig.showInfoBubble
|
||||
select_contact_fastscroller.setViews(select_contact_list) {
|
||||
select_contact_fastscroller.updateBubbleText(contacts[it].getBubbleText())
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
<?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/sort"
|
||||
android:icon="@drawable/ic_sort"
|
||||
android:title="@string/sort_by"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/filter"
|
||||
android:icon="@drawable/ic_filter"
|
||||
android:title="@string/filter"
|
||||
app:showAsAction="ifRoom"/>
|
||||
</menu>
|
Loading…
Reference in New Issue