-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
**Background** With newest firmware version you can use echo from/to flipper **Changes** - Add echo screen **Test plan** Open information screen Type text and send
- Loading branch information
Showing
9 changed files
with
207 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 77 additions & 1 deletion
78
components/info/src/main/java/com/flipper/info/main/compose/ComposeInfoScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,99 @@ | ||
package com.flipper.info.main.compose | ||
|
||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxHeight | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.foundation.lazy.items | ||
import androidx.compose.material.Button | ||
import androidx.compose.material.Divider | ||
import androidx.compose.material.Text | ||
import androidx.compose.material.TextField | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.saveable.rememberSaveable | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import com.flipper.bridge.model.FlipperGATTInformation | ||
import com.flipper.info.R | ||
|
||
@Preview( | ||
showBackground = true, | ||
showSystemUi = true | ||
) | ||
@Composable | ||
fun ComposeInfoScreen( | ||
flipperGATTInformation: FlipperGATTInformation = FlipperGATTInformation() | ||
flipperGATTInformation: FlipperGATTInformation = FlipperGATTInformation(), | ||
echoAnswers: List<ByteArray> = listOf("Test", "Test2").map { it.toByteArray() }, | ||
echoListener: (String) -> Unit = {}, | ||
) { | ||
var text by rememberSaveable { mutableStateOf("") } | ||
|
||
Column { | ||
Text(text = "Device name: ${flipperGATTInformation.deviceName ?: "Unavailable"}") | ||
Text(text = "Manufacturer: ${flipperGATTInformation.manufacturerName ?: "Unavailable"}") | ||
Text(text = "Hardware: ${flipperGATTInformation.hardwareRevision ?: "Unavailable"}") | ||
Text(text = "Firmware: ${flipperGATTInformation.softwareVersion ?: "Unavailable"}") | ||
Row( | ||
modifier = Modifier.fillMaxWidth() | ||
) { | ||
TextField( | ||
value = text, | ||
onValueChange = { | ||
text = it | ||
}, | ||
label = { Text("Type text") } | ||
) | ||
Button( | ||
onClick = { | ||
echoListener.invoke(text) | ||
} | ||
) { | ||
Image( | ||
painter = painterResource(id = R.drawable.ic_baseline_send_24), | ||
contentDescription = "Send" | ||
) | ||
} | ||
} | ||
if (echoAnswers.isEmpty()) { | ||
Text( | ||
text = "No echo answers yet", | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.fillMaxHeight() | ||
) | ||
} else { | ||
LazyColumn( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.fillMaxHeight() | ||
) { | ||
items(echoAnswers) { bytes -> | ||
EchoAnswer(String(bytes), bytes.toHex()) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun EchoAnswer(echoAnswer: String, hexRepresentation: String) { | ||
Column( | ||
modifier = Modifier.padding(all = 16.dp) | ||
) { | ||
Text(text = echoAnswer) | ||
Text(text = "HEX: $hexRepresentation") | ||
} | ||
Divider(color = Color.Black, thickness = 1.dp) | ||
} | ||
|
||
private fun ByteArray.toHex(): String = | ||
joinToString(separator = " ") { eachByte -> "%02x".format(eachByte) } |
28 changes: 27 additions & 1 deletion
28
...bridge/impl/viewmodel/FlipperViewModel.kt → ...per/info/main/service/FlipperViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
components/info/src/main/res/drawable/ic_baseline_send_24.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:autoMirrored="true" | ||
android:height="24dp" | ||
android:tint="?attr/colorControlNormal" | ||
android:viewportHeight="24" | ||
android:viewportWidth="24" | ||
android:width="24dp"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M2.01,21L23,12 2.01,3 2,10l15,2 -15,2z" /> | ||
</vector> |