Skip to content

Commit

Permalink
Merge pull request andras-adam#18 from NeoAren/edit-delete-card
Browse files Browse the repository at this point in the history
Edit + delete card features
  • Loading branch information
tamaskr committed Oct 12, 2022
2 parents 900a045 + 2e111b5 commit 48ee89a
Show file tree
Hide file tree
Showing 16 changed files with 341 additions and 117 deletions.
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
<activity
android:name=".MainActivity"
android:exported="true"
android:theme="@style/Theme.VirtualTag">
android:screenOrientation="portrait"
android:theme="@style/Theme.VirtualTag"
tools:ignore="LockedOrientationActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down
12 changes: 9 additions & 3 deletions app/src/main/java/com/virtualtag/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,20 @@ class MainActivity : ComponentActivity() {
model = cardViewModel,
id = it.arguments?.getString("id") ?: "0",
editCard = editCard,
goBack = goBack
goBack = goBack,
goHome = goHome
)
}
composable("edit/{id}") {
composable("edit/{id}",
arguments = listOf(navArgument("id") {
type = NavType.StringType
})
) {
EditScreen(
model = cardViewModel,
id = it.arguments?.getString("id") ?: "0",
goBack = goBack
goBack = goBack,
goHome = goHome
)
}
}
Expand Down
20 changes: 11 additions & 9 deletions app/src/main/java/com/virtualtag/app/ui/components/Buttons.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ import androidx.compose.ui.unit.dp
import com.virtualtag.app.R

@Composable
fun PrimaryButton(text: String, onClick: () -> Unit) {
fun PrimaryButton(text: String, onClick: () -> Unit, modifier: Modifier) {
Button(
onClick = { onClick() },
modifier = Modifier
.padding(top = 8.dp, bottom = 8.dp),
modifier = modifier,
contentPadding = PaddingValues(all = 16.dp),
elevation = ButtonDefaults.elevation(defaultElevation = 2.dp)
) {
Expand All @@ -32,11 +31,10 @@ fun PrimaryButton(text: String, onClick: () -> Unit) {
}

@Composable
fun SecondaryButton(text: String, onClick: () -> Unit) {
fun SecondaryButton(text: String, onClick: () -> Unit, modifier: Modifier) {
OutlinedButton(
onClick = { onClick() },
modifier = Modifier
.padding(top = 8.dp, bottom = 8.dp),
modifier = modifier,
contentPadding = PaddingValues(all = 16.dp),
colors = ButtonDefaults.buttonColors(backgroundColor = MaterialTheme.colors.secondaryVariant)
) {
Expand All @@ -47,9 +45,13 @@ fun SecondaryButton(text: String, onClick: () -> Unit) {
}

@Composable
fun ColorButton(colors: List<Color>, onColorSelected: (Color) -> Unit) {
fun ColorButton(colors: List<Color>, selected: Color, onColorSelected: (Color) -> Unit) {
var colorPickerOpen by remember { mutableStateOf(false) }
var currentlySelected by remember { mutableStateOf(colors[0]) }
var currentlySelected by remember { mutableStateOf(selected) }

LaunchedEffect(key1 = selected) {
currentlySelected = selected
}

Card(
modifier = Modifier
Expand Down Expand Up @@ -87,7 +89,7 @@ fun ColorButton(colors: List<Color>, onColorSelected: (Color) -> Unit) {
}

if (colorPickerOpen) {
ColorPickerDialog(
ColorPicker(
colorList = colors,
onDismiss = { colorPickerOpen = false },
currentlySelected = currentlySelected,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

@Composable
fun ColorPickerDialog(
fun ColorPicker(
colorList: List<Color>,
onDismiss: (() -> Unit),
currentlySelected: Color,
Expand All @@ -31,7 +31,7 @@ fun ColorPickerDialog(
shape = RoundedCornerShape(20.dp),
containerColor = MaterialTheme.colors.secondaryVariant,
titleContentColor = MaterialTheme.colors.secondaryVariant,
onDismissRequest = onDismiss,
onDismissRequest = {},
text = {
LazyVerticalGrid(
columns = GridCells.Fixed(3),
Expand Down
33 changes: 33 additions & 0 deletions app/src/main/java/com/virtualtag/app/ui/components/Dialog.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.virtualtag.app.ui.components

import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.MaterialTheme
import androidx.compose.material3.AlertDialog
import androidx.compose.runtime.*
import androidx.compose.ui.unit.dp

@Composable
fun Dialog(
closeDialog: (() -> Unit),
title: @Composable () -> Unit,
description: @Composable () -> Unit,
confirmButton: @Composable () -> Unit,
dismissButton: @Composable () -> Unit,
) {
AlertDialog(
shape = RoundedCornerShape(20.dp),
containerColor = MaterialTheme.colors.secondaryVariant,
titleContentColor = MaterialTheme.colors.secondaryVariant,
onDismissRequest = { closeDialog() },
title = {
title()
},
text = {
description()
},
confirmButton = { confirmButton() },
dismissButton = {
dismissButton()
}
)
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/virtualtag/app/ui/components/Logo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fun Logo(modifier: Modifier?) {
)
Text(
"TAG",
color = MaterialTheme.colors.primaryVariant,
color = MaterialTheme.colors.primary,
style = MaterialTheme.typography.h1
)
}
Expand Down

This file was deleted.

11 changes: 7 additions & 4 deletions app/src/main/java/com/virtualtag/app/ui/screens/AddScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ fun AddScreen(
)
}
}

TextField(
value = name,
onValueChange = { newName ->
Expand All @@ -126,15 +125,19 @@ fun AddScreen(
)
ColorButton(colors = cardBackGroundColors, onColorSelected = { value ->
color = colorToString(value)
})
}, selected = cardBackGroundColors[0])
}
Row {
Column(
Modifier
.weight(1f)
.padding(end = 4.dp)
) {
SecondaryButton(text = stringResource(R.string.cancel), onClick = goHome)
SecondaryButton(
text = stringResource(R.string.cancel),
onClick = goHome,
modifier = Modifier.padding(top = 8.dp, bottom = 8.dp)
)
}
Column(
Modifier
Expand All @@ -150,7 +153,7 @@ fun AddScreen(
).show()
}
addCardToDb()
})
}, modifier = Modifier.padding(top = 8.dp, bottom = 8.dp))
}
}
}
Expand Down
Loading

0 comments on commit 48ee89a

Please sign in to comment.