better handle storage permission on import
This commit is contained in:
parent
d6bc1ab400
commit
d1009e5321
2 changed files with 9 additions and 5 deletions
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)) }
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue