Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration to AGP and Commons Library #142

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
6 changes: 5 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -58,5 +59,7 @@ class NrfToolboxApplication : Application() {

uartServer.start(this)
glsServer.start(this)

Timber.plant(Timber.DebugTree())
}
}
21 changes: 0 additions & 21 deletions app/src/main/java/no/nordicsemi/android/nrftoolbox/AppModule.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class HomeViewModel @Inject constructor(
}

fun openLogger() {
LoggerLauncher.launch(context)
LoggerLauncher.launch(context, null)
}

fun logEvent(event: ProfileOpenEvent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@ class NrfToolboxApplication : Application() {
super.onCreate()

analytics.logEvent(AppOpenEvent)

Timber.plant(Timber.DebugTree())
}
}
15 changes: 10 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
5 changes: 4 additions & 1 deletion lib_ui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ android {
}

dependencies {
implementation(libs.nordic.uilogger)
implementation(libs.nordic.theme)
implementation(libs.nordic.logger)

Expand All @@ -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)
}

This file was deleted.

This file was deleted.

42 changes: 27 additions & 15 deletions lib_ui/src/main/java/no/nordicsemi/android/ui/view/TopAppBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion profile_bps/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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))
Expand All @@ -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)
}
}

Expand All @@ -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)
[email protected] = client

client.connectionStateWithStatus
Expand Down
Loading