kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
channel editing kinda works
rodzic
36b2da72e4
commit
506796c54b
|
@ -5,8 +5,10 @@ import android.content.SharedPreferences
|
|||
import android.graphics.Bitmap
|
||||
import android.os.RemoteException
|
||||
import android.util.Base64
|
||||
import androidx.compose.Model
|
||||
import androidx.compose.mutableStateOf
|
||||
import androidx.core.content.edit
|
||||
import com.geeksville.android.BuildUtils.isEmulator
|
||||
import com.geeksville.android.Logging
|
||||
import com.geeksville.mesh.IMeshService
|
||||
import com.geeksville.mesh.MeshProtos
|
||||
|
@ -16,18 +18,21 @@ import com.google.zxing.BarcodeFormat
|
|||
import com.google.zxing.MultiFormatWriter
|
||||
import com.journeyapps.barcodescanner.BarcodeEncoder
|
||||
|
||||
@Model
|
||||
data class Channel(
|
||||
val name: String,
|
||||
val num: Int,
|
||||
val modemConfig: ModemConfig = ModemConfig.Bw125Cr45Sf128
|
||||
var name: String,
|
||||
var modemConfig: ModemConfig
|
||||
) {
|
||||
companion object {
|
||||
// Placeholder when emulating
|
||||
val emulated = Channel("Default", 7)
|
||||
val emulated = Channel("Default", ModemConfig.Bw125Cr45Sf128)
|
||||
}
|
||||
|
||||
constructor(c: MeshProtos.ChannelSettings) : this(c.name, c.channelNum, c.modemConfig) {
|
||||
constructor(c: MeshProtos.ChannelSettings) : this(c.name, c.modemConfig) {
|
||||
}
|
||||
|
||||
/// Can this channel be changed right now?
|
||||
var editable = false
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -60,7 +65,19 @@ object UIState : Logging {
|
|||
/// our activity will read this from prefs or set it to the empty string
|
||||
var ownerName: String = "MrInIDE Ownername"
|
||||
|
||||
fun getChannel() = radioConfig.value?.channelSettings?.let { Channel(it) }
|
||||
/**
|
||||
* Return the current channel info
|
||||
* FIXME, we should sim channels at the MeshService level if we are running on an emulator,
|
||||
* for now I just fake it by returning a canned channel.
|
||||
*/
|
||||
fun getChannel(): Channel? {
|
||||
val channel = radioConfig.value?.channelSettings?.let { Channel(it) }
|
||||
|
||||
return if (channel == null && isEmulator)
|
||||
Channel.emulated
|
||||
else
|
||||
channel
|
||||
}
|
||||
|
||||
/// Return an URL that represents the current channel values
|
||||
fun getChannelUrl(context: Context): String {
|
||||
|
|
|
@ -4,10 +4,10 @@ import android.content.Intent
|
|||
import androidx.compose.Composable
|
||||
import androidx.ui.core.ContextAmbient
|
||||
import androidx.ui.core.Text
|
||||
import androidx.ui.input.ImeAction
|
||||
import androidx.ui.layout.*
|
||||
import androidx.ui.material.MaterialTheme
|
||||
import androidx.ui.material.OutlinedButton
|
||||
import androidx.ui.material.ripple.Ripple
|
||||
import androidx.ui.tooling.preview.Preview
|
||||
import androidx.ui.unit.dp
|
||||
import com.geeksville.analytics.DataPair
|
||||
|
@ -31,24 +31,65 @@ fun ChannelContent(channel: Channel?) {
|
|||
|
||||
Column(modifier = LayoutSize.Fill + LayoutPadding(16.dp)) {
|
||||
if (channel != null) {
|
||||
Row(modifier = LayoutGravity.Center) {
|
||||
|
||||
Text(text = "Channel ", modifier = LayoutGravity.Center)
|
||||
|
||||
if (channel.editable) {
|
||||
// FIXME - limit to max length
|
||||
StyledTextField(
|
||||
value = channel.name,
|
||||
onValueChange = { channel.name = it },
|
||||
textStyle = typography.h4.copy(
|
||||
color = palette.onSecondary.copy(alpha = 0.8f)
|
||||
),
|
||||
imeAction = ImeAction.Send,
|
||||
onImeActionPerformed = {
|
||||
TODO()
|
||||
}
|
||||
)
|
||||
} else {
|
||||
Text(
|
||||
text = channel.name,
|
||||
style = typography.h4
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// simulated qr code
|
||||
// val image = imageResource(id = R.drawable.qrcode)
|
||||
val image = AndroidImage(UIState.getChannelQR(context))
|
||||
|
||||
ScaledImage(
|
||||
image = image,
|
||||
modifier = LayoutGravity.Center + LayoutSize.Min(200.dp, 200.dp)
|
||||
)
|
||||
|
||||
Text(
|
||||
text = "Channel: ${channel.name}",
|
||||
modifier = LayoutGravity.Center,
|
||||
style = typography.h4
|
||||
text = "Mode: ${channel.modemConfig.toHumanString()}",
|
||||
modifier = LayoutGravity.Center + LayoutPadding(bottom = 16.dp)
|
||||
)
|
||||
|
||||
Row(modifier = LayoutGravity.Center) {
|
||||
// simulated qr code
|
||||
// val image = imageResource(id = R.drawable.qrcode)
|
||||
val image = AndroidImage(UIState.getChannelQR(context))
|
||||
|
||||
ScaledImage(
|
||||
image = image,
|
||||
modifier = LayoutGravity.Center + LayoutSize.Min(200.dp, 200.dp)
|
||||
)
|
||||
OutlinedButton(onClick = {
|
||||
channel.editable = !channel.editable
|
||||
}) {
|
||||
if (channel.editable)
|
||||
VectorImage(
|
||||
id = R.drawable.ic_twotone_lock_open_24,
|
||||
tint = palette.onBackground
|
||||
)
|
||||
else
|
||||
VectorImage(
|
||||
id = R.drawable.ic_twotone_lock_24,
|
||||
tint = palette.onBackground
|
||||
)
|
||||
}
|
||||
|
||||
Ripple(bounded = false) {
|
||||
OutlinedButton(modifier = LayoutGravity.Center + LayoutPadding(start = 24.dp),
|
||||
// Only show the share buttone once we are locked
|
||||
if (!channel.editable)
|
||||
OutlinedButton(modifier = LayoutPadding(start = 24.dp),
|
||||
onClick = {
|
||||
GeeksvilleApplication.analytics.track(
|
||||
"share",
|
||||
|
@ -58,7 +99,10 @@ fun ChannelContent(channel: Channel?) {
|
|||
val sendIntent: Intent = Intent().apply {
|
||||
action = Intent.ACTION_SEND
|
||||
putExtra(Intent.EXTRA_TEXT, UIState.getChannelUrl(context))
|
||||
putExtra(Intent.EXTRA_TITLE, "A URL for joining a Meshtastic mesh")
|
||||
putExtra(
|
||||
Intent.EXTRA_TITLE,
|
||||
"A URL for joining a Meshtastic mesh"
|
||||
)
|
||||
type = "text/plain"
|
||||
}
|
||||
|
||||
|
@ -70,17 +114,7 @@ fun ChannelContent(channel: Channel?) {
|
|||
tint = palette.onBackground
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Text(
|
||||
text = "Number: ${channel.num}",
|
||||
modifier = LayoutGravity.Center
|
||||
)
|
||||
Text(
|
||||
text = "Mode: ${channel.modemConfig.toHumanString()}",
|
||||
modifier = LayoutGravity.Center
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 66e926740acb30518d1fdcb901d1cc0b0d48122c
|
||||
Subproject commit 398fdf362518e9d6869247cef09f2e071b715639
|
|
@ -0,0 +1,15 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M6,20h12L18,10L6,10v10zM12,13c1.1,0 2,0.9 2,2s-0.9,2 -2,2 -2,-0.9 -2,-2 0.9,-2 2,-2z"
|
||||
android:strokeAlpha="0.3"
|
||||
android:fillAlpha="0.3"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M18,8h-1L17,6c0,-2.76 -2.24,-5 -5,-5S7,3.24 7,6v2L6,8c-1.1,0 -2,0.9 -2,2v10c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L20,10c0,-1.1 -0.9,-2 -2,-2zM9,6c0,-1.66 1.34,-3 3,-3s3,1.34 3,3v2L9,8L9,6zM18,20L6,20L6,10h12v10zM12,17c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2z"/>
|
||||
</vector>
|
|
@ -0,0 +1,15 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M6,20h12L18,10L6,10v10zM12,13c1.1,0 2,0.9 2,2s-0.9,2 -2,2 -2,-0.9 -2,-2 0.9,-2 2,-2z"
|
||||
android:strokeAlpha="0.3"
|
||||
android:fillAlpha="0.3"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M18,8h-1L17,6c0,-2.76 -2.24,-5 -5,-5S7,3.24 7,6h2c0,-1.66 1.34,-3 3,-3s3,1.34 3,3v2L6,8c-1.1,0 -2,0.9 -2,2v10c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L20,10c0,-1.1 -0.9,-2 -2,-2zM18,20L6,20L6,10h12v10zM12,17c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2z"/>
|
||||
</vector>
|
Ładowanie…
Reference in New Issue