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

New composants #26

Merged
merged 5 commits into from
Jul 7, 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: 0 additions & 13 deletions app/src/main/java/com/eipsaferoad/owl/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import android.os.Bundle
import android.os.VibrationEffect
import android.os.Vibrator
import android.os.VibratorManager
import android.util.Log
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
Expand Down Expand Up @@ -45,7 +44,6 @@ import com.eipsaferoad.owl.models.Alarm
import com.eipsaferoad.owl.models.SoundAlarm
import com.eipsaferoad.owl.models.VibrationAlarm
import com.eipsaferoad.owl.presentation.PagesEnum
import com.eipsaferoad.owl.presentation.alarm.Alarm
import com.eipsaferoad.owl.presentation.home.Home
import com.eipsaferoad.owl.presentation.login.Login
import com.eipsaferoad.owl.presentation.settings.Settings
Expand Down Expand Up @@ -296,17 +294,6 @@ fun WearApp(context: Context, currentHeartRate: MutableState<String>, alarms: Mu
Settings(context, alarms, mVibrator, apiUrl, accessToken.value )
}
}
composable(PagesEnum.ALARM.value) {
Box(
modifier = Modifier
.fillMaxSize()
.background(MaterialTheme.colors.background),
contentAlignment = Alignment.Center
) {
TimeText()
Alarm(currentHeartRate.value, context, navController)
}
}
}
}
}
Expand Down
102 changes: 102 additions & 0 deletions app/src/main/java/com/eipsaferoad/owl/components/Button.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.eipsaferoad.owl.components

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.wear.compose.material.Text
import com.eipsaferoad.owl.presentation.theme.md_theme_light_onSurfaceVariant
import com.eipsaferoad.owl.presentation.theme.md_theme_light_primary
import com.eipsaferoad.owl.presentation.theme.md_theme_light_secondary

enum class ButtonTypeEnum() {
PRIMARY,
SECONDARY,
REDIRECTION,
}

@Composable
fun Button(type: ButtonTypeEnum, content: @Composable () -> Unit, action: () -> Unit) {
val backgroundColor = when (type) {
ButtonTypeEnum.PRIMARY -> md_theme_light_primary
ButtonTypeEnum.SECONDARY -> md_theme_light_secondary
ButtonTypeEnum.REDIRECTION -> md_theme_light_onSurfaceVariant
else -> md_theme_light_onSurfaceVariant
}

Column(
modifier = Modifier
.fillMaxSize()
.clip(shape = RoundedCornerShape(20.dp))
.background(backgroundColor)
.clickable { action() },
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally,
) {
content()
}
}

@Composable
fun ContentExample() {
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(text = "coucou")
}
}

@Composable
@Preview
fun PreviewButtonPrimary() {
Column(
modifier = Modifier
.height(50.dp)
.width(100.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Button(type = ButtonTypeEnum.PRIMARY, content = { ContentExample() }, action = { println("cpicpi") })
}
}

@Composable
@Preview
fun PreviewButtonSecondary() {
Column(
modifier = Modifier
.height(50.dp)
.width(100.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Button(type = ButtonTypeEnum.SECONDARY, content = { ContentExample() }, action = { println("cpicpi") })
}
}

@Composable
@Preview
fun PreviewButtonRedirection() {
Column(
modifier = Modifier
.height(50.dp)
.width(100.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Button(type = ButtonTypeEnum.REDIRECTION, content = { ContentExample() }, action = { println("cpicpi") })
}
}
33 changes: 33 additions & 0 deletions app/src/main/java/com/eipsaferoad/owl/components/Draggeable.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.eipsaferoad.owl.components

import androidx.compose.foundation.gestures.detectDragGestures
import androidx.compose.runtime.MutableState
import androidx.compose.ui.input.pointer.pointerInput
import kotlin.math.abs
import androidx.compose.ui.Modifier
import com.eipsaferoad.owl.models.Alarm

fun Modifier.handleDraggableModifier(
lastPosX: Float,
vibrationVal: Float,
nbrPixelToMove: Int,
alarms: MutableState<Alarm>,
dragLeft: (value: Float) -> Unit,
dragRight: (value: Float) -> Unit,
init: (value: Float) -> Unit
): Modifier {
return this.pointerInput(Unit) {
detectDragGestures { change, dragAmount ->
change.consume()
if (lastPosX == 0.0f) {
init(change.position.x)
}
if (change.previousPosition.x < change.position.x && abs(lastPosX - change.position.x) > nbrPixelToMove && vibrationVal < alarms.value.vibration.max.toFloat()) {
dragRight(change.position.x)
} else if (change.previousPosition.x > change.position.x && abs(lastPosX - change.position.x) > nbrPixelToMove && vibrationVal > alarms.value.vibration.min) {
dragLeft(change.position.x)
}
println(vibrationVal)
}
}
}
27 changes: 27 additions & 0 deletions app/src/main/java/com/eipsaferoad/owl/components/Icon.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.eipsaferoad.owl.components

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Favorite
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.tooling.preview.Preview
import com.eipsaferoad.owl.presentation.theme.OwlTheme

@Composable
fun DisplayIcon(imageVector: ImageVector, tint: Color) {
Icon(
imageVector,
contentDescription = "Favorite Icon",
tint = tint
)
}

@Composable
@Preview
fun PreviewDisplayIcon() {
OwlTheme {
DisplayIcon(Icons.Rounded.Favorite, Color.Blue)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.eipsaferoad.owl.presentation.components
package com.eipsaferoad.owl.components

import android.app.RemoteInput
import android.content.Intent
Expand Down
59 changes: 59 additions & 0 deletions app/src/main/java/com/eipsaferoad/owl/components/ToggleSwitch.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.eipsaferoad.owl.components

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.wear.compose.material.Switch
import androidx.wear.compose.material.SwitchDefaults
import com.eipsaferoad.owl.presentation.theme.md_theme_dark_tertiary
import com.eipsaferoad.owl.presentation.theme.md_theme_light_surface

@Composable
fun ToggleSwitch(isActivate: Boolean, action: (it: Boolean) -> Unit) {
Switch(
colors = SwitchDefaults.colors(
checkedThumbColor = md_theme_light_surface,
checkedTrackColor = md_theme_light_surface,
uncheckedThumbColor = md_theme_light_surface,
uncheckedTrackColor = md_theme_dark_tertiary
),
checked = isActivate,
onCheckedChange = {
action(it)
}
)
}

@Composable
@Preview
fun PreviewToggleSwitchDeactivated() {
Column(
modifier = Modifier
.height(50.dp)
.width(100.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
ToggleSwitch(false, {})
}
}

@Composable
@Preview
fun PreviewToggleSwitchActivated() {
Column(
modifier = Modifier
.height(50.dp)
.width(100.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
ToggleSwitch(true, {})
}
}
5 changes: 0 additions & 5 deletions app/src/main/java/com/eipsaferoad/owl/presentation/Page.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package com.eipsaferoad.owl.presentation

import androidx.compose.runtime.Composable

enum class PagesEnum(val value: String) {
LOGIN("login"),
HOME("home"),
SETTINGS("settings"),
ALARM("alarm")
}

typealias ComposableFun = @Composable () -> Unit
55 changes: 0 additions & 55 deletions app/src/main/java/com/eipsaferoad/owl/presentation/alarm/Alarm.kt

This file was deleted.

Loading
Loading