Skip to content

Commit

Permalink
Merge pull request #22 from NordicSemiconductor/migration/android15
Browse files Browse the repository at this point in the history
Support for Android 15
  • Loading branch information
philips77 authored Dec 9, 2024
2 parents d96b2f9 + a03beaf commit 3b3bfc6
Show file tree
Hide file tree
Showing 25 changed files with 322 additions and 283 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,23 @@ import android.os.Build
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.displayCutout
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.union
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.ExperimentalMaterial3Api
Expand Down Expand Up @@ -99,6 +105,10 @@ fun HomeScreen() {
title = { Text(text = stringResource(id = R.string.app_name)) }
)
},
contentWindowInsets = WindowInsets.navigationBars
.union(WindowInsets.displayCutout)
.union(WindowInsets(left = 16.dp, right = 16.dp))
.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Top),
snackbarHost = {
SnackbarHost(hostState = snackbarHostState)
},
Expand All @@ -109,7 +119,9 @@ fun HomeScreen() {
context = context,
scope = scope,
snackbarHostState = snackbarHostState,
innerPadding = innerPadding,
modifier = Modifier
.fillMaxSize()
.padding(innerPadding),
navigateTo = vm::navigateTo
)
}
Expand All @@ -119,7 +131,10 @@ fun HomeScreen() {
context = context,
scope = scope,
snackbarHostState = snackbarHostState,
innerPadding = innerPadding,
modifier = Modifier
.fillMaxSize()
.verticalScroll(state = rememberScrollState())
.padding(innerPadding),
navigateTo = vm::navigateTo
)
}
Expand All @@ -132,15 +147,11 @@ private fun PortraitContent(
context: Context,
scope: CoroutineScope,
snackbarHostState: SnackbarHostState,
innerPadding: PaddingValues,
modifier: Modifier = Modifier,
navigateTo: (DestinationId<Unit, *>) -> Unit
) {
Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(state = rememberScrollState())
.padding(innerPadding)
.padding(horizontal = 16.dp),
modifier = modifier,
horizontalAlignment = Alignment.CenterHorizontally
) {
Spacer(modifier = Modifier.weight(0.5f))
Expand All @@ -152,13 +163,19 @@ private fun PortraitContent(
.heightIn(min = 120.dp, max = 200.dp)
.padding(8.dp)
)

Spacer(modifier = Modifier.weight(0.5f))

val insets = WindowInsets.navigationBars.only(WindowInsetsSides.Bottom)
ProvisioningMenu(
context = context,
scope = scope,
snackbarHostState = snackbarHostState,
navigateTo = navigateTo,
modifier = Modifier.widthIn(max = 600.dp)
modifier = Modifier
.widthIn(max = 600.dp)
.windowInsetsPadding(insets)
.padding(vertical = 16.dp)
)
}
}
Expand All @@ -168,25 +185,24 @@ private fun SmallScreenLandscapeContent(
context: Context,
scope: CoroutineScope,
snackbarHostState: SnackbarHostState,
innerPadding: PaddingValues,
modifier: Modifier = Modifier,
navigateTo: (DestinationId<Unit, *>) -> Unit
) {
Row(
modifier = Modifier
.fillMaxSize()
.padding(innerPadding)
.padding(horizontal = 16.dp),
modifier = modifier,
verticalAlignment = Alignment.CenterVertically,
) {
Image(
modifier = Modifier.width(200.dp).padding(horizontal = 32.dp),
painter = painterResource(id = R.drawable.ic_nrf70),
contentDescription = stringResource(id = R.string.ic_nrf70),
)
val insets = WindowInsets.navigationBars.only(WindowInsetsSides.Bottom)
ProvisioningMenu(
modifier = Modifier
.weight(1f)
.verticalScroll(state = rememberScrollState())
.windowInsetsPadding(insets)
.padding(top = 16.dp),
context = context,
scope = scope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,9 @@

package no.nordicsemi.android.wifi.provisioner

import android.graphics.Color
import android.os.Build
import android.os.Bundle
import androidx.activity.SystemBarStyle
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import dagger.hilt.android.AndroidEntryPoint
import no.nordicsemi.android.common.navigation.NavigationView
import no.nordicsemi.android.common.theme.NordicActivity
Expand All @@ -54,30 +48,26 @@ class MainActivity : NordicActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

enableEdgeToEdge(statusBarStyle = SystemBarStyle.dark(Color.TRANSPARENT))

setContent {
NordicTheme {
Surface(modifier = Modifier.fillMaxSize()) {
NavigationView(
destinations = (HomeDestination +
BleProvisioningDestinations).run {
// Soft AP is available on Android 10 and newer.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
this + SoftApProvisionerDestinations
} else {
this
}
}.run {
// NFC is available on Android 6.0 and newer.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
this + NfcProvisionerDestinations
} else {
this
}
NavigationView(
destinations = (HomeDestination +
BleProvisioningDestinations).run {
// Soft AP is available on Android 10 and newer.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
this + SoftApProvisionerDestinations
} else {
this
}
}.run {
// NFC is available on Android 6.0 and newer.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
this + NfcProvisionerDestinations
} else {
this
}
)
}
}
)
}
}
}
Expand Down
1 change: 0 additions & 1 deletion feature/ble/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ dependencies {
implementation(libs.androidx.compose.material.iconsExtended)

implementation(libs.nordic.ui)
implementation(libs.nordic.theme)
implementation(libs.nordic.navigation)
implementation(libs.nordic.logger)
implementation(libs.nordic.core)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import androidx.compose.material.icons.outlined.BluetoothConnected
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import no.nordicsemi.android.common.theme.NordicTheme
import no.nordicsemi.android.common.ui.view.ProgressItem
import no.nordicsemi.android.common.ui.view.ProgressItemStatus
import no.nordicsemi.android.common.ui.view.WizardStepAction
Expand Down Expand Up @@ -113,62 +112,54 @@ fun ConnectionSection(
}
}

