Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix network exception uat upload emoji #122

Merged
merged 3 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions android/app/src/main/java/com/goliath/emojihub/models/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class UserDetails(
) {
val name: String = dto.name
val email: String = dto.email
val savedEmojiList: List<String>? = dto.savedEmojiList
val createdEmojiList: List<String>? = dto.createdEmojiList
val createdPostList: List<String>? = dto.createdPostList
val savedEmojiList: List<String> = dto.savedEmojiList
val createdEmojiList: List<String> = dto.createdEmojiList
val createdPostList: List<String> = dto.createdPostList

override fun equals(other: Any?): Boolean {
if (this === other) return true
Expand All @@ -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
}
}
Expand All @@ -57,13 +55,13 @@ data class UserDetailsDto(
val password: String,

@SerializedName("saved_emojis")
val savedEmojiList: List<String>?,
val savedEmojiList: List<String>,

@SerializedName("created_emojis")
val createdEmojiList: List<String>?,
val createdEmojiList: List<String>,

@SerializedName("created_posts")
val createdPostList: List<String>?
val createdPostList: List<String>
)

class RegisterUserDto(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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")
}
}
Expand All @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -211,7 +209,7 @@ fun TransformVideoPage(
fontSize = 60.sp
)
}
if(currentEmojiIndex < 2) {
if(currentEmojiIndex < createdEmojiList.size - 1) {
IconButton(onClick = {
currentEmojiIndex = (currentEmojiIndex + 1) % createdEmojiList.size
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}