From 246186f03f8460b1c58866d654d0dca35962c546 Mon Sep 17 00:00:00 2001 From: Brian Quinion Date: Fri, 2 Aug 2019 14:13:57 +0100 Subject: [PATCH 1/8] Check we have battery optimisation with PowerManager (required in addition to REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission) --- .../androidaps/utils/AndroidPermission.java | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java b/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java index 527a98dda2..2cc3662136 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java @@ -3,8 +3,13 @@ package info.nightscout.androidaps.utils; import android.Manifest; import android.app.Activity; import android.content.Context; +import android.content.Intent; import android.content.pm.PackageManager; +import android.net.Uri; import android.os.Build; +import android.os.PowerManager; +import android.provider.Settings; + import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; @@ -25,22 +30,38 @@ public class AndroidPermission { public static void askForPermission(Activity activity, String[] permission, Integer requestCode) { boolean test = false; + boolean testBattery = false; for (int i = 0; i < permission.length; i++) { test = test || (ContextCompat.checkSelfPermission(activity, permission[i]) != PackageManager.PERMISSION_GRANTED); + if (permission[i] == Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) { + PowerManager powerManager = (PowerManager) activity.getSystemService(activity.POWER_SERVICE); + String packageName = activity.getPackageName(); + testBattery = testBattery || !powerManager.isIgnoringBatteryOptimizations(packageName); + } } if (test) { ActivityCompat.requestPermissions(activity, permission, requestCode); } + if (testBattery) { + Intent i = new Intent(); + i.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); + i.setData(Uri.parse("package:" + activity.getPackageName())); + activity.startActivity(i); + } } public static void askForPermission(Activity activity, String permission, Integer requestCode) { String[] permissions = {permission}; - - if (ContextCompat.checkSelfPermission(activity, permission) != PackageManager.PERMISSION_GRANTED) - ActivityCompat.requestPermissions(activity, permissions, requestCode); + askForPermission(activity, permissions, requestCode); } public static boolean checkForPermission(Context context, String permission) { + if (permission == Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) { + PowerManager powerManager = (PowerManager) context.getSystemService(context.POWER_SERVICE); + String packageName = context.getPackageName(); + return ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED + && powerManager.isIgnoringBatteryOptimizations(packageName); + } return ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED; } From 0c3d3f0dd87925bc1967551d05d33fb89e25dcbe Mon Sep 17 00:00:00 2001 From: Brian Quinion Date: Fri, 2 Aug 2019 14:44:39 +0100 Subject: [PATCH 2/8] Make needwhitelisting skippable to avoid issues with not being able to detect step being completed --- .../info/nightscout/androidaps/setupwizard/SWDefinition.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java index 3be94c494e..671ce8488a 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java @@ -119,7 +119,7 @@ public class SWDefinition { .validator(() -> SP.getBoolean(R.string.key_i_understand, false)) ) .add(new SWScreen(R.string.permission) - .skippable(false) + .skippable(true) .add(new SWInfotext() .label(String.format(MainApp.gs(R.string.needwhitelisting), MainApp.gs(R.string.app_name)))) .add(new SWBreak()) From f439f1c6dd9705fa3dfcf0e9b1c0db4f39159ad7 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 3 Aug 2019 18:54:53 +0200 Subject: [PATCH 3/8] revert skippable in wizard --- .../info/nightscout/androidaps/setupwizard/SWDefinition.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java index 671ce8488a..3be94c494e 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java @@ -119,7 +119,7 @@ public class SWDefinition { .validator(() -> SP.getBoolean(R.string.key_i_understand, false)) ) .add(new SWScreen(R.string.permission) - .skippable(true) + .skippable(false) .add(new SWInfotext() .label(String.format(MainApp.gs(R.string.needwhitelisting), MainApp.gs(R.string.app_name)))) .add(new SWBreak()) From c9d1cc6a246d5f014752cdf96c8d9bace6e0ec37 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 3 Aug 2019 19:11:16 +0200 Subject: [PATCH 4/8] SDK checking cleanup --- .../androidaps/setupwizard/SWDefinition.java | 34 +++++++++--------- .../androidaps/utils/AndroidPermission.java | 36 +++++++++---------- 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java index 3be94c494e..d18307f0b8 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java @@ -125,10 +125,10 @@ public class SWDefinition { .add(new SWBreak()) .add(new SWButton() .text(R.string.askforpermission) - .visibility(() -> Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !AndroidPermission.checkForPermission(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) + .visibility(() -> AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) .action(() -> AndroidPermission.askForPermission(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, AndroidPermission.CASE_BATTERY))) - .visibility(() -> Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !AndroidPermission.checkForPermission(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) - .validator(() -> !(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !AndroidPermission.checkForPermission(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS))) + .visibility(() -> AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) + .validator(() -> !(AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS))) ) .add(new SWScreen(R.string.permission) .skippable(false) @@ -137,10 +137,10 @@ public class SWDefinition { .add(new SWBreak()) .add(new SWButton() .text(R.string.askforpermission) - .visibility(() -> Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !AndroidPermission.checkForPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION)) + .visibility(() -> AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION)) .action(() -> AndroidPermission.askForPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION, AndroidPermission.CASE_LOCATION))) - .visibility(() -> Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !AndroidPermission.checkForPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION)) - .validator(() -> !(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !AndroidPermission.checkForPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION))) + .visibility(() -> AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION)) + .validator(() -> !(AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION))) ) .add(new SWScreen(R.string.permission) .skippable(false) @@ -149,10 +149,10 @@ public class SWDefinition { .add(new SWBreak()) .add(new SWButton() .text(R.string.askforpermission) - .visibility(() -> Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !AndroidPermission.checkForPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) + .visibility(() -> AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) .action(() -> AndroidPermission.askForPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE, AndroidPermission.CASE_STORAGE))) - .visibility(() -> Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !AndroidPermission.checkForPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) - .validator(() -> !(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !AndroidPermission.checkForPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE))) + .visibility(() -> AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) + .validator(() -> !(AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE))) ) .add(new SWScreen(R.string.nav_import) .add(new SWInfotext() @@ -161,7 +161,7 @@ public class SWDefinition { .add(new SWButton() .text(R.string.nav_import) .action(() -> ImportExportPrefs.importSharedPreferences(getActivity()))) - .visibility(() -> ImportExportPrefs.file.exists() && !(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !AndroidPermission.checkForPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE))) + .visibility(() -> ImportExportPrefs.file.exists() && !(AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE))) ) .add(new SWScreen(R.string.nsclientinternal_title) .skippable(true) @@ -486,10 +486,10 @@ public class SWDefinition { .add(new SWBreak()) .add(new SWButton() .text(R.string.askforpermission) - .visibility(() -> Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !AndroidPermission.checkForPermission(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) + .visibility(() -> AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) .action(() -> AndroidPermission.askForPermission(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, AndroidPermission.CASE_BATTERY))) - .visibility(() -> Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !AndroidPermission.checkForPermission(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) - .validator(() -> !(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !AndroidPermission.checkForPermission(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS))) + .visibility(() -> AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) + .validator(() -> !(AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS))) ) .add(new SWScreen(R.string.permission) .skippable(false) @@ -498,10 +498,10 @@ public class SWDefinition { .add(new SWBreak()) .add(new SWButton() .text(R.string.askforpermission) - .visibility(() -> Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !AndroidPermission.checkForPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) + .visibility(() -> AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) .action(() -> AndroidPermission.askForPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE, AndroidPermission.CASE_STORAGE))) - .visibility(() -> Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !AndroidPermission.checkForPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) - .validator(() -> !(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !AndroidPermission.checkForPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE))) + .visibility(() -> AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) + .validator(() -> !(AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE))) ) .add(new SWScreen(R.string.nav_import) .add(new SWInfotext() @@ -510,7 +510,7 @@ public class SWDefinition { .add(new SWButton() .text(R.string.nav_import) .action(() -> ImportExportPrefs.importSharedPreferences(getActivity()))) - .visibility(() -> ImportExportPrefs.file.exists() && !(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !AndroidPermission.checkForPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE))) + .visibility(() -> ImportExportPrefs.file.exists() && !(AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE))) ) .add(new SWScreen(R.string.nsclientinternal_title) .skippable(true) diff --git a/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java b/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java index 2cc3662136..f7b50a0f70 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java @@ -55,31 +55,29 @@ public class AndroidPermission { askForPermission(activity, permissions, requestCode); } - public static boolean checkForPermission(Context context, String permission) { + public static boolean permissionNotGranted(Context context, String permission) { if (permission == Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) { - PowerManager powerManager = (PowerManager) context.getSystemService(context.POWER_SERVICE); + PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); String packageName = context.getPackageName(); - return ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED - && powerManager.isIgnoringBatteryOptimizations(packageName); + return ContextCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED + || !powerManager.isIgnoringBatteryOptimizations(packageName); } - return ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED; + return ContextCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED; } public static synchronized void notifyForSMSPermissions(Activity activity) { if (SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)) { - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) { - if (!checkForPermission(activity, Manifest.permission.RECEIVE_SMS)) { - NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_SMS, MainApp.gs(R.string.smscommunicator_missingsmspermission), Notification.URGENT); - notification.action(MainApp.gs(R.string.request), () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.RECEIVE_SMS, - Manifest.permission.SEND_SMS, - Manifest.permission.RECEIVE_MMS}, AndroidPermission.CASE_SMS)); - MainApp.bus().post(new EventNewNotification(notification)); - } else - MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_SMS)); - } + if (permissionNotGranted(activity, Manifest.permission.RECEIVE_SMS)) { + NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_SMS, MainApp.gs(R.string.smscommunicator_missingsmspermission), Notification.URGENT); + notification.action(MainApp.gs(R.string.request), () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.RECEIVE_SMS, + Manifest.permission.SEND_SMS, + Manifest.permission.RECEIVE_MMS}, AndroidPermission.CASE_SMS)); + MainApp.bus().post(new EventNewNotification(notification)); + } else + MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_SMS)); // Following is a bug in Android 8 if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O) { - if (!checkForPermission(activity, Manifest.permission.READ_PHONE_STATE)) { + if (permissionNotGranted(activity, Manifest.permission.READ_PHONE_STATE)) { NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_PHONESTATE, MainApp.gs(R.string.smscommunicator_missingphonestatepermission), Notification.URGENT); notification.action(MainApp.gs(R.string.request), () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.READ_PHONE_STATE}, AndroidPermission.CASE_PHONESTATE)); @@ -92,7 +90,7 @@ public class AndroidPermission { public static synchronized void notifyForBatteryOptimizationPermission(Activity activity) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - if (!checkForPermission(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) { + if (permissionNotGranted(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) { NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_BATTERY, String.format(MainApp.gs(R.string.needwhitelisting), MainApp.gs(R.string.app_name)), Notification.URGENT); notification.action(MainApp.gs(R.string.request), () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS}, AndroidPermission.CASE_BATTERY)); MainApp.bus().post(new EventNewNotification(notification)); @@ -103,7 +101,7 @@ public class AndroidPermission { public static synchronized void notifyForStoragePermission(Activity activity) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - if (!checkForPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { + if (permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_STORAGE, MainApp.gs(R.string.needstoragepermission), Notification.URGENT); notification.action(MainApp.gs(R.string.request), () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, AndroidPermission.CASE_STORAGE)); @@ -115,7 +113,7 @@ public class AndroidPermission { public static synchronized void notifyForLocationPermissions(Activity activity) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - if (!checkForPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION)) { + if (permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION)) { NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_LOCATION, MainApp.gs(R.string.needlocationpermission), Notification.URGENT); notification.action(MainApp.gs(R.string.request), () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, AndroidPermission.CASE_LOCATION)); MainApp.bus().post(new EventNewNotification(notification)); From 81eeb66538a432513782910910357f0d47b84d5d Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 3 Aug 2019 20:00:56 +0200 Subject: [PATCH 5/8] SDK checking cleanup 2 --- .../RequestDexcomPermissionActivity.kt | 6 +-- .../dialog/RileyLinkBLEScanActivity.java | 54 +++++++++---------- .../pump/common/utils/LocationHelper.java | 10 ++-- .../plugins/source/SourceDexcomPlugin.kt | 2 +- 4 files changed, 30 insertions(+), 42 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/activities/RequestDexcomPermissionActivity.kt b/app/src/main/java/info/nightscout/androidaps/activities/RequestDexcomPermissionActivity.kt index 321c7d07ea..af370ff021 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/RequestDexcomPermissionActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/RequestDexcomPermissionActivity.kt @@ -11,11 +11,7 @@ class RequestDexcomPermissionActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - requestPermissions(arrayOf(SourceDexcomPlugin.PERMISSION), requestCode) - } else { - finish() - } + requestPermissions(arrayOf(SourceDexcomPlugin.PERMISSION), requestCode) } override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RileyLinkBLEScanActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RileyLinkBLEScanActivity.java index 9a6fa87d11..0dd5538503 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RileyLinkBLEScanActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RileyLinkBLEScanActivity.java @@ -1,15 +1,5 @@ package info.nightscout.androidaps.plugins.pump.common.dialog; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import android.Manifest; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; @@ -21,7 +11,6 @@ import android.bluetooth.le.ScanSettings; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; -import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.ParcelUuid; @@ -41,6 +30,16 @@ import androidx.appcompat.widget.Toolbar; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst; @@ -89,7 +88,7 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { mHandler = new Handler(); mLeDeviceListAdapter = new LeDeviceListAdapter(); - listBTScan = (ListView)findViewById(R.id.rileylink_listBTScan); + listBTScan = (ListView) findViewById(R.id.rileylink_listBTScan); listBTScan.setAdapter(mLeDeviceListAdapter); listBTScan.setOnItemClickListener((parent, view, position, id) -> { @@ -99,7 +98,7 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { mLEScanner.stopScan(mScanCallback2); } - TextView textview = (TextView)view.findViewById(R.id.rileylink_device_address); + TextView textview = (TextView) view.findViewById(R.id.rileylink_device_address); String bleAddress = textview.getText().toString(); SP.putString(RileyLinkConst.Prefs.RileyLinkAddress, bleAddress); @@ -114,7 +113,7 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { finish(); }); - toolbarBTScan = (Toolbar)findViewById(R.id.rileylink_toolbarBTScan); + toolbarBTScan = (Toolbar) findViewById(R.id.rileylink_toolbarBTScan); toolbarBTScan.setTitle(R.string.rileylink_scanner_title); setSupportActionBar(toolbarBTScan); @@ -161,8 +160,8 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { // you can selectively disable BLE-related features. if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // your code that requires permission - ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_COARSE_LOCATION }, - PERMISSION_REQUEST_COARSE_LOCATION); + ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, + PERMISSION_REQUEST_COARSE_LOCATION); } // Ensures Bluetooth is available on the device and it is enabled. If not, @@ -171,20 +170,15 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { Toast.makeText(this, R.string.rileylink_scanner_ble_not_enabled, Toast.LENGTH_SHORT).show(); } else { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - // Will request that GPS be enabled for devices running Marshmallow or newer. - if (!LocationHelper.isLocationEnabled(this)) { - LocationHelper.requestLocationForBluetooth(this); - } - } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); - startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); + // Will request that GPS be enabled for devices running Marshmallow or newer. + if (!LocationHelper.isLocationEnabled(this)) { + LocationHelper.requestLocationForBluetooth(this); } mLEScanner = mBluetoothAdapter.getBluetoothLeScanner(); settings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build(); filters = Arrays.asList(new ScanFilter.Builder().setServiceUuid( - ParcelUuid.fromString(GattAttributes.SERVICE_RADIO)).build()); + ParcelUuid.fromString(GattAttributes.SERVICE_RADIO)).build()); } } @@ -268,7 +262,7 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { private String getDeviceDebug(BluetoothDevice device) { return "BluetoothDevice [name=" + device.getName() + ", address=" + device.getAddress() + // - ", type=" + device.getType(); // + ", alias=" + device.getAlias(); + ", type=" + device.getType(); // + ", alias=" + device.getAlias(); } @@ -276,7 +270,7 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { public void onScanFailed(int errorCode) { Log.e("Scan Failed", "Error Code: " + errorCode); Toast.makeText(mContext, MainApp.gs(R.string.rileylink_scanner_scanning_error, errorCode), - Toast.LENGTH_LONG).show(); + Toast.LENGTH_LONG).show(); } }; @@ -384,11 +378,11 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { if (view == null) { view = mInflator.inflate(R.layout.rileylink_scan_item, null); viewHolder = new ViewHolder(); - viewHolder.deviceAddress = (TextView)view.findViewById(R.id.rileylink_device_address); - viewHolder.deviceName = (TextView)view.findViewById(R.id.rileylink_device_name); + viewHolder.deviceAddress = (TextView) view.findViewById(R.id.rileylink_device_address); + viewHolder.deviceName = (TextView) view.findViewById(R.id.rileylink_device_name); view.setTag(viewHolder); } else { - viewHolder = (ViewHolder)view.getTag(); + viewHolder = (ViewHolder) view.getTag(); } BluetoothDevice device = mLeDevices.get(i); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/LocationHelper.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/LocationHelper.java index d5b56311a3..98682679a7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/LocationHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/LocationHelper.java @@ -24,11 +24,11 @@ public class LocationHelper { * @return true if location is enabled, false otherwise. */ public static boolean isLocationEnabled(Context context) { - LocationManager locationManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE); + LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); return (locationManager != null && // - (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) || // - locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))); + (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) || // + locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))); // return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); } @@ -69,9 +69,7 @@ public class LocationHelper { */ public static void requestLocationForBluetooth(Activity activity) { // Location needs to be enabled for Bluetooth discovery on Marshmallow. - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - LocationHelper.requestLocation(activity); - } + LocationHelper.requestLocation(activity); } // public static Boolean locationPermission(ActivityWithMenu act) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/SourceDexcomPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/SourceDexcomPlugin.kt index 6119c07c37..1cf438b14d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/SourceDexcomPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/SourceDexcomPlugin.kt @@ -44,7 +44,7 @@ object SourceDexcomPlugin : PluginBase(PluginDescription() override fun onStart() { super.onStart() - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && ContextCompat.checkSelfPermission(MainApp.instance(), PERMISSION) != PackageManager.PERMISSION_GRANTED) { + if (ContextCompat.checkSelfPermission(MainApp.instance(), PERMISSION) != PackageManager.PERMISSION_GRANTED) { val intent = Intent(MainApp.instance(), RequestDexcomPermissionActivity::class.java) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) MainApp.instance().startActivity(intent) From 93ecd43e2efe785ac363471ac106840d5f475eaf Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 3 Aug 2019 20:01:55 +0200 Subject: [PATCH 6/8] handle callback from ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS --- .../nightscout/androidaps/MainActivity.java | 2 +- .../setupwizard/SetupWizardActivity.java | 8 +++ .../androidaps/utils/AndroidPermission.java | 70 +++++++++---------- 3 files changed, 42 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.java b/app/src/main/java/info/nightscout/androidaps/MainActivity.java index 360898ee00..2c8a56bdd7 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.java @@ -335,7 +335,7 @@ public class MainActivity extends AppCompatActivity { case AndroidPermission.CASE_LOCATION: case AndroidPermission.CASE_SMS: case AndroidPermission.CASE_BATTERY: - case AndroidPermission.CASE_PHONESTATE: + case AndroidPermission.CASE_PHONE_STATE: break; } } diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SetupWizardActivity.java b/app/src/main/java/info/nightscout/androidaps/setupwizard/SetupWizardActivity.java index 777463583d..3e2c638363 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SetupWizardActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SetupWizardActivity.java @@ -3,6 +3,8 @@ package info.nightscout.androidaps.setupwizard; import android.content.Intent; import android.content.pm.PackageManager; import android.os.Bundle; + +import androidx.annotation.Nullable; import androidx.core.app.ActivityCompat; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; @@ -223,4 +225,10 @@ public class SetupWizardActivity extends AppCompatActivity { updateButtons(); } + @Override + protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (requestCode == AndroidPermission.CASE_BATTERY) + updateButtons(); + } } diff --git a/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java b/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java index f7b50a0f70..7963ae0545 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java @@ -1,6 +1,7 @@ package info.nightscout.androidaps.utils; import android.Manifest; +import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.Intent; @@ -26,15 +27,16 @@ public class AndroidPermission { public static final int CASE_SMS = 0x2; public static final int CASE_LOCATION = 0x3; public static final int CASE_BATTERY = 0x4; - public static final int CASE_PHONESTATE = 0x5; + public static final int CASE_PHONE_STATE = 0x5; - public static void askForPermission(Activity activity, String[] permission, Integer requestCode) { + @SuppressLint("BatteryLife") + private static void askForPermission(Activity activity, String[] permission, Integer requestCode) { boolean test = false; boolean testBattery = false; - for (int i = 0; i < permission.length; i++) { - test = test || (ContextCompat.checkSelfPermission(activity, permission[i]) != PackageManager.PERMISSION_GRANTED); - if (permission[i] == Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) { - PowerManager powerManager = (PowerManager) activity.getSystemService(activity.POWER_SERVICE); + for (String s : permission) { + test = test || (ContextCompat.checkSelfPermission(activity, s) != PackageManager.PERMISSION_GRANTED); + if (s.equals(Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) { + PowerManager powerManager = (PowerManager) activity.getSystemService(Context.POWER_SERVICE); String packageName = activity.getPackageName(); testBattery = testBattery || !powerManager.isIgnoringBatteryOptimizations(packageName); } @@ -46,7 +48,7 @@ public class AndroidPermission { Intent i = new Intent(); i.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); i.setData(Uri.parse("package:" + activity.getPackageName())); - activity.startActivity(i); + activity.startActivityForResult(i, CASE_BATTERY); } } @@ -56,13 +58,13 @@ public class AndroidPermission { } public static boolean permissionNotGranted(Context context, String permission) { - if (permission == Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) { + boolean selfCheck = ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED; + if (permission.equals(Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) { PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); String packageName = context.getPackageName(); - return ContextCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED - || !powerManager.isIgnoringBatteryOptimizations(packageName); + selfCheck = selfCheck && powerManager.isIgnoringBatteryOptimizations(packageName); } - return ContextCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED; + return !selfCheck; } public static synchronized void notifyForSMSPermissions(Activity activity) { @@ -80,7 +82,7 @@ public class AndroidPermission { if (permissionNotGranted(activity, Manifest.permission.READ_PHONE_STATE)) { NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_PHONESTATE, MainApp.gs(R.string.smscommunicator_missingphonestatepermission), Notification.URGENT); notification.action(MainApp.gs(R.string.request), () -> - AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.READ_PHONE_STATE}, AndroidPermission.CASE_PHONESTATE)); + AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.READ_PHONE_STATE}, AndroidPermission.CASE_PHONE_STATE)); MainApp.bus().post(new EventNewNotification(notification)); } else MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_PHONESTATE)); @@ -89,36 +91,30 @@ public class AndroidPermission { } public static synchronized void notifyForBatteryOptimizationPermission(Activity activity) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - if (permissionNotGranted(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) { - NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_BATTERY, String.format(MainApp.gs(R.string.needwhitelisting), MainApp.gs(R.string.app_name)), Notification.URGENT); - notification.action(MainApp.gs(R.string.request), () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS}, AndroidPermission.CASE_BATTERY)); - MainApp.bus().post(new EventNewNotification(notification)); - } else - MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_BATTERY)); - } + if (permissionNotGranted(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) { + NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_BATTERY, String.format(MainApp.gs(R.string.needwhitelisting), MainApp.gs(R.string.app_name)), Notification.URGENT); + notification.action(MainApp.gs(R.string.request), () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS}, AndroidPermission.CASE_BATTERY)); + MainApp.bus().post(new EventNewNotification(notification)); + } else + MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_BATTERY)); } public static synchronized void notifyForStoragePermission(Activity activity) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - if (permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_STORAGE, MainApp.gs(R.string.needstoragepermission), Notification.URGENT); - notification.action(MainApp.gs(R.string.request), () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, - Manifest.permission.WRITE_EXTERNAL_STORAGE}, AndroidPermission.CASE_STORAGE)); - MainApp.bus().post(new EventNewNotification(notification)); - } else - MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_STORAGE)); - } + if (permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { + NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_STORAGE, MainApp.gs(R.string.needstoragepermission), Notification.URGENT); + notification.action(MainApp.gs(R.string.request), () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, + Manifest.permission.WRITE_EXTERNAL_STORAGE}, AndroidPermission.CASE_STORAGE)); + MainApp.bus().post(new EventNewNotification(notification)); + } else + MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_STORAGE)); } public static synchronized void notifyForLocationPermissions(Activity activity) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - if (permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION)) { - NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_LOCATION, MainApp.gs(R.string.needlocationpermission), Notification.URGENT); - notification.action(MainApp.gs(R.string.request), () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, AndroidPermission.CASE_LOCATION)); - MainApp.bus().post(new EventNewNotification(notification)); - } else - MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_LOCATION)); - } + if (permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION)) { + NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_LOCATION, MainApp.gs(R.string.needlocationpermission), Notification.URGENT); + notification.action(MainApp.gs(R.string.request), () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, AndroidPermission.CASE_LOCATION)); + MainApp.bus().post(new EventNewNotification(notification)); + } else + MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_LOCATION)); } } From 49ae8747fdf0835bcfe31eb9fb72f1654043a0a8 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 3 Aug 2019 21:22:24 +0200 Subject: [PATCH 7/8] remove code redundancy --- .../androidaps/setupwizard/SWDefinition.java | 941 ++++++++---------- app/src/main/res/values/strings.xml | 1 - 2 files changed, 389 insertions(+), 553 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java index d18307f0b8..0ba3cbad97 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java @@ -2,14 +2,11 @@ package info.nightscout.androidaps.setupwizard; import android.Manifest; import android.content.Intent; -import android.os.Build; + import androidx.appcompat.app.AppCompatActivity; import com.squareup.otto.Subscribe; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.util.ArrayList; import java.util.List; @@ -21,18 +18,19 @@ import info.nightscout.androidaps.events.EventConfigBuilderChange; import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginType; -import info.nightscout.androidaps.plugins.general.careportal.CareportalFragment; -import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog; -import info.nightscout.androidaps.plugins.general.careportal.OptionsToShow; +import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesFragment; import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin; -import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; +import info.nightscout.androidaps.plugins.general.careportal.CareportalFragment; +import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog; +import info.nightscout.androidaps.plugins.general.careportal.OptionsToShow; import info.nightscout.androidaps.plugins.general.maintenance.ImportExportPrefs; import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin; import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientStatus; +import info.nightscout.androidaps.plugins.general.nsclient.services.NSClientService; import info.nightscout.androidaps.plugins.profile.local.LocalProfileFragment; import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin; import info.nightscout.androidaps.plugins.profile.ns.NSProfileFragment; @@ -56,8 +54,6 @@ import info.nightscout.androidaps.utils.PasswordProtection; import info.nightscout.androidaps.utils.SP; public class SWDefinition { - private static Logger log = LoggerFactory.getLogger(SWDefinition.class); - private AppCompatActivity activity; private List screens = new ArrayList<>(); @@ -69,11 +65,11 @@ public class SWDefinition { return activity; } - public List getScreens() { + List getScreens() { return screens; } - SWDefinition add(SWScreen newScreen) { + private SWDefinition add(SWScreen newScreen) { screens.add(newScreen); return this; } @@ -85,553 +81,394 @@ public class SWDefinition { SWDefinitionNSClient(); } + private SWScreen screenSetupWizard = new SWScreen(R.string.nav_setupwizard) + .add(new SWInfotext() + .label(R.string.welcometosetupwizard)); + + private SWScreen screenLanguage = new SWScreen(R.string.language) + .skippable(false) + .add(new SWRadioButton() + .option(R.array.languagesArray, R.array.languagesValues) + .preferenceId(R.string.key_language).label(R.string.language) + .comment(R.string.setupwizard_language_prompt)) + .validator(() -> { + String lang = SP.getString("language", "en"); + LocaleHelper.setLocale(MainApp.instance().getApplicationContext(), lang); + return SP.contains(R.string.key_language); + }); + + private SWScreen screenEula = new SWScreen(R.string.end_user_license_agreement) + .skippable(false) + .add(new SWInfotext() + .label(R.string.end_user_license_agreement_text)) + .add(new SWBreak()) + .add(new SWButton() + .text(R.string.end_user_license_agreement_i_understand) + .visibility(() -> !SP.getBoolean(R.string.key_i_understand, false)) + .action(() -> { + SP.putBoolean(R.string.key_i_understand, true); + MainApp.bus().post(new EventSWUpdate(false)); + })) + .visibility(() -> !SP.getBoolean(R.string.key_i_understand, false)) + .validator(() -> SP.getBoolean(R.string.key_i_understand, false)); + + private SWScreen screenPermissionBattery = new SWScreen(R.string.permission) + .skippable(false) + .add(new SWInfotext() + .label(String.format(MainApp.gs(R.string.needwhitelisting), MainApp.gs(R.string.app_name)))) + .add(new SWBreak()) + .add(new SWButton() + .text(R.string.askforpermission) + .visibility(() -> AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) + .action(() -> AndroidPermission.askForPermission(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, AndroidPermission.CASE_BATTERY))) + .visibility(() -> AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) + .validator(() -> !(AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS))); + + private SWScreen screenPermissionBt = new SWScreen(R.string.permission) + .skippable(false) + .add(new SWInfotext() + .label(MainApp.gs(R.string.needlocationpermission))) + .add(new SWBreak()) + .add(new SWButton() + .text(R.string.askforpermission) + .visibility(() -> AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION)) + .action(() -> AndroidPermission.askForPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION, AndroidPermission.CASE_LOCATION))) + .visibility(() -> AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION)) + .validator(() -> !(AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION))); + + private SWScreen screenPermissionStore = new SWScreen(R.string.permission) + .skippable(false) + .add(new SWInfotext() + .label(MainApp.gs(R.string.needstoragepermission))) + .add(new SWBreak()) + .add(new SWButton() + .text(R.string.askforpermission) + .visibility(() -> AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) + .action(() -> AndroidPermission.askForPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE, AndroidPermission.CASE_STORAGE))) + .visibility(() -> AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) + .validator(() -> !(AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE))); + + private SWScreen screenImport = new SWScreen(R.string.nav_import) + .add(new SWInfotext() + .label(R.string.storedsettingsfound)) + .add(new SWBreak()) + .add(new SWButton() + .text(R.string.nav_import) + .action(() -> ImportExportPrefs.importSharedPreferences(getActivity()))) + .visibility(() -> ImportExportPrefs.file.exists() && !(AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE))); + + private SWScreen screenNsClient = new SWScreen(R.string.nsclientinternal_title) + .skippable(true) + .add(new SWInfotext() + .label(R.string.nsclientinfotext)) + .add(new SWBreak()) + .add(new SWButton() + .text(R.string.enable_nsclient) + .action(() -> { + NSClientPlugin.getPlugin().setPluginEnabled(PluginType.GENERAL, true); + NSClientPlugin.getPlugin().setFragmentVisible(PluginType.GENERAL, true); + ConfigBuilderFragment.processOnEnabledCategoryChanged(NSClientPlugin.getPlugin(), PluginType.GENERAL); + ConfigBuilderPlugin.getPlugin().storeSettings("SetupWizard"); + MainApp.bus().post(new EventConfigBuilderChange()); + MainApp.bus().post(new EventSWUpdate(true)); + }) + .visibility(() -> !NSClientPlugin.getPlugin().isEnabled(PluginType.GENERAL))) + .add(new SWEditUrl() + .preferenceId(R.string.key_nsclientinternal_url) + .updateDelay(5) + .label(R.string.nsclientinternal_url_title) + .comment(R.string.nsclientinternal_url_dialogmessage)) + .add(new SWEditString() + .validator(text -> text.length() >= 12) + .preferenceId(R.string.key_nsclientinternal_api_secret) + .updateDelay(5) + .label(R.string.nsclientinternal_secret_dialogtitle) + .comment(R.string.nsclientinternal_secret_dialogmessage)) + .add(new SWBreak()) + .add(new SWEventListener(this) + .label(R.string.status) + .initialStatus(NSClientPlugin.getPlugin().status) + .listener(new Object() { + @Subscribe + public void onEventNSClientStatus(EventNSClientStatus event) { + MainApp.bus().post(new EventSWLabel(event.status)); + } + }) + ) + .add(new SWBreak()) + .validator(() -> NSClientPlugin.getPlugin().nsClientService != null && NSClientService.isConnected && NSClientService.hasWriteAuth) + .visibility(() -> !(NSClientPlugin.getPlugin().nsClientService != null && NSClientService.isConnected && NSClientService.hasWriteAuth)); + + private SWScreen screenAge = new SWScreen(R.string.patientage) + .skippable(false) + .add(new SWInfotext() + .label(R.string.patientage_summary)) + .add(new SWBreak()) + .add(new SWRadioButton() + .option(R.array.ageArray, R.array.ageValues) + .preferenceId(R.string.key_age) + .label(R.string.patientage) + .comment(R.string.patientage_summary)) + .validator(() -> SP.contains(R.string.key_age)); + + private SWScreen screenInsulin = new SWScreen(R.string.configbuilder_insulin) + .skippable(false) + .add(new SWPlugin() + .option(PluginType.INSULIN, R.string.configbuilder_insulin_description) + .makeVisible(false) + .label(R.string.configbuilder_insulin)) + .add(new SWBreak()) + .add(new SWInfotext() + .label(R.string.diawarning)) + .add(new SWBreak()) + .add(new SWButton() + .text(R.string.insulinsourcesetup) + .action(() -> { + final PluginBase plugin = (PluginBase) ConfigBuilderPlugin.getPlugin().getActiveInsulin(); + if (plugin != null) { + PasswordProtection.QueryPassword(activity, R.string.settings_password, "settings_password", () -> { + Intent i = new Intent(activity, PreferencesActivity.class); + i.putExtra("id", plugin.getPreferencesId()); + activity.startActivity(i); + }, null); + } + }) + .visibility(() -> ConfigBuilderPlugin.getPlugin().getActiveInsulin() != null && ((PluginBase) ConfigBuilderPlugin.getPlugin().getActiveInsulin()).getPreferencesId() > 0)) + .validator(() -> ConfigBuilderPlugin.getPlugin().getActiveInsulin() != null); + + private SWScreen screenBgSource = new SWScreen(R.string.configbuilder_bgsource) + .skippable(false) + .add(new SWPlugin() + .option(PluginType.BGSOURCE, R.string.configbuilder_bgsource_description) + .label(R.string.configbuilder_bgsource)) + .add(new SWBreak()) + .add(new SWButton() + .text(R.string.bgsourcesetup) + .action(() -> { + final PluginBase plugin = (PluginBase) ConfigBuilderPlugin.getPlugin().getActiveBgSource(); + if (plugin != null) { + PasswordProtection.QueryPassword(activity, R.string.settings_password, "settings_password", () -> { + Intent i = new Intent(activity, PreferencesActivity.class); + i.putExtra("id", plugin.getPreferencesId()); + activity.startActivity(i); + }, null); + } + }) + .visibility(() -> ConfigBuilderPlugin.getPlugin().getActiveBgSource() != null && ((PluginBase) ConfigBuilderPlugin.getPlugin().getActiveBgSource()).getPreferencesId() > 0)) + .validator(() -> ConfigBuilderPlugin.getPlugin().getActiveBgSource() != null); + + private SWScreen screenProfile = new SWScreen(R.string.configbuilder_profile) + .skippable(false) + .add(new SWInfotext() + .label(R.string.setupwizard_profile_description)) + .add(new SWBreak()) + .add(new SWPlugin() + .option(PluginType.PROFILE, R.string.configbuilder_profile_description) + .label(R.string.configbuilder_profile)) + .validator(() -> ConfigBuilderPlugin.getPlugin().getActiveProfileInterface() != null); + + private SWScreen screenNsProfile = new SWScreen(R.string.nsprofile) + .skippable(false) + .add(new SWInfotext() + .label(R.string.adjustprofileinns)) + .add(new SWFragment(this) + .add(new NSProfileFragment())) + .validator(() -> NSProfilePlugin.getPlugin().getProfile() != null && NSProfilePlugin.getPlugin().getProfile().getDefaultProfile() != null && NSProfilePlugin.getPlugin().getProfile().getDefaultProfile().isValid("StartupWizard")) + .visibility(() -> NSProfilePlugin.getPlugin().isEnabled(PluginType.PROFILE)); + + private SWScreen screenLocalProfile = new SWScreen(R.string.localprofile) + .skippable(false) + .add(new SWFragment(this) + .add(new LocalProfileFragment())) + .validator(() -> LocalProfilePlugin.getPlugin().getProfile() != null && LocalProfilePlugin.getPlugin().getProfile().getDefaultProfile() != null && LocalProfilePlugin.getPlugin().getProfile().getDefaultProfile().isValid("StartupWizard")) + .visibility(() -> LocalProfilePlugin.getPlugin().isEnabled(PluginType.PROFILE)); + + private SWScreen screenSimpleProfile = new SWScreen(R.string.simpleprofile) + .skippable(false) + .add(new SWFragment(this) + .add(new SimpleProfileFragment())) + .validator(() -> SimpleProfilePlugin.getPlugin().getProfile() != null && SimpleProfilePlugin.getPlugin().getProfile().getDefaultProfile() != null && SimpleProfilePlugin.getPlugin().getProfile().getDefaultProfile().isValid("StartupWizard")) + .visibility(() -> SimpleProfilePlugin.getPlugin().isEnabled(PluginType.PROFILE)); + + private SWScreen screenProfileSwitch = new SWScreen(R.string.profileswitch) + .skippable(false) + .add(new SWInfotext() + .label(R.string.profileswitch_ismissing)) + .add(new SWButton() + .text(R.string.profileswitch) + .action(() -> { + NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog(); + final OptionsToShow profileSwitch = CareportalFragment.PROFILESWITCHDIRECT; + profileSwitch.executeProfileSwitch = true; + newDialog.setOptions(profileSwitch, R.string.careportal_profileswitch); + newDialog.show(getActivity().getSupportFragmentManager(), "NewNSTreatmentDialog"); + })) + .validator(() -> ProfileFunctions.getInstance().getProfile() != null) + .visibility(() -> ProfileFunctions.getInstance().getProfile() == null); + + private SWScreen screenPump = new SWScreen(R.string.configbuilder_pump) + .skippable(false) + .add(new SWPlugin() + .option(PluginType.PUMP, R.string.configbuilder_pump_description) + .label(R.string.configbuilder_pump)) + .add(new SWBreak()) + .add(new SWButton() + .text(R.string.pumpsetup) + .action(() -> { + final PluginBase plugin = (PluginBase) ConfigBuilderPlugin.getPlugin().getActivePump(); + if (plugin != null) { + PasswordProtection.QueryPassword(activity, R.string.settings_password, "settings_password", () -> { + Intent i = new Intent(activity, PreferencesActivity.class); + i.putExtra("id", plugin.getPreferencesId()); + activity.startActivity(i); + }, null); + } + }) + .visibility(() -> (ConfigBuilderPlugin.getPlugin().getActivePump() != null && ((PluginBase) ConfigBuilderPlugin.getPlugin().getActivePump()).getPreferencesId() > 0))) + .add(new SWButton() + .text(R.string.readstatus) + .action(() -> ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("Clicked connect to pump", null)) + .visibility(() -> ConfigBuilderPlugin.getPlugin().getActivePump() != null)) + .add(new SWEventListener(this) + .listener(new Object() { + @Subscribe + public void onEventPumpStatusChanged(EventPumpStatusChanged event) { + MainApp.bus().post(new EventSWLabel(event.textStatus())); + } + }) + ) + .validator(() -> ConfigBuilderPlugin.getPlugin().getActivePump() != null && ConfigBuilderPlugin.getPlugin().getActivePump().isInitialized()); + + private SWScreen screenAps = new SWScreen(R.string.configbuilder_aps) + .skippable(false) + .add(new SWInfotext() + .label(R.string.setupwizard_aps_description)) + .add(new SWBreak()) + .add(new SWHtmlLink() + .label("https://openaps.readthedocs.io/en/latest/")) + .add(new SWBreak()) + .add(new SWPlugin() + .option(PluginType.APS, R.string.configbuilder_aps_description) + .label(R.string.configbuilder_aps)) + .add(new SWButton() + .text(R.string.apssetup) + .action(() -> { + final PluginBase plugin = (PluginBase) ConfigBuilderPlugin.getPlugin().getActiveAPS(); + if (plugin != null) { + PasswordProtection.QueryPassword(activity, R.string.settings_password, "settings_password", () -> { + Intent i = new Intent(activity, PreferencesActivity.class); + i.putExtra("id", plugin.getPreferencesId()); + activity.startActivity(i); + }, null); + } + }) + .visibility(() -> ConfigBuilderPlugin.getPlugin().getActiveAPS() != null && ((PluginBase) ConfigBuilderPlugin.getPlugin().getActiveAPS()).getPreferencesId() > 0)) + .validator(() -> ConfigBuilderPlugin.getPlugin().getActiveAPS() != null) + .visibility(() -> Config.APS); + + private SWScreen screenApsMode = new SWScreen(R.string.apsmode_title) + .skippable(false) + .add(new SWRadioButton() + .option(R.array.aps_modeArray, R.array.aps_modeValues) + .preferenceId(R.string.key_aps_mode).label(R.string.apsmode_title) + .comment(R.string.setupwizard_preferred_aps_mode)) + .validator(() -> SP.contains(R.string.key_aps_mode)); + + private SWScreen screenLoop = new SWScreen(R.string.configbuilder_loop) + .skippable(false) + .add(new SWInfotext() + .label(R.string.setupwizard_loop_description)) + .add(new SWBreak()) + .add(new SWButton() + .text(R.string.enableloop) + .action(() -> { + LoopPlugin.getPlugin().setPluginEnabled(PluginType.LOOP, true); + LoopPlugin.getPlugin().setFragmentVisible(PluginType.LOOP, true); + ConfigBuilderFragment.processOnEnabledCategoryChanged(LoopPlugin.getPlugin(), PluginType.LOOP); + ConfigBuilderPlugin.getPlugin().storeSettings("SetupWizard"); + MainApp.bus().post(new EventConfigBuilderChange()); + MainApp.bus().post(new EventSWUpdate(true)); + }) + .visibility(() -> !LoopPlugin.getPlugin().isEnabled(PluginType.LOOP))) + .validator(() -> LoopPlugin.getPlugin().isEnabled(PluginType.LOOP)) + .visibility(() -> !LoopPlugin.getPlugin().isEnabled(PluginType.LOOP) && Config.APS); + + private SWScreen screenSensitivity = new SWScreen(R.string.configbuilder_sensitivity) + .skippable(false) + .add(new SWInfotext() + .label(R.string.setupwizard_sensitivity_description)) + .add(new SWHtmlLink() + .label(R.string.setupwizard_sensitivity_url)) + .add(new SWBreak()) + .add(new SWPlugin() + .option(PluginType.SENSITIVITY, R.string.configbuilder_sensitivity_description) + .label(R.string.configbuilder_sensitivity)) + .add(new SWBreak()) + .add(new SWButton() + .text(R.string.sensitivitysetup) + .action(() -> { + final PluginBase plugin = (PluginBase) ConfigBuilderPlugin.getPlugin().getActiveSensitivity(); + if (plugin != null) { + PasswordProtection.QueryPassword(activity, R.string.settings_password, "settings_password", () -> { + Intent i = new Intent(activity, PreferencesActivity.class); + i.putExtra("id", plugin.getPreferencesId()); + activity.startActivity(i); + }, null); + } + }) + .visibility(() -> ConfigBuilderPlugin.getPlugin().getActiveSensitivity() != null && ((PluginBase) ConfigBuilderPlugin.getPlugin().getActiveSensitivity()).getPreferencesId() > 0)) + .validator(() -> ConfigBuilderPlugin.getPlugin().getActiveSensitivity() != null); + + private SWScreen getScreenObjectives = new SWScreen(R.string.objectives) + .skippable(false) + .add(new SWInfotext() + .label(R.string.startobjective)) + .add(new SWBreak()) + .add(new SWFragment(this) + .add(new ObjectivesFragment())) + .validator(() -> ObjectivesPlugin.getPlugin().objectives.get(0).isStarted()) + .visibility(() -> !ObjectivesPlugin.getPlugin().objectives.get(0).isStarted() && Config.APS); + private void SWDefinitionFull() { // List all the screens here - add(new SWScreen(R.string.nav_setupwizard) - .add(new SWInfotext() - .label(R.string.welcometosetupwizard)) - ) - .add(new SWScreen(R.string.language) - .skippable(false) - .add(new SWRadioButton() - .option(R.array.languagesArray, R.array.languagesValues) - .preferenceId(R.string.key_language).label(R.string.language) - .comment(R.string.setupwizard_language_prompt)) - .validator(() -> { - String lang = SP.getString("language", "en"); - LocaleHelper.setLocale(MainApp.instance().getApplicationContext(), lang); - return SP.contains(R.string.key_language); - }) - ) - .add(new SWScreen(R.string.end_user_license_agreement) - .skippable(false) - .add(new SWInfotext() - .label(R.string.end_user_license_agreement_text)) - .add(new SWBreak()) - .add(new SWButton() - .text(R.string.end_user_license_agreement_i_understand) - .visibility(() -> !SP.getBoolean(R.string.key_i_understand, false)) - .action(() -> { - SP.putBoolean(R.string.key_i_understand, true); - MainApp.bus().post(new EventSWUpdate(false)); - })) - .visibility(() -> !SP.getBoolean(R.string.key_i_understand, false)) - .validator(() -> SP.getBoolean(R.string.key_i_understand, false)) - ) - .add(new SWScreen(R.string.permission) - .skippable(false) - .add(new SWInfotext() - .label(String.format(MainApp.gs(R.string.needwhitelisting), MainApp.gs(R.string.app_name)))) - .add(new SWBreak()) - .add(new SWButton() - .text(R.string.askforpermission) - .visibility(() -> AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) - .action(() -> AndroidPermission.askForPermission(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, AndroidPermission.CASE_BATTERY))) - .visibility(() -> AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) - .validator(() -> !(AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS))) - ) - .add(new SWScreen(R.string.permission) - .skippable(false) - .add(new SWInfotext() - .label(MainApp.gs(R.string.needlocationpermission))) - .add(new SWBreak()) - .add(new SWButton() - .text(R.string.askforpermission) - .visibility(() -> AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION)) - .action(() -> AndroidPermission.askForPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION, AndroidPermission.CASE_LOCATION))) - .visibility(() -> AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION)) - .validator(() -> !(AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION))) - ) - .add(new SWScreen(R.string.permission) - .skippable(false) - .add(new SWInfotext() - .label(MainApp.gs(R.string.needstoragepermission))) - .add(new SWBreak()) - .add(new SWButton() - .text(R.string.askforpermission) - .visibility(() -> AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) - .action(() -> AndroidPermission.askForPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE, AndroidPermission.CASE_STORAGE))) - .visibility(() -> AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) - .validator(() -> !(AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE))) - ) - .add(new SWScreen(R.string.nav_import) - .add(new SWInfotext() - .label(R.string.storedsettingsfound)) - .add(new SWBreak()) - .add(new SWButton() - .text(R.string.nav_import) - .action(() -> ImportExportPrefs.importSharedPreferences(getActivity()))) - .visibility(() -> ImportExportPrefs.file.exists() && !(AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE))) - ) - .add(new SWScreen(R.string.nsclientinternal_title) - .skippable(true) - .add(new SWInfotext() - .label(R.string.nsclientinfotext)) - .add(new SWBreak()) - .add(new SWButton() - .text(R.string.enable_nsclient) - .action(() -> { - NSClientPlugin.getPlugin().setPluginEnabled(PluginType.GENERAL, true); - NSClientPlugin.getPlugin().setFragmentVisible(PluginType.GENERAL, true); - ConfigBuilderFragment.processOnEnabledCategoryChanged(NSClientPlugin.getPlugin(), PluginType.GENERAL); - ConfigBuilderPlugin.getPlugin().storeSettings("SetupWizard"); - MainApp.bus().post(new EventConfigBuilderChange()); - MainApp.bus().post(new EventSWUpdate(true)); - }) - .visibility(() -> !NSClientPlugin.getPlugin().isEnabled(PluginType.GENERAL))) - .add(new SWEditUrl() - .preferenceId(R.string.key_nsclientinternal_url) - .updateDelay(5) - .label(R.string.nsclientinternal_url_title) - .comment(R.string.nsclientinternal_url_dialogmessage)) - .add(new SWEditString() - .validator(text -> text.length() >= 12) - .preferenceId(R.string.key_nsclientinternal_api_secret) - .updateDelay(5) - .label(R.string.nsclientinternal_secret_dialogtitle) - .comment(R.string.nsclientinternal_secret_dialogmessage)) - .add(new SWBreak()) - .add(new SWEventListener(this) - .label(R.string.status) - .initialStatus(NSClientPlugin.getPlugin().status) - .listener(new Object() { - @Subscribe - public void onEventNSClientStatus(EventNSClientStatus event) { - MainApp.bus().post(new EventSWLabel(event.status)); - } - }) - ) - .add(new SWBreak()) - .validator(() -> NSClientPlugin.getPlugin().nsClientService != null && NSClientPlugin.getPlugin().nsClientService.isConnected && NSClientPlugin.getPlugin().nsClientService.hasWriteAuth) - .visibility(() -> !(NSClientPlugin.getPlugin().nsClientService != null && NSClientPlugin.getPlugin().nsClientService.isConnected && NSClientPlugin.getPlugin().nsClientService.hasWriteAuth)) - ) - .add(new SWScreen(R.string.patientage) - .skippable(false) - .add(new SWInfotext() - .label(R.string.patientage_summary)) - .add(new SWBreak()) - .add(new SWRadioButton() - .option(R.array.ageArray, R.array.ageValues) - .preferenceId(R.string.key_age) - .label(R.string.patientage) - .comment(R.string.patientage_summary)) - .validator(() -> SP.contains(R.string.key_age)) - ) - .add(new SWScreen(R.string.configbuilder_insulin) - .skippable(false) - .add(new SWPlugin() - .option(PluginType.INSULIN, R.string.configbuilder_insulin_description) - .makeVisible(false) - .label(R.string.configbuilder_insulin)) - .add(new SWBreak()) - .add(new SWInfotext() - .label(R.string.diawarning)) - .add(new SWBreak()) - .add(new SWButton() - .text(R.string.insulinsourcesetup) - .action(() -> { - final PluginBase plugin = (PluginBase) ConfigBuilderPlugin.getPlugin().getActiveInsulin(); - PasswordProtection.QueryPassword(activity, R.string.settings_password, "settings_password", () -> { - Intent i = new Intent(activity, PreferencesActivity.class); - i.putExtra("id", plugin.getPreferencesId()); - activity.startActivity(i); - }, null); - }) - .visibility(() -> ConfigBuilderPlugin.getPlugin().getActiveInsulin()!= null && ((PluginBase) ConfigBuilderPlugin.getPlugin().getActiveInsulin()).getPreferencesId() > 0)) - .validator(() -> ConfigBuilderPlugin.getPlugin().getActiveInsulin() != null) - ) - .add(new SWScreen(R.string.configbuilder_bgsource) - .skippable(false) - .add(new SWPlugin() - .option(PluginType.BGSOURCE, R.string.configbuilder_bgsource_description) - .label(R.string.configbuilder_bgsource)) - .add(new SWBreak()) - .add(new SWButton() - .text(R.string.bgsourcesetup) - .action(() -> { - final PluginBase plugin = (PluginBase) ConfigBuilderPlugin.getPlugin().getActiveBgSource(); - PasswordProtection.QueryPassword(activity, R.string.settings_password, "settings_password", () -> { - Intent i = new Intent(activity, PreferencesActivity.class); - i.putExtra("id", plugin.getPreferencesId()); - activity.startActivity(i); - }, null); - }) - .visibility(() -> ConfigBuilderPlugin.getPlugin().getActiveBgSource()!= null && ((PluginBase) ConfigBuilderPlugin.getPlugin().getActiveBgSource()).getPreferencesId() > 0)) - .validator(() -> ConfigBuilderPlugin.getPlugin().getActiveBgSource() != null) - ) - .add(new SWScreen(R.string.configbuilder_profile) - .skippable(false) - .add(new SWInfotext() - .label(R.string.setupwizard_profile_description)) - .add(new SWBreak()) - .add(new SWPlugin() - .option(PluginType.PROFILE, R.string.configbuilder_profile_description) - .label(R.string.configbuilder_profile)) - .validator(() -> ConfigBuilderPlugin.getPlugin().getActiveProfileInterface() != null) - ) - .add(new SWScreen(R.string.nsprofile) - .skippable(false) - .add(new SWInfotext() - .label(R.string.adjustprofileinns)) - .add(new SWFragment(this) - .add(new NSProfileFragment())) - .validator(() -> NSProfilePlugin.getPlugin().getProfile() != null && NSProfilePlugin.getPlugin().getProfile().getDefaultProfile().isValid("StartupWizard")) - .visibility(() -> NSProfilePlugin.getPlugin().isEnabled(PluginType.PROFILE)) - ) - .add(new SWScreen(R.string.localprofile) - .skippable(false) - .add(new SWFragment(this) - .add(new LocalProfileFragment())) - .validator(() -> LocalProfilePlugin.getPlugin().getProfile() != null && LocalProfilePlugin.getPlugin().getProfile().getDefaultProfile().isValid("StartupWizard")) - .visibility(() -> LocalProfilePlugin.getPlugin().isEnabled(PluginType.PROFILE)) - ) - .add(new SWScreen(R.string.simpleprofile) - .skippable(false) - .add(new SWFragment(this) - .add(new SimpleProfileFragment())) - .validator(() -> SimpleProfilePlugin.getPlugin().getProfile() != null && SimpleProfilePlugin.getPlugin().getProfile().getDefaultProfile().isValid("StartupWizard")) - .visibility(() -> SimpleProfilePlugin.getPlugin().isEnabled(PluginType.PROFILE)) - ) - .add(new SWScreen(R.string.profileswitch) - .skippable(false) - .add(new SWInfotext() - .label(R.string.profileswitch_ismissing)) - .add(new SWButton() - .text(R.string.profileswitch) - .action(() -> { - NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog(); - final OptionsToShow profileswitch = CareportalFragment.PROFILESWITCHDIRECT; - profileswitch.executeProfileSwitch = true; - newDialog.setOptions(profileswitch, R.string.careportal_profileswitch); - newDialog.show(getActivity().getSupportFragmentManager(), "NewNSTreatmentDialog"); - })) - .validator(() -> ProfileFunctions.getInstance().getProfile() != null) - .visibility(() -> ProfileFunctions.getInstance().getProfile() == null) - ) - .add(new SWScreen(R.string.configbuilder_pump) - .skippable(false) - .add(new SWPlugin() - .option(PluginType.PUMP, R.string.configbuilder_pump_description) - .label(R.string.configbuilder_pump)) - .add(new SWBreak()) - .add(new SWButton() - .text(R.string.pumpsetup) - .action(() -> { - final PluginBase plugin = (PluginBase) ConfigBuilderPlugin.getPlugin().getActivePump(); - PasswordProtection.QueryPassword(activity, R.string.settings_password, "settings_password", () -> { - Intent i = new Intent(activity, PreferencesActivity.class); - i.putExtra("id", plugin.getPreferencesId()); - activity.startActivity(i); - }, null); - }) - .visibility(() -> ((PluginBase) ConfigBuilderPlugin.getPlugin().getActivePump()).getPreferencesId() > 0)) - .add(new SWButton() - .text(R.string.readstatus) - .action(() -> ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("Clicked connect to pump", null)) - .visibility(() -> ConfigBuilderPlugin.getPlugin().getActivePump() != null)) - .add(new SWEventListener(this) - .listener(new Object() { - @Subscribe - public void onEventPumpStatusChanged(EventPumpStatusChanged event) { - MainApp.bus().post(new EventSWLabel(event.textStatus())); - } - }) - ) - .validator(() -> ConfigBuilderPlugin.getPlugin().getActivePump() != null && ConfigBuilderPlugin.getPlugin().getActivePump().isInitialized()) - ) - .add(new SWScreen(R.string.configbuilder_aps) - .skippable(false) - .add(new SWInfotext() - .label(R.string.setupwizard_aps_description)) - .add(new SWBreak()) - .add(new SWHtmlLink() - .label("https://openaps.readthedocs.io/en/latest/")) - .add(new SWBreak()) - .add(new SWPlugin() - .option(PluginType.APS, R.string.configbuilder_aps_description) - .label(R.string.configbuilder_aps)) - .add(new SWButton() - .text(R.string.apssetup) - .action(() -> { - final PluginBase plugin = (PluginBase) ConfigBuilderPlugin.getPlugin().getActiveAPS(); - PasswordProtection.QueryPassword(activity, R.string.settings_password, "settings_password", () -> { - Intent i = new Intent(activity, PreferencesActivity.class); - i.putExtra("id", plugin.getPreferencesId()); - activity.startActivity(i); - }, null); - }) - .visibility(() -> ConfigBuilderPlugin.getPlugin().getActiveAPS() != null && ((PluginBase) ConfigBuilderPlugin.getPlugin().getActiveAPS()).getPreferencesId() > 0)) - .validator(() -> ConfigBuilderPlugin.getPlugin().getActiveAPS() != null) - .visibility(() -> Config.APS) - ) - .add(new SWScreen(R.string.apsmode_title) - .skippable(false) - .add(new SWRadioButton() - .option(R.array.aps_modeArray, R.array.aps_modeValues) - .preferenceId(R.string.key_aps_mode).label(R.string.apsmode_title) - .comment(R.string.setupwizard_preferred_aps_mode)) - .validator(() -> SP.contains(R.string.key_aps_mode)) - ) - .add(new SWScreen(R.string.configbuilder_loop) - .skippable(false) - .add(new SWInfotext() - .label(R.string.setupwizard_loop_description)) - .add(new SWBreak()) - .add(new SWButton() - .text(R.string.enableloop) - .action(() -> { - LoopPlugin.getPlugin().setPluginEnabled(PluginType.LOOP, true); - LoopPlugin.getPlugin().setFragmentVisible(PluginType.LOOP, true); - ConfigBuilderFragment.processOnEnabledCategoryChanged(LoopPlugin.getPlugin(), PluginType.LOOP); - ConfigBuilderPlugin.getPlugin().storeSettings("SetupWizard"); - MainApp.bus().post(new EventConfigBuilderChange()); - MainApp.bus().post(new EventSWUpdate(true)); - }) - .visibility(() -> !LoopPlugin.getPlugin().isEnabled(PluginType.LOOP))) - .validator(() -> LoopPlugin.getPlugin().isEnabled(PluginType.LOOP)) - .visibility(() -> !LoopPlugin.getPlugin().isEnabled(PluginType.LOOP) && Config.APS) - ) - .add(new SWScreen(R.string.configbuilder_sensitivity) - .skippable(false) - .add(new SWInfotext() - .label(R.string.setupwizard_sensitivity_description)) - .add(new SWHtmlLink() - .label(R.string.setupwizard_sensitivity_url)) - .add(new SWBreak()) - .add(new SWPlugin() - .option(PluginType.SENSITIVITY, R.string.configbuilder_sensitivity_description) - .label(R.string.configbuilder_sensitivity)) - .add(new SWBreak()) - .add(new SWButton() - .text(R.string.sensitivitysetup) - .action(() -> { - final PluginBase plugin = (PluginBase) ConfigBuilderPlugin.getPlugin().getActiveSensitivity(); - PasswordProtection.QueryPassword(activity, R.string.settings_password, "settings_password", () -> { - Intent i = new Intent(activity, PreferencesActivity.class); - i.putExtra("id", plugin.getPreferencesId()); - activity.startActivity(i); - }, null); - }) - .visibility(() -> ConfigBuilderPlugin.getPlugin().getActiveSensitivity() != null && ((PluginBase) ConfigBuilderPlugin.getPlugin().getActiveSensitivity()).getPreferencesId() > 0)) - .validator(() -> ConfigBuilderPlugin.getPlugin().getActiveSensitivity() != null) - ) - .add(new SWScreen(R.string.objectives) - .skippable(false) - .add(new SWInfotext() - .label(R.string.setupwizard_objectives_description)) - .add(new SWButton() - .text(R.string.enableobjectives) - .action(() -> { - ObjectivesPlugin.getPlugin().setPluginEnabled(PluginType.CONSTRAINTS, true); - ObjectivesPlugin.getPlugin().setFragmentVisible(PluginType.CONSTRAINTS, true); - ConfigBuilderFragment.processOnEnabledCategoryChanged(ObjectivesPlugin.getPlugin(), PluginType.CONSTRAINTS); - ConfigBuilderPlugin.getPlugin().storeSettings("SetupWizard"); - MainApp.bus().post(new EventConfigBuilderChange()); - MainApp.bus().post(new EventSWUpdate(true)); - }) - .visibility(() -> !ObjectivesPlugin.getPlugin().isFragmentVisible())) - .validator(() -> ObjectivesPlugin.getPlugin().isEnabled(PluginType.CONSTRAINTS)) - .visibility(() -> !ObjectivesPlugin.getPlugin().isFragmentVisible() && Config.APS) - ) - .add(new SWScreen(R.string.objectives) - .skippable(false) - .add(new SWInfotext() - .label(R.string.startobjective)) - .add(new SWBreak()) - .add(new SWFragment(this) - .add(new ObjectivesFragment())) - .validator(() -> ObjectivesPlugin.getPlugin().objectives.get(0).isStarted()) - .visibility(() -> !ObjectivesPlugin.getPlugin().objectives.get(0).isStarted() && Config.APS) - ) + add(screenSetupWizard) + .add(screenLanguage) + .add(screenEula) + .add(screenPermissionBattery) + .add(screenPermissionBt) + .add(screenPermissionStore) + .add(screenImport) + .add(screenNsClient) + .add(screenAge) + .add(screenInsulin) + .add(screenBgSource) + .add(screenProfile) + .add(screenNsProfile) + .add(screenLocalProfile) + .add(screenSimpleProfile) + .add(screenProfileSwitch) + .add(screenPump) + .add(screenAps) + .add(screenApsMode) + .add(screenLoop) + .add(screenSensitivity) + .add(getScreenObjectives) ; } private void SWDefinitionNSClient() { // List all the screens here - add(new SWScreen(R.string.nav_setupwizard) - .add(new SWInfotext() - .label(R.string.welcometosetupwizard)) - ) - .add(new SWScreen(R.string.language) - .skippable(false) - .add(new SWRadioButton() - .option(R.array.languagesArray, R.array.languagesValues) - .preferenceId(R.string.key_language).label(R.string.language) - .comment(R.string.setupwizard_language_prompt)) - .validator(() -> { - String lang = SP.getString("language", "en"); - LocaleHelper.setLocale(MainApp.instance().getApplicationContext(), lang); - return SP.contains(R.string.key_language); - }) - ) - .add(new SWScreen(R.string.end_user_license_agreement) - .skippable(false) - .add(new SWInfotext() - .label(R.string.end_user_license_agreement_text)) - .add(new SWBreak()) - .add(new SWButton() - .text(R.string.end_user_license_agreement_i_understand) - .visibility(() -> !SP.getBoolean(R.string.key_i_understand, false)) - .action(() -> { - SP.putBoolean(R.string.key_i_understand, true); - MainApp.bus().post(new EventSWUpdate(false)); - })) - .visibility(() -> !SP.getBoolean(R.string.key_i_understand, false)) - .validator(() -> SP.getBoolean(R.string.key_i_understand, false)) - ) - .add(new SWScreen(R.string.permission) - .skippable(false) - .add(new SWInfotext() - .label(String.format(MainApp.gs(R.string.needwhitelisting), MainApp.gs(R.string.app_name)))) - .add(new SWBreak()) - .add(new SWButton() - .text(R.string.askforpermission) - .visibility(() -> AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) - .action(() -> AndroidPermission.askForPermission(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, AndroidPermission.CASE_BATTERY))) - .visibility(() -> AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) - .validator(() -> !(AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS))) - ) - .add(new SWScreen(R.string.permission) - .skippable(false) - .add(new SWInfotext() - .label(MainApp.gs(R.string.needstoragepermission))) - .add(new SWBreak()) - .add(new SWButton() - .text(R.string.askforpermission) - .visibility(() -> AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) - .action(() -> AndroidPermission.askForPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE, AndroidPermission.CASE_STORAGE))) - .visibility(() -> AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) - .validator(() -> !(AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE))) - ) - .add(new SWScreen(R.string.nav_import) - .add(new SWInfotext() - .label(R.string.storedsettingsfound)) - .add(new SWBreak()) - .add(new SWButton() - .text(R.string.nav_import) - .action(() -> ImportExportPrefs.importSharedPreferences(getActivity()))) - .visibility(() -> ImportExportPrefs.file.exists() && !(AndroidPermission.permissionNotGranted(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE))) - ) - .add(new SWScreen(R.string.nsclientinternal_title) - .skippable(true) - .add(new SWInfotext() - .label(R.string.nsclientinfotext)) - .add(new SWBreak()) - .add(new SWButton() - .text(R.string.enable_nsclient) - .action(() -> { - NSClientPlugin.getPlugin().setPluginEnabled(PluginType.GENERAL, true); - NSClientPlugin.getPlugin().setFragmentVisible(PluginType.GENERAL, true); - ConfigBuilderFragment.processOnEnabledCategoryChanged(NSClientPlugin.getPlugin(), PluginType.GENERAL); - ConfigBuilderPlugin.getPlugin().storeSettings("SetupWizard"); - MainApp.bus().post(new EventConfigBuilderChange()); - MainApp.bus().post(new EventSWUpdate(true)); - }) - .visibility(() -> !NSClientPlugin.getPlugin().isEnabled(PluginType.GENERAL))) - .add(new SWEditUrl() - .preferenceId(R.string.key_nsclientinternal_url) - .updateDelay(5) - .label(R.string.nsclientinternal_url_title) - .comment(R.string.nsclientinternal_url_dialogmessage)) - .add(new SWEditString() - .validator(text -> text.length() >= 12) - .updateDelay(5) - .preferenceId(R.string.key_nsclientinternal_api_secret) - .label(R.string.nsclientinternal_secret_dialogtitle) - .comment(R.string.nsclientinternal_secret_dialogmessage)) - .add(new SWBreak()) - .add(new SWEventListener(this) - .label(R.string.status) - .initialStatus(NSClientPlugin.getPlugin().status) - .listener(new Object() { - @Subscribe - public void onEventNSClientStatus(EventNSClientStatus event) { - MainApp.bus().post(new EventSWLabel(event.status)); - } - }) - ) - .add(new SWBreak()) - .validator(() -> NSClientPlugin.getPlugin().nsClientService != null && NSClientPlugin.getPlugin().nsClientService.isConnected && NSClientPlugin.getPlugin().nsClientService.hasWriteAuth) - .visibility(() -> !(NSClientPlugin.getPlugin().nsClientService != null && NSClientPlugin.getPlugin().nsClientService.isConnected && NSClientPlugin.getPlugin().nsClientService.hasWriteAuth)) - ) - .add(new SWScreen(R.string.configbuilder_bgsource) - .skippable(false) - .add(new SWPlugin() - .option(PluginType.BGSOURCE, R.string.configbuilder_bgsource_description) - .label(R.string.configbuilder_bgsource)) - .add(new SWBreak()) - .add(new SWButton() - .text(R.string.bgsourcesetup) - .action(() -> { - final PluginBase plugin = (PluginBase) ConfigBuilderPlugin.getPlugin().getActiveBgSource(); - PasswordProtection.QueryPassword(activity, R.string.settings_password, "settings_password", () -> { - Intent i = new Intent(activity, PreferencesActivity.class); - i.putExtra("id", plugin.getPreferencesId()); - activity.startActivity(i); - }, null); - }) - .visibility(() -> ConfigBuilderPlugin.getPlugin().getActiveBgSource()!= null && ((PluginBase) ConfigBuilderPlugin.getPlugin().getActiveBgSource()).getPreferencesId() > 0)) - .validator(() -> ConfigBuilderPlugin.getPlugin().getActiveBgSource() != null) - ) - .add(new SWScreen(R.string.patientage) - .skippable(false) - .add(new SWInfotext() - .label(R.string.patientage_summary)) - .add(new SWBreak()) - .add(new SWRadioButton() - .option(R.array.ageArray, R.array.ageValues) - .preferenceId(R.string.key_age) - .label(R.string.patientage) - .comment(R.string.patientage_summary)) - .validator(() -> SP.contains(R.string.key_age)) - ) - .add(new SWScreen(R.string.configbuilder_insulin) - .skippable(false) - .add(new SWPlugin() - .option(PluginType.INSULIN, R.string.configbuilder_insulin_description) - .makeVisible(false) - .label(R.string.configbuilder_insulin)) - .add(new SWBreak()) - .add(new SWInfotext() - .label(R.string.diawarning)) - .add(new SWBreak()) - .add(new SWButton() - .text(R.string.insulinsourcesetup) - .action(() -> { - final PluginBase plugin = (PluginBase) ConfigBuilderPlugin.getPlugin().getActiveInsulin(); - PasswordProtection.QueryPassword(activity, R.string.settings_password, "settings_password", () -> { - Intent i = new Intent(activity, PreferencesActivity.class); - i.putExtra("id", plugin.getPreferencesId()); - activity.startActivity(i); - }, null); - }) - .visibility(() -> ConfigBuilderPlugin.getPlugin().getActiveInsulin()!= null && ((PluginBase) ConfigBuilderPlugin.getPlugin().getActiveInsulin()).getPreferencesId() > 0)) - .validator(() -> ConfigBuilderPlugin.getPlugin().getActiveInsulin() != null) - ) - .add(new SWScreen(R.string.configbuilder_sensitivity) - .skippable(false) - .add(new SWInfotext() - .label(R.string.setupwizard_sensitivity_description)) - .add(new SWHtmlLink() - .label(R.string.setupwizard_sensitivity_url)) - .add(new SWBreak()) - .add(new SWPlugin() - .option(PluginType.SENSITIVITY, R.string.configbuilder_sensitivity_description) - .label(R.string.configbuilder_sensitivity)) - .add(new SWBreak()) - .add(new SWButton() - .text(R.string.sensitivitysetup) - .action(() -> { - final PluginBase plugin = (PluginBase) ConfigBuilderPlugin.getPlugin().getActiveSensitivity(); - PasswordProtection.QueryPassword(activity, R.string.settings_password, "settings_password", () -> { - Intent i = new Intent(activity, PreferencesActivity.class); - i.putExtra("id", plugin.getPreferencesId()); - activity.startActivity(i); - }, null); - }) - .visibility(() -> ConfigBuilderPlugin.getPlugin().getActiveSensitivity() != null && ((PluginBase) ConfigBuilderPlugin.getPlugin().getActiveSensitivity()).getPreferencesId() > 0)) - .validator(() -> ConfigBuilderPlugin.getPlugin().getActiveSensitivity() != null) - ) + add(screenSetupWizard) + .add(screenLanguage) + .add(screenEula) + .add(screenPermissionBattery) + .add(screenPermissionStore) + .add(screenImport) + .add(screenNsClient) + .add(screenBgSource) + .add(screenAge) + .add(screenInsulin) + .add(screenSensitivity) ; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0760633e37..992c01638e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1150,7 +1150,6 @@ Changes must be done in NS Skip setup wizard Press the button below to enable AndroidAPS to suggest/make basal changes - Press the button below to enable Objectives. Look in the Objectives tab, after you finish this wizard, to make AndroidAPS completely functional.\n Enable Objectives Configure APS plugin startupwizard_processed From 4bbb77907fbae0aca6b33c7991ead1ce9e607b9a Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 3 Aug 2019 23:22:30 +0200 Subject: [PATCH 8/8] separate config for pumpcontrol --- .../androidaps/setupwizard/SWDefinition.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java index 0ba3cbad97..b39f2209b3 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java @@ -75,8 +75,10 @@ public class SWDefinition { } SWDefinition() { - if (Config.APS || Config.PUMPCONTROL) + if (Config.APS) SWDefinitionFull(); + else if (Config.PUMPCONTROL) + SWDefinitionPumpControl(); else if (Config.NSCLIENT) SWDefinitionNSClient(); } @@ -456,6 +458,29 @@ public class SWDefinition { ; } + private void SWDefinitionPumpControl() { + // List all the screens here + add(screenSetupWizard) + .add(screenLanguage) + .add(screenEula) + .add(screenPermissionBattery) + .add(screenPermissionBt) + .add(screenPermissionStore) + .add(screenImport) + .add(screenNsClient) + .add(screenAge) + .add(screenInsulin) + .add(screenBgSource) + .add(screenProfile) + .add(screenNsProfile) + .add(screenLocalProfile) + .add(screenSimpleProfile) + .add(screenProfileSwitch) + .add(screenPump) + .add(screenSensitivity) + ; + } + private void SWDefinitionNSClient() { // List all the screens here add(screenSetupWizard)