Remove unneeded "Home" page, remove unneeded nav controller.
parent
b0045dd499
commit
bcab9dcd9f
@ -1,168 +0,0 @@
|
||||
package dev.equestria.pluralwear.presentation.activity.home
|
||||
|
||||
import dev.equestria.pluralwear.pluralkt.fulltypes.PkFullSystem
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.wrapContentSize
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.tooling.preview.Devices
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.ExperimentalUnitApi
|
||||
import androidx.compose.ui.unit.TextUnit
|
||||
import androidx.compose.ui.unit.TextUnitType
|
||||
import androidx.navigation.NavHostController
|
||||
import androidx.wear.compose.material.Chip
|
||||
import androidx.wear.compose.material.ChipDefaults
|
||||
import androidx.wear.compose.material.Icon
|
||||
import androidx.wear.compose.material.MaterialTheme
|
||||
import androidx.wear.compose.material.Text
|
||||
import androidx.wear.compose.material.TimeText
|
||||
import dev.equestria.pluralwear.R
|
||||
import dev.equestria.pluralwear.components.ScalingLazyColumnWithRSB
|
||||
import java.util.Calendar
|
||||
|
||||
class HomeActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContent {
|
||||
HomePage(null, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun HomePage(system: PkFullSystem?, navigator: NavHostController?) {
|
||||
TimeText()
|
||||
|
||||
ScalingLazyColumnWithRSB(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
snap = true
|
||||
) {
|
||||
item {
|
||||
if (system != null) {
|
||||
Greeting(
|
||||
//if (system.name != null) system.name!! else "No Name"
|
||||
if (system.front != null) {
|
||||
if (system.front!!.members.isEmpty()) {
|
||||
if (system.name != null) system.name!! else "No Name"
|
||||
} else if (system.front!!.members.size <= 2) {
|
||||
var name = system.front!!.members
|
||||
name.joinToString(", ") {
|
||||
if(it.displayName != null) it.displayName!! else it.name
|
||||
}
|
||||
} else {
|
||||
if (system.name != null) system.name!! else "No Name"
|
||||
}
|
||||
} else {
|
||||
if (system.name != null) system.name!! else "No Name"
|
||||
}
|
||||
)
|
||||
} else {
|
||||
Greeting(null)
|
||||
}
|
||||
}
|
||||
|
||||
item {
|
||||
NavItem(
|
||||
label = "Front Info",
|
||||
drawableId = R.drawable.baseline_account_box_24,
|
||||
drawableDescriptor = "White box with person inside"
|
||||
) {
|
||||
navigator?.navigate("front")
|
||||
}
|
||||
}
|
||||
|
||||
item {
|
||||
Chip(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
onClick = { navigator?.navigate("switch") },
|
||||
label = { Text("Register switch") },
|
||||
colors = ChipDefaults.secondaryChipColors(),
|
||||
icon = {
|
||||
Icon(
|
||||
painter = painterResource(id = R.drawable.baseline_switch_account_24),
|
||||
contentDescription = "Switch",
|
||||
modifier = Modifier
|
||||
.size(ChipDefaults.IconSize)
|
||||
.wrapContentSize(align = Alignment.Center),
|
||||
tint = Color.Unspecified
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun NavItem(
|
||||
label: String,
|
||||
drawableId: Int,
|
||||
drawableDescriptor: String,
|
||||
onClick: () -> Unit
|
||||
) {
|
||||
Chip(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
onClick = {
|
||||
onClick.invoke()
|
||||
},
|
||||
label = { Text(label) },
|
||||
colors = ChipDefaults.secondaryChipColors(),
|
||||
icon = {
|
||||
Icon(
|
||||
painter = painterResource(id = drawableId),
|
||||
contentDescription = drawableDescriptor,
|
||||
modifier = Modifier
|
||||
.size(ChipDefaults.IconSize)
|
||||
.wrapContentSize(align = Alignment.Center),
|
||||
tint = Color.Unspecified
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalUnitApi::class)
|
||||
@Composable
|
||||
fun Greeting(greetingName: String?) {
|
||||
val greeting = when (Calendar.getInstance().get(Calendar.HOUR_OF_DAY)) {
|
||||
6, 7, 8, 9, 10, 11 -> stringResource(R.string.greeting_morning)
|
||||
12, 13, 14, 15, 16 -> stringResource(R.string.greeting_afternoon)
|
||||
else -> stringResource(R.string.greeting_evening)
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Text(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
textAlign = TextAlign.Center,
|
||||
color = MaterialTheme.colors.onSurface,
|
||||
text = stringResource(R.string.greeting, greeting)
|
||||
)
|
||||
if (greetingName != null) {
|
||||
Text(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth(),
|
||||
textAlign = TextAlign.Center,
|
||||
color = MaterialTheme.colors.onSurfaceVariant,
|
||||
text = greetingName,
|
||||
fontSize = TextUnit(1.9F, TextUnitType.Em)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Preview(device = Devices.WEAR_OS_SMALL_ROUND, showSystemUi = true)
|
||||
@Composable
|
||||
fun DefaultPreview() {
|
||||
HomePage(null, null)
|
||||
}
|
Loading…
Reference in New Issue