Skip to content

Commit 2d942c3

Browse files
authored
🔀 :: (#648) password validator 수정
🔀 :: (#648) password validator 수정
2 parents 0460cba + 405f884 commit 2d942c3

File tree

19 files changed

+344
-87
lines changed

19 files changed

+344
-87
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ jobs:
2525
run: |
2626
echo $PROD_BASE_URL >> ./local.properties
2727
echo $DEV_BASE_URL >> ./local.properties
28+
echo $TERMS_URL >> ./local.properties
2829
cat
2930
env:
3031
PROD_BASE_URL: ${{secrets.PROD_BASE_URL}}
3132
DEV_BASE_URL: ${{secrets.DEV_BASE_URL}}
33+
TERMS_URL: ${{secrets.TERMS_URL}}
3234

3335
- name: Grant execute permission for gradlew
3436
run: chmod +x gradlew

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ android {
1717
minSdk = libs.versions.minSdk.get().toInt()
1818
targetSdk = libs.versions.targetSdk.get().toInt()
1919

20-
versionCode = 6
21-
versionName = "v1.2.0"
20+
versionCode = 8
21+
versionName = "v1.2.2"
2222

2323
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
2424
}

data/src/main/java/team/aliens/dms/android/data/meal/repository/MealRepository.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ import team.aliens.dms.android.data.meal.model.Meal
66
abstract class MealRepository {
77

88
abstract suspend fun fetchMeal(date: LocalDate): Meal
9+
10+
abstract suspend fun updateMeal(date: LocalDate): Meal
911
}

data/src/main/java/team/aliens/dms/android/data/meal/repository/MealRepositoryImpl.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@ internal class MealRepositoryImpl @Inject constructor(
1717
databaseMealDataSource.queryMeal(date).toModel()
1818
} catch (_: Exception) {
1919
try {
20-
networkMealDataSource.fetchMeals(date).toModel().also { meals ->
21-
databaseMealDataSource.saveMeals(meals.toEntity())
22-
}
23-
.find { it.date == date }!!
20+
this.updateMeal(date = date)
2421
} catch (_: Exception) {
2522
throw CannotFindMealException()
2623
}
2724
}
25+
26+
override suspend fun updateMeal(date: LocalDate): Meal {
27+
return networkMealDataSource.fetchMeals(date).toModel().also { meals ->
28+
databaseMealDataSource.saveMeals(meals.toEntity())
29+
}
30+
.find { it.date == date }!!
31+
}
2832
}

feature/src/main/java/team/aliens/dms/android/feature/editpassword/2_SetPasswordScreen.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ internal fun EditPasswordSetPasswordScreen(
9999

100100
EditPasswordSideEffect.PasswordFormatError -> isPasswordFormatError = true
101101

102+
EditPasswordSideEffect.PasswordEditFailure -> toast.showErrorToast(
103+
message = context.getString(R.string.edit_password_error_password_edit_failure),
104+
)
105+
102106
else -> {/* explicit blank */
103107
}
104108
}

feature/src/main/java/team/aliens/dms/android/feature/editpassword/EditPasswordViewModel.kt

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,30 @@ class EditPasswordViewModel @Inject constructor(
5757
),
5858
)
5959

