-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ce721c
commit 6f95a5b
Showing
7 changed files
with
418 additions
and
418 deletions.
There are no files selected for viewing
47 changes: 24 additions & 23 deletions
47
app/create_tag_sheet/src/main/java/com/example/createtagsheet/CreateTagSheetContract.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,25 @@ | ||
package com.example.createtagsheet | ||
|
||
import com.example.core.arch.ViewEffect | ||
import com.example.core.arch.ViewEvent | ||
import com.example.core.arch.ViewState | ||
|
||
class CreateTagSheetContract { | ||
|
||
sealed class Event : ViewEvent { | ||
data object CreateButtonActionClick : Event() | ||
data object TagCreatedButtonActionClick : Event() | ||
} | ||
|
||
data class State( | ||
var isCreated: Boolean, | ||
) : ViewState | ||
|
||
sealed class Effect : ViewEffect { | ||
sealed class Navigation : Effect() { | ||
data object CreateTag : Effect() | ||
data object TagCreated : Effect() | ||
} | ||
} | ||
package com.example.createtagsheet | ||
|
||
import com.example.core.arch.ViewEffect | ||
import com.example.core.arch.ViewEvent | ||
import com.example.core.arch.ViewState | ||
|
||
class CreateTagSheetContract { | ||
|
||
sealed class Event : ViewEvent { | ||
data object CreateButtonActionClick : Event() | ||
data object TagCreatedButtonActionClick : Event() | ||
data class SetIsCreated(val isCreated: Boolean) : Event() | ||
} | ||
|
||
data class State( | ||
var isCreated: Boolean, | ||
) : ViewState | ||
|
||
sealed class Effect : ViewEffect { | ||
sealed class Navigation : Effect() { | ||
data object CreateTag : Effect() | ||
data object TagCreated : Effect() | ||
} | ||
} | ||
} |
73 changes: 38 additions & 35 deletions
73
app/create_tag_sheet/src/main/java/com/example/createtagsheet/CreateTagSheetViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,39 @@ | ||
package com.example.createtagsheet | ||
|
||
import com.example.core.arch.BaseViewModel | ||
|
||
class CreateTagSheetViewModel : | ||
BaseViewModel<CreateTagSheetContract.State, CreateTagSheetContract.Event, CreateTagSheetContract.Effect>() { | ||
|
||
override fun setInitialState(): CreateTagSheetContract.State { | ||
return CreateTagSheetContract.State( | ||
isCreated = false, | ||
) | ||
} | ||
|
||
override fun onEventReceived(event: CreateTagSheetContract.Event) { | ||
when (event) { | ||
CreateTagSheetContract.Event.CreateButtonActionClick -> { | ||
applyEffect { | ||
CreateTagSheetContract.Effect.Navigation.CreateTag | ||
} | ||
} | ||
|
||
CreateTagSheetContract.Event.TagCreatedButtonActionClick -> { | ||
applyEffect { | ||
CreateTagSheetContract.Effect.Navigation.TagCreated | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
fun setIsCreated(isCreated: Boolean) { | ||
setState { | ||
copy(isCreated = isCreated) | ||
} | ||
} | ||
package com.example.createtagsheet | ||
|
||
import com.example.core.arch.BaseViewModel | ||
|
||
class CreateTagSheetViewModel : | ||
BaseViewModel<CreateTagSheetContract.State, CreateTagSheetContract.Event, CreateTagSheetContract.Effect>() { | ||
|
||
override fun setInitialState(): CreateTagSheetContract.State { | ||
return CreateTagSheetContract.State( | ||
isCreated = false, | ||
) | ||
} | ||
|
||
override fun onEventReceived(event: CreateTagSheetContract.Event) { | ||
when (event) { | ||
CreateTagSheetContract.Event.CreateButtonActionClick -> { | ||
applyEffect { | ||
CreateTagSheetContract.Effect.Navigation.CreateTag | ||
} | ||
} | ||
|
||
CreateTagSheetContract.Event.TagCreatedButtonActionClick -> { | ||
applyEffect { | ||
CreateTagSheetContract.Effect.Navigation.TagCreated | ||
} | ||
} | ||
|
||
is CreateTagSheetContract.Event.SetIsCreated -> { | ||
setIsCreated(event.isCreated) | ||
} | ||
} | ||
} | ||
|
||
private fun setIsCreated(isCreated: Boolean) { | ||
setState { | ||
copy(isCreated = isCreated) | ||
} | ||
} | ||
} |
181 changes: 90 additions & 91 deletions
181
app/create_tag_sheet/src/main/java/com/example/createtagsheet/composables/CreateTagInput.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,90 @@ | ||
package com.example.createtagsheet.composables | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.border | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.offset | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.foundation.text.BasicTextField | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.SolidColor | ||
import androidx.compose.ui.res.stringResource | ||
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.sp | ||
import androidx.constraintlayout.compose.ConstraintLayout | ||
import com.example.createtagsheet.R | ||
|
||
private val layoutMargins = PaddingValues(bottom = 18.dp) | ||
private val textMargins = PaddingValues(15.dp, 10.dp, 15.dp, 10.dp) | ||
private val borderColor = Color(0xFFF2575D) | ||
private val roundingSize = 8.dp | ||
|
||
@Composable | ||
private fun textStyle(defaultTextColor: Color = MaterialTheme.colorScheme.primary) = | ||
MaterialTheme.typography.bodyLarge.copy( | ||
color = defaultTextColor | ||
) | ||
|
||
@Composable | ||
private fun labelTextStyle(defaultTextColor: Color = borderColor) = | ||
MaterialTheme.typography.titleMedium.copy( | ||
fontSize = 12.sp, | ||
textAlign = TextAlign.Center, | ||
color = defaultTextColor, | ||
) | ||
|
||
@Composable | ||
fun CreateTagInput() { | ||
var textFieldValue by remember { mutableStateOf(TextFieldValue("")) } | ||
|
||
ConstraintLayout( | ||
modifier = Modifier | ||
.padding(layoutMargins) | ||
) | ||
{ | ||
|
||
Box( | ||
modifier = Modifier | ||
.width(286.dp) | ||
.height(48.dp) | ||
.border(1.dp, borderColor, RoundedCornerShape(roundingSize)) | ||
.background( | ||
MaterialTheme.colorScheme.background, | ||
shape = RoundedCornerShape(roundingSize) | ||
), | ||
) { | ||
BasicTextField( | ||
value = textFieldValue, | ||
onValueChange = { textFieldValue = it }, | ||
textStyle = textStyle(), | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(textMargins), | ||
cursorBrush = SolidColor(MaterialTheme.colorScheme.tertiary), | ||
) | ||
} | ||
|
||
Text( | ||
modifier = Modifier | ||
.width(123.dp) | ||
.height(15.dp) | ||
.offset(10.dp, 48.dp), | ||
text = stringResource(R.string.create_tag_label), | ||
style = labelTextStyle() | ||
) | ||
} | ||
} | ||
package com.example.createtagsheet.composables | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.border | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.offset | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.foundation.text.BasicTextField | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.SolidColor | ||
import androidx.compose.ui.res.stringResource | ||
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.sp | ||
import androidx.constraintlayout.compose.ConstraintLayout | ||
import com.example.createtagsheet.R | ||
|
||
private val layoutMargins = PaddingValues(bottom = 18.dp) | ||
private val textMargins = PaddingValues(15.dp, 10.dp, 15.dp, 10.dp) | ||
private val borderColor = Color(0xFFF2575D) | ||
private val roundingSize = 8.dp | ||
|
||
@Composable | ||
private fun textStyle(defaultTextColor: Color = MaterialTheme.colorScheme.primary) = | ||
MaterialTheme.typography.bodyLarge.copy( | ||
color = defaultTextColor | ||
) | ||
|
||
@Composable | ||
private fun labelTextStyle(defaultTextColor: Color = borderColor) = | ||
MaterialTheme.typography.titleMedium.copy( | ||
fontSize = 12.sp, | ||
textAlign = TextAlign.Center, | ||
color = defaultTextColor, | ||
) | ||
|
||
@Composable | ||
fun CreateTagInput() { | ||
var textFieldValue by remember { mutableStateOf(TextFieldValue("")) } | ||
|
||
ConstraintLayout( | ||
modifier = Modifier | ||
.padding(layoutMargins) | ||
) | ||
{ | ||
Box( | ||
modifier = Modifier | ||
.width(286.dp) | ||
.height(48.dp) | ||
.border(1.dp, borderColor, RoundedCornerShape(roundingSize)) | ||
.background( | ||
MaterialTheme.colorScheme.background, | ||
shape = RoundedCornerShape(roundingSize) | ||
), | ||
) { | ||
BasicTextField( | ||
value = textFieldValue, | ||
onValueChange = { textFieldValue = it }, | ||
textStyle = textStyle(), | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(textMargins), | ||
cursorBrush = SolidColor(MaterialTheme.colorScheme.tertiary), | ||
) | ||
} | ||
|
||
Text( | ||
modifier = Modifier | ||
.width(123.dp) | ||
.height(15.dp) | ||
.offset(10.dp, 48.dp), | ||
text = stringResource(R.string.create_tag_label), | ||
style = labelTextStyle() | ||
) | ||
} | ||
} |
91 changes: 46 additions & 45 deletions
91
app/create_tag_sheet/src/main/java/com/example/createtagsheet/composables/CreateTagSheet.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,46 @@ | ||
package com.example.createtagsheet.composables | ||
|
||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.ui.Modifier | ||
import androidx.constraintlayout.compose.ConstraintLayout | ||
import com.example.createtagsheet.CreateTagSheetContract | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.collect | ||
import kotlinx.coroutines.flow.onEach | ||
|
||
@Composable | ||
fun CreateTagSheet( | ||
state: CreateTagSheetContract.State, | ||
effectFlow: Flow<CreateTagSheetContract.Effect>?, | ||
onEventSent: (event: CreateTagSheetContract.Event) -> Unit, | ||
createNewTag: () -> Unit, | ||
tagCreated: () -> Unit, | ||
) { | ||
LaunchedEffect(true) { | ||
effectFlow?.onEach { effect -> | ||
when (effect) { | ||
is CreateTagSheetContract.Effect.Navigation.CreateTag -> { | ||
createNewTag() | ||
} | ||
|
||
is CreateTagSheetContract.Effect.Navigation.TagCreated -> { | ||
tagCreated() | ||
} | ||
} | ||
}?.collect() | ||
} | ||
|
||
ConstraintLayout( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
) { | ||
if (state.isCreated) { | ||
TagCreatedView(onEventSent = onEventSent) | ||
} else { | ||
CreateTagView(onEventSent = onEventSent) | ||
} | ||
} | ||
} | ||
package com.example.createtagsheet.composables | ||
|
||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.ui.Modifier | ||
import androidx.constraintlayout.compose.ConstraintLayout | ||
import com.example.createtagsheet.CreateTagSheetContract | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.collect | ||
import kotlinx.coroutines.flow.onEach | ||
|
||
@Composable | ||
fun CreateTagSheet( | ||
state: CreateTagSheetContract.State, | ||
effectFlow: Flow<CreateTagSheetContract.Effect>?, | ||
onEventSent: (event: CreateTagSheetContract.Event) -> Unit, | ||
createNewTag: () -> Unit, | ||
tagCreated: () -> Unit, | ||
) { | ||
LaunchedEffect(true) { | ||
effectFlow?.onEach { effect -> | ||
when (effect) { | ||
is CreateTagSheetContract.Effect.Navigation.CreateTag -> { | ||
createNewTag() | ||
onEventSent(CreateTagSheetContract.Event.SetIsCreated(true)) | ||
} | ||
|
||
is CreateTagSheetContract.Effect.Navigation.TagCreated -> { | ||
tagCreated() | ||
} | ||
} | ||
}?.collect() | ||
} | ||
|
||
ConstraintLayout( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
) { | ||
if (state.isCreated) { | ||
TagCreatedView(onEventSent = onEventSent) | ||
} else { | ||
CreateTagView(onEventSent = onEventSent) | ||
} | ||
} | ||
} |
Oops, something went wrong.