From 49a1fc95433871003b05a3befc460cca98399962 Mon Sep 17 00:00:00 2001 From: Wooyeol Lee Date: Mon, 4 Dec 2023 22:25:27 +0900 Subject: [PATCH] refactor: make consistency on emoji fetch mode as sortByDate --- .../java/com/goliath/emojihub/viewmodels/EmojiViewModel.kt | 6 +++--- .../src/main/java/com/goliath/emojihub/views/EmojiPage.kt | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/android/app/src/main/java/com/goliath/emojihub/viewmodels/EmojiViewModel.kt b/android/app/src/main/java/com/goliath/emojihub/viewmodels/EmojiViewModel.kt index 05017e12..e3e014cd 100644 --- a/android/app/src/main/java/com/goliath/emojihub/viewmodels/EmojiViewModel.kt +++ b/android/app/src/main/java/com/goliath/emojihub/viewmodels/EmojiViewModel.kt @@ -36,7 +36,7 @@ class EmojiViewModel @Inject constructor( private val _unSaveEmojiState = MutableStateFlow?>(null) val unSaveEmojiState = _unSaveEmojiState.asStateFlow() - var sortingMode by mutableIntStateOf(0) + var sortByDate by mutableIntStateOf(0) val emojiList = emojiUseCase.emojiList val myCreatedEmojiList = emojiUseCase.myCreatedEmojiList @@ -47,7 +47,7 @@ class EmojiViewModel @Inject constructor( fun fetchEmojiList() { viewModelScope.launch { - emojiUseCase.fetchEmojiList(sortingMode) + emojiUseCase.fetchEmojiList(sortByDate) .cachedIn(viewModelScope) .collect { emojiUseCase.updateEmojiList(it) @@ -56,7 +56,7 @@ class EmojiViewModel @Inject constructor( } fun toggleSortingMode() { - sortingMode = if (sortingMode == 1 ) 0 else 1 + sortByDate = sortByDate xor 1 fetchEmojiList() } diff --git a/android/app/src/main/java/com/goliath/emojihub/views/EmojiPage.kt b/android/app/src/main/java/com/goliath/emojihub/views/EmojiPage.kt index 537c8d39..b3e81c4e 100644 --- a/android/app/src/main/java/com/goliath/emojihub/views/EmojiPage.kt +++ b/android/app/src/main/java/com/goliath/emojihub/views/EmojiPage.kt @@ -17,7 +17,6 @@ import androidx.activity.result.contract.ActivityResultContracts import androidx.compose.foundation.layout.padding import androidx.compose.foundation.background import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth @@ -113,11 +112,11 @@ fun EmojiPage( Button( onClick = { viewModel.toggleSortingMode() }, colors = ButtonDefaults.buttonColors( - backgroundColor = if (viewModel.sortingMode == 0) Black else LightGray, + backgroundColor = if (viewModel.sortByDate == 0) Black else LightGray, contentColor = White ) ) { - Text(text = if (viewModel.sortingMode == 1) "Sort by Date" else "Sort by Save Count", fontSize = 12.sp) + Text(text = if (viewModel.sortByDate == 1) "Sort by Date" else "Sort by Save Count", fontSize = 12.sp) } }