diff --git a/android/app/src/main/java/com/goliath/emojihub/models/User.kt b/android/app/src/main/java/com/goliath/emojihub/models/User.kt index 3253a32d..1d638bcf 100644 --- a/android/app/src/main/java/com/goliath/emojihub/models/User.kt +++ b/android/app/src/main/java/com/goliath/emojihub/models/User.kt @@ -17,9 +17,9 @@ class UserDetails( ) { val name: String = dto.name val email: String = dto.email - val savedEmojiList: List? = dto.savedEmojiList - val createdEmojiList: List? = dto.createdEmojiList - val createdPostList: List? = dto.createdPostList + val savedEmojiList: List = dto.savedEmojiList + val createdEmojiList: List = dto.createdEmojiList + val createdPostList: List = dto.createdPostList override fun equals(other: Any?): Boolean { if (this === other) return true @@ -31,17 +31,15 @@ class UserDetails( if (email != other.email) return false if (savedEmojiList != other.savedEmojiList) return false if (createdEmojiList != other.createdEmojiList) return false - if (createdPostList != other.createdPostList) return false - - return true + return createdPostList == other.createdPostList } override fun hashCode(): Int { var result = name.hashCode() result = 31 * result + email.hashCode() - result = 31 * result + (savedEmojiList?.hashCode() ?: 0) - result = 31 * result + (createdEmojiList?.hashCode() ?: 0) - result = 31 * result + (createdPostList?.hashCode() ?: 0) + result = 31 * result + savedEmojiList.hashCode() + result = 31 * result + createdEmojiList.hashCode() + result = 31 * result + createdPostList.hashCode() return result } } @@ -57,13 +55,13 @@ data class UserDetailsDto( val password: String, @SerializedName("saved_emojis") - val savedEmojiList: List?, + val savedEmojiList: List, @SerializedName("created_emojis") - val createdEmojiList: List?, + val createdEmojiList: List, @SerializedName("created_posts") - val createdPostList: List? + val createdPostList: List ) class RegisterUserDto( 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 4a3b1446..a8cc54cb 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 @@ -124,12 +124,12 @@ class EmojiUseCaseImpl @Inject constructor( errorController.setErrorState(response.code()) false } - } catch (e: IOException) { - Log.e("EmojiUseCase", "IOException") - false } catch (e: ConnectException) { errorController.setErrorState(CustomError.INTERNAL_SERVER_ERROR.statusCode) false + } catch (e: IOException) { + Log.e("EmojiUseCase", "IOException") + false } catch (e: Exception) { Log.e("EmojiUseCase", "Unknown Exception on uploadEmoji: ${e.message}") false 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 8263f562..343ed340 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 @@ -13,15 +13,12 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size -import androidx.compose.foundation.layout.width import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material.Button import androidx.compose.material.Icon import androidx.compose.material.IconButton import androidx.compose.material.Scaffold import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ArrowBack -import androidx.compose.material.icons.filled.ArrowForward import androidx.compose.material.icons.filled.NavigateBefore import androidx.compose.material.icons.filled.NavigateNext import androidx.compose.material3.CenterAlignedTopAppBar @@ -31,6 +28,7 @@ import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.setValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember @@ -59,17 +57,17 @@ import java.io.File @OptIn(ExperimentalMaterial3Api::class) @Composable fun TransformVideoPage( - viewModel: EmojiViewModel, + emojiViewModel: EmojiViewModel, ) { val context = LocalContext.current val navController = LocalNavController.current val coroutineScope = rememberCoroutineScope() var showSuccessDialog by remember { mutableStateOf(false) } - var currentEmojiIndex by remember { mutableStateOf(0) } + var currentEmojiIndex by remember { mutableIntStateOf(0) } val exoPlayer = remember { ExoPlayer.Builder(context).build().apply { - setMediaItem(MediaItem.fromUri(viewModel.videoUri)) + setMediaItem(MediaItem.fromUri(emojiViewModel.videoUri)) repeatMode = Player.REPEAT_MODE_ALL prepare() } @@ -103,7 +101,7 @@ fun TransformVideoPage( onClick = { if (createdEmojiList.isEmpty()) { coroutineScope.launch { - createdEmojiList = viewModel.createEmoji(viewModel.videoUri) + createdEmojiList = emojiViewModel.createEmoji(emojiViewModel.videoUri) Log.d("TransformVideoPage", "createdEmojis: $createdEmojiList") } } @@ -112,7 +110,7 @@ fun TransformVideoPage( // Query to get the actual file path val projection = arrayOf(MediaStore.Images.Media.DATA) val cursor = context.contentResolver.query( - viewModel.videoUri, projection, null, null, null + emojiViewModel.videoUri, projection, null, null, null ) cursor?.use { @@ -125,7 +123,7 @@ fun TransformVideoPage( Log.d("TransformVideoPage", "videoPath: $realPath") coroutineScope.launch { // FIXME: add choose emoji dialog from topK emojis - val success = viewModel.uploadEmoji( + val success = emojiViewModel.uploadEmoji( createdEmojiList[currentEmojiIndex].emojiUnicode, createdEmojiList[currentEmojiIndex].emojiClassName, videoFile @@ -211,7 +209,7 @@ fun TransformVideoPage( fontSize = 60.sp ) } - if(currentEmojiIndex < 2) { + if(currentEmojiIndex < createdEmojiList.size - 1) { IconButton(onClick = { currentEmojiIndex = (currentEmojiIndex + 1) % createdEmojiList.size }, diff --git a/android/app/src/main/java/com/goliath/emojihub/views/components/PlayEmojiView.kt b/android/app/src/main/java/com/goliath/emojihub/views/components/PlayEmojiView.kt index d0a46eda..0503acd9 100644 --- a/android/app/src/main/java/com/goliath/emojihub/views/components/PlayEmojiView.kt +++ b/android/app/src/main/java/com/goliath/emojihub/views/components/PlayEmojiView.kt @@ -242,13 +242,10 @@ fun checkEmojiHasSaved(currentUserDetails: UserDetails?, currentEmoji: Emoji): B if (currentUserDetails == null) return false Log.d("checkEmojiHasSaved", "currentUserDetails.savedEmojiList: ${currentUserDetails.savedEmojiList}") Log.d("checkEmojiHasSaved", "currentEmoji.id: ${currentEmoji.id}") - if (currentUserDetails.savedEmojiList?.contains(currentEmoji.id) == true) - return true - return false + return currentUserDetails.savedEmojiList.contains(currentEmoji.id) } fun checkEmojiHasCreated(currentUser: User?, currentEmoji: Emoji): Boolean { if (currentUser == null) return false - if (currentUser.name == currentEmoji.createdBy) return true - return false + return currentUser.name == currentEmoji.createdBy } \ No newline at end of file