Skip to content

Commit

Permalink
Feat : 설정 화면 API 연동
Browse files Browse the repository at this point in the history
  • Loading branch information
DongChyeon committed Jun 18, 2024
1 parent 7f031d8 commit 7060c7b
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 43 deletions.
6 changes: 5 additions & 1 deletion app/src/main/java/com/dev/briefing/BriefingNavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.dev.briefing
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.compose.NavHost
import store.newsbriefing.app.feature.auth.navigateToSignIn
import store.newsbriefing.app.feature.auth.signInRoute
import store.newsbriefing.app.feature.auth.signInScreen
import store.newsbriefing.app.feature.bookmark.bookmarkScreen
Expand Down Expand Up @@ -40,7 +41,10 @@ fun BriefingNavHost(
navigateUp = appState.navController::navigateUp
)
settingScreen(
showSnackbar = appState::showSnackBar
showSnackbar = appState::showSnackBar,
navigateUp = appState.navController::navigateUp,
navigateToSignIn = appState.navController::navigateToSignIn,
appVersion = BuildConfig.VERSION_NAME
)
signInScreen(
showSnackBar = appState::showSnackBar,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object Config {
compileSdkVersion = 34,
applicationId = "com.dev.briefing",
versionCode = 1,
versionName = "1.0",
versionName = "2.0.0",
nameSpace = "com.dev.briefing"
)
val jvm = JvmConfig(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import store.newsbriefing.app.core.model.MemberToken

interface MemberTokenRepository {
fun getMemberToken() : Flow<MemberToken>
suspend fun clearMemberToken()
suspend fun saveMemberToken(memberId : Long, accessToken: String, refreshToken: String)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package store.newsbriefing.app.core.data.repository.impl

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import store.newsbriefing.app.core.data.repository.MemberTokenRepository
import store.newsbriefing.app.core.datastore.datasource.UserAuthTokenDataSource
Expand All @@ -16,6 +15,10 @@ class DefaultMemberTokenRepository @Inject constructor(private val userAuthToken
}
}

override suspend fun clearMemberToken() {
userAuthTokenDataSource.clear()
}

override suspend fun saveMemberToken(
memberId: Long,
accessToken: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ package store.newsbriefing.app.feature.auth
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import androidx.navigation.navOptions
import store.newsbriefing.app.feature.auth.signIn.SignInRoute

const val signInRoute = "signIn_route"

fun NavController.navigateToSignIn() {
navigate(signInRoute)
navigate(signInRoute, navOptions {
popUpTo(signInRoute) {
inclusive = true
}
})
}

fun NavGraphBuilder.signInScreen(showSnackBar : (String) -> Unit, navigateToHome : () -> Unit) {
Expand Down
2 changes: 2 additions & 0 deletions feature/setting/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ android {
}

dependencies {
implementation(projects.core.data)

api(projects.core.model)
api(projects.core.common)
api(projects.core.designsystem)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ fun NavController.navigateToSetting() {
}

fun NavGraphBuilder.settingScreen(
showSnackbar: (String) -> Unit
showSnackbar: (String) -> Unit,
navigateUp: () -> Unit,
navigateToSignIn: () -> Unit,
appVersion: String
) {
composable(
route = settingRoute
) {
SettingRoute(
showSnackbar = showSnackbar
showSnackbar = showSnackbar,
navigateUp = navigateUp,
navigateToSignIn = navigateToSignIn,
appVersion = appVersion
)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package store.newsbriefing.app.feature.setting

import android.content.Intent
import android.net.Uri
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
Expand All @@ -16,86 +18,126 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.core.content.ContextCompat.startActivity
import androidx.hilt.navigation.compose.hiltViewModel
import kotlinx.coroutines.flow.collectLatest
import store.newsbriefing.app.core.designsystem.theme.BriefingTheme
import store.newsbriefing.app.core.designsystem.theme.Pretendard

@Composable
internal fun SettingRoute(
showSnackbar: (String) -> Unit
showSnackbar: (String) -> Unit,
navigateUp: () -> Unit,
navigateToSignIn: () -> Unit,
appVersion: String,
settingViewModel: SettingViewModel = hiltViewModel()
) {
LaunchedEffect(Unit) {
settingViewModel.eventFlow.collectLatest { event ->
when (event) {
is SettingEvent.ErrorOccurred -> {
showSnackbar(event.message)
}
is SettingEvent.Logout, is SettingEvent.DeleteMember -> {
navigateToSignIn()
}
}
}
}

SettingScreen(
showSnackbar = showSnackbar
showSnackbar = showSnackbar,
navigateUp = navigateUp,
logout = settingViewModel::logout,
deleteMember = settingViewModel::deleteMember,
appVersion = appVersion
)
}

@Preview
@Composable
fun SettingScrrenPreview() {
BriefingTheme {
SettingScreen(
showSnackbar = {}
)
}
}

@Composable
internal fun SettingScreen(
showSnackbar: (String) -> Unit
showSnackbar: (String) -> Unit,
navigateUp: () -> Unit,
logout: () -> Unit,
deleteMember: () -> Unit,
appVersion: String
) {
val context = LocalContext.current

Column(
modifier = Modifier
.fillMaxSize()
.background(BriefingTheme.colorScheme.BackgroundWhite)
.verticalScroll(rememberScrollState())
) {
TopBar {

navigateUp()
}

SettingTitle("구독 서비스")
SettingItem("Briefing Premium") {
SettingTitle(stringResource(id = R.string.subscription_service))
SettingItem(stringResource(id = R.string.briefing_premium)) {

}

SettingTitle("앱 정보")
AppVersionItem("2.0.0")
SettingItem("피드백 및 문의하기") {

SettingTitle(stringResource(id = R.string.app_information))
AppVersionItem(appVersion)
SettingItem(stringResource(id = R.string.feedback_and_inquiry)) {
val intent =
Intent(Intent.ACTION_VIEW, Uri.parse("https://forms.gle/HQXmEBkQ6wyW9jiw7"))
startActivity(context, intent, null)
}
SettingItem("버전 노트") {

SettingItem(stringResource(id = R.string.version_note)) {
val intent = Intent(
Intent.ACTION_VIEW,
Uri.parse("https://onve.notion.site/Briefing-8af692ff041c4fc6931b2fc897411e6d?pvs=4")
)
startActivity(context, intent, null)
}

SettingTitle("개인 정보 보호")
SettingItem("이용 약관") {

SettingTitle(stringResource(id = R.string.privacy_policy))
SettingItem(stringResource(id = R.string.terms_of_service)) {
val intent = Intent(
Intent.ACTION_VIEW,
Uri.parse("https://sites.google.com/view/brieifinguse/%ED%99%88")
)
startActivity(context, intent, null)
}
SettingItem("개인정보처리방침") {

SettingItem(stringResource(id = R.string.data_processing_policy)) {
val intent = Intent(
Intent.ACTION_VIEW,
Uri.parse("https://sites.google.com/view/briefing-private/%ED%99%88")
)
startActivity(context, intent, null)
}
SettingItem("유의 사항") {

SettingItem(stringResource(id = R.string.precautions)) {
val intent = Intent(
Intent.ACTION_VIEW,
Uri.parse("https://onve.notion.site/Briefing-e1cb17e2e7c54d3b9a7036b29ee9b11a?pvs=4")
)
startActivity(context, intent, null)
}

SettingTitle("회원 관리")
SettingItem("로그아웃") {

SettingTitle(stringResource(id = R.string.user_management))
SettingItem(stringResource(id = R.string.logout)) {
logout()
}
SettingItem(
"회원 탈퇴",
stringResource(id = R.string.withdrawal),
BriefingTheme.colorScheme.TextRed
) {

deleteMember()
}
}
}
Expand Down Expand Up @@ -124,7 +166,7 @@ private fun TopBar(
modifier = Modifier
.fillMaxWidth()
.align(Alignment.Center),
text = "설정",
text = stringResource(id = R.string.setting_title),
style = TextStyle(
fontFamily = Pretendard,
fontWeight = FontWeight.Medium,
Expand Down Expand Up @@ -211,7 +253,7 @@ private fun AppVersionItem(
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
text ="앱 버전",
text = stringResource(id = R.string.app_version),
style = TextStyle(
fontFamily = Pretendard,
fontWeight = FontWeight.Normal,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package store.newsbriefing.app.feature.setting

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import store.newsbriefing.app.core.common.util.EventFlow
import store.newsbriefing.app.core.common.util.MutableEventFlow
import store.newsbriefing.app.core.common.util.asEventFlow
import store.newsbriefing.app.core.data.repository.MemberRepository
import store.newsbriefing.app.core.data.repository.MemberTokenRepository
import javax.inject.Inject

sealed class SettingEvent {
data class ErrorOccurred(val message: String) : SettingEvent()
data object Logout : SettingEvent()
data object DeleteMember : SettingEvent()
}

@HiltViewModel
class SettingViewModel @Inject constructor(
private val memberRepository: MemberRepository,
private val memberTokenRepository: MemberTokenRepository
) : ViewModel() {
val eventFlow: EventFlow<SettingEvent>
get() = _eventFlow.asEventFlow()
private val _eventFlow = MutableEventFlow<SettingEvent>()

fun logout() = viewModelScope.launch {
memberTokenRepository.clearMemberToken()
_eventFlow.emit(SettingEvent.Logout)
}

fun deleteMember() = viewModelScope.launch {
val userId = memberTokenRepository.getMemberToken().first().memberId
memberRepository.deleteMember(userId)
_eventFlow.emit(SettingEvent.DeleteMember)
}
}
17 changes: 17 additions & 0 deletions feature/setting/src/main/res/values/string.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="setting_title">설정</string>
<string name="subscription_service">구독 서비스</string>
<string name="briefing_premium">Briefing Premium</string>
<string name="app_information">앱 정보</string>
<string name="app_version">앱 버전</string>
<string name="feedback_and_inquiry">피드백 및 문의하기</string>
<string name="version_note">버전 노트</string>
<string name="privacy_policy">개인 정보 보호</string>
<string name="terms_of_service">이용 약관</string>
<string name="data_processing_policy">개인정보처리방침</string>
<string name="precautions">유의 사항</string>
<string name="user_management">회원 관리</string>
<string name="logout">로그아웃</string>
<string name="withdrawal">회원 탈퇴</string>
</resources>

0 comments on commit 7060c7b

Please sign in to comment.