Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page home #12

Merged
merged 5 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions app/src/main/java/com/eipsaferoad/owl/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class MainActivity : ComponentActivity(),
CapabilityClient.OnCapabilityChangedListener {

private var bpm: MutableState<String> = mutableStateOf("0")
private var isAlarmActivated: MutableState<Boolean> = mutableStateOf(true)
private var accessToken: MutableState<String?> = mutableStateOf(null)
private var url: MutableState<String> = mutableStateOf("")
private var activityContext: Context? = null
Expand Down Expand Up @@ -88,7 +89,7 @@ class MainActivity : ComponentActivity(),
setTheme(android.R.style.Theme_DeviceDefault)
url.value = ReadEnvVar.readEnvVar(this, ReadEnvVar.EnvVar.API_URL)
setContent {
WearApp(this, bpm.value, url.value) { token -> accessToken.value = token }
WearApp(this, bpm, isAlarmActivated, url.value) { token -> accessToken.value = token }
}
}

Expand Down Expand Up @@ -203,7 +204,7 @@ fun login(apiUrl: String, email: String, password: String, navController: NavHos
}

@Composable
fun WearApp(context: Context, currentHeartRate: String, apiUrl: String, setAccessToken: (token: String) -> Unit) {
fun WearApp(context: Context, currentHeartRate: MutableState<String>, isAlarmActivated: MutableState<Boolean>, apiUrl: String, setAccessToken: (token: String) -> Unit) {
val navController = rememberSwipeDismissableNavController()
val email = LocalStorage.getData(context, "email");
val password = LocalStorage.getData(context, "password");
Expand All @@ -224,7 +225,7 @@ fun WearApp(context: Context, currentHeartRate: String, apiUrl: String, setAcces
contentAlignment = Alignment.Center
) {
TimeText()
Home(currentHeartRate, context, navController)
Home(currentHeartRate, context, navController, isAlarmActivated.value)
}
}
composable(PagesEnum.LOGIN.value) {
Expand Down Expand Up @@ -257,7 +258,7 @@ fun WearApp(context: Context, currentHeartRate: String, apiUrl: String, setAcces
contentAlignment = Alignment.Center
) {
TimeText()
Alarm(currentHeartRate, context, navController)
Alarm(currentHeartRate.value, context, navController)
}
}
}
Expand All @@ -267,5 +268,7 @@ fun WearApp(context: Context, currentHeartRate: String, apiUrl: String, setAcces
@Preview(device = Devices.WEAR_OS_SMALL_ROUND, showSystemUi = true)
@Composable
fun DefaultPreview() {
WearApp(LocalContext.current , "42", "", {})
var bpm: MutableState<String> = mutableStateOf("0")
var isAlarmActivated: MutableState<Boolean> = mutableStateOf(true)
WearApp(LocalContext.current , bpm, isAlarmActivated, "", {})
}
222 changes: 182 additions & 40 deletions app/src/main/java/com/eipsaferoad/owl/presentation/home/Home.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
package com.eipsaferoad.owl.presentation.home

import android.content.Context
import androidx.compose.animation.core.RepeatMode
import androidx.compose.animation.core.animateFloat
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.rememberInfiniteTransition
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Clear
import androidx.compose.material.icons.rounded.Favorite
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
Expand All @@ -32,11 +53,11 @@ import com.eipsaferoad.owl.presentation.theme.OwlTheme
import com.eipsaferoad.owl.utils.LocalStorage

@Composable
fun Home(currentHeartRate: String, context: Context, navController: NavHostController) {
if (currentHeartRate.toInt() < 50 && currentHeartRate.toInt() != 0) {
Alarm(currentHeartRate, context, navController)
fun Home(currentHeartRate: MutableState<String>, context: Context, navController: NavHostController, isAlarmActivated: Boolean) {
if (isAlarmActivated && currentHeartRate.value.toInt() < 50 && currentHeartRate.value.toInt() != 0) {
Alarm(currentHeartRate)
} else {
NoAlarm(currentHeartRate, context, navController)
NoAlarm(currentHeartRate.value, context, navController)
}
}

Expand All @@ -47,31 +68,48 @@ fun NoAlarm(currentHeartRate: String, context: Context, navController: NavHostCo
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Icon(
imageVector = Icons.Rounded.Favorite,
contentDescription = "Favorite Icon",
tint = Color.Red
)
Text(
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.Center,
fontWeight = FontWeight.Bold,
color = Color.White,
text = currentHeartRate,
fontSize = 40.sp
)
Buttons(context = context, navController = navController)
LazyColumn(
modifier = Modifier.height(200.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
item {
Column(
modifier = Modifier.padding(bottom = 100.dp, top = 70.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Icon(
imageVector = Icons.Rounded.Favorite,
contentDescription = "Favorite Icon",
tint = Color.Red
)
Text(
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.Center,
fontWeight = FontWeight.Bold,
color = Color.White,
text = currentHeartRate,
fontSize = 40.sp
)
}
}
item {
Buttons(context = context, navController = navController)
}
}
}
}

@Composable
fun Buttons(context: Context, navController: NavHostController) {
Column(
modifier = Modifier.padding(bottom = 40.dp),
verticalArrangement = Arrangement.spacedBy(10.dp)
) {
Button(
modifier = Modifier
.width(200.dp),
.width(150.dp),
shape = RoundedCornerShape(10),
colors = ButtonDefaults.buttonColors(backgroundColor = MaterialTheme.colorScheme.primary),
onClick = {
Expand All @@ -84,7 +122,7 @@ fun Buttons(context: Context, navController: NavHostController) {
)
}
Button(
modifier = Modifier.width(200.dp),
modifier = Modifier.width(150.dp),
shape = RoundedCornerShape(10),
colors = ButtonDefaults.buttonColors(backgroundColor = MaterialTheme.colorScheme.tertiary),
onClick = {
Expand All @@ -94,47 +132,151 @@ fun Buttons(context: Context, navController: NavHostController) {
}
) {
Text(
fontSize = 20.sp,
fontSize = 17.sp,
text = "DISCONNECTION",
)
}
}
}

@Composable
fun Alarm(currentHeartRate: String, context: Context, navController: NavHostController) {
Column(
fun MultiColorBorderCircularColumn(
borderColors: List<Color>,
content: @Composable () -> Unit
) {
val transition = rememberInfiniteTransition(label = "")

val rotation by transition.animateFloat(
initialValue = 0f,
targetValue = 360f,
animationSpec = infiniteRepeatable(
animation = tween(durationMillis = 5000),
repeatMode = RepeatMode.Restart
), label = ""
)

Surface(
modifier = Modifier
.fillMaxSize()
.border(
width = 5.dp,
color = Color.Transparent,
shape = CircleShape
)
.graphicsLayer(
rotationZ = rotation
),
contentColor = Color.White
) {
Box(
modifier = Modifier
.fillMaxSize()
.border(
width = 7.dp,
brush = borderBrushMultiColor(borderColors),
shape = CircleShape
)
.background(MaterialTheme.colorScheme.background)
) {
content()
}
}
}

@Composable
fun borderBrushMultiColor(colors: List<Color>): Brush {
return Brush.linearGradient(
colors = colors,
)
}

@Composable
fun Alarm(currentHeartRate: MutableState<String>) {
Box(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
contentAlignment = Alignment.Center
) {
// Background element
MultiColorBorderCircularColumn(
borderColors = listOf(
MaterialTheme.colorScheme.secondary,
Color.Transparent,
MaterialTheme.colorScheme.secondary,
)
) {}
Column(
modifier = Modifier
.padding(30.dp)
.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally,
) {
Column(
modifier = Modifier
.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.Center,
fontWeight = FontWeight.Bold,
color = MaterialTheme.colorScheme.error,
text = currentHeartRate.value,
fontSize = 20.sp
)
Text(
modifier = Modifier
.fillMaxWidth()
.padding(bottom = 20.dp),
textAlign = TextAlign.Center,
fontWeight = FontWeight.Bold,
color = MaterialTheme.colorScheme.secondary,
text = "SOS",
fontSize = 30.sp
)
Button(
onClick = {
currentHeartRate.value = "100"
}
) {
CircleIcon(icon = Icons.Rounded.Clear, tint = MaterialTheme.colorScheme.surface)
}
}
}
}
}

@Composable
fun CircleIcon(icon: ImageVector, tint: Color) {
Box(
modifier = Modifier
.size(50.dp)
.background(color = MaterialTheme.colorScheme.secondary, shape = CircleShape) // Background circle
) {
Icon(
imageVector = Icons.Rounded.Favorite,
contentDescription = "Favorite Icon",
tint = Color.Red
)
Text(
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.Center,
fontWeight = FontWeight.Bold,
color = Color.White,
text = currentHeartRate,
fontSize = 40.sp
modifier = Modifier
.align(Alignment.Center)
.size(100.dp),
tint = tint,
imageVector = icon,
contentDescription = "Icon description"
)
}
}

@Composable
@Preview(device = Devices.WEAR_OS_LARGE_ROUND, showSystemUi = true)
fun PreviewHome() {
val bpm: MutableState<String> = mutableStateOf("0")
val navController = rememberSwipeDismissableNavController()
OwlTheme {
Home(currentHeartRate = "42", LocalContext.current, navController)
Home(bpm, LocalContext.current, navController, true)
}
}

@Composable
@Preview(device = Devices.WEAR_OS_LARGE_ROUND, showSystemUi = true)
@Preview
fun PreviewButtons() {
val navController = rememberSwipeDismissableNavController()
OwlTheme {
Expand All @@ -145,9 +287,9 @@ fun PreviewButtons() {
@Composable
@Preview(device = Devices.WEAR_OS_LARGE_ROUND, showSystemUi = true)
fun PreviewAlarm() {
val navController = rememberSwipeDismissableNavController()
val bpm: MutableState<String> = mutableStateOf("0")
OwlTheme {
Alarm(currentHeartRate = "42", LocalContext.current, navController)
Alarm(currentHeartRate = bpm)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ val md_theme_light_error = Color(0xFFFC0404)
val md_theme_light_errorContainer = Color(0xFFFFDAD6)
val md_theme_light_onError = Color(0xFFFFFFFF)
val md_theme_light_onErrorContainer = Color(0xFF410002)
val md_theme_light_background = Color(0xFFFFFBFF)
val md_theme_light_background = Color(0xFF000000)
val md_theme_light_onBackground = Color(0xFF1F1B16)
val md_theme_light_surface = Color(0xFFFFFBFF)
val md_theme_light_surface = Color(0xFF00275B)
val md_theme_light_onSurface = Color(0xFF1F1B16)
val md_theme_light_surfaceVariant = Color(0xFFF0E0CF)
val md_theme_light_onSurfaceVariant = Color(0xFF4F4539)
Expand Down Expand Up @@ -53,9 +53,9 @@ val md_theme_dark_error = Color(0xFFFC0404)
val md_theme_dark_errorContainer = Color(0xFF93000A)
val md_theme_dark_onError = Color(0xFF690005)
val md_theme_dark_onErrorContainer = Color(0xFFFFDAD6)
val md_theme_dark_background = Color(0xFF1F1B16)
val md_theme_dark_background = Color(0xFF000000)
val md_theme_dark_onBackground = Color(0xFFEAE1D9)
val md_theme_dark_surface = Color(0xFF1F1B16)
val md_theme_dark_surface = Color(0xFF00275B)
val md_theme_dark_onSurface = Color(0xFFEAE1D9)
val md_theme_dark_surfaceVariant = Color(0xFF4F4539)
val md_theme_dark_onSurfaceVariant = Color(0xFFD3C4B4)
Expand Down
Loading