From d55bc9104aa75df587b29a3856e1e3bb2c320254 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 7 May 2020 23:14:15 +0200 Subject: [PATCH] adding some permission handling --- app/src/main/AndroidManifest.xml | 4 +-- .../dialer/activities/MainActivity.kt | 6 ++-- .../dialer/fragments/ContactsFragment.kt | 36 +++++++++++++++++-- .../dialer/fragments/RecentsFragment.kt | 19 ++++++++-- app/src/main/res/values/strings.xml | 3 ++ 5 files changed, 58 insertions(+), 10 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index baafac16..797cb4ed 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -4,8 +4,8 @@ package="com.simplemobiletools.dialer" android:installLocation="auto"> - - + + + activity?.runOnUiThread { + refreshContacts(contacts) + } + } + } + } + } } diff --git a/app/src/main/kotlin/com/simplemobiletools/dialer/fragments/RecentsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/dialer/fragments/RecentsFragment.kt index d51a49d0..0175c7be 100644 --- a/app/src/main/kotlin/com/simplemobiletools/dialer/fragments/RecentsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/dialer/fragments/RecentsFragment.kt @@ -6,6 +6,7 @@ import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.PERMISSION_READ_CALL_LOG import com.simplemobiletools.dialer.R import com.simplemobiletools.dialer.extensions.config +import com.simplemobiletools.dialer.helpers.RecentsHelper import com.simplemobiletools.dialer.models.RecentCall import kotlinx.android.synthetic.main.fragment_recents.view.* @@ -18,12 +19,11 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage } recents_placeholder.text = context.getString(placeholderResId) - recents_placeholder_2.apply { setTextColor(context.config.primaryColor) underlineText() setOnClickListener { - + requestCallLogPermission() } } } @@ -39,4 +39,19 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage recents_list.beVisible() } } + + private fun requestCallLogPermission() { + activity?.handlePermission(PERMISSION_READ_CALL_LOG) { + if (it) { + recents_placeholder.text = context.getString(R.string.no_previous_calls) + recents_placeholder_2.beGone() + + RecentsHelper(context).getRecentCalls { recents -> + activity?.runOnUiThread { + updateRecents(recents) + } + } + } + } + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fbf6f43e..074a3854 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2,6 +2,9 @@ Simple Dialer Dialer + + Could not access your contacts + No previous calls have been found Could not access the call history