@Preview(heightDp = 200)
@Preview(heightDp = 200, showBackground = true)
@Composable
private fun DeviceStatusNotConnectedPreview() {
NordicTheme {
ConnectionSection(
state = BleViewEntity(
device = MockServerDevice("Device", "00:11:22:33:44:55"),
version = Success(VersionDomain(1)),
isConnected = false,
),
onEvent = {},
)
}
ConnectionSection(
state = BleViewEntity(
device = MockServerDevice("Device", "00:11:22:33:44:55"),
version = Success(VersionDomain(1)),
isConnected = false,
),
onEvent = {},
)
}

@Preview(heightDp = 200)
@Preview(heightDp = 200, showBackground = true)
@Composable
private fun DeviceStatusPreview() {
NordicTheme {
ConnectionSection(
state = BleViewEntity(
device = MockServerDevice("Device", "00:11:22:33:44:55"),
version = Success(VersionDomain(1)),
status = Loading(),
isConnected = true,
),
onEvent = {},
)
}
ConnectionSection(
state = BleViewEntity(
device = MockServerDevice("Device", "00:11:22:33:44:55"),
version = Success(VersionDomain(1)),
status = Loading(),
isConnected = true,
),
onEvent = {},
)
}
@Preview(heightDp = 200)
@Preview(heightDp = 200, showBackground = true)
@Composable
private fun DeviceStatusVersionErrorPreview() {
NordicTheme {
ConnectionSection(
state = BleViewEntity(
device = MockServerDevice("Device", "00:11:22:33:44:55"),
version = Error(Exception("Some error")),
isConnected = true,
),
onEvent = {},
)
}
ConnectionSection(
state = BleViewEntity(
device = MockServerDevice("Device", "00:11:22:33:44:55"),
version = Error(Exception("Some error")),
isConnected = true,
),
onEvent = {},
)
}
@Preview(heightDp = 200)
@Preview(heightDp = 200, showBackground = true)
@Composable
private fun DeviceStatusStatusErrorPreview() {
NordicTheme {
ConnectionSection(
state = BleViewEntity(
device = MockServerDevice("Device", "00:11:22:33:44:55"),
version = Success(VersionDomain(1)),
status = Error(Exception("Some error")),
isConnected = true,
),
onEvent = {},
)
}
ConnectionSection(
state = BleViewEntity(
device = MockServerDevice("Device", "00:11:22:33:44:55"),
version = Success(VersionDomain(1)),
status = Error(Exception("Some error")),
isConnected = true,
),
onEvent = {},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import no.nordicsemi.android.common.core.parseBold
import no.nordicsemi.android.common.theme.NordicTheme
import no.nordicsemi.android.common.ui.view.StatusItem
import no.nordicsemi.android.common.ui.view.WizardStepAction
import no.nordicsemi.android.common.ui.view.WizardStepComponent
Expand Down Expand Up @@ -119,24 +118,20 @@ private fun SelectedDeviceView(
}
}

@Preview(heightDp = 200)
@Preview(heightDp = 200, showBackground = true)
@Composable
private fun NotSelectedDeviceViewPreview() {
NordicTheme {
NotSelectedDeviceView(onEvent = {})
}
NotSelectedDeviceView(onEvent = {})
}

@Preview(heightDp = 200)
@Preview(heightDp = 200, showBackground = true)
@Composable
private fun SelectedDeviceViewPreview() {
NordicTheme {
SelectedDeviceView(
state = BleViewEntity(
device = MockServerDevice(),
version = Loading(),
),
onEvent = {},
)
}
SelectedDeviceView(
state = BleViewEntity(
device = MockServerDevice(),
version = Loading(),
),
onEvent = {},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,16 @@
package no.nordicsemi.android.wifi.provisioner.ble.view

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.displayCutout
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.union
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.ExperimentalMaterial3Api
Expand Down Expand Up @@ -95,19 +102,25 @@ fun BleProvisioningScreen() {
onNavigationButtonClick = viewModel::navigateUp
)
},
contentWindowInsets = WindowInsets.navigationBars
.union(WindowInsets.displayCutout)
.union(WindowInsets(left = 16.dp, right = 16.dp))
.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Top),
) { innerPadding ->
Column(
modifier = Modifier
.fillMaxWidth()
.padding(innerPadding)
.padding(horizontal = 16.dp),
.padding(innerPadding),
horizontalAlignment = Alignment.CenterHorizontally
) {
RequireBluetooth {

val insets = WindowInsets.navigationBars.only(WindowInsetsSides.Bottom)
OutlinedCard(
modifier = Modifier
.widthIn(max = 600.dp)
.verticalScroll(rememberScrollState())
.windowInsetsPadding(insets)
.padding(vertical = 16.dp),
) {
Column(modifier = Modifier.padding(16.dp)) {
Expand Down
Loading

0 comments on commit 3b3bfc6

Please sign in to comment.