From acc69d4dcb1624f50db4dee155f5cb7afa22e826 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 4 Aug 2018 23:03:34 +0200 Subject: [PATCH] use helper functions for checking some permissions --- app/build.gradle | 2 +- .../simplemobiletools/contacts/activities/MainActivity.kt | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 51461aae..6d73b7b0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -45,7 +45,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:4.5.17' + implementation 'com.simplemobiletools:commons:4.5.18' implementation 'joda-time:joda-time:2.9.9' implementation 'com.facebook.stetho:stetho:1.5.0' implementation 'com.android.support.constraint:constraint-layout:1.1.2' diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/MainActivity.kt index f41aed05..68991246 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/MainActivity.kt @@ -4,13 +4,11 @@ import android.Manifest import android.app.SearchManager import android.content.Context import android.content.Intent -import android.content.pm.PackageManager import android.graphics.drawable.ColorDrawable import android.net.Uri import android.os.Bundle import android.os.Handler import android.support.v4.app.ActivityCompat -import android.support.v4.content.ContextCompat import android.support.v4.view.MenuItemCompat import android.support.v4.view.ViewPager import android.support.v7.widget.SearchView @@ -73,13 +71,11 @@ class MainActivity : SimpleActivity(), RefreshContactsListener { if (it) { 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 - val hasGetAccountsPermission = ContextCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS) == PackageManager.PERMISSION_GRANTED - if (!hasGetAccountsPermission) { + if (!hasPermission(PERMISSION_GET_ACCOUNTS)) { ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.GET_ACCOUNTS), 34) } - val hasWriteCallLogPermission = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_CALL_LOG) == PackageManager.PERMISSION_GRANTED - if (!hasWriteCallLogPermission) { + if (!hasPermission(PERMISSION_WRITE_CALL_LOG)) { ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_CALL_LOG), 35) }