60-
private fun editPassword() = viewModelScope.launch(Dispatchers.IO) {
60+
private fun editPassword() = run {
6161
val capturedState = stateFlow.value
62-
if (capturedState.newPassword != capturedState.newPasswordRepeat) {
62+
val newPassword = capturedState.newPassword
63+
val newPasswordRepeat = capturedState.newPasswordRepeat
64+
65+
if (newPassword != newPasswordRepeat) {
6366
postSideEffect(EditPasswordSideEffect.PasswordMismatch)
64-
return@launch
67+
return@run
6568
}
66-
if (!checkIfPasswordValid(capturedState.newPassword)) {
69+
if (!checkIfPasswordValid(newPassword)) {
6770
postSideEffect(EditPasswordSideEffect.PasswordFormatError)
68-
return@launch
71+
return@run
6972
}
70-
71-
runCatching {
72-
userRepository.editPassword(
73-
currentPassword = capturedState.currentPassword,
74-
newPassword = capturedState.newPassword,
75-
)
76-
}.onSuccess {
77-
postSideEffect(EditPasswordSideEffect.PasswordEdited)
78-
}.onFailure {
79-
it.printStackTrace()
80-
postSideEffect(EditPasswordSideEffect.PasswordFormatError)
73+
viewModelScope.launch(Dispatchers.IO) {
74+
runCatching {
75+
userRepository.editPassword(
76+
currentPassword = capturedState.currentPassword,
77+
newPassword = newPassword,
78+
)
79+
}.onSuccess {
80+
postSideEffect(EditPasswordSideEffect.PasswordEdited)
81+
}.onFailure {
82+
postSideEffect(EditPasswordSideEffect.PasswordEditFailure)
83+
}
8184
}
8285
}
8386
}
@@ -111,4 +114,5 @@ sealed class EditPasswordSideEffect : SideEffect() {
111114
data object PasswordEdited : EditPasswordSideEffect()
112115
data object PasswordFormatError : EditPasswordSideEffect()
113116
data object PasswordMismatch : EditPasswordSideEffect()
117+
data object PasswordEditFailure : EditPasswordSideEffect()
114118
}

feature/src/main/java/team/aliens/dms/android/feature/main/home/HomeScreen.kt

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import androidx.compose.material3.ExperimentalMaterial3Api
3434
import androidx.compose.material3.Icon
3535
import androidx.compose.material3.OutlinedCard
3636
import androidx.compose.material3.Text
37+
import androidx.compose.material3.pulltorefresh.PullToRefreshContainer
38+
import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState
3739
import androidx.compose.runtime.Composable
3840
import androidx.compose.runtime.Immutable
3941
import androidx.compose.runtime.LaunchedEffect
@@ -49,6 +51,7 @@ import androidx.compose.ui.draw.clip
4951
import androidx.compose.ui.graphics.Brush
5052
import androidx.compose.ui.graphics.Color
5153
import androidx.compose.ui.graphics.graphicsLayer
54+
import androidx.compose.ui.input.nestedscroll.nestedScroll
5255
import androidx.compose.ui.input.pointer.pointerInput
5356
import androidx.compose.ui.platform.LocalContext
5457
import androidx.compose.ui.res.painterResource
@@ -67,12 +70,13 @@ import team.aliens.dms.android.core.designsystem.DmsCalendar
6770
import team.aliens.dms.android.core.designsystem.DmsScaffold
6871
import team.aliens.dms.android.core.designsystem.DmsTheme
6972
import team.aliens.dms.android.core.designsystem.DmsTopAppBar
73+
import team.aliens.dms.android.core.designsystem.LocalToast
7074
import team.aliens.dms.android.core.designsystem.ModalBottomSheet
7175
import team.aliens.dms.android.core.designsystem.OutlinedButton
7276
import team.aliens.dms.android.core.designsystem.PrimaryDefault
7377
import team.aliens.dms.android.core.designsystem.ShadowDefaults
78+
import team.aliens.dms.android.core.designsystem.TextButton
7479
import team.aliens.dms.android.core.designsystem.clickable
75-
import team.aliens.dms.android.core.designsystem.rememberToastState
7680
import team.aliens.dms.android.core.ui.DefaultHorizontalSpace
7781
import team.aliens.dms.android.core.ui.DefaultVerticalSpace
7882
import team.aliens.dms.android.core.ui.PaddingDefaults
@@ -100,13 +104,29 @@ internal fun HomeScreen(
100104
onChangeBottomAppBarVisibility: (visible: Boolean) -> Unit,
101105
onNavigateToAnnouncementList: () -> Unit,
102106
) {
103-
val toast = rememberToastState()
107+
val toast = LocalToast.current
104108
val context = LocalContext.current
105-
106109
val uiState by viewModel.stateFlow.collectAsStateWithLifecycle()
110+
val pullToRefreshState = rememberPullToRefreshState()
111+
112+
val onRefresh = remember {
113+
{
114+
pullToRefreshState.startRefresh()
115+
viewModel.postIntent(HomeIntent.UpdateMeal); Unit
116+
}
117+
}
107118
viewModel.sideEffectFlow.collectInLaunchedEffectWithLifecycle { sideEffect ->
108119
when (sideEffect) {
109-
HomeSideEffect.CannotFindMeal -> toast.showErrorToast(context.getString(R.string.meal_error_not_found)) // FIXME: toast not showing
120+
HomeSideEffect.CannotFindMeal, HomeSideEffect.MealUpdateFailed -> toast.showErrorToast(
121+
context.getString(R.string.meal_error_not_found),
122+
)
123+
124+
HomeSideEffect.MealUpdated -> {
125+
pullToRefreshState.endRefresh()
126+
toast.showSuccessToast(
127+
message = context.getString(R.string.home_success_meal_refreshed),
128+
)
129+
}
110130
}
111131
}
112132

@@ -119,6 +139,12 @@ internal fun HomeScreen(
119139

120140
val (shouldShowCalendar, onShouldShowCalendarChange) = remember { mutableStateOf(false) }
121141

142+
LaunchedEffect(pullToRefreshState.isRefreshing) {
143+
if (pullToRefreshState.isRefreshing) {
144+
onRefresh()
145+
}
146+
}
147+
122148
if (shouldShowCalendar) {
123149
ModalBottomSheet(
124150
onDismissRequest = {
@@ -151,6 +177,7 @@ internal fun HomeScreen(
151177
) { padValues ->
152178
Column(
153179
modifier = Modifier
180+
.nestedScroll(pullToRefreshState.nestedScrollConnection)
154181
.animateContentSize()
155182
.background(brush = HomeBackgroundBrush)
156183
.fillMaxSize()
@@ -192,9 +219,18 @@ internal fun HomeScreen(
192219
meal = uiState.currentMeal,
193220
onNextDay = { onSelectedDateChange(uiState.selectedDate.plusDays(1)) },
194221
onPreviousDay = { onSelectedDateChange(uiState.selectedDate.minusDays(1)) },
222+
onRefresh = onRefresh,
195223
)
196224
Spacer(modifier = Modifier.height(92.dp))
197225
}
226+
Box(
227+
modifier = Modifier
228+
.fillMaxWidth()
229+
.padding(top = padValues.calculateTopPadding()),
230+
contentAlignment = Alignment.TopCenter,
231+
) {
232+
PullToRefreshContainer(state = pullToRefreshState)
233+
}
198234
}
199235
}
200236

@@ -362,6 +398,7 @@ private fun MealCards(
362398
meal: Meal,
363399
onNextDay: () -> Unit,
364400
onPreviousDay: () -> Unit,
401+
onRefresh: () -> Unit,
365402
) {
366403
val pagerState = rememberPagerState(
367404
initialPage = getProperMeal(),
@@ -444,6 +481,7 @@ private fun MealCards(
444481
)
445482
}
446483
},
484+
onRefresh = onRefresh,
447485
)
448486
}
449487
}
@@ -479,6 +517,7 @@ private fun MealCard(
479517
kcalOfDinner: String?,
480518
onSwipeToLeft: () -> Unit,
481519
onSwipeToRight: () -> Unit,
520+
onRefresh: () -> Unit,
482521
) {
483522
var dragDirection: DragDirection? by remember { mutableStateOf(null) }
484523

@@ -519,14 +558,24 @@ private fun MealCard(
519558
),
520559
elevation = CardDefaults.outlinedCardElevation(defaultElevation = ShadowDefaults.SmallElevation),
521560
) {
561+
val dishes = when (currentCardType) {
562+
BREAKFAST -> breakfast
563+
LUNCH -> lunch
564+
DINNER -> dinner
565+
}
566+
if (dishes.isEmpty()) {
567+
TextButton(
568+
modifier = Modifier.fillMaxWidth(),
569+
onClick = onRefresh,
570+
colors = ButtonDefaults.textGrayButtonColors(),
571+
) {
572+
Text(text = stringResource(id = R.string.refresh))
573+
}
574+
}
522575
Dishes(
523576
modifier = Modifier.fillMaxWidth(),
524577
iconRes = currentCardType.iconRes,
525-
dishes = when (currentCardType) {
526-
BREAKFAST -> breakfast
527-
LUNCH -> lunch
528-
DINNER -> dinner
529-
},
578+
dishes = dishes,
530579
kcal = when (currentCardType) {
531580
BREAKFAST -> kcalOfBreakfast
532581
LUNCH -> kcalOfLunch

feature/src/main/java/team/aliens/dms/android/feature/main/home/HomeViewModel.kt

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ internal class HomeViewModel @Inject constructor(
2525
) {
2626
init {
2727
fetchWhetherNewNoticeExists()
28-
updateMeal(date = stateFlow.value.selectedDate)
28+
updateDate(date = stateFlow.value.selectedDate)
2929
}
3030

3131
override fun processIntent(intent: HomeIntent) {
3232
when (intent) {
33-
is HomeIntent.UpdateSelectedDate -> updateMeal(intent.selectedDate)
33+
is HomeIntent.UpdateSelectedDate -> updateDate(intent.selectedDate)
34+
HomeIntent.UpdateMeal -> updateMeal()
3435
}
3536
}
3637

@@ -44,7 +45,7 @@ internal class HomeViewModel @Inject constructor(
4445
}
4546
}
4647

47-
private fun updateMeal(date: LocalDate) {
48+
private fun updateDate(date: LocalDate) {
4849
viewModelScope.launch(Dispatchers.IO) {
4950
runCatching {
5051
mealRepository.fetchMeal(date)
@@ -62,6 +63,27 @@ internal class HomeViewModel @Inject constructor(
6263
}
6364
}
6465
}
66+
67+
private fun updateMeal() =
68+
viewModelScope.launch(Dispatchers.IO) {
69+
println("LOGLOG1")
70+
val capturedDate = stateFlow.value.selectedDate
71+
runCatching {
72+
mealRepository.updateMeal(capturedDate)
73+
}.onSuccess { meal ->
74+
reduce(
75+
newState = stateFlow.value.copy(
76+
selectedDate = capturedDate,
77+
currentMeal = meal,
78+
),
79+
)
80+
postSideEffect(HomeSideEffect.MealUpdated)
81+
}.onFailure {
82+
postSideEffect(HomeSideEffect.MealUpdateFailed)
83+
}.also {
84+
println("LOGLOG ${it.isSuccess}")
85+
}
86+
}
6587
}
6688

6789
internal data class HomeUiState(
@@ -94,10 +116,13 @@ internal data class HomeUiState(
94116

95117
internal sealed class HomeIntent : Intent() {
96118
class UpdateSelectedDate(val selectedDate: LocalDate) : HomeIntent()
119+
data object UpdateMeal : HomeIntent()
97120
}
98121

99122
internal sealed class HomeSideEffect : SideEffect() {
100123
data object CannotFindMeal : HomeSideEffect()
124+
data object MealUpdated : HomeSideEffect()
125+
data object MealUpdateFailed : HomeSideEffect()
101126
}
102127

103128
/*

feature/src/main/java/team/aliens/dms/android/feature/signup/6_SetPasswordScreen.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ internal fun SignUpSetPasswordScreen(
6060
val (shouldShowQuitSignUpDialog, onShouldShowQuitSignUpDialogChange) = remember {
6161
mutableStateOf(false)
6262
}
63+
64+
val (isPasswordInvalid, onChangeIsPasswordInvalid) = remember(
65+
uiState.password,
66+
uiState.passwordRepeat
67+
) {
68+
mutableStateOf(false)
69+
}
70+
6371
if (shouldShowQuitSignUpDialog) {
6472
AlertDialog(
6573
title = { Text(text = stringResource(id = R.string.sign_up)) },
@@ -90,6 +98,13 @@ internal fun SignUpSetPasswordScreen(
9098
message = context.getString(R.string.sign_up_set_password_error_password_mismatch),
9199
)
92100

101+
SignUpSideEffect.InvalidPassword -> {
102+
toast.showErrorToast(
103+
message = context.getString(R.string.sign_up_set_password_invalid_password),
104+
)
105+
onChangeIsPasswordInvalid(true)
106+
}
107+
93108
else -> {/* explicit blank */
94109
}
95110
}
@@ -167,4 +182,4 @@ internal fun SignUpSetPasswordScreen(
167182
BackHandler {
168183
onShouldShowQuitSignUpDialogChange(true)
169184
}
170-
}
185+
}

0 commit comments

Comments
 (0)