From 5727265589066c8c0c5f1c06da8f71aeb98e0df7 Mon Sep 17 00:00:00 2001 From: 2018JunYoungLim Date: Wed, 6 Dec 2023 13:40:13 +0900 Subject: [PATCH 1/3] fix: change button -> dropDownMenu --- android/.idea/deploymentTargetDropDown.xml | 17 +++++++ .../emojihub/viewmodels/EmojiViewModel.kt | 5 --- .../com/goliath/emojihub/views/EmojiPage.kt | 45 +++++++++++++++---- 3 files changed, 53 insertions(+), 14 deletions(-) create mode 100644 android/.idea/deploymentTargetDropDown.xml diff --git a/android/.idea/deploymentTargetDropDown.xml b/android/.idea/deploymentTargetDropDown.xml new file mode 100644 index 00000000..2ed6eec2 --- /dev/null +++ b/android/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file 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 66514e2f..3b75e8f8 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 @@ -57,11 +57,6 @@ class EmojiViewModel @Inject constructor( } } - fun toggleSortingMode() { - sortByDate = sortByDate xor 1 - fetchEmojiList() - } - fun fetchMyCreatedEmojiList() { viewModelScope.launch { emojiUseCase.fetchMyCreatedEmojiList() 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 aa77cbe0..dc967bf0 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 @@ -18,6 +18,8 @@ import androidx.compose.foundation.lazy.grid.GridCells import androidx.compose.foundation.lazy.grid.LazyVerticalGrid import androidx.compose.material.Button import androidx.compose.material.ButtonDefaults +import androidx.compose.material.DropdownMenu +import androidx.compose.material.DropdownMenuItem import androidx.compose.material.Icon import androidx.compose.material.IconButton import androidx.compose.material.Text @@ -34,6 +36,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.DpOffset import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.core.content.ContextCompat @@ -41,6 +44,7 @@ import androidx.hilt.navigation.compose.hiltViewModel import androidx.paging.compose.collectAsLazyPagingItems import com.goliath.emojihub.LocalNavController import com.goliath.emojihub.NavigationDestination +import com.goliath.emojihub.extensions.toEmoji import com.goliath.emojihub.navigateAsOrigin import com.goliath.emojihub.ui.theme.Color.Black import com.goliath.emojihub.ui.theme.Color.LightGray @@ -64,6 +68,7 @@ fun EmojiPage() { val emojiList = emojiViewModel.emojiList.collectAsLazyPagingItems() var showNonUserDialog by remember { mutableStateOf(false) } + var dropDownMenuExpanded by remember { mutableStateOf(false) } val permissionLauncher = rememberLauncherForActivityResult( ActivityResultContracts.RequestPermission() @@ -118,16 +123,38 @@ fun EmojiPage() { horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically ) { - Text("Trending 🔥", fontSize = 20.sp, fontWeight = FontWeight.Bold) + Text(text = if (emojiViewModel.sortByDate == 0) "Trending 🔥" else "Recently added " + "U+D83D U+DD52".toEmoji(), fontSize = 20.sp, fontWeight = FontWeight.Bold) - Button( - onClick = { emojiViewModel.toggleSortingMode() }, - colors = ButtonDefaults.buttonColors( - backgroundColor = if (emojiViewModel.sortByDate == 0) Black else LightGray, - contentColor = White - ) - ) { - Text(text = if (emojiViewModel.sortByDate == 1) "Sort by Date" else "Sort by Save Count", fontSize = 12.sp) + Column { + Button( + onClick = { dropDownMenuExpanded = true }, + colors = ButtonDefaults.buttonColors( + backgroundColor = Black, + contentColor = White + ) + ) { + Text(text = "Sort by", fontSize = 12.sp) + } + + DropdownMenu( + expanded = dropDownMenuExpanded, + onDismissRequest = { dropDownMenuExpanded = false } + ) { + DropdownMenuItem(onClick = { + emojiViewModel.sortByDate = 1 + emojiViewModel.fetchEmojiList() + dropDownMenuExpanded = false + }) { + Text(text = "created date") + } + DropdownMenuItem(onClick = { + emojiViewModel.sortByDate = 0 + emojiViewModel.fetchEmojiList() + dropDownMenuExpanded = false + }) { + Text(text = "save count") + } + } } } From 6391ae540722d9eefec9de78f5dd49662f51def2 Mon Sep 17 00:00:00 2001 From: 2018JunYoungLim Date: Wed, 6 Dec 2023 13:59:43 +0900 Subject: [PATCH 2/3] remove toggle sorting mode test --- .../emojihub/viewmodels/EmojiViewModelTest.kt | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/android/app/src/test/java/com/goliath/emojihub/viewmodels/EmojiViewModelTest.kt b/android/app/src/test/java/com/goliath/emojihub/viewmodels/EmojiViewModelTest.kt index 1c0afe34..b9e8cf0a 100644 --- a/android/app/src/test/java/com/goliath/emojihub/viewmodels/EmojiViewModelTest.kt +++ b/android/app/src/test/java/com/goliath/emojihub/viewmodels/EmojiViewModelTest.kt @@ -58,22 +58,22 @@ class EmojiViewModelTest { coVerify(exactly = 1) { emojiUseCase.updateEmojiList(any()) } } - @Test - fun toggleSortingMode_success_updateTrendingEmojiList() = runTest { - // given - // for simplicity of testing, we return the same list for both cases - val sampleFetchedEmojiList = createDeterministicTrendingEmojiList(10) - coEvery { - emojiUseCase.fetchEmojiList(1) - } returns sampleFetchedEmojiList - // when - emojiViewModel.toggleSortingMode() - advanceUntilIdle() - // then - coVerify(exactly = 1) { emojiUseCase.fetchEmojiList(1) } - coVerify(exactly = 1) { emojiUseCase.updateEmojiList(any()) } - assertEquals(1, emojiViewModel.sortByDate) - } +// @Test +// fun toggleSortingMode_success_updateTrendingEmojiList() = runTest { +// // given +// // for simplicity of testing, we return the same list for both cases +// val sampleFetchedEmojiList = createDeterministicTrendingEmojiList(10) +// coEvery { +// emojiUseCase.fetchEmojiList(1) +// } returns sampleFetchedEmojiList +// // when +// emojiViewModel.toggleSortingMode() +// advanceUntilIdle() +// // then +// coVerify(exactly = 1) { emojiUseCase.fetchEmojiList(1) } +// coVerify(exactly = 1) { emojiUseCase.updateEmojiList(any()) } +// assertEquals(1, emojiViewModel.sortByDate) +// } @Test fun fetchMyCreatedEmojiList_success_updateMyCreatedEmojiList() = runTest { From a31d78a61aeb95b953c5ef6f731ea9b8f2dbc665 Mon Sep 17 00:00:00 2001 From: Wooyeol Lee Date: Wed, 6 Dec 2023 14:30:27 +0900 Subject: [PATCH 3/3] fix: update fetchEmojiList test using sortByDate field --- .../emojihub/viewmodels/EmojiViewModelTest.kt | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/android/app/src/test/java/com/goliath/emojihub/viewmodels/EmojiViewModelTest.kt b/android/app/src/test/java/com/goliath/emojihub/viewmodels/EmojiViewModelTest.kt index b9e8cf0a..32291e01 100644 --- a/android/app/src/test/java/com/goliath/emojihub/viewmodels/EmojiViewModelTest.kt +++ b/android/app/src/test/java/com/goliath/emojihub/viewmodels/EmojiViewModelTest.kt @@ -58,22 +58,23 @@ class EmojiViewModelTest { coVerify(exactly = 1) { emojiUseCase.updateEmojiList(any()) } } -// @Test -// fun toggleSortingMode_success_updateTrendingEmojiList() = runTest { -// // given -// // for simplicity of testing, we return the same list for both cases -// val sampleFetchedEmojiList = createDeterministicTrendingEmojiList(10) -// coEvery { -// emojiUseCase.fetchEmojiList(1) -// } returns sampleFetchedEmojiList -// // when -// emojiViewModel.toggleSortingMode() -// advanceUntilIdle() -// // then -// coVerify(exactly = 1) { emojiUseCase.fetchEmojiList(1) } -// coVerify(exactly = 1) { emojiUseCase.updateEmojiList(any()) } -// assertEquals(1, emojiViewModel.sortByDate) -// } + @Test + fun toggleSortingMode_success_updateLatestEmojiList() = runTest { + // given + // for simplicity of testing, we return the same list for both cases + val sampleFetchedEmojiList = createDeterministicTrendingEmojiList(10) + coEvery { + emojiUseCase.fetchEmojiList(1) + } returns sampleFetchedEmojiList + // when + emojiViewModel.sortByDate = 1 + emojiViewModel.fetchEmojiList() + advanceUntilIdle() + // then + assertEquals(1, emojiViewModel.sortByDate) + coVerify(exactly = 1) { emojiUseCase.fetchEmojiList(1) } + coVerify(exactly = 1) { emojiUseCase.updateEmojiList(any()) } + } @Test fun fetchMyCreatedEmojiList_success_updateMyCreatedEmojiList() = runTest {