Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feat/back-emojiAPI2
Browse files Browse the repository at this point in the history
# Conflicts:
#	springboot/src/main/kotlin/com/goliath/emojihub/springboot/domain/emoji/service/EmojiService.kt
  • Loading branch information
yangchanhk98 committed Dec 7, 2023
2 parents 8526990 + 15c7e50 commit b5bfd55
Show file tree
Hide file tree
Showing 55 changed files with 1,743 additions and 538 deletions.
17 changes: 0 additions & 17 deletions android/.idea/deploymentTargetDropDown.xml

This file was deleted.

59 changes: 54 additions & 5 deletions android/app/src/main/java/com/goliath/emojihub/RootActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
Expand All @@ -32,8 +33,11 @@ import com.goliath.emojihub.views.LoginPage
import com.goliath.emojihub.views.MainPage
import com.goliath.emojihub.views.SignUpPage
import com.goliath.emojihub.views.TransformVideoPage
import com.goliath.emojihub.views.components.CreatedEmojiListView
import com.goliath.emojihub.views.components.CreatedPostListView
import com.goliath.emojihub.views.components.CustomDialog
import com.goliath.emojihub.views.components.PlayEmojiView
import com.goliath.emojihub.views.components.SavedEmojiListView
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

Expand All @@ -50,7 +54,10 @@ class RootActivity : ComponentActivity() {

setContent {
EmojiHubTheme {
Box(Modifier.fillMaxSize().background(Color.White)) {
Box(
Modifier
.fillMaxSize()
.background(Color.White)) {
val accessToken = userViewModel.accessTokenState.collectAsState().value
val error by apiErrorController.apiErrorState.collectAsState()

Expand Down Expand Up @@ -110,20 +117,62 @@ class RootActivity : ComponentActivity() {
}

composable(NavigationDestination.TransformVideo) {
val emojiViewModel = hiltViewModel<EmojiViewModel>()
val parentEntry = remember(it) {
navController.getBackStackEntry(NavigationDestination.MainPage)
}
val emojiViewModel = hiltViewModel<EmojiViewModel>(parentEntry)
TransformVideoPage(emojiViewModel)
}

composable(NavigationDestination.PlayEmojiVideo) {
val emojiViewModel = hiltViewModel<EmojiViewModel>()
PlayEmojiView(emojiViewModel)
val parentEntry = remember(it) {
navController.getBackStackEntry(NavigationDestination.MainPage)
}
val emojiViewModel = hiltViewModel<EmojiViewModel>(parentEntry)
val userViewModel = hiltViewModel<UserViewModel>(parentEntry)
PlayEmojiView(emojiViewModel, userViewModel)
}

composable(NavigationDestination.CreatePost) {
val postViewModel = hiltViewModel<PostViewModel>()
val parentEntry = remember(it) {
navController.getBackStackEntry(NavigationDestination.MainPage)
}
val postViewModel = hiltViewModel<PostViewModel>(parentEntry)
CreatePostPage(postViewModel)
}

composable(NavigationDestination.MyPostList) {
val parentEntry = remember(it) {
navController.getBackStackEntry(NavigationDestination.MainPage)
}
val postViewModel = hiltViewModel<PostViewModel>(parentEntry)
CreatedPostListView(postViewModel.myPostList)
}

composable(NavigationDestination.MyEmojiList) {
val parentEntry = remember(it) {
navController.getBackStackEntry(NavigationDestination.MainPage)
}
val emojiViewModel = hiltViewModel<EmojiViewModel>(parentEntry)
CreatedEmojiListView(emojiViewModel)
}

composable(NavigationDestination.MySavedEmojiList) {
val parentEntry = remember(it) {
navController.getBackStackEntry(NavigationDestination.MainPage)
}
val emojiViewModel = hiltViewModel<EmojiViewModel>(parentEntry)
SavedEmojiListView(emojiViewModel)
}
}
}
}
}

fun NavController.navigateAsOrigin(route: String) {
navigate(route) {
while (popBackStack()) { }
launchSingleTop = true
restoreState = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ enum class CustomError(
override fun body(): String = "이미 있는 계정입니다."
},
INTERNAL_SERVER_ERROR(500) {
override fun body(): String = "접속 오류가 발생했습니다."
override fun body(): String = "네트워크 접속 오류가 발생했습니다."
},;

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.goliath.emojihub.data_sources

import androidx.compose.runtime.MutableState
import androidx.compose.runtime.Stable
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import com.goliath.emojihub.views.PageItem

class BottomNavigationController {
private val _bottomNavigationDestination = mutableStateOf(PageItem.Feed.screenRoute)

@Stable
val currentDestination: MutableState<String> = _bottomNavigationDestination
val currentDestination: State<String> = _bottomNavigationDestination

fun updateDestination(destination: PageItem) {
_bottomNavigationDestination.value = destination.screenRoute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.goliath.emojihub.data_sources

import com.goliath.emojihub.data_sources.local.X3dDataSource
import com.goliath.emojihub.data_sources.local.X3dDataSourceImpl
import com.goliath.emojihub.data_sources.remote.EmojiDataSource
import com.goliath.emojihub.data_sources.remote.EmojiDataSourceImpl
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
Expand All @@ -13,6 +15,9 @@ abstract class DataSourceModule {
@Binds
abstract fun bindsX3dDataSource(impl: X3dDataSourceImpl): X3dDataSource

@Binds
abstract fun bindsEmojiDataSource(impl: EmojiDataSourceImpl): EmojiDataSource

@Binds
abstract fun bindsApiErrorController(impl: ApiErrorControllerImpl): ApiErrorController
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ enum class EmojiFetchType {

class EmojiPagingSource @Inject constructor(
private val api: EmojiApi,
private val sortByDate : Int,
private val type: EmojiFetchType
): PagingSource<Int, EmojiDto>() {
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, EmojiDto> {
Expand All @@ -20,20 +21,21 @@ class EmojiPagingSource @Inject constructor(
return try {
val response: List<EmojiDto>? = when (type) {
EmojiFetchType.GENERAL -> {
api.fetchEmojiList(1, cursor, count).body()
api.fetchEmojiList(sortByDate, cursor, count).body()
}
EmojiFetchType.MY_CREATED -> {
api.fetchMyCreatedEmojiList(1, cursor, count).body()
api.fetchMyCreatedEmojiList(sortByDate, cursor, count).body()
}
EmojiFetchType.MY_SAVED -> {
api.fetchMySavedEmojiList(1, cursor, count).body()
api.fetchMySavedEmojiList(sortByDate, cursor, count).body()
}
}
val data = response ?: listOf()
val nextKey = if (response?.size!! < count) null else cursor + 1 //Stops infinite fetching
LoadResult.Page(
data = data,
prevKey = if (cursor == 1) null else cursor - 1,
nextKey = if (data.isEmpty()) null else cursor + 1
nextKey = nextKey
)
} catch (exception: Exception) {
LoadResult.Error(exception)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.goliath.emojihub.data_sources
import com.goliath.emojihub.EmojiHubApplication
import com.goliath.emojihub.data_sources.api.EmojiApi
import com.goliath.emojihub.data_sources.api.PostApi
import com.goliath.emojihub.data_sources.api.ReactionApi
import com.goliath.emojihub.data_sources.api.UserApi
import dagger.Module
import dagger.Provides
Expand Down Expand Up @@ -59,6 +60,11 @@ object NetworkModule {
fun providesPostRestApi(retrofit: Retrofit): PostApi =
retrofit.create(PostApi::class.java)

@Provides
@Singleton
fun providesReactionRestApi(retrofit: Retrofit): ReactionApi =
retrofit.create(ReactionApi::class.java)

// empty responses should be handled `success`
private val nullOnEmptyConverterFactory = object : Converter.Factory() {
fun converterFactory() = this
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.goliath.emojihub.data_sources

import androidx.paging.PagingSource
import androidx.paging.PagingState
import com.goliath.emojihub.data_sources.api.ReactionApi
import com.goliath.emojihub.models.ReactionWithEmojiDto
import javax.inject.Inject

class ReactionPagingSource @Inject constructor(
private val api: ReactionApi,
private val postId: String,
private val emojiUnicode: String
): PagingSource<Int, ReactionWithEmojiDto>(){
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, ReactionWithEmojiDto> {
val cursor = params.key ?: 1
val count = params.loadSize
return try {
val response: List<ReactionWithEmojiDto>? = api.fetchReactionList(postId, emojiUnicode, cursor, count).body()
val data = response ?: listOf()
val nextKey = if (response?.size!! < count) null else cursor + 1 //Stops infinite fetching
LoadResult.Page(
data = data,
prevKey = if (cursor == 1) null else cursor - 1,
nextKey = nextKey
)
} catch (exception: Exception) {
LoadResult.Error(exception)
}
}

override fun getRefreshKey(state: PagingState<Int, ReactionWithEmojiDto>): Int? {
return state.anchorPosition?.let { anchorPosition ->
state.closestPageToPosition(anchorPosition)?.prevKey?.plus(1)
?: state.closestPageToPosition(anchorPosition)?.nextKey?.minus(1)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import javax.inject.Singleton

interface LocalStorage {
var accessToken: String?
val currentUser: String?
var currentUser: String?
}

@Singleton
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.goliath.emojihub.data_sources.api

import com.goliath.emojihub.models.ReactionWithEmojiDto
import retrofit2.Response
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Path
import retrofit2.http.Query

interface ReactionApi {
@POST("reaction")
suspend fun uploadReaction(
@Query("postId") postId: String,
@Query("emojiId") emojiId: String
): Response<Unit>

@GET("reaction")
suspend fun fetchReactionList(
@Query("postId") postId: String,
@Query("emojiUnicode") emojiUnicode: String,
@Query("index") index: Int,
@Query("count") count: Int
): Response<List<ReactionWithEmojiDto>>

@GET("reaction")
suspend fun getReactionWithId(
@Path("id") id: String
): Response<Unit>

@DELETE("reaction")
suspend fun deleteReaction(
@Query("reactionId") reactionId: String
): Response<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.goliath.emojihub.data_sources.api

import com.goliath.emojihub.models.LoginUserDto
import com.goliath.emojihub.models.RegisterUserDto
import com.goliath.emojihub.models.UserDtoList
import com.goliath.emojihub.models.UserDetailsDto
import com.goliath.emojihub.models.responses.LoginResponseDto
import retrofit2.Response
import retrofit2.http.Body
Expand All @@ -15,7 +15,12 @@ interface UserApi {
@GET("user")
suspend fun fetchUserList(

): Response<Array<UserDtoList>>
): Response<Array<UserDetailsDto>>

@GET("user/me")
suspend fun fetchMyInfo(
@Header("Authorization") authToken: String
): Response<UserDetailsDto>

@POST("user/signup")
suspend fun registerUser(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.goliath.emojihub.data_sources.remote

import android.content.Context
import android.graphics.Bitmap
import android.media.MediaMetadataRetriever
import android.util.Log
import dagger.hilt.android.qualifiers.ApplicationContext
import java.io.File
import java.io.FileOutputStream
import javax.inject.Inject

interface EmojiDataSource {
fun createVideoThumbNail(videoFile: File): File?
}
class EmojiDataSourceImpl @Inject constructor(
@ApplicationContext private val context: Context
): EmojiDataSource {

override fun createVideoThumbNail(videoFile: File): File? {
val retriever = MediaMetadataRetriever()
try {
retriever.setDataSource(videoFile.absolutePath)
val bitmap = retriever.frameAtTime

bitmap?.let {
val thumbnailFile = File(context.cacheDir, "thumbnail_${videoFile.name}.jpg")
FileOutputStream(thumbnailFile).use { out ->
bitmap.compress(Bitmap.CompressFormat.JPEG, 75, out)
}
Log.d("EmojiDataSource", "Thumbnail created: ${thumbnailFile.absolutePath}")
return thumbnailFile
}
} catch (e: Exception) {
Log.e("EmojiDataSource", "ERROR creating thumbnail: ${e.message?:"Unknown error"}")
} finally {
retriever.release()
}
return null
}
}
Loading

0 comments on commit b5bfd55

Please sign in to comment.