From d1009e53218e90aac17639ff876b13467057ef4a Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 12 Nov 2020 15:27:45 +0100 Subject: [PATCH] better handle storage permission on import --- .../plugins/general/maintenance/ImportExportPrefs.kt | 4 +++- .../plugins/general/maintenance/MaintenanceFragment.kt | 10 ++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.kt index 5c5d9c843f..661dc3a2bb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.kt @@ -72,13 +72,15 @@ class ImportExportPrefs @Inject constructor( f.activity?.let { exportSharedPreferences(it) } } - fun verifyStoragePermissions(fragment: Fragment) { + fun verifyStoragePermissions(fragment: Fragment, onGranted: Runnable) { fragment.context?.let { val permission = ContextCompat.checkSelfPermission(it, Manifest.permission.WRITE_EXTERNAL_STORAGE) if (permission != PackageManager.PERMISSION_GRANTED) { // We don't have permission so prompt the user fragment.requestPermissions(PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE) + } else { + onGranted.run() } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenanceFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenanceFragment.kt index c233b6d721..a0ca451fee 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenanceFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenanceFragment.kt @@ -46,13 +46,15 @@ class MaintenanceFragment : DaggerFragment() { } nav_export.setOnClickListener { // start activity for checking permissions... - importExportPrefs.verifyStoragePermissions(this) - importExportPrefs.exportSharedPreferences(this) + importExportPrefs.verifyStoragePermissions(this) { + importExportPrefs.exportSharedPreferences(this) + } } nav_import.setOnClickListener { // start activity for checking permissions... - importExportPrefs.verifyStoragePermissions(this) - importExportPrefs.importSharedPreferences(this) + importExportPrefs.verifyStoragePermissions(this) { + importExportPrefs.importSharedPreferences(this) + } } nav_logsettings.setOnClickListener { startActivity(Intent(activity, LogSettingActivity::class.java)) } }