Skip to content

Commit

Permalink
🔀 Merge pull request #17 from snuhcs-course/feat/settings-frontend
Browse files Browse the repository at this point in the history
Feat/settings-frontend
  • Loading branch information
sukchan-0811 authored Nov 3, 2023
2 parents a0f3e33 + abe3da8 commit 4957adf
Show file tree
Hide file tree
Showing 33 changed files with 1,318 additions and 188 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavHostController
import com.example.speechbuddy.R
import com.example.speechbuddy.compose.utils.AuthTopAppBarUi
import com.example.speechbuddy.compose.utils.ButtonLevel
import com.example.speechbuddy.compose.utils.ButtonUi
import com.example.speechbuddy.compose.utils.TextFieldUi
import com.example.speechbuddy.compose.utils.TitleUi
import com.example.speechbuddy.compose.utils.TopAppBarUi
import com.example.speechbuddy.ui.models.EmailVerificationErrorType
import com.example.speechbuddy.viewmodel.EmailVerificationViewModel

Expand All @@ -47,7 +47,9 @@ fun EmailVerificationScreen(
Surface(
modifier = modifier.fillMaxSize()
) {
Scaffold(topBar = { TopAppBarUi(onBackClick = onBackClick) }) {
Scaffold(
topBar = { AuthTopAppBarUi(onBackClick = onBackClick) }
) {
Column(
modifier = Modifier
.fillMaxSize()
Expand All @@ -72,7 +74,7 @@ fun EmailVerificationScreen(
// Email Text Field
TextFieldUi(value = viewModel.emailInput,
onValueChange = { viewModel.setEmail(it) },
label = { Text(text = stringResource(id = R.string.email_field)) },
label = { Text(text = stringResource(id = R.string.email)) },
supportingButton = {
ButtonUi(
text = stringResource(id = R.string.send_validation_code),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.speechbuddy.compose.home

import android.annotation.SuppressLint
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
Expand All @@ -14,7 +13,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
Expand All @@ -26,6 +24,7 @@ import com.example.speechbuddy.compose.settings.SettingsScreen
import com.example.speechbuddy.compose.symbolcreation.SymbolCreationScreen
import com.example.speechbuddy.compose.symbolselection.SymbolSelectionScreen
import com.example.speechbuddy.compose.texttospeech.TextToSpeechScreen
import com.example.speechbuddy.compose.utils.NoRippleInteractionSource
import com.example.speechbuddy.ui.SpeechBuddyTheme

data class BottomNavItem(
Expand All @@ -34,22 +33,19 @@ data class BottomNavItem(
val iconResId: Int
)

@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun HomeScreen(

) {
fun HomeScreen() {
val navController = rememberNavController()
val navItems = listOf(
BottomNavItem(
"symbol_selection",
R.string.symbol_selection,
R.string.talk_with_symbols,
R.drawable.outline_touch_app_24
),
BottomNavItem(
"text_to_speech",
R.string.text_to_speech,
R.string.talk_with_speech,
R.drawable.outline_volume_up_24
),
BottomNavItem(
Expand All @@ -69,16 +65,15 @@ fun HomeScreen(
BottomNavigationBar(
items = navItems,
navController = navController,
modifier = Modifier
.height(100.dp),
onItemClick = {
navController.navigate(it.route)
}
)
}
) {
) { paddingValues ->
HomeScreenNavHost(
navController = navController
navController = navController,
bottomPaddingValues = paddingValues
)
}
}
Expand Down Expand Up @@ -110,28 +105,38 @@ private fun BottomNavigationBar(
colors = NavigationBarItemDefaults.colors(
selectedIconColor = MaterialTheme.colorScheme.onPrimaryContainer,
unselectedIconColor = MaterialTheme.colorScheme.outline
)
),
interactionSource = NoRippleInteractionSource()
)
}
}
}

@Composable
private fun HomeScreenNavHost(
navController: NavHostController
navController: NavHostController,
bottomPaddingValues: PaddingValues
) {
NavHost(navController = navController, startDestination = "symbol_selection") {
composable("symbol_selection") {
SymbolSelectionScreen()
SymbolSelectionScreen(
bottomPaddingValues = bottomPaddingValues
)
}
composable("text_to_speech") {
TextToSpeechScreen()
TextToSpeechScreen(
bottomPaddingValues = bottomPaddingValues
)
}
composable("symbol_creation") {
SymbolCreationScreen()
SymbolCreationScreen(
bottomPaddingValues = bottomPaddingValues
)
}
composable("settings") {
SettingsScreen()
SettingsScreen(
bottomPaddingValues = bottomPaddingValues
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import com.example.speechbuddy.R
import com.example.speechbuddy.compose.utils.AuthTopAppBarUi
import com.example.speechbuddy.compose.utils.ButtonLevel
import com.example.speechbuddy.compose.utils.ButtonUi
import com.example.speechbuddy.compose.utils.TextFieldUi
import com.example.speechbuddy.compose.utils.TitleUi
import com.example.speechbuddy.compose.utils.TopAppBarUi
import com.example.speechbuddy.ui.models.LoginErrorType
import com.example.speechbuddy.viewmodel.LoginViewModel

Expand All @@ -46,7 +46,7 @@ fun LoginScreen(

Surface(modifier = modifier.fillMaxSize()) {
Scaffold(
topBar = { TopAppBarUi(onBackClick = onBackClick) }
topBar = { AuthTopAppBarUi(onBackClick = onBackClick) }
) {
Column(
modifier = Modifier
Expand All @@ -66,7 +66,7 @@ fun LoginScreen(
TextFieldUi(
value = viewModel.emailInput,
onValueChange = { viewModel.setEmail(it) },
label = { Text(stringResource(id = R.string.email_field)) },
label = { Text(stringResource(id = R.string.email)) },
supportingText = {
if (isEmailError) {
Text(stringResource(id = uiState.error!!.messageId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import com.example.speechbuddy.compose.utils.ButtonLevel
import com.example.speechbuddy.compose.utils.ButtonUi
import com.example.speechbuddy.compose.utils.TextFieldUi
import com.example.speechbuddy.compose.utils.TitleUi
import com.example.speechbuddy.compose.utils.TopAppBarUi
import com.example.speechbuddy.compose.utils.AuthTopAppBarUi
import com.example.speechbuddy.ui.models.ResetPasswordErrorType
import com.example.speechbuddy.viewmodel.ResetPasswordViewModel

Expand All @@ -48,7 +48,7 @@ fun ResetPasswordScreen(
) {
Scaffold(
topBar = {
TopAppBarUi(
AuthTopAppBarUi(
onBackClick = onBackClick
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package com.example.speechbuddy.compose.settings

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
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.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
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.example.speechbuddy.R
import com.example.speechbuddy.compose.utils.AlertDialogUi
import com.example.speechbuddy.compose.utils.ButtonLevel
import com.example.speechbuddy.compose.utils.ButtonUi
import com.example.speechbuddy.compose.utils.HomeTopAppBarUi
import com.example.speechbuddy.compose.utils.TitleUi
import com.example.speechbuddy.ui.models.AccountSettingsAlert
import com.example.speechbuddy.viewmodel.AccountSettingsViewModel

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AccountSettings(
modifier: Modifier = Modifier,
onBackClick: () -> Unit,
bottomPaddingValues: PaddingValues,
viewModel: AccountSettingsViewModel = hiltViewModel()
) {
val uiState by viewModel.uiState.collectAsState()

Surface(
modifier = modifier.fillMaxSize()
) {
Scaffold(
topBar = {
HomeTopAppBarUi(
title = stringResource(id = R.string.settings),
onBackClick = onBackClick,
isBackClickEnabled = true
)
}
) { topPaddingValues ->
Column(
modifier = Modifier
.fillMaxSize()
.padding(
top = topPaddingValues.calculateTopPadding(),
bottom = bottomPaddingValues.calculateBottomPadding()
)
.padding(24.dp),
verticalArrangement = Arrangement.Center
) {
TitleUi(title = stringResource(id = R.string.account))

Spacer(modifier = Modifier.height(20.dp))

Column(
verticalArrangement = Arrangement.spacedBy(10.dp)
) {
SettingsRow(
label = stringResource(id = R.string.email),
content = {
SettingsRowText(text = uiState.email)
}
)

SettingsRow(
label = stringResource(id = R.string.nickname),
content = {
SettingsRowText(text = uiState.nickname)
}
)
}

Spacer(modifier = Modifier.height(80.dp))

Column(
verticalArrangement = Arrangement.spacedBy(14.dp)
) {
ButtonUi(
text = stringResource(id = R.string.logout),
onClick = { viewModel.showAlert(AccountSettingsAlert.LOGOUT) }
)

ButtonUi(
text = stringResource(id = R.string.withdraw),
onClick = { viewModel.showAlert(AccountSettingsAlert.WITHDRAW) },
level = ButtonLevel.QUATERNARY
)
}
}
}
}

uiState.alert?.let { alert ->
when (alert) {
AccountSettingsAlert.LOGOUT -> {
AlertDialogUi(
title = stringResource(id = R.string.logout),
text = stringResource(id = R.string.logout_warning),
dismissButtonText = stringResource(id = R.string.dismiss),
confirmButtonText = stringResource(id = R.string.logout),
onDismiss = { viewModel.hideAlert() },
onConfirm = { viewModel.logout() }
)
}

AccountSettingsAlert.WITHDRAW -> {
AlertDialogUi(
title = stringResource(id = R.string.withdraw),
text = stringResource(id = R.string.withdraw_warning),
dismissButtonText = stringResource(id = R.string.dismiss),
confirmButtonText = stringResource(id = R.string.proceed),
onDismiss = { viewModel.hideAlert() },
onConfirm = {
viewModel.showAlert(AccountSettingsAlert.WITHDRAW_PROCEED)
}
)
}

AccountSettingsAlert.WITHDRAW_PROCEED -> {
AlertDialogUi(
title = stringResource(id = R.string.withdraw),
text = stringResource(id = R.string.withdraw_proceed_warning),
dismissButtonText = stringResource(id = R.string.dismiss),
confirmButtonText = stringResource(id = R.string.withdraw),
onDismiss = { viewModel.hideAlert() },
onConfirm = { viewModel.deleteAccount() }
)
}
}
}
}
Loading

0 comments on commit 4957adf

Please sign in to comment.