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.target.Target
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
import com.simplemobiletools.contacts.extensions.config
@ -35,6 +36,8 @@ class ContactActivity : SimpleActivity() {
setContentView(R.layout.activity_contact)
supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_cross)
handlePermission(PERMISSION_READ_CONTACTS) {
if (it) {
handlePermission(PERMISSION_WRITE_CONTACTS) {
if (it) {
initContact()
@ -43,6 +46,11 @@ class ContactActivity : SimpleActivity() {
finish()
}
}
} else {
toast(R.string.no_contacts_permission)
finish()
}
}
}
private fun initContact() {

View File

@ -10,6 +10,7 @@ import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.commons.helpers.LICENSE_KOTLIN
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.interfaces.RefreshRecyclerViewListener
import com.simplemobiletools.contacts.BuildConfig
@ -36,6 +37,8 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
appLaunched()
contacts_fab.setOnClickListener { addNewContact() }
handlePermission(PERMISSION_READ_CONTACTS) {
if (it) {
handlePermission(PERMISSION_WRITE_CONTACTS) {
if (it) {
initContacts()
@ -44,6 +47,11 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
finish()
}
}
} else {
toast(R.string.no_contacts_permission)
finish()
}
}
storeStateVariables()
}