From c47d5a4113c870ba2e1394ec02ff9269dca9ee10 Mon Sep 17 00:00:00 2001 From: LLan Date: Wed, 8 Jan 2025 18:06:23 +0100 Subject: [PATCH] Cleanup --- app/src/main/AndroidManifest.xml | 1 - .../activities/SettingsActivity.java | 4 ++-- .../healthconnect/HealthConnectUtils.java | 23 ++++++++----------- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3494d6506..cee5337a5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -104,7 +104,6 @@ - > continuationString = new Continuation>() { + Continuation> continuationString = new Continuation>() { @NotNull @Override public CoroutineContext getContext() { @@ -346,7 +346,7 @@ public class SettingsActivity extends AbstractSettingsActivityV2 { if ((boolean) exportHealthConnectEnabled) { if(!grantedPermissions.containsAll(healthConnectUtils.requiredHealthConnectPermissions)) { // If we weren't enabled at some point already, show Permission screen - healthConnectUtils.healthConnectLauncherInit().launch(healthConnectUtils.requiredHealthConnectPermissions); + healthConnectUtils.activityResultLauncher.launch(healthConnectUtils.requiredHealthConnectPermissions); } } return true; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/healthconnect/HealthConnectUtils.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/healthconnect/HealthConnectUtils.java index 4daad0a3f..1fa6f7047 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/healthconnect/HealthConnectUtils.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/healthconnect/HealthConnectUtils.java @@ -52,22 +52,26 @@ import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs; public class HealthConnectUtils { private static final Logger LOG = LoggerFactory.getLogger(HealthConnectUtils.class); private final PreferenceFragmentCompat preferenceFragmentCompat; - Class stepsRecordJavaClass = StepsRecord.class; - Class heartrateRecordJavaClass = HeartRateRecord.class; - KClass stepsRecordKClass = JvmClassMappingKt.getKotlinClass(stepsRecordJavaClass); - KClass heartrateRecordKClass = JvmClassMappingKt.getKotlinClass(heartrateRecordJavaClass); - public Set requiredHealthConnectPermissions = Set.of( + public final ActivityResultLauncher> activityResultLauncher; + private final Class stepsRecordJavaClass = StepsRecord.class; + private final Class heartrateRecordJavaClass = HeartRateRecord.class; + private final KClass stepsRecordKClass = JvmClassMappingKt.getKotlinClass(stepsRecordJavaClass); + private final KClass heartrateRecordKClass = JvmClassMappingKt.getKotlinClass(heartrateRecordJavaClass); + public final Set requiredHealthConnectPermissions = Set.of( HealthPermission.getReadPermission(stepsRecordKClass), HealthPermission.getWritePermission(stepsRecordKClass), HealthPermission.getReadPermission(heartrateRecordKClass), HealthPermission.getWritePermission(heartrateRecordKClass) ); - public ActivityResultContract, Set> requestPermissionResultContract = PermissionController.createRequestPermissionResultContract(); public HealthConnectUtils(PreferenceFragmentCompat fragmentCompat) { preferenceFragmentCompat = fragmentCompat; + activityResultLauncher = preferenceFragmentCompat.registerForActivityResult( + requestPermissionResultContract, + this::permissionCallback + ); } @SuppressLint("RestrictedApi") @@ -89,13 +93,6 @@ public class HealthConnectUtils { } } - public ActivityResultLauncher> healthConnectLauncherInit() { - return preferenceFragmentCompat.registerForActivityResult( - requestPermissionResultContract, - this::permissionCallback - ); - } - public HealthConnectClient healthConnectInit(Context context) { // First check if we can even use Health Connect int availabilityStatus = HealthConnectClient.getSdkStatus(context);