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 2 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
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) == true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기 == true는 빼도 되지 않을까요?

Copy link
Contributor Author

@thisisWooyeol thisisWooyeol Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peng-u-0807 savedEmojiList 자체가 null일 수 있어서 == true 를 추가해주었습니다!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thisisWooyeol 안 그래도 제가 바로 앞 pr(#121 )에서 savedEmojiList를 빈 리스트로 초기화해서 아마 back에서 받을 때 아예 null이지는 않을 겁니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yangchanhk98 그럼 savedEmojiList, createdEmojiList, createdPostList 전부 non-null 로 바꾸겠습니다!

}

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
}