Skip to content

Commit e772533

Browse files
authored
Merge pull request #44 from nordicsemi/improvements/ui
Many UI improvements
2 parents 161e096 + 4c604e6 commit e772533

19 files changed

Lines changed: 770 additions & 979 deletions

app/src/main/java/no/nordicsemi/android/ei/HorizontalPagerTab.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import androidx.compose.material.icons.Icons
1111
import androidx.compose.material.icons.filled.ModelTraining
1212
import androidx.compose.material.icons.filled.Science
1313
import androidx.compose.ui.graphics.vector.ImageVector
14+
import no.nordicsemi.android.common.ui.view.PagerViewEntity
1415

1516
/**
1617
* HorizontalPagerTab

app/src/main/java/no/nordicsemi/android/ei/comms/CommsManager.kt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ class CommsManager(
8787
var inferencingState by mutableStateOf<InferencingState>(InferencingState.Stopped)
8888
private set
8989

90-
var inferenceResults = mutableStateListOf<InferencingMessage.InferenceResults>()
91-
private set
90+
private var _inferenceResults = mutableStateListOf<InferencingMessage.InferenceResults>()
91+
var inferenceResults: List<InferencingMessage.InferenceResults> = _inferenceResults.asReversed()
9292

9393
/** The emitter is used to publish data to a flow, when a collector is registered. */
9494
private var emitter: ((DeviceState) -> Unit)? = null
@@ -285,18 +285,17 @@ class CommsManager(
285285
dataSample = deviceMessage
286286
)
287287
is InferencingResponse.Start -> {
288-
inferenceResults.clear()
288+
_inferenceResults.clear()
289289
inferencingState = InferencingState.Started
290290
}
291291
is InferencingResponse.Stop -> {
292292
inferencingState = InferencingState.Stopped
293293
}
294294
is InferencingMessage.InferenceResults -> {
295295
inferencingState = InferencingState.Started
296-
inferenceResults.add(deviceMessage)
297-
}
298-
else -> {
296+
_inferenceResults.add(deviceMessage)
299297
}
298+
else -> {}
300299
}
301300
}
302301
}
@@ -390,18 +389,17 @@ class CommsManager(
390389
client.newCall(request = request)
391390
.enqueue(responseCallback = object : Callback {
392391
override fun onFailure(call: Call, e: IOException) {
393-
samplingState = Finished(false, e.message)
392+
samplingState = Finished(e.message)
394393
isSamplingRequestedFromDevice = false
395394
}
396395

397396
override fun onResponse(call: Call, response: okhttp3.Response) {
398397
samplingState = Finished(
399-
sampleFinished = true,
400398
error = response
401399
.takeIf { !it.isSuccessful }
402400
?.let {
403401
"Error while uploading sample. ${String(it.body.bytes())}"
404-
} ?: run { "Data sample uploaded." }
402+
}
405403
)
406404
isSamplingRequestedFromDevice = false
407405
}

app/src/main/java/no/nordicsemi/android/ei/model/Message.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,7 @@ sealed class Message {
8383

8484
}
8585

86-
data class Finished(
87-
val sampleFinished: Boolean = true,
88-
val error: String? = null
89-
) : Sample()
86+
data class Finished(val error: String? = null) : Sample()
9087

9188
object Unknown : Sample()
9289
}

app/src/main/java/no/nordicsemi/android/ei/ui/Dashboard.kt

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import androidx.compose.foundation.layout.WindowInsets
2424
import androidx.compose.foundation.layout.WindowInsetsSides
2525
import androidx.compose.foundation.layout.aspectRatio
2626
import androidx.compose.foundation.layout.consumeWindowInsets
27+
import androidx.compose.foundation.layout.displayCutout
2728
import androidx.compose.foundation.layout.fillMaxHeight
2829
import androidx.compose.foundation.layout.fillMaxSize
2930
import androidx.compose.foundation.layout.fillMaxWidth
@@ -35,6 +36,8 @@ import androidx.compose.foundation.layout.padding
3536
import androidx.compose.foundation.layout.requiredSize
3637
import androidx.compose.foundation.layout.safeDrawing
3738
import androidx.compose.foundation.layout.size
39+
import androidx.compose.foundation.layout.statusBars
40+
import androidx.compose.foundation.layout.union
3841
import androidx.compose.foundation.layout.width
3942
import androidx.compose.foundation.layout.windowInsetsPadding
4043
import androidx.compose.foundation.lazy.LazyColumn
@@ -217,7 +220,7 @@ fun Dashboard(
217220
.padding(horizontal = 16.dp, vertical = 16.dp),
218221
text = stringResource(id = R.string.title_projects),
219222
color = MaterialTheme.colorScheme.onSurface,
220-
style = MaterialTheme.typography.titleLarge
223+
style = MaterialTheme.typography.labelLarge
221224
)
222225
}
223226
items(
@@ -276,7 +279,7 @@ fun Dashboard(
276279
type = key.type,
277280
onCreateKey = {
278281
missingKey = null
279-
282+
280283
viewModel.createKey(
281284
project = key.project,
282285
type = key.type,
@@ -296,49 +299,52 @@ fun Dashboard(
296299
ShowDownloadingDevelopmentKeysDialog()
297300
}
298301
}
302+
val innerPadding = WindowInsets.displayCutout.union(WindowInsets.statusBars)
299303
Surface(
300-
modifier = with(Modifier) {
301-
offset(y = (56.dp))
302-
.padding(
303-
start = 16.dp,
304-
top = when {
305-
isLargeScreen -> 32.dp
306-
else -> 56.dp
307-
}
308-
)
309-
.border(
310-
border = BorderStroke(3.dp, color = MaterialTheme.colorScheme.onPrimary),
311-
shape = CircleShape
312-
)
313-
.height(UserAppBarImageSize)
314-
.aspectRatio(1.0f)
315-
.shadow(
316-
elevation = 4.dp,
317-
shape = CircleShape
318-
)
319-
},
304+
modifier = Modifier
305+
.windowInsetsPadding(innerPadding)
306+
.offset(y = 16.dp)
307+
.padding(
308+
start = 16.dp,
309+
top = when {
310+
isLargeScreen -> 32.dp
311+
else -> 56.dp
312+
}
313+
)
314+
.border(
315+
border = BorderStroke(3.dp, color = MaterialTheme.colorScheme.onPrimary),
316+
shape = CircleShape
317+
)
318+
.height(UserAppBarImageSize)
319+
.aspectRatio(1.0f)
320+
.shadow(
321+
elevation = 4.dp,
322+
shape = CircleShape
323+
),
320324
shape = CircleShape,
321325
) {
322326
Image(
323327
painter = rememberAsyncImagePainter(
324328
ImageRequest.Builder(LocalContext.current).data(data = user.photo?.let { photo ->
325329
when {
326330
photo.isNotBlank() -> photo
327-
else -> Image(
328-
modifier = Modifier.border(
329-
border = BorderStroke(
330-
10.dp,
331-
color = MaterialTheme.colorScheme.surface.copy(0.6f)
332-
)
333-
),
334-
imageVector = Icons.Filled.AccountCircle,
335-
contentDescription = null,
336-
colorFilter = ColorFilter.tint(
337-
MaterialTheme.colorScheme.onSurface.copy(
338-
0.6f
331+
else -> {
332+
Image(
333+
modifier = Modifier.border(
334+
border = BorderStroke(
335+
10.dp,
336+
color = MaterialTheme.colorScheme.surface.copy(0.6f)
337+
)
338+
),
339+
imageVector = Icons.Filled.AccountCircle,
340+
contentDescription = null,
341+
colorFilter = ColorFilter.tint(
342+
MaterialTheme.colorScheme.onSurface.copy(
343+
0.6f
344+
)
339345
)
340346
)
341-
)
347+
}
342348
}
343349
} ?: Image(
344350
modifier = Modifier.border(

0 commit comments

Comments
 (0)