use new permission system and fix a few compiler warnings
This commit is contained in:
parent
5c9a8d2f60
commit
ea57e9b6cb
4 changed files with 12 additions and 13 deletions
|
@ -151,7 +151,7 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang
|
||||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||||
(savedInstanceState ?: arguments)?.let { bundle ->
|
(savedInstanceState ?: arguments)?.let { bundle ->
|
||||||
if (bundle.containsKey("id")) {
|
if (bundle.containsKey("id")) {
|
||||||
pluginId = bundle.getInt("id") ?: -1
|
pluginId = bundle.getInt("id")
|
||||||
}
|
}
|
||||||
if (bundle.containsKey("filter")) {
|
if (bundle.containsKey("filter")) {
|
||||||
filter = bundle.getString("filter") ?: ""
|
filter = bundle.getString("filter") ?: ""
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package info.nightscout.androidaps.plugins.general.maintenance
|
package info.nightscout.androidaps.plugins.general.maintenance
|
||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
|
||||||
import android.bluetooth.BluetoothAdapter
|
import android.bluetooth.BluetoothAdapter
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
|
@ -21,6 +21,7 @@ import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.LTag
|
import info.nightscout.androidaps.logging.LTag
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
import info.nightscout.androidaps.plugins.general.maintenance.formats.*
|
import info.nightscout.androidaps.plugins.general.maintenance.formats.*
|
||||||
|
import info.nightscout.androidaps.utils.AndroidPermission
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.utils.ToastUtils
|
import info.nightscout.androidaps.utils.ToastUtils
|
||||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||||
|
@ -43,12 +44,6 @@ import javax.inject.Singleton
|
||||||
* Created by mike on 03.07.2016.
|
* Created by mike on 03.07.2016.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private const val REQUEST_EXTERNAL_STORAGE = 1
|
|
||||||
private val PERMISSIONS_STORAGE = arrayOf(
|
|
||||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
|
||||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
|
||||||
)
|
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class ImportExportPrefs @Inject constructor(
|
class ImportExportPrefs @Inject constructor(
|
||||||
private var log: AAPSLogger,
|
private var log: AAPSLogger,
|
||||||
|
@ -57,6 +52,7 @@ class ImportExportPrefs @Inject constructor(
|
||||||
private val buildHelper: BuildHelper,
|
private val buildHelper: BuildHelper,
|
||||||
private val rxBus: RxBusWrapper,
|
private val rxBus: RxBusWrapper,
|
||||||
private val passwordCheck: PasswordCheck,
|
private val passwordCheck: PasswordCheck,
|
||||||
|
private val androidPermission: AndroidPermission,
|
||||||
private val classicPrefsFormat: ClassicPrefsFormat,
|
private val classicPrefsFormat: ClassicPrefsFormat,
|
||||||
private val encryptedPrefsFormat: EncryptedPrefsFormat,
|
private val encryptedPrefsFormat: EncryptedPrefsFormat,
|
||||||
private val prefFileList: PrefFileListProvider
|
private val prefFileList: PrefFileListProvider
|
||||||
|
@ -73,12 +69,15 @@ class ImportExportPrefs @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun verifyStoragePermissions(fragment: Fragment, onGranted: Runnable) {
|
fun verifyStoragePermissions(fragment: Fragment, onGranted: Runnable) {
|
||||||
fragment.context?.let {
|
fragment.context?.let { ctx ->
|
||||||
val permission = ContextCompat.checkSelfPermission(it,
|
val permission = ContextCompat.checkSelfPermission(ctx,
|
||||||
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.activity?.let {
|
||||||
|
androidPermission.askForPermission(it, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||||
|
Manifest.permission.WRITE_EXTERNAL_STORAGE), AndroidPermission.CASE_STORAGE)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
onGranted.run()
|
onGranted.run()
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ class AndroidPermission @Inject constructor(
|
||||||
private var permission_battery_optimization_failed = false
|
private var permission_battery_optimization_failed = false
|
||||||
|
|
||||||
@SuppressLint("BatteryLife")
|
@SuppressLint("BatteryLife")
|
||||||
private fun askForPermission(activity: FragmentActivity, permission: Array<String>, requestCode: Int) {
|
fun askForPermission(activity: FragmentActivity, permission: Array<String>, requestCode: Int) {
|
||||||
var test = false
|
var test = false
|
||||||
var testBattery = false
|
var testBattery = false
|
||||||
for (s in permission) {
|
for (s in permission) {
|
||||||
|
|
|
@ -209,7 +209,7 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun displayNotConfiguredDialog() {
|
private fun displayNotConfiguredDialog() {
|
||||||
context?.let {
|
context.let {
|
||||||
UIRunnable(Runnable {
|
UIRunnable(Runnable {
|
||||||
OKDialog.show(it, resourceHelper.gs(R.string.omnipod_warning),
|
OKDialog.show(it, resourceHelper.gs(R.string.omnipod_warning),
|
||||||
resourceHelper.gs(R.string.omnipod_error_operation_not_possible_no_configuration), null)
|
resourceHelper.gs(R.string.omnipod_error_operation_not_possible_no_configuration), null)
|
||||||
|
|
Loading…
Reference in a new issue