Skip to content

Commit

Permalink
Merge pull request #67 from mash-up-kr/feature/create-folder-ui
Browse files Browse the repository at this point in the history
홈과 보관함 폴더 생성/이름 변경 UI 및 navigation 추가
  • Loading branch information
ddyeon authored Jul 11, 2024
2 parents ab1ab42 + 66093bb commit fa64dd3
Show file tree
Hide file tree
Showing 26 changed files with 484 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import androidx.navigation.navOptions
import com.mashup.core.navigation.NavigationRoute
import com.mashup.dorabangs.core.designsystem.component.bottomnavigation.BottomNavigationDestination
import com.mashup.dorabangs.feature.navigation.navigateToHome
import com.mashup.dorabangs.feature.storage.navigation.navigateToStorage
import com.mashup.dorabangs.feature.navigation.navigateToStorage

@Composable
fun rememberDoraAppState(navController: NavHostController = rememberNavController()): DoraAppState {
Expand Down
24 changes: 20 additions & 4 deletions app/src/main/java/com/mashup/dorabangs/navigation/MainNavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ import com.dorabangs.feature.navigation.navigateToSaveLinkSelectFolder
import com.dorabangs.feature.navigation.saveLinkNavigation
import com.dorabangs.feature.navigation.saveLinkSelectFolder
import com.mashup.core.navigation.NavigationRoute
import com.mashup.dorabangs.feature.navigation.homeCreateFolderNavigation
import com.mashup.dorabangs.feature.navigation.homeNavigation
import com.mashup.dorabangs.feature.navigation.navigateToHome
import com.mashup.dorabangs.feature.navigation.navigateToHomeCrateFolder
import com.mashup.dorabangs.feature.navigation.navigateToStorageDetail
import com.mashup.dorabangs.feature.navigation.navigateToStorageFolderManage
import com.mashup.dorabangs.feature.navigation.onBoardingNavigation
import com.mashup.dorabangs.feature.storage.navigation.storageDetailNavigation
import com.mashup.dorabangs.feature.storage.navigation.storageNavigation
import com.mashup.dorabangs.feature.navigation.storageDetailNavigation
import com.mashup.dorabangs.feature.navigation.storageFolderManageNavigation
import com.mashup.dorabangs.feature.navigation.storageNavigation
import com.mashup.feature.classification.navigation.classificationNavigation
import com.mashup.feature.classification.navigation.navigateToClassification

Expand All @@ -28,6 +33,7 @@ fun MainNavHost(
navController = appState.navController,
startDestination = startDestination,
) {
onBoardingNavigation { appState.navController.navigateToHome() }
homeNavigation(
navigateToClassification = { appState.navController.navigateToClassification() },
navigateToSaveScreenWithLink = { copiedUrl ->
Expand All @@ -36,9 +42,19 @@ fun MainNavHost(
navigateToSaveScreenWithoutLink = {
appState.navController.navigateToSaveLink()
},
navigateToCreateFolder = { appState.navController.navigateToHomeCrateFolder() },
)
homeCreateFolderNavigation(
navController = appState.navController,
onClickBackIcon = { appState.navController.popBackStack() },
)
storageNavigation(
navigateToStorageDetail = { appState.navController.navigateToStorageDetail() },
navigateToFolderManage = { folderManageType -> appState.navController.navigateToStorageFolderManage(folderManageType = folderManageType) },
)
storageFolderManageNavigation(
onClickBackIcon = { appState.navController.popBackStack() },
)
onBoardingNavigation { appState.navController.navigateToHome() }
storageNavigation(appState.navController)
storageDetailNavigation(appState.navController)
classificationNavigation(
onClickBackIcon = { appState.navController.popBackStack() },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mashup.dorabangs.core.designsystem.component.bottomsheet

import androidx.annotation.StringRes
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
Expand All @@ -21,6 +22,8 @@ object DoraBottomSheet : BottomSheetType {
override fun MoreButtonBottomSheet(
modifier: Modifier,
isShowSheet: Boolean,
firstItemName: Int,
secondItemName: Int,
onClickDeleteLinkButton: () -> Unit,
onClickMoveFolderButton: () -> Unit,
onDismissRequest: () -> Unit,
Expand All @@ -39,12 +42,12 @@ object DoraBottomSheet : BottomSheetType {
items = listOf(
BottomSheetItemUIModel(
icon = R.drawable.ic_plus,
itemName = stringResource(id = R.string.more_button_bottom_sheet_remove_link),
itemName = stringResource(id = firstItemName),
color = DoraColorTokens.Alert,
),
BottomSheetItemUIModel(
icon = R.drawable.ic_plus,
itemName = stringResource(id = R.string.more_button_bottom_sheet_moving_folder),
itemName = stringResource(id = secondItemName),
),
),
onClickItem = { index ->
Expand All @@ -66,6 +69,8 @@ object DoraBottomSheet : BottomSheetType {
isShowSheet: Boolean,
folderList: List<SelectableBottomSheetItemUIModel>,
onDismissRequest: () -> Unit,
onClickCreateFolder: () -> Unit,
onClickMoveFolder: () -> Unit,
) {
if (isShowSheet) {
DoraBaseBottomSheet(
Expand Down Expand Up @@ -93,13 +98,15 @@ object DoraBottomSheet : BottomSheetType {
itemName = stringResource(id = R.string.moving_folder_dialog_add_folder),
isSelected = false,
),
onClickItem = onClickCreateFolder,
)
}

items(folderList.size) { index ->
DoraBottomSheetFolderItem(
modifier = Modifier.fillMaxWidth(),
data = folderList[index],
onClickItem = onClickMoveFolder,
)
}

Expand All @@ -125,6 +132,8 @@ sealed interface BottomSheetType {
fun MoreButtonBottomSheet(
modifier: Modifier,
isShowSheet: Boolean,
@StringRes firstItemName: Int,
@StringRes secondItemName: Int,
onClickDeleteLink: () -> Unit,
onClickMoveFolder: () -> Unit,
onDismissRequest: () -> Unit,
Expand All @@ -136,5 +145,7 @@ sealed interface BottomSheetType {
isShowSheet: Boolean,
folderList: List<SelectableBottomSheetItemUIModel>,
onDismissRequest: () -> Unit,
onClickCreateFolder: () -> Unit,
onClickMoveFolder: () -> Unit,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ fun DoraBottomSheetFolderItem(
data: SelectableBottomSheetItemUIModel,
modifier: Modifier = Modifier,
background: Color = BottomSheetColorTokens.MovingFolderColor,
onClickItem: () -> Unit = {},
) {
Row(
modifier = modifier
Expand All @@ -102,10 +103,11 @@ fun DoraBottomSheetFolderItem(
verticalAlignment = Alignment.CenterVertically,
) {
DoraFolderListItem(
BottomSheetItemUIModel(
data = BottomSheetItemUIModel(
icon = data.icon,
itemName = data.itemName,
),
modifier = Modifier.clickable { onClickItem() },
)
if (data.isSelected) {
Icon(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package com.mashup.core.navigation

sealed class NavigationRoute(val route: String) {
object OnBoardingScreen : NavigationRoute("onboarding")
object HomeScreen : NavigationRoute("home")
object HomeScreen : NavigationRoute("home") {
object HomeCreateFolder : NavigationRoute("home/createFolder")
}
object StorageScreen : NavigationRoute("storage") {
object StorageDetailScreen : NavigationRoute("storage/detail")
object StorageFolderManageScreen : NavigationRoute("storage/folderManage")
}
object ClassificationScreen : NavigationRoute("classification")
object SaveLink : NavigationRoute("save/copiedUrl") {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.mashup.dorabangs.feature.createfolder

import android.util.Log
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import com.mashup.dorabangs.core.designsystem.component.buttons.DoraButtons
import com.mashup.dorabangs.core.designsystem.component.textfield.DoraTextField
import com.mashup.dorabangs.core.designsystem.component.topbar.DoraTopBar
import com.mashup.dorabangs.core.designsystem.theme.LinkSaveColorTokens
import com.mashup.dorabangs.feature.home.HomeViewModel
import com.mashup.dorabangs.home.R

@Composable
fun HomeCreateFolderRoute(
homeViewModel: HomeViewModel = hiltViewModel(),
onClickBackIcon: () -> Unit,
) {
Log.d("DOAROA", "HomeCreateFolderRoute: $homeViewModel")
HomeCreateFolderScreen(
onClickBackIcon = onClickBackIcon,
onClickSaveButton = {},
)
}

@Composable
fun HomeCreateFolderScreen(
onClickBackIcon: () -> Unit,
onClickSaveButton: () -> Unit,
modifier: Modifier = Modifier,
) {
Column(
modifier = modifier
.fillMaxSize()
.background(color = LinkSaveColorTokens.ContainerColor),
) {
DoraTopBar.BackNavigationTopBar(
modifier = Modifier,
title = stringResource(id = R.string.home_create_folder_title),
isTitleCenter = true,
onClickBackIcon = onClickBackIcon,
)
Spacer(modifier = Modifier.height(height = 24.dp))
Column(
modifier = modifier
.fillMaxSize()
.padding(horizontal = 20.dp),
) {
DoraTextField(
text = "",
hintText = stringResource(id = R.string.home_create_folder_hint),
labelText = stringResource(id = R.string.home_create_folder_label),
helperText = stringResource(id = R.string.home_create_folder_helper),
helperEnabled = true,
counterEnabled = true,
onValueChanged = {},
)
Spacer(modifier = Modifier.height(20.dp))
DoraButtons.DoraBtnMaxFull(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 20.dp),
buttonText = stringResource(id = R.string.home_create_folder_save),
enabled = true,
onClickButton = onClickSaveButton,
)
Spacer(modifier = Modifier.height(20.dp))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ fun HomeRoute(
navigateToClassification: () -> Unit = {},
navigateToSaveScreenWithLink: (String) -> Unit = {},
navigateToSaveScreenWithoutLink: () -> Unit = {},
navigateToCreateFolder: () -> Unit,
) {
val snackBarHostState by remember { mutableStateOf(SnackbarHostState()) }
val state by viewModel.collectAsState()
val scope = rememberCoroutineScope()

viewModel.collectSideEffect { sideEffect ->
when (sideEffect) {
is HomeSideEffect.ShowSnackBar -> {
Expand All @@ -71,10 +73,10 @@ fun HomeRoute(
)
}
}

HomeSideEffect.HideSnackBar -> {
is HomeSideEffect.HideSnackBar -> {
snackBarHostState.currentSnackbarData?.dismiss()
}
is HomeSideEffect.NavigateToCreateFolder -> navigateToCreateFolder()
}
}

Expand Down Expand Up @@ -115,6 +117,8 @@ fun HomeRoute(
DoraBottomSheet.MoreButtonBottomSheet(
modifier = Modifier.height(320.dp),
isShowSheet = state.isShowMoreButtonSheet,
firstItemName = R.string.more_button_bottom_sheet_remove_link,
secondItemName = R.string.more_button_bottom_sheet_moving_folder,
onClickDeleteLinkButton = {
viewModel.setVisibleMoreButtonBottomSheet(false)
viewModel.setVisibleDialog(true)
Expand All @@ -131,6 +135,8 @@ fun HomeRoute(
isShowSheet = state.isShowMovingFolderSheet,
folderList = testFolderListData,
onDismissRequest = { viewModel.setVisibleMovingFolderBottomSheet(false) },
onClickCreateFolder = { viewModel.setVisibleMovingFolderBottomSheet(visible = false, isNavigate = true) },
onClickMoveFolder = {},
)

DoraDialog(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package com.mashup.dorabangs.feature.home
sealed class HomeSideEffect {
data class ShowSnackBar(val copiedText: String) : HomeSideEffect()
object HideSnackBar : HomeSideEffect()
object NavigateToCreateFolder : HomeSideEffect()
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,21 @@ import javax.inject.Inject

@HiltViewModel
class HomeViewModel @Inject constructor(
private val savedStateHandle: SavedStateHandle,
val savedStateHandle: SavedStateHandle,
private val getLastCopiedUrlUseCase: GetLastCopiedUrlUseCase,
private val setLastCopiedUrlUseCase: SetLastCopiedUrlUseCase,
) : ViewModel(), ContainerHost<HomeState, HomeSideEffect> {
override val container = container<HomeState, HomeSideEffect>(HomeState())

init {
viewModelScope.doraLaunch {
savedStateHandle.getStateFlow(
"isVisibleMovingBottomSheet",
initialValue = false,
).collect { isVisible -> setVisibleMovingFolderBottomSheet(visible = isVisible) }
}
}

fun changeSelectedTapIdx(index: Int) = intent {
reduce {
state.copy(selectedIndex = index)
Expand Down Expand Up @@ -71,10 +80,11 @@ class HomeViewModel @Inject constructor(
}
}

fun setVisibleMovingFolderBottomSheet(visible: Boolean) = intent {
fun setVisibleMovingFolderBottomSheet(visible: Boolean, isNavigate: Boolean = false) = intent {
reduce {
state.copy(isShowMovingFolderSheet = visible)
}
if (isNavigate) postSideEffect(HomeSideEffect.NavigateToCreateFolder)
}

init {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.mashup.dorabangs.feature.navigation

import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptions
import androidx.navigation.compose.composable
import com.mashup.core.navigation.NavigationRoute
import com.mashup.dorabangs.feature.createfolder.HomeCreateFolderRoute
import com.mashup.dorabangs.feature.home.HomeViewModel

fun NavController.navigateToHomeCrateFolder(navOptions: NavOptions? = null) =
navigate(NavigationRoute.HomeScreen.HomeCreateFolder.route, navOptions)

fun NavGraphBuilder.homeCreateFolderNavigation(
navController: NavController,
onClickBackIcon: () -> Unit,
) {
composable(
route = NavigationRoute.HomeScreen.HomeCreateFolder.route,
) {
navController.previousBackStackEntry?.let { backStackEntry ->
val homeViewModel: HomeViewModel = hiltViewModel(backStackEntry)
homeViewModel.savedStateHandle["isVisibleMovingBottomSheet"] = true

HomeCreateFolderRoute(
homeViewModel = homeViewModel,
onClickBackIcon = onClickBackIcon,
)
} ?: HomeCreateFolderRoute(
onClickBackIcon = onClickBackIcon,
)
}
}
Loading

0 comments on commit fa64dd3

Please sign in to comment.