diff --git a/app/build.gradle b/app/build.gradle index fb310ec3..c166ec50 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -60,14 +60,15 @@ dependencies { implementation project(':profile_hts') implementation project(':profile_prx') implementation project(':profile_rscs') - implementation project(':scanner') implementation project(":lib_theme") implementation project(":lib_utils") implementation project(":lib_service") implementation libs.nordic.ble.common + implementation libs.nordic.ui.scanner + implementation libs.bundles.koin implementation libs.bundles.hilt kapt libs.bundles.hiltkapt diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/HomeScreen.kt b/app/src/main/java/no/nordicsemi/android/nrftoolbox/HomeScreen.kt index 826c1bba..16d5e6af 100644 --- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/HomeScreen.kt +++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/HomeScreen.kt @@ -1,6 +1,7 @@ package no.nordicsemi.android.nrftoolbox import android.app.Activity +import android.os.ParcelUuid import androidx.activity.OnBackPressedCallback import androidx.activity.compose.BackHandler import androidx.activity.compose.LocalOnBackPressedDispatcherOwner @@ -15,6 +16,7 @@ import androidx.compose.ui.platform.LocalLifecycleOwner import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController @@ -32,6 +34,7 @@ import no.nordicsemi.ui.scanner.navigation.view.FindDeviceScreen @Composable internal fun HomeScreen() { val navController = rememberNavController() + val deviceHolder: HomeViewModel = hiltViewModel() val activity = LocalContext.current as Activity BackHandler { @@ -46,17 +49,56 @@ internal fun HomeScreen() { NavHost(navController = navController, startDestination = NavDestination.HOME.id) { composable(NavDestination.HOME.id) { - FindDeviceScreen() - HomeView { goHome() } + HomeView { navController.navigate(it.id) } + } + composable(NavDestination.CSC.id) { + FindDeviceScreen(ParcelUuid(NavDestination.CSC.uuid)) { + deviceHolder.onDeviceSelected(it) + CSCScreen { goHome() } + } + } + composable(NavDestination.HRS.id) { + FindDeviceScreen(ParcelUuid(NavDestination.HRS.uuid)) { + deviceHolder.onDeviceSelected(it) + HRSScreen { goHome() } + } + } + composable(NavDestination.HTS.id) { + FindDeviceScreen(ParcelUuid(NavDestination.HTS.uuid)) { + deviceHolder.onDeviceSelected(it) + HTSScreen { goHome() } + } + } + composable(NavDestination.GLS.id) { + FindDeviceScreen(ParcelUuid(NavDestination.GLS.uuid)) { + deviceHolder.onDeviceSelected(it) + GLSScreen { goHome() } + } + } + composable(NavDestination.BPS.id) { + FindDeviceScreen(ParcelUuid(NavDestination.BPS.uuid)) { + deviceHolder.onDeviceSelected(it) + BPSScreen { goHome() } + } + } + composable(NavDestination.PRX.id) { + FindDeviceScreen(ParcelUuid(NavDestination.PRX.uuid)) { + deviceHolder.onDeviceSelected(it) + PRXScreen { goHome() } + } + } + composable(NavDestination.RSCS.id) { + FindDeviceScreen(ParcelUuid(NavDestination.RSCS.uuid)) { + deviceHolder.onDeviceSelected(it) + RSCSScreen { goHome() } + } + } + composable(NavDestination.CGMS.id) { + FindDeviceScreen(ParcelUuid(NavDestination.CGMS.uuid)) { + deviceHolder.onDeviceSelected(it) + CGMScreen { goHome() } + } } - composable(NavDestination.CSC.id) { CSCScreen { goHome() } } - composable(NavDestination.HRS.id) { HRSScreen { goHome() } } - composable(NavDestination.HTS.id) { HTSScreen { goHome() } } - composable(NavDestination.GLS.id) { GLSScreen { goHome() } } - composable(NavDestination.BPS.id) { BPSScreen { goHome() } } - composable(NavDestination.PRX.id) { PRXScreen { goHome() } } - composable(NavDestination.RSCS.id) { RSCSScreen { goHome() } } - composable(NavDestination.CGMS.id) { CGMScreen { goHome() } } } } diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/HomeViewModel.kt b/app/src/main/java/no/nordicsemi/android/nrftoolbox/HomeViewModel.kt new file mode 100644 index 00000000..5fc55093 --- /dev/null +++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/HomeViewModel.kt @@ -0,0 +1,17 @@ +package no.nordicsemi.android.nrftoolbox + +import androidx.lifecycle.ViewModel +import dagger.hilt.android.lifecycle.HiltViewModel +import no.nordicsemi.android.service.SelectedBluetoothDeviceHolder +import no.nordicsemi.ui.scanner.DiscoveredBluetoothDevice +import javax.inject.Inject + +@HiltViewModel +class HomeViewModel @Inject constructor( + private val deviceHolder: SelectedBluetoothDeviceHolder +) : ViewModel() { + + fun onDeviceSelected(device: DiscoveredBluetoothDevice) { + deviceHolder.attachDevice(device.device) + } +} diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/NavDestination.kt b/app/src/main/java/no/nordicsemi/android/nrftoolbox/NavDestination.kt index fafc7fd2..d6e8374f 100644 --- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/NavDestination.kt +++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/NavDestination.kt @@ -1,15 +1,25 @@ package no.nordicsemi.android.nrftoolbox +import no.nordicsemi.android.bps.repository.BPS_SERVICE_UUID +import no.nordicsemi.android.cgms.repository.CGMS_SERVICE_UUID +import no.nordicsemi.android.csc.service.CYCLING_SPEED_AND_CADENCE_SERVICE_UUID +import no.nordicsemi.android.gls.repository.GLS_SERVICE_UUID +import no.nordicsemi.android.hrs.service.HR_SERVICE_UUID +import no.nordicsemi.android.hts.service.HT_SERVICE_UUID +import no.nordicsemi.android.prx.service.PRX_SERVICE_UUID +import no.nordicsemi.android.rscs.service.RSCS_SERVICE_UUID +import java.util.* + const val ARGS_KEY = "args" -enum class NavDestination(val id: String, val pairingRequired: Boolean) { - HOME("home-screen", false), - CSC("csc-screen", false), - HRS("hrs-screen", false), - HTS("hts-screen", false), - GLS("gls-screen", true), - BPS("bps-screen", false), - PRX("prx-screen", true), - RSCS("rscs-screen", false), - CGMS("cgms-screen", false); +enum class NavDestination(val id: String, val uuid: UUID?, val pairingRequired: Boolean) { + HOME("home-screen", null, false), + CSC("csc-screen", CYCLING_SPEED_AND_CADENCE_SERVICE_UUID, false), + HRS("hrs-screen", HR_SERVICE_UUID, false), + HTS("hts-screen", HT_SERVICE_UUID, false), + GLS("gls-screen", GLS_SERVICE_UUID, true), + BPS("bps-screen", BPS_SERVICE_UUID, false), + PRX("prx-screen", PRX_SERVICE_UUID, true), + RSCS("rscs-screen", RSCS_SERVICE_UUID, false), + CGMS("cgms-screen", CGMS_SERVICE_UUID, false); } diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/NrfToolboxApplication.kt b/app/src/main/java/no/nordicsemi/android/nrftoolbox/NrfToolboxApplication.kt index ce115ffb..8a02680e 100644 --- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/NrfToolboxApplication.kt +++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/NrfToolboxApplication.kt @@ -2,6 +2,19 @@ package no.nordicsemi.android.nrftoolbox import android.app.Application import dagger.hilt.android.HiltAndroidApp +import no.nordicsemi.ui.scanner.scannerModule +import org.koin.android.ext.koin.androidContext +import org.koin.core.context.startKoin @HiltAndroidApp -class NrfToolboxApplication : Application() +class NrfToolboxApplication : Application() { + + override fun onCreate() { + super.onCreate() + + startKoin { + androidContext(this@NrfToolboxApplication) + modules(scannerModule) + } + } +} diff --git a/lib_theme/src/main/java/no/nordicsemi/android/theme/view/dialog/StringListDialog.kt b/lib_theme/src/main/java/no/nordicsemi/android/theme/view/dialog/StringListDialog.kt index 726d2321..3ce0d0a9 100644 --- a/lib_theme/src/main/java/no/nordicsemi/android/theme/view/dialog/StringListDialog.kt +++ b/lib_theme/src/main/java/no/nordicsemi/android/theme/view/dialog/StringListDialog.kt @@ -13,12 +13,12 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.verticalScroll +import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp @@ -38,6 +38,7 @@ fun StringListDialog(config: StringListDialogConfig) { fun StringListView(config: StringListDialogConfig) { Card( modifier = Modifier.height(300.dp), + backgroundColor = MaterialTheme.colorScheme.surfaceVariant, shape = RoundedCornerShape(10.dp), elevation = 0.dp ) { diff --git a/profile_cgms/src/main/java/no/nordicsemi/android/cgms/repository/CGMManager.kt b/profile_cgms/src/main/java/no/nordicsemi/android/cgms/repository/CGMManager.kt index a915ab82..f754bae6 100644 --- a/profile_cgms/src/main/java/no/nordicsemi/android/cgms/repository/CGMManager.kt +++ b/profile_cgms/src/main/java/no/nordicsemi/android/cgms/repository/CGMManager.kt @@ -54,7 +54,7 @@ import no.nordicsemi.android.service.BatteryManager import java.util.* /** Cycling Speed and Cadence service UUID. */ -val CGMS_UUID = UUID.fromString("0000181F-0000-1000-8000-00805f9b34fb") +val CGMS_SERVICE_UUID = UUID.fromString("0000181F-0000-1000-8000-00805f9b34fb") private val CGM_STATUS_UUID = UUID.fromString("00002AA9-0000-1000-8000-00805f9b34fb") private val CGM_FEATURE_UUID = UUID.fromString("00002AA8-0000-1000-8000-00805f9b34fb") private val CGM_MEASUREMENT_UUID = UUID.fromString("00002AA7-0000-1000-8000-00805f9b34fb") @@ -378,7 +378,7 @@ internal class CGMManager( } override fun isRequiredServiceSupported(gatt: BluetoothGatt): Boolean { - val service = gatt.getService(CGMS_UUID) + val service = gatt.getService(CGMS_SERVICE_UUID) if (service != null) { cgmStatusCharacteristic = service.getCharacteristic(CGM_STATUS_UUID) cgmFeatureCharacteristic = service.getCharacteristic(CGM_FEATURE_UUID) diff --git a/profile_prx/src/main/java/no/nordicsemi/android/prx/service/PRXManager.kt b/profile_prx/src/main/java/no/nordicsemi/android/prx/service/PRXManager.kt index 7b39a5f7..484856ed 100644 --- a/profile_prx/src/main/java/no/nordicsemi/android/prx/service/PRXManager.kt +++ b/profile_prx/src/main/java/no/nordicsemi/android/prx/service/PRXManager.kt @@ -41,7 +41,7 @@ import java.util.* val LINK_LOSS_SERVICE_UUID = UUID.fromString("00001803-0000-1000-8000-00805f9b34fb") /** Immediate Alert service UUID. */ -val IMMEDIATE_ALERT_SERVICE_UUID = UUID.fromString("00001802-0000-1000-8000-00805f9b34fb") +val PRX_SERVICE_UUID = UUID.fromString("00001802-0000-1000-8000-00805f9b34fb") /** Alert Level characteristic UUID. */ val ALERT_LEVEL_CHARACTERISTIC_UUID = UUID.fromString("00002A06-0000-1000-8000-00805f9b34fb") @@ -97,7 +97,7 @@ internal class PRXManager( } override fun onServerReady(server: BluetoothGattServer) { - val immediateAlertService = server.getService(IMMEDIATE_ALERT_SERVICE_UUID) + val immediateAlertService = server.getService(PRX_SERVICE_UUID) if (immediateAlertService != null) { localAlertLevelCharacteristic = immediateAlertService.getCharacteristic( ALERT_LEVEL_CHARACTERISTIC_UUID @@ -118,7 +118,7 @@ internal class PRXManager( override fun isOptionalServiceSupported(gatt: BluetoothGatt): Boolean { super.isOptionalServiceSupported(gatt) - val iaService = gatt.getService(IMMEDIATE_ALERT_SERVICE_UUID) + val iaService = gatt.getService(PRX_SERVICE_UUID) if (iaService != null) { alertLevelCharacteristic = iaService.getCharacteristic( ALERT_LEVEL_CHARACTERISTIC_UUID diff --git a/settings.gradle b/settings.gradle index a7e90f1c..36eba593 100644 --- a/settings.gradle +++ b/settings.gradle @@ -6,6 +6,7 @@ dependencyResolutionManagement { google() maven { url 'https://jitpack.io' } mavenCentral() + mavenLocal() jcenter() // Warning: this repository is going to shut down soon } @@ -15,6 +16,7 @@ dependencyResolutionManagement { alias('nordic-ble-common').to('no.nordicsemi.android:ble-common:2.3.1') alias('nordic-log').to('no.nordicsemi.android:log:2.3.0') alias('nordic-scanner').to('no.nordicsemi.android.support.v18:scanner:1.5.0') + alias('nordic-ui-scanner').to('no.nordicsemi.android.common:ui-scanner:1.0.0') alias('localbroadcastmanager').to('androidx.localbroadcastmanager:localbroadcastmanager:1.0.0') alias('material').to('com.google.android.material:material:1.5.0-beta01') @@ -44,6 +46,11 @@ dependencyResolutionManagement { bundle('hilt', ['hilt-android', 'hilt-compose', 'hilt-lifecycle']) bundle('hiltkapt', ['hilt-compiler', 'hilt-lifecyclecompiler']) + version('koin', '3.1.2') + alias('koin-android').to('io.insert-koin', 'koin-android').versionRef('koin') + alias('koin-compose').to('io.insert-koin', 'koin-androidx-compose').versionRef('koin') + bundle('koin', ['koin-android', 'koin-compose']) + alias('kotlin-coroutines').to('org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2') alias('google-permissions').to('com.google.accompanist:accompanist-permissions:0.18.0') alias('chart').to('com.github.PhilJay:MPAndroidChart:v3.1.0')