From 679f0ead4556bf10d67acba918e181da8d45ca1c Mon Sep 17 00:00:00 2001 From: Wooyeol Lee Date: Sun, 10 Dec 2023 22:58:42 +0900 Subject: [PATCH 1/2] fix: show error dialog on network error fix: change class labels --- .../zero_shot_classname_to_unicode.json | 20 ++-- .../zero_shot_classname_to_unicode_100.json | 102 ++++++++++++++++++ .../data_sources/ApiErrorController.kt | 5 +- .../repositories/remote/ClipRepository.kt | 7 +- 4 files changed, 122 insertions(+), 12 deletions(-) create mode 100644 android/app/src/main/assets/zero_shot_classname_to_unicode_100.json diff --git a/android/app/src/main/assets/zero_shot_classname_to_unicode.json b/android/app/src/main/assets/zero_shot_classname_to_unicode.json index e0c53145..6c8d40bf 100644 --- a/android/app/src/main/assets/zero_shot_classname_to_unicode.json +++ b/android/app/src/main/assets/zero_shot_classname_to_unicode.json @@ -1,12 +1,12 @@ { - "call": "U+1F919", - "dislike": "U+1F645", - "fist": "U+1F44A", - "like": "U+1F44D", - "mute": "U+1F92B", - "ok": "U+1F646", - "palm": "U+1F64B", - "peace": "U+270C", - "rock": "U+1F918", - "stop": "U+270B" + "clapping hands": "U+1F44F", + "I love it": "U+2764 U+FE0F", + "selfie": "U+1F933", + "punch": "U+1F44A", + "I see you": "U+1F440", + "no": "U+1F645", + "so hot": "U+1F525", + "cool": "U+1F60E", + "angry": "U+1F620", + "praying hands": "U+1F64F" } \ No newline at end of file diff --git a/android/app/src/main/assets/zero_shot_classname_to_unicode_100.json b/android/app/src/main/assets/zero_shot_classname_to_unicode_100.json new file mode 100644 index 00000000..a5b6ee03 --- /dev/null +++ b/android/app/src/main/assets/zero_shot_classname_to_unicode_100.json @@ -0,0 +1,102 @@ +{ + "call": "U+1F919", + "dislike": "U+1F645", + "fist": "U+1F44A", + "like": "U+1F44D", + "mute": "U+1F92B", + "ok": "U+1F646", + "palm": "U+1F64B", + "peace": "U+270C", + "rock": "U+1F918", + "stop": "U+270B", + "clapping hands": "U+1F44F", + "thumbs up": "U+1F44D", + "thumbs down": "U+1F44E", + "waving hand": "U+1F44B", + "raised hand": "U+270B", + "victory hand": "U+270C", + "crossed fingers": "U+1F91E", + "love-you gesture": "U+1F91F", + "sign of the horns": "U+1F918", + "call me hand": "U+1F919", + "flexed biceps": "U+1F4AA", + "folded hands": "U+1F64F", + "handshake": "U+1F91D", + "writing hand": "U+270D", + "selfie": "U+1F933", + "mouth": "U+1F444", + "nose": "U+1F443", + "ear": "U+1F442", + "foot": "U+1F9B6", + "leg": "U+1F9B5", + "mechanical arm": "U+1F9BE", + "mechanical leg": "U+1F9BF", + "pointing up": "U+261D", + "pointing down": "U+1F447", + "pointing left": "U+1F448", + "pointing right": "U+1F449", + "raised fist": "U+270A", + "oncoming fist": "U+1F44A", + "left-facing fist": "U+1F91B", + "right-facing fist": "U+1F91C", + "raising hands": "U+1F64C", + "open hands": "U+1F450", + "palms up together": "U+1F932", + "hand with fingers splayed": "U+1F590", + "vulcan salute": "U+1F596", + "praying hands": "U+1F64F", + "eyes": "U+1F440", + "speaking head": "U+1F5E3", + "boy": "U+1F466", + "girl": "U+1F467", + "man": "U+1F468", + "woman": "U+1F469", + "person frowning": "U+1F64D", + "person pouting": "U+1F64E", + "person gesturing no": "U+1F645", + "person gesturing ok": "U+1F646", + "person tipping hand": "U+1F481", + "person raising hand": "U+1F64B", + "person bowing": "U+1F647", + "person facepalming": "U+1F926", + "person shrugging": "U+1F937", + "weight lifter": "U+1F3CB", + "wrestlers": "U+1F93C", + "handball": "U+1F93E", + "juggling": "U+1F939", + "smile": "U+1F642", + "heart": "U+2764", + "clap": "U+1F44F", + "star": "U+2B50", + "fire": "U+1F525", + "laugh": "U+1F602", + "wink": "U+1F609", + "sad": "U+1F641", + "angry": "U+1F620", + "wow": "U+1F62E", + "cool": "U+1F60E", + "kiss": "U+1F618", + "hug": "U+1F917", + "thinking": "U+1F914", + "scream": "U+1F631", + "rolling eyes": "U+1F644", + "sleep": "U+1F634", + "sweat": "U+1F613", + "nerd": "U+1F913", + "money-mouth": "U+1F911", + "sick": "U+1F912", + "dizzy": "U+1F635", + "party": "U+1F973", + "cat": "U+1F431", + "dog": "U+1F436", + "sun": "U+2600", + "moon": "U+1F319", + "cloud": "U+2601", + "rain": "U+1F327", + "snow": "U+1F328", + "lightning": "U+1F329", + "tornado": "U+1F32A", + "wind": "U+1F32C", + "fog": "U+1F32B", + "rainbow": "U+1F308" +} \ No newline at end of file diff --git a/android/app/src/main/java/com/goliath/emojihub/data_sources/ApiErrorController.kt b/android/app/src/main/java/com/goliath/emojihub/data_sources/ApiErrorController.kt index 69f5a820..d2b29a75 100644 --- a/android/app/src/main/java/com/goliath/emojihub/data_sources/ApiErrorController.kt +++ b/android/app/src/main/java/com/goliath/emojihub/data_sources/ApiErrorController.kt @@ -52,7 +52,10 @@ enum class CustomError( }, INTERNAL_SERVER_ERROR(500) { override fun body(): String = "네트워크 접속 오류가 발생했습니다." - },; + }, + NETWORK_IS_BUSY(503) { + override fun body(): String = "네트워크가 혼잡합니다.\n잠시 후 다시 시도해주세요." + }; companion object { fun getBy(statusCode: Int) = values().firstOrNull { it.statusCode == statusCode } diff --git a/android/app/src/main/java/com/goliath/emojihub/repositories/remote/ClipRepository.kt b/android/app/src/main/java/com/goliath/emojihub/repositories/remote/ClipRepository.kt index 75c19b95..fdcd4a69 100644 --- a/android/app/src/main/java/com/goliath/emojihub/repositories/remote/ClipRepository.kt +++ b/android/app/src/main/java/com/goliath/emojihub/repositories/remote/ClipRepository.kt @@ -2,6 +2,8 @@ package com.goliath.emojihub.repositories.remote import android.net.Uri import android.util.Log +import com.goliath.emojihub.data_sources.ApiErrorController +import com.goliath.emojihub.data_sources.CustomError import com.goliath.emojihub.data_sources.api.ClipApi import com.goliath.emojihub.data_sources.local.MediaDataSource import com.goliath.emojihub.models.ClipRequestDto @@ -18,7 +20,8 @@ interface ClipRepository { @Singleton class ClipRepositoryImpl @Inject constructor( private val clipApi: ClipApi, - private val mediaDataSource: MediaDataSource + private val mediaDataSource: MediaDataSource, + private val errorController: ApiErrorController ): ClipRepository { // FIXME: Default emojis should be topK different emojis -> use just 3 emojis for now override val DEFAULT_EMOJI_LIST = listOf( @@ -79,9 +82,11 @@ class ClipRepositoryImpl @Inject constructor( } } Log.e("ClipRepository", "Clip inference response is not successful") + errorController.setErrorState(CustomError.NETWORK_IS_BUSY.statusCode) return emptyList() } catch (e: Exception) { Log.e("ClipRepository", "Error running clip inference ${e.message}") + errorController.setErrorState(CustomError.NETWORK_IS_BUSY.statusCode) } return emptyList() } From c0c1b570c9ef72c564a5824fea5b261eff95d821 Mon Sep 17 00:00:00 2001 From: Wooyeol Lee Date: Sun, 10 Dec 2023 23:24:39 +0900 Subject: [PATCH 2/2] fix: clip repo test error --- .../emojihub/repositories/remote/ClipRepositoryImplTest.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/android/app/src/test/java/com/goliath/emojihub/repositories/remote/ClipRepositoryImplTest.kt b/android/app/src/test/java/com/goliath/emojihub/repositories/remote/ClipRepositoryImplTest.kt index 289f343c..bcf1f27a 100644 --- a/android/app/src/test/java/com/goliath/emojihub/repositories/remote/ClipRepositoryImplTest.kt +++ b/android/app/src/test/java/com/goliath/emojihub/repositories/remote/ClipRepositoryImplTest.kt @@ -3,6 +3,7 @@ package com.goliath.emojihub.repositories.remote import android.graphics.Bitmap import android.media.MediaMetadataRetriever import android.net.Uri +import com.goliath.emojihub.data_sources.ApiErrorController import com.goliath.emojihub.data_sources.api.ClipApi import com.goliath.emojihub.data_sources.local.MediaDataSource import com.goliath.emojihub.mockLogClass @@ -12,6 +13,7 @@ import io.mockk.coEvery import io.mockk.coVerify import io.mockk.every import io.mockk.mockk +import io.mockk.spyk import io.mockk.verify import kotlinx.coroutines.runBlocking import org.json.JSONObject @@ -27,7 +29,8 @@ import retrofit2.Response class ClipRepositoryImplTest { private val clipApi = mockk() private val mediaDataSource = mockk() - private val clipRepositoryImpl = ClipRepositoryImpl(clipApi, mediaDataSource) + private val errorController = spyk() + private val clipRepositoryImpl = ClipRepositoryImpl(clipApi, mediaDataSource, errorController) private val fakeJSONMap = hashMapOf( "like" to "U+1F44D",