create and use StealthButton to start en edit timer

This commit is contained in:
brreynie 2023-04-22 20:57:49 +02:00
parent 3956c6e5b6
commit 0df2b93851
4 changed files with 84 additions and 10 deletions

6
.idea/kotlinc.xml generated Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="KotlinJpsPluginSettings">
<option name="version" value="1.8.0-release" />
</component>
</project>

2
.idea/misc.xml generated
View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View file

@ -1,11 +1,24 @@
package be.ugent.sel.studeez.common.composable
import androidx.annotation.StringRes
import androidx.compose.material.*
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Button
import androidx.compose.material.ButtonColors
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import be.ugent.sel.studeez.R
import be.ugent.sel.studeez.common.ext.basicButton
import be.ugent.sel.studeez.common.ext.card
@Composable
@ -14,12 +27,55 @@ fun BasicTextButton(@StringRes text: Int, modifier: Modifier, action: () -> Unit
}
@Composable
fun BasicButton(@StringRes text: Int, modifier: Modifier, action: () -> Unit) {
fun BasicButton(
@StringRes text: Int,
modifier: Modifier,
colors: ButtonColors = ButtonDefaults.buttonColors(),
border: BorderStroke? = null,
onClick: () -> Unit,
) {
Button(
onClick = action,
modifier = modifier
onClick = onClick,
modifier = modifier,
shape = RoundedCornerShape(20.dp),
colors = colors,
border = border,
) {
Text(text = stringResource(text), fontSize = 16.sp)
Text(
text = stringResource(text),
fontSize = 16.sp
)
}
}
@Preview
@Composable
fun BasicButtonPreview() {
BasicButton(text = R.string.add_timer, modifier = Modifier.basicButton()) {}
}
@Composable
fun StealthButton(
@StringRes text: Int,
onClick: () -> Unit,
) {
BasicButton(
text = text,
onClick = onClick,
modifier = Modifier.card(),
colors = ButtonDefaults.buttonColors(
backgroundColor = Color.Transparent,
contentColor = Color.DarkGray,
),
border = BorderStroke(3.dp, Color.DarkGray),
)
}
@Preview
@Composable
fun StealthButtonCardPreview() {
StealthButton(text = R.string.edit) {
}
}

View file

@ -1,12 +1,15 @@
package be.ugent.sel.studeez.screens.timer_overview
import android.annotation.SuppressLint
import androidx.annotation.StringRes
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.Scaffold
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
@ -20,8 +23,8 @@ import androidx.hilt.navigation.compose.hiltViewModel
import be.ugent.sel.studeez.R
import be.ugent.sel.studeez.common.composable.BasicButton
import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate
import be.ugent.sel.studeez.common.composable.StealthButton
import be.ugent.sel.studeez.common.ext.basicButton
import be.ugent.sel.studeez.common.ext.card
import be.ugent.sel.studeez.data.local.models.timer_info.CustomTimerInfo
import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo
import be.ugent.sel.studeez.resources
@ -77,7 +80,9 @@ fun TimerEntry(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
) {
Column {
Column(
Modifier.padding(horizontal = 10.dp)
) {
Text(
text = timerInfo.name,
fontWeight = FontWeight.Bold,
@ -90,7 +95,7 @@ fun TimerEntry(
)
}
if (canDisplay) {
BasicButton(buttonName, Modifier.card()) {
StealthButton(buttonName) {
buttonFunction(timerInfo)
}
}
@ -98,6 +103,7 @@ fun TimerEntry(
}
}
@SuppressLint("UnusedMaterialScaffoldPaddingParameter")
@Preview
@Composable
fun TimerEntryPreview() {
@ -106,5 +112,11 @@ fun TimerEntryPreview() {
"This is the description of the timer",
60
)
TimerEntry(timerInfo = timerInfo, true) { }
Scaffold() {
Column() {
TimerEntry(timerInfo = timerInfo, true, buttonName = R.string.edit) { }
TimerEntry(timerInfo = timerInfo, true, buttonName = R.string.edit) { }
TimerEntry(timerInfo = timerInfo, true, buttonName = R.string.edit) { }
}
}
}