handle both write and read contact permissions

This commit is contained in:
tibbi 2017-12-12 20:19:15 +01:00
parent efc70f1e18
commit 7b849cb090
2 changed files with 20 additions and 4 deletions

View File

@ -15,6 +15,7 @@ import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.request.target.Target import com.bumptech.glide.request.target.Target
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CONTACTS import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CONTACTS
import com.simplemobiletools.contacts.R import com.simplemobiletools.contacts.R
import com.simplemobiletools.contacts.extensions.config import com.simplemobiletools.contacts.extensions.config
@ -35,9 +36,16 @@ class ContactActivity : SimpleActivity() {
setContentView(R.layout.activity_contact) setContentView(R.layout.activity_contact)
supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_cross) supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_cross)
handlePermission(PERMISSION_WRITE_CONTACTS) { handlePermission(PERMISSION_READ_CONTACTS) {
if (it) { if (it) {
initContact() handlePermission(PERMISSION_WRITE_CONTACTS) {
if (it) {
initContact()
} else {
toast(R.string.no_contacts_permission)
finish()
}
}
} else { } else {
toast(R.string.no_contacts_permission) toast(R.string.no_contacts_permission)
finish() finish()

View File

@ -10,6 +10,7 @@ import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.extensions.updateTextColors import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.commons.helpers.LICENSE_KOTLIN import com.simplemobiletools.commons.helpers.LICENSE_KOTLIN
import com.simplemobiletools.commons.helpers.LICENSE_MULTISELECT import com.simplemobiletools.commons.helpers.LICENSE_MULTISELECT
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CONTACTS import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CONTACTS
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
import com.simplemobiletools.contacts.BuildConfig import com.simplemobiletools.contacts.BuildConfig
@ -36,9 +37,16 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
appLaunched() appLaunched()
contacts_fab.setOnClickListener { addNewContact() } contacts_fab.setOnClickListener { addNewContact() }
handlePermission(PERMISSION_WRITE_CONTACTS) { handlePermission(PERMISSION_READ_CONTACTS) {
if (it) { if (it) {
initContacts() handlePermission(PERMISSION_WRITE_CONTACTS) {
if (it) {
initContacts()
} else {
toast(R.string.no_contacts_permission)
finish()
}
}
} else { } else {
toast(R.string.no_contacts_permission) toast(R.string.no_contacts_permission)
finish() finish()