use new permission system and fix a few compiler warnings

This commit is contained in:
AdrianLxM 2020-11-29 20:44:57 +01:00
parent 5c9a8d2f60
commit ea57e9b6cb
4 changed files with 12 additions and 13 deletions

View file

@ -151,7 +151,7 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
(savedInstanceState ?: arguments)?.let { bundle ->
if (bundle.containsKey("id")) {
pluginId = bundle.getInt("id") ?: -1
pluginId = bundle.getInt("id")
}
if (bundle.containsKey("filter")) {
filter = bundle.getString("filter") ?: ""

View file

@ -1,13 +1,13 @@
package info.nightscout.androidaps.plugins.general.maintenance
import android.Manifest
import androidx.appcompat.app.AppCompatActivity
import android.bluetooth.BluetoothAdapter
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.provider.Settings
import androidx.annotation.StringRes
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
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.plugins.bus.RxBusWrapper
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.ToastUtils
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
@ -43,12 +44,6 @@ import javax.inject.Singleton
* 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
class ImportExportPrefs @Inject constructor(
private var log: AAPSLogger,
@ -57,6 +52,7 @@ class ImportExportPrefs @Inject constructor(
private val buildHelper: BuildHelper,
private val rxBus: RxBusWrapper,
private val passwordCheck: PasswordCheck,
private val androidPermission: AndroidPermission,
private val classicPrefsFormat: ClassicPrefsFormat,
private val encryptedPrefsFormat: EncryptedPrefsFormat,
private val prefFileList: PrefFileListProvider
@ -73,12 +69,15 @@ class ImportExportPrefs @Inject constructor(
}
fun verifyStoragePermissions(fragment: Fragment, onGranted: Runnable) {
fragment.context?.let {
val permission = ContextCompat.checkSelfPermission(it,
fragment.context?.let { ctx ->
val permission = ContextCompat.checkSelfPermission(ctx,
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)
fragment.activity?.let {
androidPermission.askForPermission(it, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE), AndroidPermission.CASE_STORAGE)
}
} else {
onGranted.run()
}

View file

@ -46,7 +46,7 @@ class AndroidPermission @Inject constructor(
private var permission_battery_optimization_failed = false
@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 testBattery = false
for (s in permission) {

View file

@ -209,7 +209,7 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
}
private fun displayNotConfiguredDialog() {
context?.let {
context.let {
UIRunnable(Runnable {
OKDialog.show(it, resourceHelper.gs(R.string.omnipod_warning),
resourceHelper.gs(R.string.omnipod_error_operation_not_possible_no_configuration), null)