From 03d412a1e62551f2d415b90e08d31f2f4d7b93b6 Mon Sep 17 00:00:00 2001 From: 2018JunYoungLim Date: Wed, 15 Nov 2023 00:55:26 +0900 Subject: [PATCH 1/7] feat: fetch emoji list --- android/.idea/deploymentTargetDropDown.xml | 17 ----------------- .../repositories/remote/EmojiRepository.kt | 4 +++- .../goliath/emojihub/usecases/EmojiUseCase.kt | 18 +++++++++++++++++- 3 files changed, 20 insertions(+), 19 deletions(-) delete mode 100644 android/.idea/deploymentTargetDropDown.xml diff --git a/android/.idea/deploymentTargetDropDown.xml b/android/.idea/deploymentTargetDropDown.xml deleted file mode 100644 index bee3ed65..00000000 --- a/android/.idea/deploymentTargetDropDown.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/android/app/src/main/java/com/goliath/emojihub/repositories/remote/EmojiRepository.kt b/android/app/src/main/java/com/goliath/emojihub/repositories/remote/EmojiRepository.kt index c3cb3bff..cc32bdea 100644 --- a/android/app/src/main/java/com/goliath/emojihub/repositories/remote/EmojiRepository.kt +++ b/android/app/src/main/java/com/goliath/emojihub/repositories/remote/EmojiRepository.kt @@ -3,6 +3,7 @@ package com.goliath.emojihub.repositories.remote import android.util.Log import com.goliath.emojihub.data_sources.api.EmojiApi import com.goliath.emojihub.models.EmojiDto +import com.goliath.emojihub.models.FetchEmojiListDto import com.goliath.emojihub.models.UploadEmojiDto import com.google.gson.Gson import okhttp3.MediaType @@ -29,7 +30,8 @@ class EmojiRepositoryImpl @Inject constructor( private val emojiApi: EmojiApi ): EmojiRepository { override suspend fun fetchEmojiList(numLimit: Int): List { - TODO("Not yet implemented") + val fetchEmojiListDto = FetchEmojiListDto(1, 0, 10) + return emojiApi.fetchEmojiList(fetchEmojiListDto).body() ?: arrayListOf() } override suspend fun getEmojiWithId(id: String): EmojiDto? { diff --git a/android/app/src/main/java/com/goliath/emojihub/usecases/EmojiUseCase.kt b/android/app/src/main/java/com/goliath/emojihub/usecases/EmojiUseCase.kt index 0ff5faed..ea87bd4d 100644 --- a/android/app/src/main/java/com/goliath/emojihub/usecases/EmojiUseCase.kt +++ b/android/app/src/main/java/com/goliath/emojihub/usecases/EmojiUseCase.kt @@ -3,14 +3,21 @@ package com.goliath.emojihub.usecases import android.net.Uri import android.util.Log import com.goliath.emojihub.data_sources.ApiErrorController +import com.goliath.emojihub.models.Emoji +import com.goliath.emojihub.models.EmojiDto + import com.goliath.emojihub.models.UploadEmojiDto import com.goliath.emojihub.repositories.local.X3dRepository import com.goliath.emojihub.repositories.remote.EmojiRepository +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow import java.io.File import javax.inject.Inject import javax.inject.Singleton interface EmojiUseCase { + val emojiListState: StateFlow> suspend fun fetchEmojiList(numInt: Int) fun createEmoji(videoUri: Uri): Pair? @@ -25,8 +32,17 @@ class EmojiUseCaseImpl @Inject constructor( private val model: X3dRepository, private val errorController: ApiErrorController ): EmojiUseCase { + + private val _emojiListState = MutableStateFlow>(emptyList()) + override val emojiListState: StateFlow> + get() = _emojiListState override suspend fun fetchEmojiList(numInt: Int) { - repository.fetchEmojiList(numInt) + try{ + val emojiList = repository.fetchEmojiList(numInt) + _emojiListState.emit(emojiList) + } catch (e: Exception) { + errorController.setErrorState(-1) + } } override fun createEmoji(videoUri: Uri): Pair? { From 3bf407f18b403f05c7170d21babfd2f5fb8b5695 Mon Sep 17 00:00:00 2001 From: 2018JunYoungLim Date: Wed, 15 Nov 2023 01:48:14 +0900 Subject: [PATCH 2/7] feat: display emojis in emoji page --- .../goliath/emojihub/usecases/EmojiUseCase.kt | 3 ++- .../emojihub/viewmodels/EmojiViewModel.kt | 19 +++++++++++++++++++ .../emojihub/views/BottomNavigationBar.kt | 2 +- .../com/goliath/emojihub/views/EmojiPage.kt | 16 ++++++++++------ .../emojihub/views/components/EmojiCell.kt | 2 ++ 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/android/app/src/main/java/com/goliath/emojihub/usecases/EmojiUseCase.kt b/android/app/src/main/java/com/goliath/emojihub/usecases/EmojiUseCase.kt index ea87bd4d..b61ab3cd 100644 --- a/android/app/src/main/java/com/goliath/emojihub/usecases/EmojiUseCase.kt +++ b/android/app/src/main/java/com/goliath/emojihub/usecases/EmojiUseCase.kt @@ -35,7 +35,8 @@ class EmojiUseCaseImpl @Inject constructor( private val _emojiListState = MutableStateFlow>(emptyList()) override val emojiListState: StateFlow> - get() = _emojiListState + get() = _emojiListState.asStateFlow() + override suspend fun fetchEmojiList(numInt: Int) { try{ val emojiList = repository.fetchEmojiList(numInt) 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 9a9d5789..9a3081c1 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 @@ -5,9 +5,15 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope import com.goliath.emojihub.models.Emoji +import com.goliath.emojihub.models.EmojiDto import com.goliath.emojihub.usecases.EmojiUseCase import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.launch import java.io.File import javax.inject.Inject @@ -19,6 +25,19 @@ class EmojiViewModel @Inject constructor( var currentEmoji: Emoji? = null var isBottomSheetShown by mutableStateOf(false) + private val _emojiList = MutableStateFlow>(emptyList()) + val emojiList: StateFlow> = _emojiList.asStateFlow() + + fun fetchEmojiList(numInt: Int) + { + viewModelScope.launch { + emojiUseCase.fetchEmojiList(numInt) + + val emojis = emojiUseCase.emojiListState.value.map { dto -> Emoji(dto) } + _emojiList.emit(emojis) + } + } + fun createEmoji(videoUri: Uri): Pair? { val (emojiName, emojiUnicode) = emojiUseCase.createEmoji(videoUri)?: return null diff --git a/android/app/src/main/java/com/goliath/emojihub/views/BottomNavigationBar.kt b/android/app/src/main/java/com/goliath/emojihub/views/BottomNavigationBar.kt index 602bf6df..4d02e3e3 100644 --- a/android/app/src/main/java/com/goliath/emojihub/views/BottomNavigationBar.kt +++ b/android/app/src/main/java/com/goliath/emojihub/views/BottomNavigationBar.kt @@ -24,7 +24,7 @@ fun BottomNavigationBar( } composable(PageItem.Emoji.screenRoute) { - EmojiPage((1..10).map{ createDummyEmoji() }) + EmojiPage() } composable(PageItem.Profile.screenRoute) { 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 84235c83..a3605923 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 @@ -22,6 +22,7 @@ import androidx.compose.foundation.layout.height import androidx.compose.foundation.lazy.grid.items import androidx.compose.material.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.collectAsState import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp @@ -41,7 +42,7 @@ import com.goliath.emojihub.views.components.TopNavigationBar @Composable fun EmojiPage( - emojiList: List +// emojiList: List ) { val context = LocalContext.current val navController = LocalNavController.current @@ -62,6 +63,8 @@ fun EmojiPage( } } + val emojiList = viewModel.emojiList.collectAsState().value + Column(Modifier.background(White)) { TopNavigationBar("Emoji", shouldNavigate = false) { IconButton(onClick = { @@ -98,6 +101,7 @@ fun EmojiPage( horizontalArrangement = Arrangement.spacedBy(4.dp), verticalArrangement = Arrangement.spacedBy(4.dp), ) { + Log.d("asdf", "asdfasdf: $emojiList") items(emojiList, key = { it.id }) { emoji -> EmojiCell(emoji = emoji) { viewModel.currentEmoji = emoji @@ -109,8 +113,8 @@ fun EmojiPage( } } -@Preview -@Composable -fun EmojiPagePreview() { - EmojiPage(emojiList = (1..10).map { createDummyEmoji() }) -} \ No newline at end of file +//@Preview +//@Composable +//fun EmojiPagePreview() { +// EmojiPage(emojiList = (1..10).map { createDummyEmoji() }) +//} \ No newline at end of file diff --git a/android/app/src/main/java/com/goliath/emojihub/views/components/EmojiCell.kt b/android/app/src/main/java/com/goliath/emojihub/views/components/EmojiCell.kt index 0ef4078d..fece5219 100644 --- a/android/app/src/main/java/com/goliath/emojihub/views/components/EmojiCell.kt +++ b/android/app/src/main/java/com/goliath/emojihub/views/components/EmojiCell.kt @@ -1,5 +1,6 @@ package com.goliath.emojihub.views.components +import android.util.Log import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.runtime.Composable @@ -32,6 +33,7 @@ fun EmojiCell ( emoji: Emoji, onSelected: (Emoji) -> Unit ) { + Log.d("EmojiCell", "Emoji passed: ${emoji.id}") Card ( modifier = Modifier.fillMaxWidth().height(292.dp).clickable { onSelected(emoji) }, shape = RoundedCornerShape(4.dp), From d2b5fa0c45d25054ed73a21c0f391a4a5786f67d Mon Sep 17 00:00:00 2001 From: 2018JunYoungLim Date: Wed, 15 Nov 2023 03:08:22 +0900 Subject: [PATCH 3/7] fix: EmojiPage.kt --- .../src/main/java/com/goliath/emojihub/views/EmojiPage.kt | 6 ++++++ 1 file changed, 6 insertions(+) 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 a3605923..9f0216d9 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 @@ -22,6 +22,7 @@ import androidx.compose.foundation.layout.height import androidx.compose.foundation.lazy.grid.items import androidx.compose.material.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview @@ -63,6 +64,11 @@ fun EmojiPage( } } + LaunchedEffect(Unit) + { + viewModel.fetchEmojiList(10) + } + val emojiList = viewModel.emojiList.collectAsState().value Column(Modifier.background(White)) { From 7da622fb666d55d99682e89f224c88286a40bf45 Mon Sep 17 00:00:00 2001 From: 2018JunYoungLim Date: Thu, 16 Nov 2023 02:07:31 +0900 Subject: [PATCH 4/7] fix emoji API call, add log messages --- .../emojihub/data_sources/api/EmojiApi.kt | 4 +++- .../repositories/remote/EmojiRepository.kt | 17 +++++++++++++++-- .../goliath/emojihub/usecases/EmojiUseCase.kt | 1 + .../emojihub/viewmodels/EmojiViewModel.kt | 2 ++ .../com/goliath/emojihub/views/EmojiPage.kt | 1 - .../emojihub/views/components/EmojiCell.kt | 3 ++- 6 files changed, 23 insertions(+), 5 deletions(-) diff --git a/android/app/src/main/java/com/goliath/emojihub/data_sources/api/EmojiApi.kt b/android/app/src/main/java/com/goliath/emojihub/data_sources/api/EmojiApi.kt index b52741a7..5e411fb6 100644 --- a/android/app/src/main/java/com/goliath/emojihub/data_sources/api/EmojiApi.kt +++ b/android/app/src/main/java/com/goliath/emojihub/data_sources/api/EmojiApi.kt @@ -17,7 +17,9 @@ import retrofit2.http.Query interface EmojiApi { @GET("emoji") suspend fun fetchEmojiList( - @Body body: FetchEmojiListDto + @Query("sortByDate") sortByDate: Int, + @Query("index") index: Int, + @Query("count") count: Int ): Response> @GET("emoji") diff --git a/android/app/src/main/java/com/goliath/emojihub/repositories/remote/EmojiRepository.kt b/android/app/src/main/java/com/goliath/emojihub/repositories/remote/EmojiRepository.kt index cc32bdea..647d1e9b 100644 --- a/android/app/src/main/java/com/goliath/emojihub/repositories/remote/EmojiRepository.kt +++ b/android/app/src/main/java/com/goliath/emojihub/repositories/remote/EmojiRepository.kt @@ -30,8 +30,21 @@ class EmojiRepositoryImpl @Inject constructor( private val emojiApi: EmojiApi ): EmojiRepository { override suspend fun fetchEmojiList(numLimit: Int): List { - val fetchEmojiListDto = FetchEmojiListDto(1, 0, 10) - return emojiApi.fetchEmojiList(fetchEmojiListDto).body() ?: arrayListOf() +// val fetchEmojiListDto = FetchEmojiListDto(1, 0, 10) + try { + val response = emojiApi.fetchEmojiList(1, 1, 10) + + if(response.isSuccessful && response.body() != null) { + Log.d("Fetch_E_L", "Successfully fetched ${response.body()!!.size} emojis") + return response.body()!! + } else { + val errorBody = response.errorBody()?.string() ?: "Unknown error" + Log.d("Fetch_E_L", "Failed to fetch emojis: $errorBody") + } + } catch(e: Exception) { + Log.e("Fetch_E_L", "Error fetching emojis", e) + } + return listOf() } override suspend fun getEmojiWithId(id: String): EmojiDto? { diff --git a/android/app/src/main/java/com/goliath/emojihub/usecases/EmojiUseCase.kt b/android/app/src/main/java/com/goliath/emojihub/usecases/EmojiUseCase.kt index b61ab3cd..38ddb180 100644 --- a/android/app/src/main/java/com/goliath/emojihub/usecases/EmojiUseCase.kt +++ b/android/app/src/main/java/com/goliath/emojihub/usecases/EmojiUseCase.kt @@ -41,6 +41,7 @@ class EmojiUseCaseImpl @Inject constructor( try{ val emojiList = repository.fetchEmojiList(numInt) _emojiListState.emit(emojiList) + Log.d("Fetch_E_L", "USECASE DONE: $emojiList") } catch (e: Exception) { errorController.setErrorState(-1) } 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 9a3081c1..7371a235 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 @@ -1,6 +1,7 @@ package com.goliath.emojihub.viewmodels import android.net.Uri +import android.util.Log import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue @@ -35,6 +36,7 @@ class EmojiViewModel @Inject constructor( val emojis = emojiUseCase.emojiListState.value.map { dto -> Emoji(dto) } _emojiList.emit(emojis) + Log.d("Fetch_E_L", "VIEWMODEL DONE: $emojis") } } 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 9f0216d9..0c29ead0 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 @@ -107,7 +107,6 @@ fun EmojiPage( horizontalArrangement = Arrangement.spacedBy(4.dp), verticalArrangement = Arrangement.spacedBy(4.dp), ) { - Log.d("asdf", "asdfasdf: $emojiList") items(emojiList, key = { it.id }) { emoji -> EmojiCell(emoji = emoji) { viewModel.currentEmoji = emoji diff --git a/android/app/src/main/java/com/goliath/emojihub/views/components/EmojiCell.kt b/android/app/src/main/java/com/goliath/emojihub/views/components/EmojiCell.kt index fece5219..294541fe 100644 --- a/android/app/src/main/java/com/goliath/emojihub/views/components/EmojiCell.kt +++ b/android/app/src/main/java/com/goliath/emojihub/views/components/EmojiCell.kt @@ -33,7 +33,8 @@ fun EmojiCell ( emoji: Emoji, onSelected: (Emoji) -> Unit ) { - Log.d("EmojiCell", "Emoji passed: ${emoji.id}") + Log.d("Fetch_E_L", "Emoji passed: ${emoji.id}") + Log.d("Fetch_E_L", "unicode is: ${emoji.unicode}") Card ( modifier = Modifier.fillMaxWidth().height(292.dp).clickable { onSelected(emoji) }, shape = RoundedCornerShape(4.dp), From 24a9eb24342fdab98424a6cb297d96c39328ea81 Mon Sep 17 00:00:00 2001 From: 2018JunYoungLim Date: Thu, 16 Nov 2023 02:21:09 +0900 Subject: [PATCH 5/7] fix: toEmoji() to handle multiple unicode, add error handling with warning emoji --- .../java/com/goliath/emojihub/extensions/Extensions.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/java/com/goliath/emojihub/extensions/Extensions.kt b/android/app/src/main/java/com/goliath/emojihub/extensions/Extensions.kt index d2951074..d58b5360 100644 --- a/android/app/src/main/java/com/goliath/emojihub/extensions/Extensions.kt +++ b/android/app/src/main/java/com/goliath/emojihub/extensions/Extensions.kt @@ -1,5 +1,10 @@ package com.goliath.emojihub.extensions fun String.toEmoji(): String { - return String(Character.toChars(this.substring(2).toInt(16))) + return try { + this.trim().split(" ").map { it.removePrefix("U+").toInt(16) } + .joinToString("") { Character.toChars(it).joinToString("") } + } catch (e: Exception){ + "\u26A0\uFE0F" + } } \ No newline at end of file From 63f14f0305521a6f7d6626f564acd57e8ceebf87 Mon Sep 17 00:00:00 2001 From: 2018JunYoungLim Date: Thu, 16 Nov 2023 02:42:15 +0900 Subject: [PATCH 6/7] change emoji for exception --- .../src/main/java/com/goliath/emojihub/extensions/Extensions.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/app/src/main/java/com/goliath/emojihub/extensions/Extensions.kt b/android/app/src/main/java/com/goliath/emojihub/extensions/Extensions.kt index d58b5360..09c9c68f 100644 --- a/android/app/src/main/java/com/goliath/emojihub/extensions/Extensions.kt +++ b/android/app/src/main/java/com/goliath/emojihub/extensions/Extensions.kt @@ -5,6 +5,6 @@ fun String.toEmoji(): String { this.trim().split(" ").map { it.removePrefix("U+").toInt(16) } .joinToString("") { Character.toChars(it).joinToString("") } } catch (e: Exception){ - "\u26A0\uFE0F" + "\u2764\uFE0F" } } \ No newline at end of file From 81f574fc9b8dbe6a7067b6355a6ede8fbbaeff86 Mon Sep 17 00:00:00 2001 From: 2018JunYoungLim Date: Thu, 16 Nov 2023 06:43:22 +0900 Subject: [PATCH 7/7] fix createEmoji to return unicode --- .../com/goliath/emojihub/viewmodels/EmojiViewModel.kt | 10 +--------- .../com/goliath/emojihub/views/TransformVideoPage.kt | 3 ++- 2 files changed, 3 insertions(+), 10 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 7371a235..5a50b801 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 @@ -41,15 +41,7 @@ class EmojiViewModel @Inject constructor( } fun createEmoji(videoUri: Uri): Pair? { - val (emojiName, emojiUnicode) = emojiUseCase.createEmoji(videoUri)?: return null - - val emojiCharArray = emojiUnicode.replace("U+", "") - .split(" ").map { - val codePoint = it.toInt(16) - codePoint.toChar() - }.toCharArray() - val emoji = String(emojiCharArray) - return Pair(emojiName, emoji) + return emojiUseCase.createEmoji(videoUri) } suspend fun uploadEmoji(emojiUnicode: String, emojiLabel: String, videoFile: File): Boolean { diff --git a/android/app/src/main/java/com/goliath/emojihub/views/TransformVideoPage.kt b/android/app/src/main/java/com/goliath/emojihub/views/TransformVideoPage.kt index a76e3f43..d3acf835 100644 --- a/android/app/src/main/java/com/goliath/emojihub/views/TransformVideoPage.kt +++ b/android/app/src/main/java/com/goliath/emojihub/views/TransformVideoPage.kt @@ -33,6 +33,7 @@ import androidx.media3.common.Player import androidx.media3.exoplayer.ExoPlayer import androidx.media3.ui.PlayerView import com.goliath.emojihub.LocalNavController +import com.goliath.emojihub.extensions.toEmoji import com.goliath.emojihub.viewmodels.EmojiViewModel import com.goliath.emojihub.views.components.CustomDialog import kotlinx.coroutines.launch @@ -130,7 +131,7 @@ fun TransformVideoPage( horizontalAlignment = Alignment.CenterHorizontally ) { Text( - text = resultEmoji!!.second, + text = resultEmoji!!.second.toEmoji(), fontSize = 48.sp ) Text (