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

Feature/Main Room Create #75

Merged
merged 12 commits into from
Apr 17, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,19 @@ fun SeugiTextField(
},
label = null,
trailingIcon = {
SeugiIconButton(
resId = R.drawable.ic_close_fill,
onClick = onClickDelete,
enabled = enabled,
colors = IconButtonColors(
containerColor = colors.focusedContainerColor,
disabledContainerColor = colors.disabledContainerColor,
contentColor = colors.focusedTextColor,
disabledContentColor = colors.disabledTextColor,
),
)
if (value != "") {
SeugiIconButton(
resId = R.drawable.ic_close_fill,
onClick = onClickDelete,
enabled = enabled,
colors = IconButtonColors(
containerColor = colors.focusedContainerColor,
disabledContainerColor = colors.disabledContainerColor,
contentColor = colors.focusedTextColor,
disabledContentColor = colors.disabledTextColor,
),
)
}
},
contentPadding = TextFieldDefaults.contentPaddingWithoutLabel(start = 16.dp, end = 16.dp),
shape = shape,
Expand Down
14 changes: 14 additions & 0 deletions designsystem/src/main/res/drawable/ic_close_line.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M4.293,4.657C4.683,4.266 5.317,4.266 5.707,4.657L19.707,18.657C20.098,19.047 20.098,19.681 19.707,20.071C19.317,20.462 18.683,20.462 18.293,20.071L4.293,6.071C3.902,5.681 3.902,5.047 4.293,4.657Z"
android:fillColor="#000000"
android:fillType="evenOdd"/>
<path
android:pathData="M4.293,20.071C3.902,19.681 3.902,19.047 4.293,18.657L18.293,4.657C18.683,4.266 19.317,4.266 19.707,4.657C20.098,5.047 20.098,5.681 19.707,6.071L5.707,20.071C5.317,20.462 4.683,20.462 4.293,20.071Z"
android:fillColor="#000000"
android:fillType="evenOdd"/>
</vector>
1 change: 1 addition & 0 deletions feature-main/main/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ dependencies {
implementation(projects.featureMain.chatDatail)
implementation(projects.featureMain.home)
implementation(projects.featureMain.room)
implementation(projects.featureMain.roomCreate)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import com.apeun.gidaechi.home.navigation.HOME_ROUTE
import com.apeun.gidaechi.home.navigation.homeScreen
import com.apeun.gidaechi.room.navigation.ROOM_ROUTE
import com.apeun.gidaechi.room.navigation.roomScreen
import com.apeun.gidaechi.roomcreate.navigation.navigateToRoomCreate
import com.apeun.gidaechi.roomcreate.navigation.roomCreateScreen

private const val NAVIGATION_ANIM = 400

Expand Down Expand Up @@ -98,7 +100,16 @@ internal fun MainScreen(navHostController: NavHostController = rememberNavContro

roomScreen(
navigateToChatDetail = {},
navigateToCreateRoom = {},
navigateToCreateRoom = {
navHostController.navigateToRoomCreate()
},
)

roomCreateScreen(
popBackStack = {
navHostController.popBackStack()
},
onNavigationVisibleChange = onNavigationVisibleChange,
)
}
}
Expand Down
1 change: 1 addition & 0 deletions feature-main/room-create/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
11 changes: 11 additions & 0 deletions feature-main/room-create/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
plugins {
alias(libs.plugins.seugi.android.feature)
}

android {
namespace = "com.apeun.gidaechi.roomcreate"
}
dependencies {

implementation(projects.designsystem)
}
Empty file.
21 changes: 21 additions & 0 deletions feature-main/room-create/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
4 changes: 4 additions & 0 deletions feature-main/room-create/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.apeun.gidaechi.roomcreate

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.LifecycleResumeEffect
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.apeun.gidaechi.roomcreate.screen.FirstScreen
import com.apeun.gidaechi.roomcreate.screen.SecondScreen

@Composable
internal fun RoomCreateScreen(viewModel: RoomCreateViewModel = hiltViewModel(), popBackStack: () -> Unit, onNavigationVisibleChange: (Boolean) -> Unit) {
val state by viewModel.state.collectAsStateWithLifecycle()
var nowScreen by remember { mutableStateOf(1) }
LaunchedEffect(key1 = true) {
onNavigationVisibleChange(false)
viewModel.loadUser()
}

LifecycleResumeEffect(key1 = Unit) {
onNavigationVisibleChange(false)
onPauseOrDispose {
onNavigationVisibleChange(true)
}
}

AnimatedVisibility(visible = nowScreen == 1) {
FirstScreen(
state = state,
updateChecked = {
viewModel.updateChecked(it)
},
popBackStack = popBackStack,
nextScreen = {
if (state.checkedMemberState.size > 0) {
nowScreen = 2
}
},
)
}

AnimatedVisibility(visible = nowScreen == 2) {
val memberCount = state.checkedMemberState.size - 1
SecondScreen(
placeholder = "${state.checkedMemberState[0].name} ${if (memberCount > 0) "외 ${memberCount}명" else ""}",
onNameSuccess = {
},
popBackStack = {
nowScreen = 1
},
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.apeun.gidaechi.roomcreate

import androidx.lifecycle.ViewModel
import com.apeun.gidaechi.roomcreate.model.RoomCreateUiState
import com.apeun.gidaechi.roomcreate.model.TestMemberItem
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow

@HiltViewModel
class RoomCreateViewModel @Inject constructor() : ViewModel() {

private val _state = MutableStateFlow(RoomCreateUiState())
val state = _state.asStateFlow()

fun loadUser() {
val users = mutableListOf<TestMemberItem>()
for (i in 1..30) {
users.add(
TestMemberItem(
id = i,
name = "노영재 ${i}세",
),
)
}
_state.value = _state.value.copy(
userItem = users.toImmutableList(),
)
}

fun updateChecked(userId: Int) {
_state.value = _state.value.copy(
userItem = _state.value.userItem.map {
if (it.id == userId) {
it.copy(
checked = it.checked.not(),
)
} else {
it
}
}.toImmutableList(),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.apeun.gidaechi.roomcreate.model

import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList

data class RoomCreateUiState(
val userItem: ImmutableList<TestMemberItem> = persistentListOf(),
) {
val checkedMemberState: ImmutableList<TestMemberItem> by lazy {
userItem.filter { it.checked }.toImmutableList()
}
}

data class TestMemberItem(
val id: Int = 0,
val name: String,
val memberProfile: String? = null,
val checked: Boolean = false,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.apeun.gidaechi.roomcreate.navigation

import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptions
import androidx.navigation.compose.composable
import com.apeun.gidaechi.roomcreate.RoomCreateScreen

const val ROOM_CREATE_ROUTE = "room_create"

fun NavController.navigateToRoomCreate(navOptions: NavOptions? = null) = navigate(ROOM_CREATE_ROUTE, navOptions)

fun NavGraphBuilder.roomCreateScreen(popBackStack: () -> Unit, onNavigationVisibleChange: (Boolean) -> Unit) {
composable(ROOM_CREATE_ROUTE) {
RoomCreateScreen(
popBackStack = popBackStack,
onNavigationVisibleChange = onNavigationVisibleChange,
)
}
}
Loading
Loading