diff --git a/app/build.gradle.kts b/app/build.gradle.kts index ef135bbec..ab4e1bc3c 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -66,7 +66,7 @@ dependencies { implementation(libs.nordic.theme) implementation(libs.nordic.navigation) implementation(libs.nordic.blek.uiscanner) - implementation(libs.nordic.uilogger) + implementation(libs.nordic.logger) implementation(libs.nordic.permissions.ble) implementation(libs.nordic.analytics) @@ -79,4 +79,8 @@ dependencies { implementation(libs.androidx.lifecycle.runtime.compose) implementation(libs.androidx.hilt.navigation.compose) + + // Timber & SLF4J + implementation (libs.slf4j.timber) + implementation(libs.nordic.log.timber) } diff --git a/app/src/debug/java/no/nordicsemi/android/nrftoolbox/NrfToolboxApplication.kt b/app/src/debug/java/no/nordicsemi/android/nrftoolbox/NrfToolboxApplication.kt index 835d019f2..9379a68bd 100644 --- a/app/src/debug/java/no/nordicsemi/android/nrftoolbox/NrfToolboxApplication.kt +++ b/app/src/debug/java/no/nordicsemi/android/nrftoolbox/NrfToolboxApplication.kt @@ -37,6 +37,7 @@ import no.nordicsemi.android.analytics.AppAnalytics import no.nordicsemi.android.analytics.AppOpenEvent import no.nordicsemi.android.gls.GLSServer import no.nordicsemi.android.uart.UartServer +import timber.log.Timber import javax.inject.Inject @HiltAndroidApp @@ -58,5 +59,7 @@ class NrfToolboxApplication : Application() { uartServer.start(this) glsServer.start(this) + + Timber.plant(Timber.DebugTree()) } } diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/AppModule.kt b/app/src/main/java/no/nordicsemi/android/nrftoolbox/AppModule.kt deleted file mode 100644 index 0e242fad4..000000000 --- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/AppModule.kt +++ /dev/null @@ -1,21 +0,0 @@ -package no.nordicsemi.android.nrftoolbox - -import android.content.Context -import dagger.Module -import dagger.Provides -import dagger.hilt.InstallIn -import dagger.hilt.android.qualifiers.ApplicationContext -import dagger.hilt.components.SingletonComponent -import no.nordicsemi.android.common.logger.BleLogger -import no.nordicsemi.android.common.logger.DefaultConsoleLogger - -@Suppress("unused") -@Module -@InstallIn(SingletonComponent::class) -internal class AppModule { - - @Provides - fun provideNordicLogger( - @ApplicationContext context: Context - ): BleLogger = DefaultConsoleLogger(context) -} diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/view/FeatureButton.kt b/app/src/main/java/no/nordicsemi/android/nrftoolbox/view/FeatureButton.kt index 44be060b8..27fcd0f02 100644 --- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/view/FeatureButton.kt +++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/view/FeatureButton.kt @@ -61,7 +61,6 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import no.nordicsemi.android.nrftoolbox.R -@OptIn(ExperimentalMaterial3Api::class) @Composable fun FeatureButton( @DrawableRes iconId: Int, diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/view/HomeView.kt b/app/src/main/java/no/nordicsemi/android/nrftoolbox/view/HomeView.kt index 828306ea6..f3765adab 100644 --- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/view/HomeView.kt +++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/view/HomeView.kt @@ -34,7 +34,6 @@ package no.nordicsemi.android.nrftoolbox.view import androidx.compose.foundation.layout.* import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll -import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Scaffold import androidx.compose.material3.Text @@ -69,7 +68,6 @@ private const val DFU_LINK = "https://play.google.com/store/apps/details?id=no.n private const val LOGGER_PACKAGE_NAME = "no.nordicsemi.android.log" -@OptIn(ExperimentalMaterial3Api::class) @Composable fun HomeScreen() { val viewModel: HomeViewModel = hiltViewModel() diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/view/TitleAppBar.kt b/app/src/main/java/no/nordicsemi/android/nrftoolbox/view/TitleAppBar.kt index 50057e80f..ac65aa3b7 100644 --- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/view/TitleAppBar.kt +++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/view/TitleAppBar.kt @@ -33,8 +33,8 @@ package no.nordicsemi.android.nrftoolbox.view import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.SmallTopAppBar import androidx.compose.material3.Text +import androidx.compose.material3.TopAppBar import androidx.compose.material3.TopAppBarDefaults import androidx.compose.runtime.Composable import androidx.compose.ui.res.colorResource @@ -44,9 +44,9 @@ import no.nordicsemi.android.nrftoolbox.R @OptIn(ExperimentalMaterial3Api::class) @Composable fun TitleAppBar(text: String) { - SmallTopAppBar( + TopAppBar( title = { Text(text, maxLines = 2) }, - colors = TopAppBarDefaults.smallTopAppBarColors( + colors = TopAppBarDefaults.topAppBarColors( scrolledContainerColor = MaterialTheme.colorScheme.primary, containerColor = colorResource(id = R.color.appBarColor), titleContentColor = MaterialTheme.colorScheme.onPrimary, diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/viewmodel/HomeViewModel.kt b/app/src/main/java/no/nordicsemi/android/nrftoolbox/viewmodel/HomeViewModel.kt index 7928ab0fb..94b1434a8 100644 --- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/viewmodel/HomeViewModel.kt +++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/viewmodel/HomeViewModel.kt @@ -114,7 +114,7 @@ class HomeViewModel @Inject constructor( } fun openLogger() { - LoggerLauncher.launch(context) + LoggerLauncher.launch(context, null) } fun logEvent(event: ProfileOpenEvent) { diff --git a/app/src/release/java/no/nordicsemi/android/nrftoolbox/NrfToolboxApplication.kt b/app/src/release/java/no/nordicsemi/android/nrftoolbox/NrfToolboxApplication.kt index 05cb85b97..4654c38ee 100644 --- a/app/src/release/java/no/nordicsemi/android/nrftoolbox/NrfToolboxApplication.kt +++ b/app/src/release/java/no/nordicsemi/android/nrftoolbox/NrfToolboxApplication.kt @@ -47,5 +47,7 @@ class NrfToolboxApplication : Application() { super.onCreate() analytics.logEvent(AppOpenEvent) + + Timber.plant(Timber.DebugTree()) } } diff --git a/build.gradle.kts b/build.gradle.kts index b8e2230ab..1488c80c3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -32,20 +32,25 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { alias(libs.plugins.android.application) apply false + alias(libs.plugins.android.library) apply false + alias(libs.plugins.compose.compiler) apply false + alias(libs.plugins.kotlin.android) apply false + alias(libs.plugins.kotlin.parcelize) apply false + alias(libs.plugins.kotlin.serialization) apply false alias(libs.plugins.kotlin.jvm) apply false alias(libs.plugins.kotlin.kapt) apply false - alias(libs.plugins.ksp) apply false - alias(libs.plugins.kotlin.serialization) apply false - alias(libs.plugins.kotlin.parcelize) apply false alias(libs.plugins.hilt) apply false alias(libs.plugins.secrets) apply false alias(libs.plugins.protobuf) apply false + alias(libs.plugins.ksp) apply false + alias(libs.plugins.google.services) apply false + alias(libs.plugins.firebase.crashlytics) apply false + + // Nordic plugins are defined in https://github.com/NordicSemiconductor/Android-Gradle-Plugins alias(libs.plugins.nordic.application) apply false alias(libs.plugins.nordic.application.compose) apply false alias(libs.plugins.nordic.library) apply false alias(libs.plugins.nordic.library.compose) apply false alias(libs.plugins.nordic.hilt) apply false alias(libs.plugins.nordic.feature) apply false - alias(libs.plugins.google.services) apply false - alias(libs.plugins.firebase.crashlytics) apply false } diff --git a/gradle.properties b/gradle.properties index cb91515fb..ed8e6c24a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -50,3 +50,5 @@ android.useAndroidX=true kotlin.code.style=official android.nonTransitiveRClass=false +# https://github.com/google/ksp/issues/1942#issuecomment-2157733096 +ksp.useKSP2=true diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 876a631cb..e5fd6cc98 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -31,7 +31,7 @@ #Mon Feb 14 14:46:55 CET 2022 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/lib_analytics/src/main/java/no/nordicsemi/android/analytics/Events.kt b/lib_analytics/src/main/java/no/nordicsemi/android/analytics/Events.kt index 3e1f196d5..16f78812e 100644 --- a/lib_analytics/src/main/java/no/nordicsemi/android/analytics/Events.kt +++ b/lib_analytics/src/main/java/no/nordicsemi/android/analytics/Events.kt @@ -35,7 +35,7 @@ import android.os.Bundle sealed class FirebaseEvent(val eventName: String, val params: Bundle?) -object AppOpenEvent : FirebaseEvent("APP_OPEN", null) +data object AppOpenEvent : FirebaseEvent("APP_OPEN", null) class ProfileOpenEvent : FirebaseEvent { diff --git a/lib_ui/build.gradle.kts b/lib_ui/build.gradle.kts index 41ca294fe..584864b27 100644 --- a/lib_ui/build.gradle.kts +++ b/lib_ui/build.gradle.kts @@ -42,7 +42,6 @@ android { } dependencies { - implementation(libs.nordic.uilogger) implementation(libs.nordic.theme) implementation(libs.nordic.logger) @@ -52,4 +51,8 @@ dependencies { implementation(libs.androidx.compose.material.iconsExtended) implementation(libs.androidx.core.ktx) implementation(libs.androidx.activity.compose) + + // Timber & SLF4J + implementation (libs.slf4j.timber) + implementation(libs.nordic.log.timber) } diff --git a/lib_ui/src/main/java/no/nordicsemi/android/ui/view/NordicLoggerFactory.kt b/lib_ui/src/main/java/no/nordicsemi/android/ui/view/NordicLoggerFactory.kt deleted file mode 100644 index 3e668674c..000000000 --- a/lib_ui/src/main/java/no/nordicsemi/android/ui/view/NordicLoggerFactory.kt +++ /dev/null @@ -1,9 +0,0 @@ -package no.nordicsemi.android.ui.view - -import android.content.Context -import no.nordicsemi.android.common.logger.BleLoggerAndLauncher - -interface NordicLoggerFactory { - - fun createNordicLogger(context: Context, profile: String?, key: String, name: String?): BleLoggerAndLauncher -} diff --git a/lib_ui/src/main/java/no/nordicsemi/android/ui/view/NordicLoggerFactoryHiltModule.kt b/lib_ui/src/main/java/no/nordicsemi/android/ui/view/NordicLoggerFactoryHiltModule.kt deleted file mode 100644 index ce8bc4a7f..000000000 --- a/lib_ui/src/main/java/no/nordicsemi/android/ui/view/NordicLoggerFactoryHiltModule.kt +++ /dev/null @@ -1,28 +0,0 @@ -package no.nordicsemi.android.ui.view - -import android.content.Context -import dagger.Module -import dagger.Provides -import dagger.hilt.InstallIn -import dagger.hilt.components.SingletonComponent -import no.nordicsemi.android.common.logger.BleLoggerAndLauncher -import no.nordicsemi.android.common.logger.DefaultBleLogger - -@Module -@InstallIn(SingletonComponent::class) -class NordicLoggerFactoryHiltModule { - - @Provides - fun createLogger(): NordicLoggerFactory { - return object : NordicLoggerFactory { - override fun createNordicLogger( - context: Context, - profile: String?, - key: String, - name: String?, - ): BleLoggerAndLauncher { - return DefaultBleLogger.create(context, profile, key, name) - } - } - } -} diff --git a/lib_ui/src/main/java/no/nordicsemi/android/ui/view/TopAppBar.kt b/lib_ui/src/main/java/no/nordicsemi/android/ui/view/TopAppBar.kt index 95b3974c9..bf06b6082 100644 --- a/lib_ui/src/main/java/no/nordicsemi/android/ui/view/TopAppBar.kt +++ b/lib_ui/src/main/java/no/nordicsemi/android/ui/view/TopAppBar.kt @@ -36,11 +36,18 @@ import androidx.compose.foundation.layout.size import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ArrowBack import androidx.compose.material.icons.filled.Close -import androidx.compose.material3.* +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.material3.TopAppBar +import androidx.compose.material3.TopAppBarDefaults import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color -import androidx.compose.ui.res.colorResource import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp @@ -51,11 +58,11 @@ import no.nordicsemi.android.ui.R @OptIn(ExperimentalMaterial3Api::class) @Composable fun CloseIconAppBar(text: String, onClick: () -> Unit) { - SmallTopAppBar( + TopAppBar( title = { Text(text, maxLines = 2) }, - colors = TopAppBarDefaults.smallTopAppBarColors( + colors = TopAppBarDefaults.topAppBarColors( scrolledContainerColor = MaterialTheme.colorScheme.primary, - containerColor = colorResource(id = R.color.appBarColor), + containerColor = MaterialTheme.colorScheme.primaryContainer, titleContentColor = MaterialTheme.colorScheme.onPrimary, actionIconContentColor = MaterialTheme.colorScheme.onPrimary, navigationIconContentColor = MaterialTheme.colorScheme.onPrimary, @@ -74,11 +81,11 @@ fun CloseIconAppBar(text: String, onClick: () -> Unit) { @OptIn(ExperimentalMaterial3Api::class) @Composable fun LoggerBackIconAppBar(text: String, onClick: () -> Unit) { - SmallTopAppBar( + TopAppBar( title = { Text(text, maxLines = 2) }, - colors = TopAppBarDefaults.smallTopAppBarColors( + colors = TopAppBarDefaults.topAppBarColors( scrolledContainerColor = MaterialTheme.colorScheme.primary, - containerColor = colorResource(id = R.color.appBarColor), + containerColor = MaterialTheme.colorScheme.primaryContainer, titleContentColor = MaterialTheme.colorScheme.onPrimary, actionIconContentColor = MaterialTheme.colorScheme.onPrimary, navigationIconContentColor = MaterialTheme.colorScheme.onPrimary, @@ -108,11 +115,11 @@ fun LoggerBackIconAppBar(text: String, onClick: () -> Unit) { @OptIn(ExperimentalMaterial3Api::class) @Composable fun BackIconAppBar(text: String, onClick: () -> Unit) { - SmallTopAppBar( + TopAppBar( title = { Text(text, maxLines = 2) }, - colors = TopAppBarDefaults.smallTopAppBarColors( + colors = TopAppBarDefaults.topAppBarColors( scrolledContainerColor = MaterialTheme.colorScheme.primary, - containerColor = colorResource(id = R.color.appBarColor), + containerColor = MaterialTheme.colorScheme.primaryContainer, titleContentColor = MaterialTheme.colorScheme.onPrimary, actionIconContentColor = MaterialTheme.colorScheme.onPrimary, navigationIconContentColor = MaterialTheme.colorScheme.onPrimary, @@ -131,12 +138,17 @@ fun BackIconAppBar(text: String, onClick: () -> Unit) { @OptIn(ExperimentalMaterial3Api::class) @Composable -fun LoggerIconAppBar(text: String, onClick: () -> Unit, onDisconnectClick: () -> Unit, onLoggerClick: () -> Unit) { - SmallTopAppBar( +fun LoggerIconAppBar( + text: String, + onClick: () -> Unit, + onDisconnectClick: () -> Unit, + onLoggerClick: () -> Unit +) { + TopAppBar( title = { Text(text, maxLines = 2) }, - colors = TopAppBarDefaults.smallTopAppBarColors( + colors = TopAppBarDefaults.topAppBarColors( scrolledContainerColor = MaterialTheme.colorScheme.primary, - containerColor = colorResource(id = R.color.appBarColor), + containerColor = MaterialTheme.colorScheme.primaryContainer, titleContentColor = MaterialTheme.colorScheme.onPrimary, actionIconContentColor = MaterialTheme.colorScheme.onPrimary, navigationIconContentColor = MaterialTheme.colorScheme.onPrimary, diff --git a/profile_bps/build.gradle.kts b/profile_bps/build.gradle.kts index 6932100e4..b9a9f6637 100644 --- a/profile_bps/build.gradle.kts +++ b/profile_bps/build.gradle.kts @@ -51,7 +51,7 @@ dependencies { implementation(libs.nordic.navigation) implementation(libs.nordic.theme) - implementation(libs.nordic.uilogger) + implementation(libs.nordic.logger) implementation(libs.androidx.compose.material3) implementation(libs.androidx.compose.material.iconsExtended) @@ -60,4 +60,8 @@ dependencies { implementation(libs.androidx.lifecycle.service) implementation(libs.androidx.hilt.navigation.compose) + + // Timber & SLF4J + implementation (libs.slf4j.timber) + implementation(libs.nordic.log.timber) } diff --git a/profile_bps/src/main/java/no/nordicsemi/android/bps/viewmodel/BPSViewModel.kt b/profile_bps/src/main/java/no/nordicsemi/android/bps/viewmodel/BPSViewModel.kt index 516e6b727..660951938 100644 --- a/profile_bps/src/main/java/no/nordicsemi/android/bps/viewmodel/BPSViewModel.kt +++ b/profile_bps/src/main/java/no/nordicsemi/android/bps/viewmodel/BPSViewModel.kt @@ -53,8 +53,7 @@ import no.nordicsemi.android.bps.view.BPSViewEvent import no.nordicsemi.android.bps.view.BPSViewState import no.nordicsemi.android.bps.view.DisconnectEvent import no.nordicsemi.android.bps.view.OpenLoggerEvent -import no.nordicsemi.android.common.logger.BleLoggerAndLauncher -import no.nordicsemi.android.common.logger.DefaultBleLogger +import no.nordicsemi.android.common.logger.LoggerLauncher import no.nordicsemi.android.common.navigation.NavigationResult import no.nordicsemi.android.common.navigation.Navigator import no.nordicsemi.android.kotlin.ble.client.main.callback.ClientBleGatt @@ -67,8 +66,11 @@ import no.nordicsemi.android.kotlin.ble.profile.bps.BloodPressureMeasurementPars import no.nordicsemi.android.kotlin.ble.profile.bps.IntermediateCuffPressureParser import no.nordicsemi.android.kotlin.ble.profile.bps.data.BloodPressureMeasurementData import no.nordicsemi.android.kotlin.ble.profile.bps.data.IntermediateCuffPressureData +import no.nordicsemi.android.log.LogSession +import no.nordicsemi.android.log.timber.nRFLoggerTree import no.nordicsemi.android.toolbox.scanner.ScannerDestinationId import no.nordicsemi.android.ui.view.StringConst +import timber.log.Timber import java.util.UUID import javax.inject.Inject @@ -93,7 +95,7 @@ internal class BPSViewModel @Inject constructor( val state = _state.asStateFlow() private var client: ClientBleGatt? = null - private lateinit var logger: BleLoggerAndLauncher + private var logger: nRFLoggerTree? = null init { navigationManager.navigateTo(ScannerDestinationId, ParcelUuid(BPS_SERVICE_UUID)) @@ -113,7 +115,7 @@ internal class BPSViewModel @Inject constructor( fun onEvent(event: BPSViewEvent) { when (event) { DisconnectEvent -> onDisconnectEvent() - OpenLoggerEvent -> logger.launch() + OpenLoggerEvent -> LoggerLauncher.launch(context, logger?.session as? LogSession) } } @@ -122,12 +124,18 @@ internal class BPSViewModel @Inject constructor( navigationManager.navigateUp() } + private fun initLogger(device: ServerDevice) { + logger?.let { Timber.uproot(it) } + logger = nRFLoggerTree(context, stringConst.APP_NAME, "BPS", device.address) + .also { Timber.plant(it) } + } + private fun startGattClient(device: ServerDevice) = viewModelScope.launch { _state.value = _state.value.copy(deviceName = device.name) - logger = DefaultBleLogger.create(context, stringConst.APP_NAME, "BPS", device.address) + initLogger(device) - val client = ClientBleGatt.connect(context, device, viewModelScope, logger = logger) + val client = ClientBleGatt.connect(context, device, viewModelScope) this@BPSViewModel.client = client client.connectionStateWithStatus diff --git a/profile_cgms/build.gradle.kts b/profile_cgms/build.gradle.kts index 7fb0265c3..b03d1ff3a 100644 --- a/profile_cgms/build.gradle.kts +++ b/profile_cgms/build.gradle.kts @@ -47,7 +47,7 @@ dependencies { implementation(libs.nordic.core) implementation(libs.nordic.theme) - implementation(libs.nordic.uilogger) + implementation(libs.nordic.logger) implementation(libs.nordic.navigation) implementation(libs.nordic.blek.uiscanner) @@ -61,4 +61,8 @@ dependencies { implementation(libs.androidx.lifecycle.service) implementation(libs.androidx.hilt.navigation.compose) + + // Timber & SLF4J + implementation(libs.slf4j.timber) + implementation(libs.nordic.log.timber) } diff --git a/profile_cgms/src/main/java/no/nordicsemi/android/cgms/repository/CGMRepository.kt b/profile_cgms/src/main/java/no/nordicsemi/android/cgms/repository/CGMRepository.kt index 7ef38ebf4..7bfdea6c5 100644 --- a/profile_cgms/src/main/java/no/nordicsemi/android/cgms/repository/CGMRepository.kt +++ b/profile_cgms/src/main/java/no/nordicsemi/android/cgms/repository/CGMRepository.kt @@ -41,15 +41,17 @@ import no.nordicsemi.android.cgms.data.CGMRecordWithSequenceNumber import no.nordicsemi.android.cgms.data.CGMServiceCommand import no.nordicsemi.android.cgms.data.CGMServiceData import no.nordicsemi.android.common.core.simpleSharedFlow -import no.nordicsemi.android.common.logger.BleLoggerAndLauncher -import no.nordicsemi.android.common.logger.DefaultBleLogger +import no.nordicsemi.android.common.logger.LoggerLauncher import no.nordicsemi.android.kotlin.ble.core.ServerDevice import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionState import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionStateWithStatus import no.nordicsemi.android.kotlin.ble.profile.gls.data.RequestStatus +import no.nordicsemi.android.log.LogSession +import no.nordicsemi.android.log.timber.nRFLoggerTree import no.nordicsemi.android.service.DisconnectAndStopEvent import no.nordicsemi.android.service.ServiceManager import no.nordicsemi.android.ui.view.StringConst +import timber.log.Timber import javax.inject.Inject import javax.inject.Singleton @@ -60,7 +62,7 @@ class CGMRepository @Inject constructor( private val serviceManager: ServiceManager, private val stringConst: StringConst ) { - private var logger: BleLoggerAndLauncher? = null + private var logger: nRFLoggerTree? = null private val _data = MutableStateFlow(CGMServiceData()) internal val data = _data.asStateFlow() @@ -92,8 +94,14 @@ class CGMRepository @Inject constructor( private fun shouldClean() = !isOnScreen && !isServiceRunning + private fun initLogger(device: ServerDevice) { + logger?.let { Timber.uproot(it) } + logger = nRFLoggerTree(context, stringConst.APP_NAME, "CGM", device.address) + .also { Timber.plant(it) } + } + fun launch(device: ServerDevice) { - logger = DefaultBleLogger.create(context, stringConst.APP_NAME, "CGM", device.address) + initLogger(device) _data.value = _data.value.copy(deviceName = device.name) serviceManager.startService(CGMService::class.java, device) } @@ -124,7 +132,7 @@ class CGMRepository @Inject constructor( } fun openLogger() { - logger?.launch() + LoggerLauncher.launch(context, logger?.session as? LogSession) } fun log(priority: Int, message: String) { diff --git a/profile_cgms/src/main/java/no/nordicsemi/android/cgms/repository/CGMService.kt b/profile_cgms/src/main/java/no/nordicsemi/android/cgms/repository/CGMService.kt index e20c50bc8..6f30f868f 100644 --- a/profile_cgms/src/main/java/no/nordicsemi/android/cgms/repository/CGMService.kt +++ b/profile_cgms/src/main/java/no/nordicsemi/android/cgms/repository/CGMService.kt @@ -132,7 +132,7 @@ internal class CGMService : NotificationService() { } private fun startGattClient(device: ServerDevice) = lifecycleScope.launch { - val client = ClientBleGatt.connect(this@CGMService, device, lifecycleScope, logger = { p, s -> repository.log(p, s) }) + val client = ClientBleGatt.connect(this@CGMService, device, lifecycleScope) this@CGMService.client = client client.connectionStateWithStatus diff --git a/profile_csc/build.gradle.kts b/profile_csc/build.gradle.kts index 63c49608a..e6f35db2a 100644 --- a/profile_csc/build.gradle.kts +++ b/profile_csc/build.gradle.kts @@ -46,8 +46,9 @@ dependencies { implementation(project(":lib_utils")) implementation(libs.nordic.core) + implementation(libs.nordic.ui) implementation(libs.nordic.theme) - implementation(libs.nordic.uilogger) + implementation(libs.nordic.logger) implementation(libs.nordic.navigation) implementation(libs.nordic.blek.client) @@ -61,4 +62,8 @@ dependencies { implementation(libs.androidx.lifecycle.service) implementation(libs.androidx.hilt.navigation.compose) + + // Timber & SLF4J + implementation (libs.slf4j.timber) + implementation(libs.nordic.log.timber) } diff --git a/profile_csc/src/main/java/no/nordicsemi/android/csc/repository/CSCRepository.kt b/profile_csc/src/main/java/no/nordicsemi/android/csc/repository/CSCRepository.kt index 2964f6645..81cd6b42c 100644 --- a/profile_csc/src/main/java/no/nordicsemi/android/csc/repository/CSCRepository.kt +++ b/profile_csc/src/main/java/no/nordicsemi/android/csc/repository/CSCRepository.kt @@ -38,8 +38,7 @@ import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.map import no.nordicsemi.android.common.core.simpleSharedFlow -import no.nordicsemi.android.common.logger.BleLoggerAndLauncher -import no.nordicsemi.android.common.logger.DefaultBleLogger +import no.nordicsemi.android.common.logger.LoggerLauncher import no.nordicsemi.android.csc.data.CSCServiceData import no.nordicsemi.android.csc.data.SpeedUnit import no.nordicsemi.android.kotlin.ble.core.ServerDevice @@ -48,9 +47,12 @@ import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionStateWithStatus import no.nordicsemi.android.kotlin.ble.profile.csc.data.CSCData import no.nordicsemi.android.kotlin.ble.profile.csc.data.WheelSize import no.nordicsemi.android.kotlin.ble.profile.csc.data.WheelSizes +import no.nordicsemi.android.log.LogSession +import no.nordicsemi.android.log.timber.nRFLoggerTree import no.nordicsemi.android.service.DisconnectAndStopEvent import no.nordicsemi.android.service.ServiceManager import no.nordicsemi.android.ui.view.StringConst +import timber.log.Timber import javax.inject.Inject import javax.inject.Singleton @@ -61,7 +63,7 @@ class CSCRepository @Inject constructor( private val serviceManager: ServiceManager, private val stringConst: StringConst ) { - private var logger: BleLoggerAndLauncher? = null + private var logger: nRFLoggerTree? = null private val _wheelSize = MutableStateFlow(WheelSizes.default) internal val wheelSize = _wheelSize.asStateFlow() @@ -91,8 +93,14 @@ class CSCRepository @Inject constructor( private fun shouldClean() = !isOnScreen && !isServiceRunning + private fun initLogger(device: ServerDevice) { + logger?.let { Timber.uproot(it) } + logger = nRFLoggerTree(context, stringConst.APP_NAME, "CSC", device.address) + .also { Timber.plant(it) } + } + fun launch(device: ServerDevice) { - logger = DefaultBleLogger.create(context, stringConst.APP_NAME, "CSC", device.address) + initLogger(device) _data.value = _data.value.copy(deviceName = device.name) serviceManager.startService(CSCService::class.java, device) } @@ -123,7 +131,7 @@ class CSCRepository @Inject constructor( } fun openLogger() { - logger?.launch() + LoggerLauncher.launch(context, logger?.session as? LogSession) } fun log(priority: Int, message: String) { diff --git a/profile_csc/src/main/java/no/nordicsemi/android/csc/repository/CSCService.kt b/profile_csc/src/main/java/no/nordicsemi/android/csc/repository/CSCService.kt index 8c62e19af..b07bedf5d 100644 --- a/profile_csc/src/main/java/no/nordicsemi/android/csc/repository/CSCService.kt +++ b/profile_csc/src/main/java/no/nordicsemi/android/csc/repository/CSCService.kt @@ -86,7 +86,7 @@ internal class CSCService : NotificationService() { } private fun startGattClient(device: ServerDevice) = lifecycleScope.launch { - val client = ClientBleGatt.connect(this@CSCService, device, lifecycleScope, logger = { p, s -> repository.log(p, s) }) + val client = ClientBleGatt.connect(this@CSCService, device, lifecycleScope) this@CSCService.client = client client.connectionStateWithStatus diff --git a/profile_csc/src/main/java/no/nordicsemi/android/csc/view/CSCContentView.kt b/profile_csc/src/main/java/no/nordicsemi/android/csc/view/CSCContentView.kt index 2140926a8..74c31f56b 100644 --- a/profile_csc/src/main/java/no/nordicsemi/android/csc/view/CSCContentView.kt +++ b/profile_csc/src/main/java/no/nordicsemi/android/csc/view/CSCContentView.kt @@ -47,7 +47,7 @@ import androidx.compose.ui.res.stringArrayResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp -import no.nordicsemi.android.common.theme.view.RadioButtonGroup +import no.nordicsemi.android.common.ui.view.RadioButtonGroup import no.nordicsemi.android.csc.R import no.nordicsemi.android.csc.data.CSCServiceData import no.nordicsemi.android.csc.data.SpeedUnit @@ -107,8 +107,10 @@ private fun SettingsSection( Column( horizontalAlignment = Alignment.CenterHorizontally ) { - SectionTitle(icon = Icons.Default.Settings, - title = stringResource(R.string.csc_settings)) + SectionTitle( + icon = Icons.Default.Settings, + title = stringResource(R.string.csc_settings) + ) Spacer(modifier = Modifier.height(16.dp)) diff --git a/profile_csc/src/main/java/no/nordicsemi/android/csc/view/CSCMappers.kt b/profile_csc/src/main/java/no/nordicsemi/android/csc/view/CSCMappers.kt index e87358f2f..a70b6d35d 100644 --- a/profile_csc/src/main/java/no/nordicsemi/android/csc/view/CSCMappers.kt +++ b/profile_csc/src/main/java/no/nordicsemi/android/csc/view/CSCMappers.kt @@ -31,8 +31,8 @@ package no.nordicsemi.android.csc.view -import no.nordicsemi.android.common.theme.view.RadioButtonItem -import no.nordicsemi.android.common.theme.view.RadioGroupViewEntity +import no.nordicsemi.android.common.ui.view.RadioButtonItem +import no.nordicsemi.android.common.ui.view.RadioGroupViewEntity import no.nordicsemi.android.csc.data.SpeedUnit import no.nordicsemi.android.kotlin.ble.profile.csc.data.CSCData import java.util.Locale @@ -52,29 +52,29 @@ internal fun CSCData.speedWithSpeedUnit(speedUnit: SpeedUnit): Float { internal fun CSCData.displaySpeed(speedUnit: SpeedUnit): String { val speedWithUnit = speedWithSpeedUnit(speedUnit) return when (speedUnit) { - SpeedUnit.M_S -> String.format("%.1f m/s", speedWithUnit) - SpeedUnit.KM_H -> String.format("%.1f km/h", speedWithUnit) - SpeedUnit.MPH -> String.format("%.1f mph", speedWithUnit) + SpeedUnit.M_S -> String.format(Locale.US, "%.1f m/s", speedWithUnit) + SpeedUnit.KM_H -> String.format(Locale.US, "%.1f km/h", speedWithUnit) + SpeedUnit.MPH -> String.format(Locale.US, "%.1f mph", speedWithUnit) } } internal fun CSCData.displayCadence(): String { - return String.format("%.0f RPM", cadence) + return String.format(Locale.US, "%.0f RPM", cadence) } internal fun CSCData.displayDistance(speedUnit: SpeedUnit): String { return when (speedUnit) { - SpeedUnit.M_S -> String.format("%.0f m", distance) - SpeedUnit.KM_H -> String.format("%.0f m", distance) - SpeedUnit.MPH -> String.format("%.0f yd", distance.toYards()) + SpeedUnit.M_S -> String.format(Locale.US, "%.0f m", distance) + SpeedUnit.KM_H -> String.format(Locale.US, "%.0f m", distance) + SpeedUnit.MPH -> String.format(Locale.US, "%.0f yd", distance.toYards()) } } internal fun CSCData.displayTotalDistance(speedUnit: SpeedUnit): String { return when (speedUnit) { - SpeedUnit.M_S -> String.format("%.2f m", totalDistance) - SpeedUnit.KM_H -> String.format("%.2f km", totalDistance.toKilometers()) - SpeedUnit.MPH -> String.format("%.2f mile", totalDistance.toMiles()) + SpeedUnit.M_S -> String.format(Locale.US, "%.2f m", totalDistance) + SpeedUnit.KM_H -> String.format(Locale.US, "%.2f km", totalDistance.toKilometers()) + SpeedUnit.MPH -> String.format(Locale.US, "%.2f mile", totalDistance.toMiles()) } } @@ -93,7 +93,7 @@ internal fun String.toSpeedUnit(): SpeedUnit { internal fun SpeedUnit.temperatureSettingsItems(): RadioGroupViewEntity { return RadioGroupViewEntity( - SpeedUnit.values().map { createRadioButtonItem(it, this) } + SpeedUnit.entries.toTypedArray().map { createRadioButtonItem(it, this) } ) } diff --git a/profile_gls/build.gradle.kts b/profile_gls/build.gradle.kts index b684a5d1e..f49b3b98c 100644 --- a/profile_gls/build.gradle.kts +++ b/profile_gls/build.gradle.kts @@ -45,9 +45,10 @@ dependencies { implementation(project(":lib_ui")) implementation(project(":lib_utils")) + implementation(libs.nordic.core) implementation(libs.nordic.theme) implementation(libs.nordic.navigation) - implementation(libs.nordic.uilogger) + implementation(libs.nordic.logger) implementation(libs.nordic.blek.client) implementation(libs.nordic.blek.profile) @@ -65,6 +66,10 @@ dependencies { implementation(libs.androidx.hilt.navigation.compose) + // Timber & SLF4J + implementation (libs.slf4j.timber) + implementation(libs.nordic.log.timber) + testImplementation(libs.hilt.android.testing) kaptTest(libs.hilt.compiler) testImplementation(libs.androidx.test.rules) @@ -73,7 +78,7 @@ dependencies { testImplementation(libs.test.mockk) testImplementation(libs.androidx.test.ext) testImplementation(libs.kotlinx.coroutines.test) - testImplementation(libs.test.slf4j.simple) + testImplementation(libs.slf4j.simple) testImplementation(libs.test.robolectric) testImplementation(libs.kotlin.junit) } diff --git a/profile_gls/src/main/java/no/nordicsemi/android/gls/GLSServer.kt b/profile_gls/src/main/java/no/nordicsemi/android/gls/GLSServer.kt index c6cce20db..8799c40f2 100644 --- a/profile_gls/src/main/java/no/nordicsemi/android/gls/GLSServer.kt +++ b/profile_gls/src/main/java/no/nordicsemi/android/gls/GLSServer.kt @@ -3,16 +3,12 @@ package no.nordicsemi.android.gls import android.annotation.SuppressLint import android.content.Context import android.os.ParcelUuid -import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.delay import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.mapNotNull import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch -import no.nordicsemi.android.common.core.DataByteArray -import no.nordicsemi.android.common.logger.BleLogger -import no.nordicsemi.android.common.logger.DefaultConsoleLogger import no.nordicsemi.android.gls.main.viewmodel.BATTERY_LEVEL_CHARACTERISTIC_UUID import no.nordicsemi.android.gls.main.viewmodel.BATTERY_SERVICE_UUID import no.nordicsemi.android.gls.main.viewmodel.GLS_SERVICE_UUID @@ -26,6 +22,7 @@ import no.nordicsemi.android.kotlin.ble.core.advertiser.BleAdvertisingData import no.nordicsemi.android.kotlin.ble.core.advertiser.BleAdvertisingSettings import no.nordicsemi.android.kotlin.ble.core.data.BleGattPermission import no.nordicsemi.android.kotlin.ble.core.data.BleGattProperty +import no.nordicsemi.android.kotlin.ble.core.data.util.DataByteArray import no.nordicsemi.android.kotlin.ble.profile.gls.RecordAccessControlPointInputParser import no.nordicsemi.android.kotlin.ble.server.main.ServerBleGatt import no.nordicsemi.android.kotlin.ble.server.main.service.ServerBleGattCharacteristic @@ -42,9 +39,6 @@ private const val STANDARD_DELAY = 1000L @Singleton class GLSServer @Inject constructor( private val scope: CoroutineScope, - @ApplicationContext - private val context: Context, - private val logger: BleLogger = DefaultConsoleLogger(context), ) { private lateinit var server: ServerBleGatt @@ -197,7 +191,6 @@ class GLSServer @Inject constructor( config = arrayOf(serviceConfig, batteryService), mock = device, scope = scope, - logger = { _, log -> println(log) } ) BleAdvertiser.create(context) diff --git a/profile_gls/src/main/java/no/nordicsemi/android/gls/main/viewmodel/GLSViewModel.kt b/profile_gls/src/main/java/no/nordicsemi/android/gls/main/viewmodel/GLSViewModel.kt index aaa32f2e5..547206775 100644 --- a/profile_gls/src/main/java/no/nordicsemi/android/gls/main/viewmodel/GLSViewModel.kt +++ b/profile_gls/src/main/java/no/nordicsemi/android/gls/main/viewmodel/GLSViewModel.kt @@ -32,10 +32,9 @@ package no.nordicsemi.android.gls.main.viewmodel import android.annotation.SuppressLint -import android.app.Application import android.content.Context import android.os.ParcelUuid -import androidx.lifecycle.AndroidViewModel +import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.qualifiers.ApplicationContext @@ -50,7 +49,7 @@ import kotlinx.coroutines.launch import no.nordicsemi.android.analytics.AppAnalytics import no.nordicsemi.android.analytics.Profile import no.nordicsemi.android.analytics.ProfileConnectedEvent -import no.nordicsemi.android.common.logger.BleLoggerAndLauncher +import no.nordicsemi.android.common.logger.LoggerLauncher import no.nordicsemi.android.common.navigation.NavigationResult import no.nordicsemi.android.common.navigation.Navigator import no.nordicsemi.android.gls.GlsDetailsDestinationId @@ -80,11 +79,13 @@ import no.nordicsemi.android.kotlin.ble.profile.gls.data.RequestStatus import no.nordicsemi.android.kotlin.ble.profile.gls.data.ResponseData import no.nordicsemi.android.kotlin.ble.profile.racp.RACPOpCode import no.nordicsemi.android.kotlin.ble.profile.racp.RACPResponseCode +import no.nordicsemi.android.log.LogSession +import no.nordicsemi.android.log.timber.nRFLoggerTree import no.nordicsemi.android.toolbox.scanner.ScannerDestinationId -import no.nordicsemi.android.ui.view.NordicLoggerFactory import no.nordicsemi.android.ui.view.StringConst import no.nordicsemi.android.utils.tryOrLog -import java.util.* +import timber.log.Timber +import java.util.UUID import javax.inject.Inject val GLS_SERVICE_UUID: UUID = UUID.fromString("00001808-0000-1000-8000-00805f9b34fb") @@ -100,15 +101,14 @@ val BATTERY_LEVEL_CHARACTERISTIC_UUID = UUID.fromString("00002A19-0000-1000-8000 @SuppressLint("MissingPermission") @HiltViewModel internal class GLSViewModel @Inject constructor( - @ApplicationContext context: Context, + @ApplicationContext private val context: Context, private val navigationManager: Navigator, private val analytics: AppAnalytics, private val stringConst: StringConst, - private val loggerFactory: NordicLoggerFactory -) : AndroidViewModel(context as Application) { +) : ViewModel() { private var client: ClientBleGatt? = null - private lateinit var logger: BleLoggerAndLauncher + private var logger: nRFLoggerTree? = null private lateinit var glucoseMeasurementCharacteristic: ClientBleGattCharacteristic private lateinit var recordAccessControlPointCharacteristic: ClientBleGattCharacteristic @@ -136,7 +136,7 @@ internal class GLSViewModel @Inject constructor( fun onEvent(event: GLSScreenViewEvent) { when (event) { - OpenLoggerEvent -> logger.launch() + OpenLoggerEvent -> LoggerLauncher.launch(context, logger?.session as? LogSession) is OnWorkingModeSelected -> onEvent(event) is OnGLSRecordClick -> navigateToDetails(event.record) DisconnectEvent -> onDisconnectEvent() @@ -167,10 +167,9 @@ internal class GLSViewModel @Inject constructor( private fun startGattClient(device: ServerDevice) = viewModelScope.launch { _state.value = _state.value.copy(deviceName = device.name) + initLogger(device) - logger = loggerFactory.createNordicLogger(getApplication(), stringConst.APP_NAME, "GLS", device.address) - - val client = ClientBleGatt.connect(getApplication(), device, viewModelScope, logger = logger) + val client = ClientBleGatt.connect(context, device, viewModelScope) this@GLSViewModel.client = client client.waitForBonding() @@ -333,4 +332,10 @@ internal class GLSViewModel @Inject constructor( _state.value = _state.value.copyWithNewRequestStatus(RequestStatus.FAILED) } } + + private fun initLogger(device: ServerDevice) { + logger?.let { Timber.uproot(it) } + logger = nRFLoggerTree(context, stringConst.APP_NAME, "GLS", device.address) + .also { Timber.plant(it) } + } } diff --git a/profile_hrs/build.gradle.kts b/profile_hrs/build.gradle.kts index 4a3c80a45..48c2e8ba4 100644 --- a/profile_hrs/build.gradle.kts +++ b/profile_hrs/build.gradle.kts @@ -48,7 +48,7 @@ dependencies { implementation(libs.nordic.core) implementation(libs.nordic.theme) implementation(libs.nordic.navigation) - implementation(libs.nordic.uilogger) + implementation(libs.nordic.logger) implementation(libs.nordic.blek.client) implementation(libs.nordic.blek.profile) @@ -63,4 +63,8 @@ dependencies { implementation(libs.androidx.lifecycle.service) implementation(libs.androidx.hilt.navigation.compose) + + // Timber & SLF4J + implementation (libs.slf4j.timber) + implementation(libs.nordic.log.timber) } diff --git a/profile_hrs/src/main/java/no/nordicsemi/android/hrs/service/HRSRepository.kt b/profile_hrs/src/main/java/no/nordicsemi/android/hrs/service/HRSRepository.kt index 220bd8439..ec6acc4f9 100644 --- a/profile_hrs/src/main/java/no/nordicsemi/android/hrs/service/HRSRepository.kt +++ b/profile_hrs/src/main/java/no/nordicsemi/android/hrs/service/HRSRepository.kt @@ -38,16 +38,18 @@ import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.map import no.nordicsemi.android.common.core.simpleSharedFlow -import no.nordicsemi.android.common.logger.BleLoggerAndLauncher -import no.nordicsemi.android.common.logger.DefaultBleLogger +import no.nordicsemi.android.common.logger.LoggerLauncher import no.nordicsemi.android.hrs.data.HRSServiceData import no.nordicsemi.android.kotlin.ble.core.ServerDevice import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionState import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionStateWithStatus import no.nordicsemi.android.kotlin.ble.profile.hrs.data.HRSData +import no.nordicsemi.android.log.LogSession +import no.nordicsemi.android.log.timber.nRFLoggerTree import no.nordicsemi.android.service.DisconnectAndStopEvent import no.nordicsemi.android.service.ServiceManager import no.nordicsemi.android.ui.view.StringConst +import timber.log.Timber import javax.inject.Inject import javax.inject.Singleton @@ -58,7 +60,7 @@ class HRSRepository @Inject constructor( private val serviceManager: ServiceManager, private val stringConst: StringConst ) { - private var logger: BleLoggerAndLauncher? = null + private var logger: nRFLoggerTree? = null private val _data = MutableStateFlow(HRSServiceData()) internal val data = _data.asStateFlow() @@ -85,8 +87,14 @@ class HRSRepository @Inject constructor( private fun shouldClean() = !isOnScreen && !isServiceRunning + private fun initLogger(device: ServerDevice) { + logger?.let { Timber.uproot(it) } + logger = nRFLoggerTree(context, stringConst.APP_NAME, "HRS", device.address) + .also { Timber.plant(it) } + } + fun launch(device: ServerDevice) { - logger = DefaultBleLogger.create(context, stringConst.APP_NAME, "HRS", device.address) + initLogger(device) _data.value = _data.value.copy(deviceName = device.name) serviceManager.startService(HRSService::class.java, device) } @@ -117,7 +125,7 @@ class HRSRepository @Inject constructor( } fun openLogger() { - logger?.launch() + LoggerLauncher.launch(context, logger?.session as? LogSession) } fun log(priority: Int, message: String) { diff --git a/profile_hrs/src/main/java/no/nordicsemi/android/hrs/service/HRSService.kt b/profile_hrs/src/main/java/no/nordicsemi/android/hrs/service/HRSService.kt index 0855a0c09..b17857746 100644 --- a/profile_hrs/src/main/java/no/nordicsemi/android/hrs/service/HRSService.kt +++ b/profile_hrs/src/main/java/no/nordicsemi/android/hrs/service/HRSService.kt @@ -88,7 +88,7 @@ internal class HRSService : NotificationService() { } private fun startGattClient(device: ServerDevice) = lifecycleScope.launch { - val client = ClientBleGatt.connect(this@HRSService, device, lifecycleScope, logger = { p, s -> repository.log(p, s) }) + val client = ClientBleGatt.connect(this@HRSService, device, lifecycleScope) this@HRSService.client = client client.waitForBonding() diff --git a/profile_hts/build.gradle.kts b/profile_hts/build.gradle.kts index 1f4b79cf6..a4dde0012 100644 --- a/profile_hts/build.gradle.kts +++ b/profile_hts/build.gradle.kts @@ -50,9 +50,10 @@ dependencies { implementation(libs.nordic.blek.uiscanner) implementation(libs.nordic.core) + implementation(libs.nordic.ui) implementation(libs.nordic.theme) implementation(libs.nordic.navigation) - implementation(libs.nordic.uilogger) + implementation(libs.nordic.logger) implementation(libs.androidx.compose.material3) implementation(libs.androidx.compose.material.iconsExtended) @@ -61,4 +62,8 @@ dependencies { implementation(libs.androidx.lifecycle.service) implementation(libs.androidx.hilt.navigation.compose) + + // Timber & SLF4J + implementation (libs.slf4j.timber) + implementation(libs.nordic.log.timber) } diff --git a/profile_hts/src/main/java/no/nordicsemi/android/hts/repository/HTSRepository.kt b/profile_hts/src/main/java/no/nordicsemi/android/hts/repository/HTSRepository.kt index b84003b2c..6942b27b1 100644 --- a/profile_hts/src/main/java/no/nordicsemi/android/hts/repository/HTSRepository.kt +++ b/profile_hts/src/main/java/no/nordicsemi/android/hts/repository/HTSRepository.kt @@ -38,17 +38,19 @@ import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.map import no.nordicsemi.android.common.core.simpleSharedFlow -import no.nordicsemi.android.common.logger.BleLoggerAndLauncher -import no.nordicsemi.android.common.logger.DefaultBleLogger +import no.nordicsemi.android.common.logger.LoggerLauncher import no.nordicsemi.android.hts.data.HTSServiceData import no.nordicsemi.android.hts.view.TemperatureUnit import no.nordicsemi.android.kotlin.ble.core.ServerDevice import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionState import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionStateWithStatus import no.nordicsemi.android.kotlin.ble.profile.hts.data.HTSData +import no.nordicsemi.android.log.LogSession +import no.nordicsemi.android.log.timber.nRFLoggerTree import no.nordicsemi.android.service.DisconnectAndStopEvent import no.nordicsemi.android.service.ServiceManager import no.nordicsemi.android.ui.view.StringConst +import timber.log.Timber import javax.inject.Inject import javax.inject.Singleton @@ -59,7 +61,7 @@ class HTSRepository @Inject constructor( private val serviceManager: ServiceManager, private val stringConst: StringConst ) { - private var logger: BleLoggerAndLauncher? = null + private var logger: nRFLoggerTree? = null private val _data = MutableStateFlow(HTSServiceData()) internal val data = _data.asStateFlow() @@ -86,9 +88,15 @@ class HTSRepository @Inject constructor( private fun shouldClean() = !isOnScreen && !isServiceRunning + private fun initLogger(device: ServerDevice) { + logger?.let { Timber.uproot(it) } + logger = nRFLoggerTree(context, stringConst.APP_NAME, "HTS", device.address) + .also { Timber.plant(it) } + } + fun launch(device: ServerDevice) { _data.value = _data.value.copy(deviceName = device.name) - logger = DefaultBleLogger.create(context, stringConst.APP_NAME, "HTS", device.address) + initLogger(device) serviceManager.startService(HTSService::class.java, device) } @@ -109,7 +117,7 @@ class HTSRepository @Inject constructor( } fun openLogger() { - logger?.launch() + LoggerLauncher.launch(context, logger?.session as? LogSession) } fun log(priority: Int, message: String) { diff --git a/profile_hts/src/main/java/no/nordicsemi/android/hts/repository/HTSService.kt b/profile_hts/src/main/java/no/nordicsemi/android/hts/repository/HTSService.kt index 460246b57..1b40888c1 100644 --- a/profile_hts/src/main/java/no/nordicsemi/android/hts/repository/HTSService.kt +++ b/profile_hts/src/main/java/no/nordicsemi/android/hts/repository/HTSService.kt @@ -86,7 +86,7 @@ internal class HTSService : NotificationService() { } private fun startGattClient(device: ServerDevice) = lifecycleScope.launch { - val client = ClientBleGatt.connect(this@HTSService, device, lifecycleScope, logger = { p, s -> repository.log(p, s) }) + val client = ClientBleGatt.connect(this@HTSService, device, lifecycleScope) this@HTSService.client = client client.connectionStateWithStatus diff --git a/profile_hts/src/main/java/no/nordicsemi/android/hts/view/HTSContentView.kt b/profile_hts/src/main/java/no/nordicsemi/android/hts/view/HTSContentView.kt index 4851bbc5d..a37944394 100644 --- a/profile_hts/src/main/java/no/nordicsemi/android/hts/view/HTSContentView.kt +++ b/profile_hts/src/main/java/no/nordicsemi/android/hts/view/HTSContentView.kt @@ -43,7 +43,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp -import no.nordicsemi.android.common.theme.view.RadioButtonGroup +import no.nordicsemi.android.common.ui.view.RadioButtonGroup import no.nordicsemi.android.hts.R import no.nordicsemi.android.hts.data.HTSServiceData import no.nordicsemi.android.ui.view.BatteryLevelView diff --git a/profile_hts/src/main/java/no/nordicsemi/android/hts/view/HTSMapper.kt b/profile_hts/src/main/java/no/nordicsemi/android/hts/view/HTSMapper.kt index 7b1ebc0f6..4519f77aa 100644 --- a/profile_hts/src/main/java/no/nordicsemi/android/hts/view/HTSMapper.kt +++ b/profile_hts/src/main/java/no/nordicsemi/android/hts/view/HTSMapper.kt @@ -31,8 +31,9 @@ package no.nordicsemi.android.hts.view -import no.nordicsemi.android.common.theme.view.RadioButtonItem -import no.nordicsemi.android.common.theme.view.RadioGroupViewEntity +import no.nordicsemi.android.common.ui.view.RadioButtonItem +import no.nordicsemi.android.common.ui.view.RadioGroupViewEntity +import java.util.Locale private const val DISPLAY_FAHRENHEIT = "°F" private const val DISPLAY_CELSIUS = "°C" @@ -40,9 +41,9 @@ private const val DISPLAY_KELVIN = "°K" internal fun displayTemperature(value: Float, temperatureUnit: TemperatureUnit): String { return when (temperatureUnit) { - TemperatureUnit.CELSIUS -> String.format("%.1f °C", value) - TemperatureUnit.FAHRENHEIT -> String.format("%.1f °F", value * 1.8f + 32f) - TemperatureUnit.KELVIN -> String.format("%.1f °K", value + 273.15f) + TemperatureUnit.CELSIUS -> String.format(Locale.US, "%.1f °C", value) + TemperatureUnit.FAHRENHEIT -> String.format(Locale.US, "%.1f °F", value * 1.8f + 32f) + TemperatureUnit.KELVIN -> String.format(Locale.US, "%.1f °K", value + 273.15f) } } @@ -57,11 +58,14 @@ internal fun String.toTemperatureUnit(): TemperatureUnit { internal fun TemperatureUnit.temperatureSettingsItems(): RadioGroupViewEntity { return RadioGroupViewEntity( - TemperatureUnit.values().map { createRadioButtonItem(it, this) } + TemperatureUnit.entries.map { createRadioButtonItem(it, this) } ) } -private fun createRadioButtonItem(unit: TemperatureUnit, selectedTemperatureUnit: TemperatureUnit): RadioButtonItem { +private fun createRadioButtonItem( + unit: TemperatureUnit, + selectedTemperatureUnit: TemperatureUnit +): RadioButtonItem { return RadioButtonItem(displayTemperature(unit), unit == selectedTemperatureUnit) } diff --git a/profile_prx/build.gradle.kts b/profile_prx/build.gradle.kts index 2b39270f1..20af01677 100644 --- a/profile_prx/build.gradle.kts +++ b/profile_prx/build.gradle.kts @@ -53,7 +53,7 @@ dependencies { implementation(libs.nordic.core) implementation(libs.nordic.theme) implementation(libs.nordic.navigation) - implementation(libs.nordic.uilogger) + implementation(libs.nordic.logger) implementation(libs.androidx.compose.material3) implementation(libs.androidx.compose.material.iconsExtended) @@ -62,4 +62,8 @@ dependencies { implementation(libs.androidx.lifecycle.service) implementation(libs.androidx.hilt.navigation.compose) + + // Timber & SLF4J + implementation (libs.slf4j.timber) + implementation(libs.nordic.log.timber) } diff --git a/profile_prx/src/main/java/no/nordicsemi/android/prx/repository/PRXRepository.kt b/profile_prx/src/main/java/no/nordicsemi/android/prx/repository/PRXRepository.kt index 9d790899e..4df1f0acd 100644 --- a/profile_prx/src/main/java/no/nordicsemi/android/prx/repository/PRXRepository.kt +++ b/profile_prx/src/main/java/no/nordicsemi/android/prx/repository/PRXRepository.kt @@ -38,16 +38,18 @@ import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.map import no.nordicsemi.android.common.core.simpleSharedFlow -import no.nordicsemi.android.common.logger.BleLoggerAndLauncher -import no.nordicsemi.android.common.logger.DefaultBleLogger +import no.nordicsemi.android.common.logger.LoggerLauncher import no.nordicsemi.android.kotlin.ble.core.ServerDevice import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionState import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionStateWithStatus import no.nordicsemi.android.kotlin.ble.profile.prx.AlarmLevel +import no.nordicsemi.android.log.LogSession +import no.nordicsemi.android.log.timber.nRFLoggerTree import no.nordicsemi.android.prx.data.PRXServiceData import no.nordicsemi.android.service.DisconnectAndStopEvent import no.nordicsemi.android.service.ServiceManager import no.nordicsemi.android.ui.view.StringConst +import timber.log.Timber import javax.inject.Inject import javax.inject.Singleton @@ -58,7 +60,7 @@ class PRXRepository @Inject internal constructor( private val serviceManager: ServiceManager, private val stringConst: StringConst ) { - private var logger: BleLoggerAndLauncher? = null + private var logger: nRFLoggerTree? = null private val _data = MutableStateFlow(PRXServiceData()) internal val data = _data.asStateFlow() @@ -88,8 +90,14 @@ class PRXRepository @Inject internal constructor( private fun shouldClean() = !isOnScreen && !isServiceRunning + private fun initLogger(device: ServerDevice) { + logger?.let { Timber.uproot(it) } + logger = nRFLoggerTree(context, stringConst.APP_NAME, "PRX", device.address) + .also { Timber.plant(it) } + } + fun launch(device: ServerDevice) { - logger = DefaultBleLogger.create(context, stringConst.APP_NAME, "PRX", device.address) + initLogger(device) _data.value = _data.value.copy(deviceName = device.name) serviceManager.startService(PRXService::class.java, device) } @@ -119,7 +127,7 @@ class PRXRepository @Inject internal constructor( } fun openLogger() { - logger?.launch() + LoggerLauncher.launch(context, logger?.session as? LogSession) } fun log(priority: Int, message: String) { diff --git a/profile_prx/src/main/java/no/nordicsemi/android/prx/repository/PRXService.kt b/profile_prx/src/main/java/no/nordicsemi/android/prx/repository/PRXService.kt index 7d916c576..e7c2723e6 100644 --- a/profile_prx/src/main/java/no/nordicsemi/android/prx/repository/PRXService.kt +++ b/profile_prx/src/main/java/no/nordicsemi/android/prx/repository/PRXService.kt @@ -164,7 +164,6 @@ internal class PRXService : NotificationService() { this@PRXService, device, lifecycleScope, - logger = { p, s -> repository.log(p, s) }, options = BleGattConnectOptions(autoConnect = true) ) this@PRXService.client = client diff --git a/profile_rscs/build.gradle.kts b/profile_rscs/build.gradle.kts index 03a732003..25607f2d4 100644 --- a/profile_rscs/build.gradle.kts +++ b/profile_rscs/build.gradle.kts @@ -48,7 +48,7 @@ dependencies { implementation(libs.nordic.core) implementation(libs.nordic.theme) implementation(libs.nordic.navigation) - implementation(libs.nordic.uilogger) + implementation(libs.nordic.logger) implementation(libs.nordic.blek.client) implementation(libs.nordic.blek.profile) @@ -61,4 +61,8 @@ dependencies { implementation(libs.androidx.lifecycle.service) implementation(libs.androidx.hilt.navigation.compose) + + // Timber & SLF4J + implementation (libs.slf4j.timber) + implementation(libs.nordic.log.timber) } diff --git a/profile_rscs/src/main/java/no/nordicsemi/android/rscs/repository/RSCSRepository.kt b/profile_rscs/src/main/java/no/nordicsemi/android/rscs/repository/RSCSRepository.kt index 53861d4fe..5993114ec 100644 --- a/profile_rscs/src/main/java/no/nordicsemi/android/rscs/repository/RSCSRepository.kt +++ b/profile_rscs/src/main/java/no/nordicsemi/android/rscs/repository/RSCSRepository.kt @@ -38,16 +38,18 @@ import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.map import no.nordicsemi.android.common.core.simpleSharedFlow -import no.nordicsemi.android.common.logger.BleLoggerAndLauncher -import no.nordicsemi.android.common.logger.DefaultBleLogger +import no.nordicsemi.android.common.logger.LoggerLauncher import no.nordicsemi.android.kotlin.ble.core.ServerDevice import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionState import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionStateWithStatus import no.nordicsemi.android.kotlin.ble.profile.rscs.data.RSCSData +import no.nordicsemi.android.log.LogSession +import no.nordicsemi.android.log.timber.nRFLoggerTree import no.nordicsemi.android.rscs.data.RSCSServiceData import no.nordicsemi.android.service.DisconnectAndStopEvent import no.nordicsemi.android.service.ServiceManager import no.nordicsemi.android.ui.view.StringConst +import timber.log.Timber import javax.inject.Inject import javax.inject.Singleton @@ -58,7 +60,7 @@ class RSCSRepository @Inject constructor( private val serviceManager: ServiceManager, private val stringConst: StringConst ) { - private var logger: BleLoggerAndLauncher? = null + private var logger: nRFLoggerTree? = null private val _data = MutableStateFlow(RSCSServiceData()) internal val data = _data.asStateFlow() @@ -85,8 +87,14 @@ class RSCSRepository @Inject constructor( private fun shouldClean() = !isOnScreen && !isServiceRunning + private fun initLogger(device: ServerDevice) { + logger?.let { Timber.uproot(it) } + logger = nRFLoggerTree(context, stringConst.APP_NAME, "RSCS", device.address) + .also { Timber.plant(it) } + } + fun launch(device: ServerDevice) { - logger = DefaultBleLogger.create(context, stringConst.APP_NAME, "RSCS", device.address) + initLogger(device) _data.value = _data.value.copy(deviceName = device.name) serviceManager.startService(RSCSService::class.java, device) } @@ -109,7 +117,7 @@ class RSCSRepository @Inject constructor( } fun openLogger() { - logger?.launch() + LoggerLauncher.launch(context, logger?.session as? LogSession) } fun log(priority: Int, message: String) { diff --git a/profile_rscs/src/main/java/no/nordicsemi/android/rscs/repository/RSCSService.kt b/profile_rscs/src/main/java/no/nordicsemi/android/rscs/repository/RSCSService.kt index 64a829922..a7f9a45a5 100644 --- a/profile_rscs/src/main/java/no/nordicsemi/android/rscs/repository/RSCSService.kt +++ b/profile_rscs/src/main/java/no/nordicsemi/android/rscs/repository/RSCSService.kt @@ -86,7 +86,7 @@ internal class RSCSService : NotificationService() { } private fun startGattClient(device: ServerDevice) = lifecycleScope.launch { - val client = ClientBleGatt.connect(this@RSCSService, device, lifecycleScope, logger = { p, s -> repository.log(p, s) }) + val client = ClientBleGatt.connect(this@RSCSService, device, lifecycleScope) this@RSCSService.client = client client.connectionStateWithStatus diff --git a/profile_uart/build.gradle.kts b/profile_uart/build.gradle.kts index cf1bd0335..1d88c4d64 100644 --- a/profile_uart/build.gradle.kts +++ b/profile_uart/build.gradle.kts @@ -52,8 +52,9 @@ dependencies { implementation(libs.nordic.core) implementation(libs.nordic.theme) + implementation(libs.nordic.ui) implementation(libs.nordic.navigation) - implementation(libs.nordic.uilogger) + implementation(libs.nordic.logger) implementation(libs.nordic.blek.client) implementation(libs.nordic.blek.profile) @@ -66,12 +67,8 @@ dependencies { implementation(libs.room.ktx) ksp(libs.room.compiler) - implementation(libs.accompanist.pager) - implementation(libs.accompanist.pagerindicators) - implementation(libs.androidx.dataStore.core) implementation(libs.androidx.dataStore.preferences) - implementation(libs.androidx.compose.material3) implementation(libs.androidx.compose.material.iconsExtended) implementation(libs.androidx.core.ktx) implementation(libs.androidx.activity.compose) @@ -79,6 +76,11 @@ dependencies { implementation(libs.androidx.hilt.navigation.compose) + + // Timber & SLF4J + implementation (libs.slf4j.timber) + implementation(libs.nordic.log.timber) + testImplementation(libs.hilt.android.testing) kaptTest(libs.hilt.compiler) testImplementation(libs.androidx.test.rules) @@ -87,7 +89,7 @@ dependencies { testImplementation(libs.test.mockk) testImplementation(libs.androidx.test.ext) testImplementation(libs.kotlinx.coroutines.test) - testImplementation(libs.test.slf4j.simple) + testImplementation(libs.slf4j.simple) testImplementation(libs.test.robolectric) testImplementation(libs.kotlin.junit) diff --git a/profile_uart/src/main/java/no/nordicsemi/android/uart/UartServer.kt b/profile_uart/src/main/java/no/nordicsemi/android/uart/UartServer.kt index 1a55aa69a..d4075f62a 100644 --- a/profile_uart/src/main/java/no/nordicsemi/android/uart/UartServer.kt +++ b/profile_uart/src/main/java/no/nordicsemi/android/uart/UartServer.kt @@ -9,13 +9,13 @@ import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.mapNotNull import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch -import no.nordicsemi.android.common.core.DataByteArray import no.nordicsemi.android.kotlin.ble.advertiser.BleAdvertiser import no.nordicsemi.android.kotlin.ble.core.MockServerDevice import no.nordicsemi.android.kotlin.ble.core.advertiser.BleAdvertisingConfig import no.nordicsemi.android.kotlin.ble.core.advertiser.BleAdvertisingData import no.nordicsemi.android.kotlin.ble.core.data.BleGattPermission import no.nordicsemi.android.kotlin.ble.core.data.BleGattProperty +import no.nordicsemi.android.kotlin.ble.core.data.util.DataByteArray import no.nordicsemi.android.kotlin.ble.server.main.ServerBleGatt import no.nordicsemi.android.kotlin.ble.server.main.service.ServerBleGattCharacteristic import no.nordicsemi.android.kotlin.ble.server.main.service.ServerBleGattCharacteristicConfig diff --git a/profile_uart/src/main/java/no/nordicsemi/android/uart/data/MacroIcon.kt b/profile_uart/src/main/java/no/nordicsemi/android/uart/data/MacroIcon.kt index 0e7613499..b8d4eded2 100644 --- a/profile_uart/src/main/java/no/nordicsemi/android/uart/data/MacroIcon.kt +++ b/profile_uart/src/main/java/no/nordicsemi/android/uart/data/MacroIcon.kt @@ -55,7 +55,7 @@ enum class MacroIcon(public val index: Int) { companion object { fun create(index: Int): MacroIcon { - return values().firstOrNull { it.index == index } + return entries.firstOrNull { it.index == index } ?: throw IllegalArgumentException("Cannot create MacroIcon for index: $index") } } diff --git a/profile_uart/src/main/java/no/nordicsemi/android/uart/db/CommentVisitor.kt b/profile_uart/src/main/java/no/nordicsemi/android/uart/db/CommentVisitor.kt index 999352954..cf8290578 100644 --- a/profile_uart/src/main/java/no/nordicsemi/android/uart/db/CommentVisitor.kt +++ b/profile_uart/src/main/java/no/nordicsemi/android/uart/db/CommentVisitor.kt @@ -51,7 +51,7 @@ internal class CommentVisitor : Visitor { val element = node.node val builder = StringBuilder("A configuration must have 9 commands, one for each button.\n Possible icons are:") - for (icon in MacroIcon.values()) builder.append("\n - ") + for (icon in MacroIcon.entries) builder.append("\n - ") .append(icon.toString()) element.comment = builder.toString() } diff --git a/profile_uart/src/main/java/no/nordicsemi/android/uart/repository/UARTRepository.kt b/profile_uart/src/main/java/no/nordicsemi/android/uart/repository/UARTRepository.kt index 80e197830..b93534e5c 100644 --- a/profile_uart/src/main/java/no/nordicsemi/android/uart/repository/UARTRepository.kt +++ b/profile_uart/src/main/java/no/nordicsemi/android/uart/repository/UARTRepository.kt @@ -38,10 +38,12 @@ import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.map import no.nordicsemi.android.common.core.simpleSharedFlow -import no.nordicsemi.android.common.logger.BleLoggerAndLauncher +import no.nordicsemi.android.common.logger.LoggerLauncher import no.nordicsemi.android.kotlin.ble.core.ServerDevice import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionState import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionStateWithStatus +import no.nordicsemi.android.log.LogSession +import no.nordicsemi.android.log.timber.nRFLoggerTree import no.nordicsemi.android.service.DisconnectAndStopEvent import no.nordicsemi.android.service.ServiceManager import no.nordicsemi.android.uart.data.ConfigurationDataSource @@ -51,8 +53,8 @@ import no.nordicsemi.android.uart.data.UARTRecord import no.nordicsemi.android.uart.data.UARTRecordType import no.nordicsemi.android.uart.data.UARTServiceData import no.nordicsemi.android.uart.data.parseWithNewLineChar -import no.nordicsemi.android.ui.view.NordicLoggerFactory import no.nordicsemi.android.ui.view.StringConst +import timber.log.Timber import javax.inject.Inject import javax.inject.Singleton @@ -63,9 +65,8 @@ class UARTRepository @Inject internal constructor( private val serviceManager: ServiceManager, private val configurationDataSource: ConfigurationDataSource, private val stringConst: StringConst, - private val loggerFactory: NordicLoggerFactory ) { - private var logger: BleLoggerAndLauncher? = null + private var logger: nRFLoggerTree? = null private val _data = MutableStateFlow(UARTServiceData()) internal val data = _data.asStateFlow() @@ -98,11 +99,17 @@ class UARTRepository @Inject internal constructor( private fun shouldClean() = !isOnScreen && !isServiceRunning fun launch(device: ServerDevice) { - logger = loggerFactory.createNordicLogger(context, stringConst.APP_NAME, "UART", device.address) + initLogger(device) _data.value = _data.value.copy(deviceName = device.name) serviceManager.startService(UARTService::class.java, device) } + private fun initLogger(device : ServerDevice) { + logger?.let { Timber.uproot(it) } + logger = nRFLoggerTree(context, stringConst.APP_NAME, "UART", device.name ?: "Unknown") + .also { Timber.plant(it) } + } + fun onConnectionStateChanged(connectionState: GattConnectionStateWithStatus?) { _data.value = _data.value.copy(connectionState = connectionState) } @@ -135,7 +142,7 @@ class UARTRepository @Inject internal constructor( } fun openLogger() { - logger?.launch() + LoggerLauncher.launch(context, logger?.session as? LogSession) } fun log(priority: Int, message: String) { diff --git a/profile_uart/src/main/java/no/nordicsemi/android/uart/repository/UARTService.kt b/profile_uart/src/main/java/no/nordicsemi/android/uart/repository/UARTService.kt index ebcac9b57..8639302b0 100644 --- a/profile_uart/src/main/java/no/nordicsemi/android/uart/repository/UARTService.kt +++ b/profile_uart/src/main/java/no/nordicsemi/android/uart/repository/UARTService.kt @@ -43,7 +43,6 @@ import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.mapNotNull import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch -import no.nordicsemi.android.common.core.DataByteArray import no.nordicsemi.android.kotlin.ble.client.main.callback.ClientBleGatt import no.nordicsemi.android.kotlin.ble.client.main.service.ClientBleGattCharacteristic import no.nordicsemi.android.kotlin.ble.client.main.service.ClientBleGattServices @@ -53,10 +52,11 @@ import no.nordicsemi.android.kotlin.ble.core.data.BleGattProperty import no.nordicsemi.android.kotlin.ble.core.data.BleWriteType import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionState import no.nordicsemi.android.kotlin.ble.core.data.Mtu +import no.nordicsemi.android.kotlin.ble.core.data.util.DataByteArray import no.nordicsemi.android.kotlin.ble.profile.battery.BatteryLevelParser import no.nordicsemi.android.service.DEVICE_DATA import no.nordicsemi.android.service.NotificationService -import java.util.* +import java.util.UUID import javax.inject.Inject val UART_SERVICE_UUID: UUID = UUID.fromString("6E400001-B5A3-F393-E0A9-E50E24DCCA9E") @@ -92,7 +92,7 @@ internal class UARTService : NotificationService() { } private fun startGattClient(device: ServerDevice) = lifecycleScope.launch { - val client = ClientBleGatt.connect(this@UARTService, device, lifecycleScope, logger = { p, s -> repository.log(p, s) }) + val client = ClientBleGatt.connect(this@UARTService, device, lifecycleScope) this@UARTService.client = client if (!client.isConnected) { diff --git a/profile_uart/src/main/java/no/nordicsemi/android/uart/view/InputSection.kt b/profile_uart/src/main/java/no/nordicsemi/android/uart/view/InputSection.kt index 597cca6ce..72f281b2b 100644 --- a/profile_uart/src/main/java/no/nordicsemi/android/uart/view/InputSection.kt +++ b/profile_uart/src/main/java/no/nordicsemi/android/uart/view/InputSection.kt @@ -45,21 +45,20 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import kotlinx.coroutines.launch -import no.nordicsemi.android.common.theme.view.RadioButtonGroup -import no.nordicsemi.android.common.theme.view.RadioButtonItem -import no.nordicsemi.android.common.theme.view.RadioGroupViewEntity +import no.nordicsemi.android.common.ui.view.RadioButtonGroup +import no.nordicsemi.android.common.ui.view.RadioButtonItem +import no.nordicsemi.android.common.ui.view.RadioGroupViewEntity import no.nordicsemi.android.uart.R import no.nordicsemi.android.uart.data.MacroEol import no.nordicsemi.android.ui.view.ScreenSection import no.nordicsemi.android.ui.view.SectionTitle import no.nordicsemi.android.utils.EMPTY -@OptIn(ExperimentalMaterial3Api::class) @Composable internal fun InputSection(onEvent: (UARTViewEvent) -> Unit) { val text = rememberSaveable { mutableStateOf(String.EMPTY) } val hint = stringResource(id = R.string.uart_input_hint) - val checkedItem = rememberSaveable { mutableStateOf(MacroEol.values()[0]) } + val checkedItem = rememberSaveable { mutableStateOf(MacroEol.entries[0]) } Row(verticalAlignment = Alignment.CenterVertically) { Box(modifier = Modifier.weight(1f)) { @@ -99,9 +98,9 @@ internal fun InputSection(onEvent: (UARTViewEvent) -> Unit) { @Composable internal fun EditInputSection(onEvent: (UARTViewEvent) -> Unit) { - val checkedItem = rememberSaveable { mutableStateOf(MacroEol.values()[0]) } + val checkedItem = rememberSaveable { mutableStateOf(MacroEol.entries[0]) } - val items = MacroEol.values().map { + val items = MacroEol.entries.map { RadioButtonItem(it.toDisplayString(), it == checkedItem.value) } val viewEntity = RadioGroupViewEntity(items) diff --git a/profile_uart/src/main/java/no/nordicsemi/android/uart/view/UARTAddConfigurationDialog.kt b/profile_uart/src/main/java/no/nordicsemi/android/uart/view/UARTAddConfigurationDialog.kt index 0d3258ba4..08fea8e06 100644 --- a/profile_uart/src/main/java/no/nordicsemi/android/uart/view/UARTAddConfigurationDialog.kt +++ b/profile_uart/src/main/java/no/nordicsemi/android/uart/view/UARTAddConfigurationDialog.kt @@ -70,7 +70,6 @@ internal fun UARTAddConfigurationDialog(onEvent: (UARTViewEvent) -> Unit, onDism ) } -@OptIn(ExperimentalMaterial3Api::class) @Composable private fun NameInput( name: MutableState, diff --git a/profile_uart/src/main/java/no/nordicsemi/android/uart/view/UARTAddMacroDialog.kt b/profile_uart/src/main/java/no/nordicsemi/android/uart/view/UARTAddMacroDialog.kt index d90ce04df..17291d256 100644 --- a/profile_uart/src/main/java/no/nordicsemi/android/uart/view/UARTAddMacroDialog.kt +++ b/profile_uart/src/main/java/no/nordicsemi/android/uart/view/UARTAddMacroDialog.kt @@ -34,12 +34,21 @@ package no.nordicsemi.android.uart.view import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.* +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.foundation.lazy.grid.GridCells import androidx.compose.foundation.lazy.grid.GridItemSpan import androidx.compose.foundation.lazy.grid.LazyVerticalGrid import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material3.* +import androidx.compose.material3.AlertDialog +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.OutlinedTextField +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.MutableState import androidx.compose.runtime.mutableStateOf @@ -52,9 +61,9 @@ import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp -import no.nordicsemi.android.common.theme.view.RadioButtonGroup -import no.nordicsemi.android.common.theme.view.RadioButtonItem -import no.nordicsemi.android.common.theme.view.RadioGroupViewEntity +import no.nordicsemi.android.common.ui.view.RadioButtonGroup +import no.nordicsemi.android.common.ui.view.RadioButtonItem +import no.nordicsemi.android.common.ui.view.RadioGroupViewEntity import no.nordicsemi.android.uart.R import no.nordicsemi.android.uart.data.MacroEol import no.nordicsemi.android.uart.data.MacroIcon @@ -67,7 +76,7 @@ private const val GRID_SIZE = 5 internal fun UARTAddMacroDialog(macro: UARTMacro?, onEvent: (UARTViewEvent) -> Unit) { val newLineChar = rememberSaveable { mutableStateOf(macro?.newLineChar ?: MacroEol.LF) } val command = rememberSaveable { mutableStateOf(macro?.command ?: String.EMPTY) } - val selectedIcon = rememberSaveable { mutableStateOf(macro?.icon ?: MacroIcon.values()[0]) } + val selectedIcon = rememberSaveable { mutableStateOf(macro?.icon ?: MacroIcon.entries.toTypedArray()[0]) } AlertDialog( onDismissRequest = { onEvent(OnEditFinish) }, @@ -130,7 +139,6 @@ internal fun UARTAddMacroDialog(macro: UARTMacro?, onEvent: (UARTViewEvent) -> U ) } -@OptIn(ExperimentalMaterial3Api::class) @Composable private fun CommandInput(command: MutableState) { Column { @@ -150,7 +158,7 @@ private fun CommandInput(command: MutableState) { @Composable private fun NewLineCharSection(checkedItem: MacroEol, onItemClick: (MacroEol) -> Unit) { - val items = MacroEol.values().map { + val items = MacroEol.entries.map { RadioButtonItem(it.toDisplayString(), it == checkedItem) } val viewEntity = RadioGroupViewEntity(items) diff --git a/profile_uart/src/main/java/no/nordicsemi/android/uart/view/UARTScreen.kt b/profile_uart/src/main/java/no/nordicsemi/android/uart/view/UARTScreen.kt index 76ab058fe..cdbefacb4 100644 --- a/profile_uart/src/main/java/no/nordicsemi/android/uart/view/UARTScreen.kt +++ b/profile_uart/src/main/java/no/nordicsemi/android/uart/view/UARTScreen.kt @@ -31,12 +31,10 @@ package no.nordicsemi.android.uart.view -import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding -import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Scaffold import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState @@ -46,16 +44,16 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel -import no.nordicsemi.android.common.theme.view.PagerView -import no.nordicsemi.android.common.theme.view.PagerViewEntity -import no.nordicsemi.android.common.theme.view.PagerViewItem +import no.nordicsemi.android.common.ui.view.PagerView +import no.nordicsemi.android.common.ui.view.PagerViewEntity +import no.nordicsemi.android.common.ui.view.PagerViewItem import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionState +import no.nordicsemi.android.kotlin.ble.ui.scanner.view.DeviceConnectingView +import no.nordicsemi.android.kotlin.ble.ui.scanner.view.DeviceDisconnectedView import no.nordicsemi.android.uart.R import no.nordicsemi.android.uart.viewmodel.UARTViewModel import no.nordicsemi.android.ui.view.NavigateUpButton import no.nordicsemi.android.ui.view.ProfileAppBar -import no.nordicsemi.android.kotlin.ble.ui.scanner.view.DeviceConnectingView -import no.nordicsemi.android.kotlin.ble.ui.scanner.view.DeviceDisconnectedView @Composable fun UARTScreen() { @@ -99,7 +97,6 @@ private fun PaddingBox(content: @Composable () -> Unit) { } } -@OptIn(ExperimentalFoundationApi::class) @Composable private fun SuccessScreen() { val input = stringResource(id = R.string.uart_input) diff --git a/profile_uart/src/main/java/no/nordicsemi/android/uart/view/UARTViewEvent.kt b/profile_uart/src/main/java/no/nordicsemi/android/uart/view/UARTViewEvent.kt index 834e0e88f..59d3ec63b 100644 --- a/profile_uart/src/main/java/no/nordicsemi/android/uart/view/UARTViewEvent.kt +++ b/profile_uart/src/main/java/no/nordicsemi/android/uart/view/UARTViewEvent.kt @@ -39,20 +39,20 @@ internal sealed class UARTViewEvent internal data class OnEditMacro(val position: Int) : UARTViewEvent() internal data class OnCreateMacro(val macro: UARTMacro) : UARTViewEvent() -internal object OnDeleteMacro : UARTViewEvent() -internal object OnEditFinish : UARTViewEvent() +internal data object OnDeleteMacro : UARTViewEvent() +internal data object OnEditFinish : UARTViewEvent() internal data class OnConfigurationSelected(val configuration: UARTConfiguration) : UARTViewEvent() internal data class OnAddConfiguration(val name: String) : UARTViewEvent() -internal object OnEditConfiguration : UARTViewEvent() -internal object OnDeleteConfiguration : UARTViewEvent() +internal data object OnEditConfiguration : UARTViewEvent() +internal data object OnDeleteConfiguration : UARTViewEvent() internal data class OnRunMacro(val macro: UARTMacro) : UARTViewEvent() internal data class OnRunInput(val text: String, val newLineChar: MacroEol) : UARTViewEvent() -internal object ClearOutputItems : UARTViewEvent() -internal object DisconnectEvent : UARTViewEvent() +internal data object ClearOutputItems : UARTViewEvent() +internal data object DisconnectEvent : UARTViewEvent() -internal object NavigateUp : UARTViewEvent() -internal object OpenLogger : UARTViewEvent() +internal data object NavigateUp : UARTViewEvent() +internal data object OpenLogger : UARTViewEvent() -internal object MacroInputSwitchClick : UARTViewEvent() +internal data object MacroInputSwitchClick : UARTViewEvent() diff --git a/profile_uart/src/main/java/no/nordicsemi/android/uart/viewmodel/UARTViewModel.kt b/profile_uart/src/main/java/no/nordicsemi/android/uart/viewmodel/UARTViewModel.kt index c528ef9d5..ed21abf1a 100644 --- a/profile_uart/src/main/java/no/nordicsemi/android/uart/viewmodel/UARTViewModel.kt +++ b/profile_uart/src/main/java/no/nordicsemi/android/uart/viewmodel/UARTViewModel.kt @@ -77,7 +77,6 @@ import no.nordicsemi.android.uart.view.OnRunMacro import no.nordicsemi.android.uart.view.OpenLogger import no.nordicsemi.android.uart.view.UARTViewEvent import no.nordicsemi.android.uart.view.UARTViewState -import no.nordicsemi.android.ui.view.NordicLoggerFactory import javax.inject.Inject @HiltViewModel @@ -86,7 +85,6 @@ internal class UARTViewModel @Inject constructor( private val navigationManager: Navigator, private val dataSource: UARTPersistentDataSource, private val analytics: AppAnalytics, - private val loggerFactory: NordicLoggerFactory ) : ViewModel() { private val _state = MutableStateFlow(UARTViewState()) diff --git a/settings.gradle.kts b/settings.gradle.kts index 3ab0ffea1..76db64550 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -50,7 +50,7 @@ dependencyResolutionManagement { } versionCatalogs { create("libs") { - from("no.nordicsemi.android.gradle:version-catalog:1.11.1") + from("no.nordicsemi.android.gradle:version-catalog:2.4") } } } @@ -79,6 +79,6 @@ include(":lib_utils") // includeBuild("../Android-Common-Libraries") //} // -if (file("../Kotlin-BLE-Library").exists()) { - includeBuild("../Kotlin-BLE-Library") -} +//if (file("../Kotlin-BLE-Library").exists()) { +// includeBuild("../Kotlin-BLE-Library") +//}