Meshtastic-Android/app/src/main/java/com/geeksville/mesh/ui/Channel.kt

97 lines
3.2 KiB
Kotlin
Raw Normal View History

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-02-17 20:00:11 -08:00
import androidx.ui.layout.*
import androidx.ui.material.MaterialTheme
import androidx.ui.material.OutlinedButton
2020-02-18 08:56:37 -08:00
import androidx.ui.material.ripple.Ripple
2020-02-17 20:00:11 -08:00
import androidx.ui.tooling.preview.Preview
import androidx.ui.unit.dp
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.UIState
2020-03-15 16:30:12 -07:00
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
@Composable
2020-03-15 16:30:12 -07:00
fun ChannelContent(channel: Channel?) {
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) {
Text(
text = "Channel: ${channel.name}",
modifier = LayoutGravity.Center,
style = typography.h4
)
2020-02-17 20:17:08 -08:00
2020-03-15 16:30:12 -07:00
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)
)
Ripple(bounded = false) {
OutlinedButton(modifier = LayoutGravity.Center + LayoutPadding(start = 24.dp),
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
putExtra(Intent.EXTRA_TEXT, UIState.getChannelUrl(context))
putExtra(Intent.EXTRA_TITLE, "A URL for joining a Meshtastic mesh")
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-02-17 20:00:11 -08:00
2020-03-15 16:30:12 -07:00
Text(
text = "Number: ${channel.num}",
modifier = LayoutGravity.Center
)
Text(
text = "Mode: ${channel.modemConfig.toHumanString()}",
modifier = LayoutGravity.Center
)
}
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
}
}