updating the way permissions are handled
This commit is contained in:
parent
e2807bf85b
commit
56646660c9
|
@ -45,7 +45,7 @@ ext {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.simplemobiletools:commons:4.5.18'
|
implementation 'com.simplemobiletools:commons:4.5.19'
|
||||||
implementation 'joda-time:joda-time:2.9.9'
|
implementation 'joda-time:joda-time:2.9.9'
|
||||||
implementation 'com.facebook.stetho:stetho:1.5.0'
|
implementation 'com.facebook.stetho:stetho:1.5.0'
|
||||||
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
|
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.simplemobiletools.contacts.activities
|
package com.simplemobiletools.contacts.activities
|
||||||
|
|
||||||
import android.Manifest
|
|
||||||
import android.app.SearchManager
|
import android.app.SearchManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
@ -8,7 +7,6 @@ import android.graphics.drawable.ColorDrawable
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.support.v4.app.ActivityCompat
|
|
||||||
import android.support.v4.view.MenuItemCompat
|
import android.support.v4.view.MenuItemCompat
|
||||||
import android.support.v4.view.ViewPager
|
import android.support.v4.view.ViewPager
|
||||||
import android.support.v7.widget.SearchView
|
import android.support.v7.widget.SearchView
|
||||||
|
@ -41,10 +39,6 @@ import kotlinx.android.synthetic.main.fragment_recents.*
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
|
|
||||||
class MainActivity : SimpleActivity(), RefreshContactsListener {
|
class MainActivity : SimpleActivity(), RefreshContactsListener {
|
||||||
// just some random constants
|
|
||||||
private val GET_ACCOUNTS_PERMISSION = 34
|
|
||||||
private val WRITE_CALL_LOG_PERMISSION = 35
|
|
||||||
|
|
||||||
private var isSearchOpen = false
|
private var isSearchOpen = false
|
||||||
private var searchMenuItem: MenuItem? = null
|
private var searchMenuItem: MenuItem? = null
|
||||||
private var werePermissionsHandled = false
|
private var werePermissionsHandled = false
|
||||||
|
@ -70,29 +64,36 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
||||||
// just get a reference to the database to make sure it is created properly
|
// just get a reference to the database to make sure it is created properly
|
||||||
dbHelper
|
dbHelper
|
||||||
|
|
||||||
|
handlePermission(PERMISSION_READ_CALL_LOG) {
|
||||||
|
if (it) {
|
||||||
|
handlePermission(PERMISSION_WRITE_CALL_LOG) {
|
||||||
|
checkContactPermissions()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
checkContactPermissions()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
storeStateVariables()
|
||||||
|
checkWhatsNewDialog()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun checkContactPermissions() {
|
||||||
handlePermission(PERMISSION_READ_CONTACTS) {
|
handlePermission(PERMISSION_READ_CONTACTS) {
|
||||||
werePermissionsHandled = true
|
werePermissionsHandled = true
|
||||||
if (it) {
|
if (it) {
|
||||||
handlePermission(PERMISSION_WRITE_CONTACTS) {
|
handlePermission(PERMISSION_WRITE_CONTACTS) {
|
||||||
// workaround for upgrading from version 3.x to 4.x as we added a new permission from an already granted permissions group
|
// workaround for upgrading from version 3.x to 4.x as we added a new permission from an already granted permissions group
|
||||||
if (!hasPermission(PERMISSION_GET_ACCOUNTS)) {
|
handlePermission(PERMISSION_GET_ACCOUNTS) {
|
||||||
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.GET_ACCOUNTS), GET_ACCOUNTS_PERMISSION)
|
storeLocalAccountData()
|
||||||
|
initFragments()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hasPermission(PERMISSION_WRITE_CALL_LOG)) {
|
|
||||||
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_CALL_LOG), WRITE_CALL_LOG_PERMISSION)
|
|
||||||
}
|
|
||||||
|
|
||||||
storeLocalAccountData()
|
|
||||||
initFragments()
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
storeLocalAccountData()
|
storeLocalAccountData()
|
||||||
initFragments()
|
initFragments()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
storeStateVariables()
|
|
||||||
checkWhatsNewDialog()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import android.util.AttributeSet
|
||||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||||
import com.simplemobiletools.commons.extensions.hasPermission
|
import com.simplemobiletools.commons.extensions.hasPermission
|
||||||
import com.simplemobiletools.commons.extensions.isActivityDestroyed
|
import com.simplemobiletools.commons.extensions.isActivityDestroyed
|
||||||
|
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CALL_LOG
|
||||||
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CALL_LOG
|
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CALL_LOG
|
||||||
import com.simplemobiletools.contacts.activities.EditContactActivity
|
import com.simplemobiletools.contacts.activities.EditContactActivity
|
||||||
import com.simplemobiletools.contacts.adapters.RecentCallsAdapter
|
import com.simplemobiletools.contacts.adapters.RecentCallsAdapter
|
||||||
|
@ -24,7 +25,9 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
|
||||||
override fun placeholderClicked() {
|
override fun placeholderClicked() {
|
||||||
activity!!.handlePermission(PERMISSION_WRITE_CALL_LOG) {
|
activity!!.handlePermission(PERMISSION_WRITE_CALL_LOG) {
|
||||||
if (it) {
|
if (it) {
|
||||||
activity?.refreshContacts(RECENTS_TAB_MASK)
|
activity!!.handlePermission(PERMISSION_READ_CALL_LOG) {
|
||||||
|
activity?.refreshContacts(RECENTS_TAB_MASK)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1318,7 +1318,7 @@ class ContactsHelper(val activity: Activity) {
|
||||||
fun getRecents(callback: (ArrayList<RecentCall>) -> Unit) {
|
fun getRecents(callback: (ArrayList<RecentCall>) -> Unit) {
|
||||||
Thread {
|
Thread {
|
||||||
val calls = ArrayList<RecentCall>()
|
val calls = ArrayList<RecentCall>()
|
||||||
if (!activity.hasPermission(PERMISSION_WRITE_CALL_LOG)) {
|
if (!activity.hasPermission(PERMISSION_WRITE_CALL_LOG) || !activity.hasPermission(PERMISSION_READ_CALL_LOG)) {
|
||||||
callback(calls)
|
callback(calls)
|
||||||
return@Thread
|
return@Thread
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue