mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-17 23:47:02 +05:30
Merge pull request #9 from msfjarvis/custom-names
Allow providing names for items
This commit is contained in:
commit
c43e8b6b41
6 changed files with 92 additions and 46 deletions
23
.editorconfig
Normal file
23
.editorconfig
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# https://editorconfig.org
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
|
end_of_line = lf
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[*.{java,kt,kts,xml}]
|
||||||
|
indent_size = 2
|
||||||
|
ij_continuation_indent_size = 2
|
||||||
|
|
||||||
|
[*.{kt,kts}]
|
||||||
|
kotlin_imports_layout=ascii
|
||||||
|
ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL
|
||||||
|
ij_kotlin_field_annotation_wrap = normal
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
|
@ -74,8 +74,8 @@ dependencies {
|
||||||
implementation "androidx.ui:ui-tooling:$compose_version"
|
implementation "androidx.ui:ui-tooling:$compose_version"
|
||||||
implementation 'com.google.android.material:material:1.3.0-alpha02'
|
implementation 'com.google.android.material:material:1.3.0-alpha02'
|
||||||
testImplementation 'junit:junit:4.13'
|
testImplementation 'junit:junit:4.13'
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2-rc03'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-rc03'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
||||||
androidTestImplementation "androidx.ui:ui-test:$compose_version"
|
androidTestImplementation "androidx.ui:ui-test:$compose_version"
|
||||||
coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:1.0.10"
|
coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:1.0.10"
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,21 +3,33 @@ package dev.msfjarvis.todo
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.compose.foundation.Text
|
import androidx.compose.foundation.Text
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.lazy.LazyColumnFor
|
import androidx.compose.foundation.lazy.LazyColumnFor
|
||||||
|
import androidx.compose.material.AlertDialog
|
||||||
import androidx.compose.material.FloatingActionButton
|
import androidx.compose.material.FloatingActionButton
|
||||||
import androidx.compose.material.MaterialTheme
|
import androidx.compose.material.MaterialTheme
|
||||||
|
import androidx.compose.material.OutlinedTextField
|
||||||
import androidx.compose.material.Scaffold
|
import androidx.compose.material.Scaffold
|
||||||
import androidx.compose.material.TopAppBar
|
import androidx.compose.material.TopAppBar
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.MutableState
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.setContent
|
import androidx.compose.ui.platform.setContent
|
||||||
import androidx.compose.ui.semantics.semantics
|
import androidx.compose.ui.semantics.semantics
|
||||||
import androidx.compose.ui.semantics.testTag
|
import androidx.compose.ui.semantics.testTag
|
||||||
|
import androidx.compose.ui.text.TextStyle
|
||||||
|
import androidx.compose.ui.text.font.FontStyle
|
||||||
|
import androidx.compose.ui.text.input.TextFieldValue
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.ui.tooling.preview.Preview
|
import androidx.ui.tooling.preview.Preview
|
||||||
import dev.msfjarvis.todo.compose.utils.IconResource
|
import dev.msfjarvis.todo.compose.utils.IconResource
|
||||||
import dev.msfjarvis.todo.data.model.TodoItem
|
import dev.msfjarvis.todo.data.model.TodoItem
|
||||||
|
@ -50,12 +62,20 @@ fun TodoApp(
|
||||||
onAdd: (item: TodoItem) -> Unit,
|
onAdd: (item: TodoItem) -> Unit,
|
||||||
onDelete: (item: TodoItem) -> Unit,
|
onDelete: (item: TodoItem) -> Unit,
|
||||||
) {
|
) {
|
||||||
|
val showingDialog = remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
if (showingDialog.value) {
|
||||||
|
ItemAddDialog(
|
||||||
|
showingDialog = showingDialog,
|
||||||
|
onAdd = onAdd,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
topBar = { TopAppBar({ Text(text = "I can Compose?") }) },
|
topBar = { TopAppBar({ Text(text = "I can Compose?") }) },
|
||||||
floatingActionButton = {
|
floatingActionButton = {
|
||||||
FloatingActionButton(
|
FloatingActionButton(
|
||||||
onClick = { onAdd.invoke(TodoItem("Item ${items.size + 1}")) },
|
onClick = { showingDialog.value = true },
|
||||||
elevation = 8.dp,
|
elevation = 8.dp,
|
||||||
modifier = Modifier.semantics { testTag = "fab" }
|
modifier = Modifier.semantics { testTag = "fab" }
|
||||||
) {
|
) {
|
||||||
|
@ -76,6 +96,50 @@ fun TodoApp(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ItemAddDialog(
|
||||||
|
showingDialog: MutableState<Boolean>,
|
||||||
|
onAdd: (item: TodoItem) -> Unit,
|
||||||
|
) {
|
||||||
|
var newItemName by mutableStateOf(TextFieldValue(""))
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = {
|
||||||
|
showingDialog.value = false
|
||||||
|
},
|
||||||
|
text = {
|
||||||
|
OutlinedTextField(
|
||||||
|
value = newItemName,
|
||||||
|
onValueChange = { newItemName = it },
|
||||||
|
label = {
|
||||||
|
Text(
|
||||||
|
text = "Name",
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
},
|
||||||
|
title = {
|
||||||
|
Text(
|
||||||
|
text = "Create new item",
|
||||||
|
)
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
Text(
|
||||||
|
text = "Add",
|
||||||
|
modifier = Modifier.padding(16.dp).clickable(onClick = {
|
||||||
|
onAdd.invoke(TodoItem(newItemName.text))
|
||||||
|
newItemName = TextFieldValue("")
|
||||||
|
showingDialog.value = false
|
||||||
|
}),
|
||||||
|
style = TextStyle(
|
||||||
|
fontSize = 18.sp,
|
||||||
|
textAlign = TextAlign.End,
|
||||||
|
fontStyle = FontStyle.Normal,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@Preview
|
@Preview
|
||||||
@Composable
|
@Composable
|
||||||
fun PreviewApp() {
|
fun PreviewApp() {
|
||||||
|
|
|
@ -15,7 +15,6 @@ import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import dev.msfjarvis.todo.data.model.TodoItem
|
import dev.msfjarvis.todo.data.model.TodoItem
|
||||||
import kotlinx.coroutines.coroutineScope
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun LazyItemScope.TodoRowItem(item: TodoItem, onLongClick: () -> Unit) {
|
fun LazyItemScope.TodoRowItem(item: TodoItem, onLongClick: () -> Unit) {
|
||||||
|
|
|
@ -2,54 +2,14 @@ package dev.msfjarvis.todo.ui
|
||||||
|
|
||||||
import androidx.compose.foundation.isSystemInDarkTheme
|
import androidx.compose.foundation.isSystemInDarkTheme
|
||||||
import androidx.compose.material.MaterialTheme
|
import androidx.compose.material.MaterialTheme
|
||||||
import androidx.compose.material.Typography
|
|
||||||
import androidx.compose.material.darkColors
|
import androidx.compose.material.darkColors
|
||||||
import androidx.compose.material.lightColors
|
import androidx.compose.material.lightColors
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.text.TextStyle
|
|
||||||
import androidx.compose.ui.text.font.FontFamily
|
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
|
||||||
import androidx.compose.ui.text.style.TextIndent
|
|
||||||
import androidx.compose.ui.unit.sp
|
|
||||||
|
|
||||||
val lightColors = lightColors(
|
|
||||||
primary = Color.White,
|
|
||||||
secondary = Color(0xFF3700B3),
|
|
||||||
background = Color.White,
|
|
||||||
surface = Color.White,
|
|
||||||
onPrimary = Color.Black,
|
|
||||||
onSecondary = Color.White,
|
|
||||||
onBackground = Color.Black,
|
|
||||||
onSurface = Color.White,
|
|
||||||
)
|
|
||||||
val darkColors = darkColors(
|
|
||||||
primary = Color(0xFF121212),
|
|
||||||
secondary = Color(0xFFBB86FC),
|
|
||||||
background = Color.Black,
|
|
||||||
surface = Color(0xFF121212),
|
|
||||||
onPrimary = Color.White,
|
|
||||||
onSecondary = Color.White,
|
|
||||||
onBackground = Color.White,
|
|
||||||
onSurface = Color.White,
|
|
||||||
)
|
|
||||||
|
|
||||||
private val typography = Typography(
|
|
||||||
body1 = TextStyle(
|
|
||||||
fontFamily = FontFamily.Serif,
|
|
||||||
fontWeight = FontWeight.Normal,
|
|
||||||
fontSize = 20.sp,
|
|
||||||
textIndent = TextIndent(firstLine = 16.sp),
|
|
||||||
textAlign = TextAlign.Justify
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TodoTheme(children: @Composable () -> Unit) {
|
fun TodoTheme(children: @Composable () -> Unit) {
|
||||||
MaterialTheme(
|
MaterialTheme(
|
||||||
colors = if (isSystemInDarkTheme()) darkColors else lightColors,
|
colors = if (isSystemInDarkTheme()) darkColors() else lightColors(),
|
||||||
content = children,
|
content = children,
|
||||||
typography = typography,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,9 +13,9 @@ import androidx.compose.material.Switch
|
||||||
import androidx.compose.material.ripple.RippleIndication
|
import androidx.compose.material.ripple.RippleIndication
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.setValue
|
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.text.TextStyle
|
import androidx.compose.ui.text.TextStyle
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue