2020-02-17 20:00:11 -08:00
|
|
|
package com.geeksville.mesh.ui
|
|
|
|
|
|
2020-03-02 08:41:16 -08:00
|
|
|
import android.content.Intent
|
2020-02-17 20:00:11 -08:00
|
|
|
import androidx.compose.Composable
|
2020-03-15 16:30:12 -07:00
|
|
|
import androidx.ui.core.ContextAmbient
|
|
|
|
|
import androidx.ui.core.Text
|
2020-03-15 18:44:10 -07:00
|
|
|
import androidx.ui.input.ImeAction
|
2020-02-17 20:00:11 -08:00
|
|
|
import androidx.ui.layout.*
|
|
|
|
|
import androidx.ui.material.MaterialTheme
|
2020-02-29 15:56:00 -08:00
|
|
|
import androidx.ui.material.OutlinedButton
|
2020-02-17 20:00:11 -08:00
|
|
|
import androidx.ui.tooling.preview.Preview
|
|
|
|
|
import androidx.ui.unit.dp
|
2020-03-03 20:07:40 -08:00
|
|
|
import com.geeksville.analytics.DataPair
|
2020-02-25 10:30:10 -08:00
|
|
|
import com.geeksville.android.GeeksvilleApplication
|
2020-02-18 08:56:37 -08:00
|
|
|
import com.geeksville.android.Logging
|
2020-02-17 20:00:11 -08:00
|
|
|
import com.geeksville.mesh.R
|
2020-03-15 16:30:12 -07:00
|
|
|
import com.geeksville.mesh.model.Channel
|
|
|
|
|
import com.geeksville.mesh.model.toHumanString
|
2020-02-17 20:00:11 -08:00
|
|
|
|
|
|
|
|
|
2020-02-18 08:56:37 -08:00
|
|
|
object ChannelLog : Logging
|
|
|
|
|
|
2020-03-02 07:46:03 -08:00
|
|
|
|
2020-03-04 13:40:09 -08:00
|
|
|
@Composable
|
2020-03-15 16:30:12 -07:00
|
|
|
fun ChannelContent(channel: Channel?) {
|
2020-03-04 12:13:21 -08:00
|
|
|
analyticsScreen(name = "channel")
|
|
|
|
|
|
2020-02-17 20:00:11 -08:00
|
|
|
val typography = MaterialTheme.typography()
|
2020-02-29 14:34:20 -08:00
|
|
|
val context = ContextAmbient.current
|
2020-02-17 20:00:11 -08:00
|
|
|
|
|
|
|
|
Column(modifier = LayoutSize.Fill + LayoutPadding(16.dp)) {
|
2020-03-15 16:30:12 -07:00
|
|
|
if (channel != null) {
|
2020-03-15 18:44:10 -07:00
|
|
|
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)
|
|
|
|
|
),
|
2020-03-17 11:35:19 -07:00
|
|
|
imeAction = ImeAction.Done,
|
2020-03-15 18:44:10 -07:00
|
|
|
onImeActionPerformed = {
|
|
|
|
|
TODO()
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
Text(
|
|
|
|
|
text = channel.name,
|
|
|
|
|
style = typography.h4
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// simulated qr code
|
|
|
|
|
// val image = imageResource(id = R.drawable.qrcode)
|
2020-03-17 11:35:19 -07:00
|
|
|
val image = AndroidImage(channel.getChannelQR())
|
2020-03-15 18:44:10 -07:00
|
|
|
|
|
|
|
|
ScaledImage(
|
|
|
|
|
image = image,
|
|
|
|
|
modifier = LayoutGravity.Center + LayoutSize.Min(200.dp, 200.dp)
|
|
|
|
|
)
|
|
|
|
|
|
2020-03-15 16:30:12 -07:00
|
|
|
Text(
|
2020-03-15 18:44:10 -07:00
|
|
|
text = "Mode: ${channel.modemConfig.toHumanString()}",
|
|
|
|
|
modifier = LayoutGravity.Center + LayoutPadding(bottom = 16.dp)
|
2020-03-04 13:40:09 -08:00
|
|
|
)
|
2020-02-17 20:17:08 -08:00
|
|
|
|
2020-03-15 16:30:12 -07:00
|
|
|
Row(modifier = LayoutGravity.Center) {
|
|
|
|
|
|
2020-03-15 18:44:10 -07:00
|
|
|
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
|
|
|
|
|
)
|
|
|
|
|
}
|
2020-03-15 16:30:12 -07:00
|
|
|
|
2020-03-15 18:44:10 -07:00
|
|
|
// Only show the share buttone once we are locked
|
|
|
|
|
if (!channel.editable)
|
|
|
|
|
OutlinedButton(modifier = LayoutPadding(start = 24.dp),
|
2020-03-15 16:30:12 -07:00
|
|
|
onClick = {
|
|
|
|
|
GeeksvilleApplication.analytics.track(
|
|
|
|
|
"share",
|
|
|
|
|
DataPair("content_type", "channel")
|
|
|
|
|
) // track how many times users share channels
|
|
|
|
|
|
|
|
|
|
val sendIntent: Intent = Intent().apply {
|
|
|
|
|
action = Intent.ACTION_SEND
|
2020-03-30 16:46:12 -07:00
|
|
|
putExtra(Intent.EXTRA_TEXT, channel.getChannelUrl().toString())
|
2020-03-15 18:44:10 -07:00
|
|
|
putExtra(
|
|
|
|
|
Intent.EXTRA_TITLE,
|
|
|
|
|
"A URL for joining a Meshtastic mesh"
|
|
|
|
|
)
|
2020-03-15 16:30:12 -07:00
|
|
|
type = "text/plain"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val shareIntent = Intent.createChooser(sendIntent, null)
|
|
|
|
|
context.startActivity(shareIntent)
|
|
|
|
|
}) {
|
|
|
|
|
VectorImage(
|
|
|
|
|
id = R.drawable.ic_twotone_share_24,
|
|
|
|
|
tint = palette.onBackground
|
|
|
|
|
)
|
|
|
|
|
}
|
2020-02-18 08:56:37 -08:00
|
|
|
}
|
2020-03-15 16:30:12 -07:00
|
|
|
}
|
2020-02-17 20:00:11 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Preview
|
|
|
|
|
@Composable
|
|
|
|
|
fun previewChannel() {
|
|
|
|
|
// another bug? It seems modaldrawerlayout not yet supported in preview
|
|
|
|
|
MaterialTheme(colors = palette) {
|
2020-03-15 16:30:12 -07:00
|
|
|
ChannelContent(Channel.emulated)
|
2020-02-17 20:00:11 -08:00
|
|
|
}
|
|
|
|
|
}
|