Skip to content

Commit

Permalink
Merge pull request #157 from WithPeace/feat/#156-release_to_110
Browse files Browse the repository at this point in the history
Feat/#156 release to 110
  • Loading branch information
rhkrwngud445 authored Jul 3, 2024
2 parents b44ef03 + 972e307 commit 7b20e78
Show file tree
Hide file tree
Showing 9 changed files with 236 additions and 34 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
defaultConfig {
applicationId = "com.withpeace.withpeace"
targetSdk = 34
versionCode = 7
versionName = "1.0.2"
versionCode = 8
versionName = "1.1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
96 changes: 92 additions & 4 deletions app/src/main/java/com/withpeace/withpeace/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,24 @@ import androidx.activity.compose.setContent
import androidx.activity.result.ActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
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.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.core.splashscreen.SplashScreen
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.WindowCompat
Expand Down Expand Up @@ -56,15 +73,24 @@ class MainActivity : ComponentActivity() {
lifecycleScope.launch {
splashScreen = installSplashScreen()
splashScreen.setKeepOnScreenCondition { true }

repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.uiState.collect { uiState ->
when (uiState) {
MainUiState.Home -> composeStart(HOME_ROUTE)
MainUiState.Login -> composeStart(LOGIN_ROUTE)
MainUiState.Update -> {}
MainUiState.Update -> {
showForceUpdateDialog()
}

MainUiState.Error -> finish()
MainUiState.Error -> {
//TODO 에러 화면으로 이동
Toast.makeText(
this@MainActivity,
"네트워크 상태가 원활하지 않습니다.",
Toast.LENGTH_SHORT,
).show()
finish()
}
MainUiState.Loading -> {}
}
splashScreen.setKeepOnScreenCondition { false }
Expand All @@ -73,6 +99,68 @@ class MainActivity : ComponentActivity() {
}
}

private fun showForceUpdateDialog() {
setContent {
WithpeaceTheme {
Column(
modifier = Modifier
.fillMaxSize()
.background(WithpeaceTheme.colors.SystemWhite),
) {
Dialog(
onDismissRequest = {

},
) {
Surface(
modifier = Modifier
.clip(RoundedCornerShape(10.dp))
.background(WithpeaceTheme.colors.SystemWhite)
.padding(24.dp),
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.background(WithpeaceTheme.colors.SystemWhite),
) {
Text(
color = WithpeaceTheme.colors.SystemBlack,
text = "새로운 버전이 업데이트 되었어요",
textAlign = TextAlign.Center,
style = WithpeaceTheme.typography.title2,
)
Spacer(modifier = Modifier.height(16.dp))
Text(
color = WithpeaceTheme.colors.SystemGray1,
text = "더 나아진 청하를 이용하기 위해\n 지금 업데이트 해주세요.",
textAlign = TextAlign.Center,
style = WithpeaceTheme.typography.body,
)
Spacer(modifier = Modifier.height(16.dp))
TextButton(
onClick = {
redirectToPlayStore()
},
modifier = Modifier
.clip(RoundedCornerShape(10.dp))
.background(WithpeaceTheme.colors.MainPurple)
.width(264.dp),
) {
Text(
color = WithpeaceTheme.colors.SystemWhite,
text = "업데이트하기",
textAlign = TextAlign.Center,
style = WithpeaceTheme.typography.body,
)
}
}
}
}
}

}
}
}

private fun ComponentActivity.composeStart(startDestination: String) {
setContent {
CompositionLocalProvider(
Expand All @@ -94,7 +182,7 @@ class MainActivity : ComponentActivity() {
startUpdateFlow(appUpdateManager, appUpdateInfo)
} else {
Toast.makeText(this, "앱을 사용하려면 업데이트가 필요해요!", Toast.LENGTH_LONG).show()
redirectToPlayStore()
// redirectToPlayStore()
}
}
}
Expand Down
36 changes: 30 additions & 6 deletions app/src/main/java/com/withpeace/withpeace/WithpeaceApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.SnackbarResult
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
Expand All @@ -19,6 +19,9 @@ import androidx.navigation.NavHostController
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.withpeace.withpeace.core.designsystem.theme.WithpeaceTheme
import com.withpeace.withpeace.core.designsystem.ui.snackbar.CheonghaSnackbar
import com.withpeace.withpeace.core.designsystem.ui.snackbar.SnackbarState
import com.withpeace.withpeace.core.designsystem.ui.snackbar.SnackbarType
import com.withpeace.withpeace.navigation.WithpeaceNavHost
import kotlinx.coroutines.launch

Expand All @@ -29,9 +32,18 @@ fun WithpeaceApp(
navController: NavHostController = rememberNavController(),
) {
val snackBarHostState = remember { SnackbarHostState() }
var snackBarState: SnackbarState =
remember { SnackbarState("", SnackbarType.Normal) }
val coroutineScope = rememberCoroutineScope()
fun showSnackBar(message: String) = coroutineScope.launch {
snackBarHostState.showSnackbar(message)
fun showSnackBar(snackbarState: SnackbarState) = coroutineScope.launch {
snackBarState = snackbarState
snackBarHostState.currentSnackbarData?.dismiss()
val snackbarResult = snackBarHostState.showSnackbar(snackbarState.message)
when (snackbarResult) {
SnackbarResult.Dismissed -> Unit
SnackbarResult.ActionPerformed ->
(snackbarState.snackbarType as SnackbarType.Navigator).action()
}
}

val navBackStackEntry by navController.currentBackStackEntryAsState()
Expand All @@ -51,10 +63,22 @@ fun WithpeaceApp(
)
}
},
modifier = Modifier.fillMaxSize().semantics {
testTagsAsResourceId = true
modifier = Modifier
.fillMaxSize()
.semantics {
testTagsAsResourceId = true
},
snackbarHost = {
SnackbarHost(snackBarHostState)
{
when (snackBarState.snackbarType) {
is SnackbarType.Navigator -> {}
is SnackbarType.Normal -> {
CheonghaSnackbar(data = it)
}
}
}
},
snackbarHost = { SnackbarHost(snackBarHostState) },
containerColor = WithpeaceTheme.colors.SystemWhite,
) { innerPadding ->
WithpeaceNavHost(
Expand Down
35 changes: 18 additions & 17 deletions app/src/main/java/com/withpeace/withpeace/navigation/NavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.navigation.navOptions
import androidx.navigation.navigation
import com.app.profileeditor.navigation.navigateProfileEditor
import com.app.profileeditor.navigation.profileEditorNavGraph
import com.withpeace.withpeace.core.designsystem.ui.snackbar.SnackbarState
import com.withpeace.withpeace.feature.gallery.navigation.galleryNavGraph
import com.withpeace.withpeace.feature.gallery.navigation.navigateToGallery
import com.withpeace.withpeace.feature.home.navigation.homeNavGraph
Expand Down Expand Up @@ -46,15 +47,15 @@ fun WithpeaceNavHost(
modifier: Modifier = Modifier,
navController: NavHostController,
startDestination: String = LOGIN_ROUTE,
onShowSnackBar: (message: String) -> Unit,
onShowSnackBar: (SnackbarState) -> Unit,
) {
NavHost(
modifier = modifier,
navController = navController,
startDestination = startDestination,
) {
loginNavGraph(
onShowSnackBar = onShowSnackBar,
onShowSnackBar = { onShowSnackBar(SnackbarState(it)) },
onSignUpNeeded = {
navController.navigateToPolicyConsent()
},
Expand All @@ -70,7 +71,7 @@ fun WithpeaceNavHost(
},
)
policyConsentGraph(
onShowSnackBar = onShowSnackBar,
onShowSnackBar = { onShowSnackBar(SnackbarState(it)) },
onSuccessToNext = {
navController.navigateSignUp()
},
Expand All @@ -82,21 +83,21 @@ fun WithpeaceNavHost(
},
)
termsOfServiceGraph(
onShowSnackBar = onShowSnackBar,
onShowSnackBar = { onShowSnackBar(SnackbarState(it)) },
onClickBackButton = {
navController.popBackStack()
},
)

privacyPolicyGraph(
onShowSnackBar = onShowSnackBar,
onShowSnackBar = { onShowSnackBar(SnackbarState(it)) },
onClickBackButton = {
navController.popBackStack()
},
)

signUpNavGraph(
onShowSnackBar = onShowSnackBar,
onShowSnackBar = { onShowSnackBar(SnackbarState(it)) },
onNavigateToGallery = {
navController.navigateToGallery(imageLimit = 1)
},
Expand All @@ -112,7 +113,7 @@ fun WithpeaceNavHost(
},
)
registerPostNavGraph(
onShowSnackBar = onShowSnackBar,
onShowSnackBar = { onShowSnackBar(SnackbarState(it)) },
onCompleteRegisterPost = { postId ->
navController.navigateToPostDetail(
postId,
Expand Down Expand Up @@ -160,21 +161,21 @@ fun WithpeaceNavHost(
)
navController.popBackStack()
},
onShowSnackBar = onShowSnackBar,
onShowSnackBar = { onShowSnackBar(SnackbarState(it)) },
)
homeNavGraph(
onShowSnackBar = onShowSnackBar,
onShowSnackBar = { onShowSnackBar(SnackbarState(it)) },
onPolicyClick = {
navController.navigateToPolicyDetail(policy = it)
},
)
policyDetailNavGraph(
onShowSnackBar = onShowSnackBar,
onShowSnackBar = { onShowSnackBar(SnackbarState(it)) },
onClickBackButton = { navController.popBackStack() },
)
navigation(startDestination = MY_PAGE_ROUTE, MY_PAGE_NESTED_ROUTE) {
myPageNavGraph(
onShowSnackBar = onShowSnackBar,
onShowSnackBar = { onShowSnackBar(SnackbarState(it)) },
onEditProfile = { nickname, profileImageUrl ->
navController.navigateProfileEditor(
nickname = nickname,
Expand Down Expand Up @@ -204,7 +205,7 @@ fun WithpeaceNavHost(
},
)
profileEditorNavGraph(
onShowSnackBar = onShowSnackBar,
onShowSnackBar = { onShowSnackBar(SnackbarState(it)) },
onClickBackButton = {
navController.popBackStack()
},
Expand All @@ -225,7 +226,7 @@ fun WithpeaceNavHost(
)
}
postDetailGraph(
onShowSnackBar = onShowSnackBar,
onShowSnackBar = { onShowSnackBar(SnackbarState(it)) },
onClickBackButton = navController::popBackStack,
onClickEditButton = {
navController.currentBackStackEntry?.savedStateHandle?.set(
Expand All @@ -242,10 +243,10 @@ fun WithpeaceNavHost(
set(POST_LIST_DELETED_POST_ID_ARGUMENT, it)
}
navController.popBackStack()
}
},
)
postListGraph(
onShowSnackBar = onShowSnackBar,
onShowSnackBar = { onShowSnackBar(SnackbarState(it)) },
navigateToPostDetail = navController::navigateToPostDetail,
onAuthExpired = {
onAuthExpired(onShowSnackBar, navController)
Expand All @@ -255,10 +256,10 @@ fun WithpeaceNavHost(
}

private fun onAuthExpired(
onShowSnackBar: (message: String) -> Unit,
onShowSnackBar: (SnackbarState) -> Unit,
navController: NavHostController,
) {
onShowSnackBar("세션이 만료되었습니다. 로그인 후 다시 시도해 주세요.")
onShowSnackBar(SnackbarState("세션이 만료되었습니다. 로그인 후 다시 시도해 주세요."))
navController.navigateLogin(
navOptions = navOptions {
popUpTo(navController.graph.id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ val systemError = Color(0xFFF0474B)
val systemSuccess = Color(0xFF3BD569)
val systemHyperLink = Color(0xFF20BCBB)

val snackbarBlack = Color(0xFF000000)

data class WithPeaceColor(
val MainPurple: Color = mainPurple,
val SubPurple: Color = subPurple,
Expand All @@ -43,6 +45,7 @@ data class WithPeaceColor(
val SystemGray4: Color = systemGray4,
val SystemSuccess: Color = systemSuccess,
val SystemHyperLink: Color = systemHyperLink,
val SnackbarBlack: Color = snackbarBlack,
)

val lightColor = WithPeaceColor()
Expand Down
Loading

0 comments on commit 7b20e78

Please sign in to comment.