better handle storage permission on import

This commit is contained in:
Milos Kozak 2020-11-12 15:27:45 +01:00
parent d6bc1ab400
commit d1009e5321
2 changed files with 9 additions and 5 deletions

View file

@ -72,13 +72,15 @@ class ImportExportPrefs @Inject constructor(
f.activity?.let { exportSharedPreferences(it) } f.activity?.let { exportSharedPreferences(it) }
} }
fun verifyStoragePermissions(fragment: Fragment) { fun verifyStoragePermissions(fragment: Fragment, onGranted: Runnable) {
fragment.context?.let { fragment.context?.let {
val permission = ContextCompat.checkSelfPermission(it, val permission = ContextCompat.checkSelfPermission(it,
Manifest.permission.WRITE_EXTERNAL_STORAGE) Manifest.permission.WRITE_EXTERNAL_STORAGE)
if (permission != PackageManager.PERMISSION_GRANTED) { if (permission != PackageManager.PERMISSION_GRANTED) {
// We don't have permission so prompt the user // We don't have permission so prompt the user
fragment.requestPermissions(PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE) fragment.requestPermissions(PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE)
} else {
onGranted.run()
} }
} }
} }

View file

@ -46,14 +46,16 @@ class MaintenanceFragment : DaggerFragment() {
} }
nav_export.setOnClickListener { nav_export.setOnClickListener {
// start activity for checking permissions... // start activity for checking permissions...
importExportPrefs.verifyStoragePermissions(this) importExportPrefs.verifyStoragePermissions(this) {
importExportPrefs.exportSharedPreferences(this) importExportPrefs.exportSharedPreferences(this)
} }
}
nav_import.setOnClickListener { nav_import.setOnClickListener {
// start activity for checking permissions... // start activity for checking permissions...
importExportPrefs.verifyStoragePermissions(this) importExportPrefs.verifyStoragePermissions(this) {
importExportPrefs.importSharedPreferences(this) importExportPrefs.importSharedPreferences(this)
} }
}
nav_logsettings.setOnClickListener { startActivity(Intent(activity, LogSettingActivity::class.java)) } nav_logsettings.setOnClickListener { startActivity(Intent(activity, LogSettingActivity::class.java)) }
} }
} }