Skip to content

Commit

Permalink
feat: 문의하기 네비게이션 추가 (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
easyhz committed Aug 27, 2024
1 parent e5bfddd commit 4f25d2f
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/com/easyhz/noffice/NofficeApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ internal fun NofficeApp(
navController = navController,
)
myPageGraph(
snackBarHostState = snackBarHostState,
navigateToUp = navController::navigateUp,
navigateToTerms = navController::navigateToTerms,
navigateToNotice = navController::navigateToNotice,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.easyhz.noffice.navigation.my_page

import androidx.compose.material3.SnackbarHostState
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
Expand All @@ -19,6 +20,7 @@ import com.easyhz.noffice.navigation.my_page.screen.Terms
import com.easyhz.noffice.navigation.my_page.screen.Withdrawal

internal fun NavGraphBuilder.myPageGraph(
snackBarHostState: SnackbarHostState,
navigateToUp: () -> Unit,
navigateToTerms: (TermsType) -> Unit,
navigateToNotice: () -> Unit,
Expand All @@ -29,6 +31,7 @@ internal fun NavGraphBuilder.myPageGraph(
) {
composable<MyPage> {
MyPageScreen(
snackBarHostState = snackBarHostState,
navigateToUp = navigateToUp,
navigateToTerms = navigateToTerms,
navigateToNotice = navigateToNotice,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.easyhz.noffice.feature.my_page.contract

import android.net.Uri
import androidx.annotation.StringRes
import com.easyhz.noffice.core.common.base.UiSideEffect

sealed class MyPageSideEffect: UiSideEffect() {
Expand All @@ -9,4 +10,5 @@ sealed class MyPageSideEffect: UiSideEffect() {
data object NavigateToGallery: MyPageSideEffect()
data class NavigateToCamera(val uri: Uri): MyPageSideEffect()
data object RequestFocus: MyPageSideEffect()
data class ShowSnackBar(@StringRes val stringId: Int): MyPageSideEffect()
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.easyhz.noffice.feature.my_page.contract.menu

import android.net.Uri
import com.easyhz.noffice.core.common.base.UiSideEffect

sealed class MenuSideEffect: UiSideEffect() {
data class NavigateToInquiry(val uri: Uri): MenuSideEffect()
data object NavigateToNotice: MenuSideEffect()
data object NavigateToServiceOfTerms: MenuSideEffect()
data object NavigateToPrivacyPolicy: MenuSideEffect()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.easyhz.noffice.feature.my_page.screen

import android.net.Uri
import com.easyhz.noffice.core.common.base.BaseViewModel
import com.easyhz.noffice.feature.my_page.contract.menu.MenuIntent
import com.easyhz.noffice.feature.my_page.contract.menu.MenuSideEffect
Expand All @@ -24,10 +25,8 @@ class MyPageMenuViewModel @Inject constructor(

private fun onClickMenuItem(item: MyPageMenu) {
when(item) {
MyPageMenu.INQUIRY -> { }
MyPageMenu.NOTICE -> {
handleNoticeMenu()
}
MyPageMenu.INQUIRY -> { navigateToInquiry() }
MyPageMenu.NOTICE -> { handleNoticeMenu() }
MyPageMenu.TERMS_OF_SERVICE -> { handleTermsOfService() }
MyPageMenu.PRIVACY_POLICY -> { handlePrivacyPolicy() }
MyPageMenu.NOTIFICATION -> { handleNotificationMenu() }
Expand All @@ -40,6 +39,11 @@ class MyPageMenuViewModel @Inject constructor(
}
}

private fun navigateToInquiry() {
val uri = Uri.parse("http://pf.kakao.com/_IsRgG")
postSideEffect { MenuSideEffect.NavigateToInquiry(uri) }
}

private fun handleNotificationMenu() {
reduce { copy(isCheckedNotification = !currentState.isCheckedNotification) }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.easyhz.noffice.feature.my_page.screen

import android.content.Context
import android.content.Intent
import android.net.Uri
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.PickVisualMediaRequest
import androidx.activity.result.contract.ActivityResultContracts
Expand All @@ -15,6 +18,7 @@ import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
Expand All @@ -23,6 +27,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.ImeAction
Expand Down Expand Up @@ -61,6 +66,7 @@ fun MyPageScreen(
modifier: Modifier = Modifier,
viewModel: MyPageViewModel = hiltViewModel(),
menuViewModel: MyPageMenuViewModel = hiltViewModel(),
snackBarHostState: SnackbarHostState,
navigateToUp: () -> Unit,
navigateToTerms: (TermsType) -> Unit,
navigateToNotice: () -> Unit,
Expand All @@ -69,7 +75,7 @@ fun MyPageScreen(
) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
val menuState by menuViewModel.uiState.collectAsStateWithLifecycle()

val context = LocalContext.current
val scrollState = rememberScrollState()
val focusRequester = remember { FocusRequester() }
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
Expand Down Expand Up @@ -209,16 +215,28 @@ fun MyPageScreen(
is MyPageSideEffect.RequestFocus -> {
focusRequester.requestFocus()
}
is MyPageSideEffect.ShowSnackBar -> {
snackBarHostState.showSnackbar(
message = context.getString(sideEffect.stringId),
withDismissAction = true
)
}
}
}

menuViewModel.sideEffect.collectInSideEffectWithLifecycle { sideEffect ->
when(sideEffect) {
is MenuSideEffect.NavigateToInquiry -> { startActivity(context, sideEffect.uri) }
is MenuSideEffect.NavigateToNotice -> { navigateToNotice() }
is MenuSideEffect.NavigateToServiceOfTerms -> { navigateToTerms(TermsType.SERVICE_OF_TERMS) }
is MenuSideEffect.NavigateToPrivacyPolicy -> { navigateToTerms(TermsType.PRIVACY_POLICY) }
is MenuSideEffect.NavigateToConsentToInformation -> { navigateToConsent() }
is MenuSideEffect.NavigateToWithdrawal -> { navigateToWithdrawal() }
}
}
}

private fun startActivity(context: Context, uri: Uri) {
val intent = Intent(Intent.ACTION_VIEW, uri)
context.startActivity(intent)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.net.Uri
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.viewModelScope
import com.easyhz.noffice.core.common.base.BaseViewModel
import com.easyhz.noffice.core.common.error.handleError
import com.easyhz.noffice.core.common.util.errorLogging
import com.easyhz.noffice.core.design_system.util.bottomSheet.ImageSelectionBottomSheetItem
import com.easyhz.noffice.domain.organization.usecase.image.GetTakePictureUriUseCase
import com.easyhz.noffice.feature.my_page.contract.MyPageIntent
Expand Down Expand Up @@ -72,8 +74,8 @@ class MyPageViewModel @Inject constructor(
postSideEffect { MyPageSideEffect.NavigateToCamera(it) }
}
.onFailure {
// TODO fail 처리
println("fail: $it")
errorLogging(this.javaClass.simpleName, "navigateToCamera", it)
showSnackBar(it.handleError())
}
}
private fun onTakePicture(isUsed: Boolean) {
Expand Down Expand Up @@ -119,4 +121,8 @@ class MyPageViewModel @Inject constructor(
private fun navigateToUp() {
postSideEffect { MyPageSideEffect.NavigateToUp }
}

private fun showSnackBar(stringId: Int) {
postSideEffect { MyPageSideEffect.ShowSnackBar(stringId) }
}
}

0 comments on commit 4f25d2f

Please sign in to comment.