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

#PAR-381 : 싱글 모드 단일 조회 API 연동 + Shimmer Effect 적용 #225

Merged
merged 21 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
84a128f
feat : ResultRepository Single 기록 조회 추가 #PAR-381
nohjunh Oct 10, 2023
36f975c
feat : GetSingleHistoryUseCase 추가 #PAR-381
nohjunh Oct 10, 2023
b8ef1f9
feat : 싱글 기록 조회 data class 정의 #PAR-381
nohjunh Oct 10, 2023
f39bff5
feat : 싱글 기록 조회 ApiService 추가 #PAR-381
nohjunh Oct 10, 2023
1717e4c
feat : ResultDataSource 싱글 기록 조회 추가 #PAR-381
nohjunh Oct 10, 2023
e75de97
feat : ShimmerEffect 블랙테마 분기 추가 #PAR-381
nohjunh Oct 10, 2023
8840dd7
refactor : ShimmerEffect 코드 리팩토링 #PAR-381
nohjunh Oct 10, 2023
1cd0c38
refactor : RunningHistory Composable을 빼고 기존 mockData를 RunningHistoryD…
nohjunh Oct 10, 2023
0a06bd6
feat : ShimmerRunningHistory 컴포저블 추가 #PAR-381
nohjunh Oct 10, 2023
32dbd1d
feat : StatusElement 파라미터 theme 적용 #PAR-381
nohjunh Oct 10, 2023
f1dcb45
feat : RunningHistoryState 추가 및 SingleHistory 처리 #PAR-381
nohjunh Oct 10, 2023
a33663d
feat : 싱글 기록 조회 API MyPageViewModel 연동 #PAR-381
nohjunh Oct 10, 2023
d9662cb
feat : MyPageScreen 싱글 기록 조회 결과 반영 #PAR-381
nohjunh Oct 10, 2023
bab2ad8
refactor : 의도를 명확하게 하기 위한 컴포저블 네이밍 변경 #PAR-381
nohjunh Oct 10, 2023
dfb326d
refactor : 테스트를 위해 넣은 delay 제거 #PAR-381
nohjunh Oct 10, 2023
c7fd9be
feat : MyPage에서 SingleResult Navigation 추가 #PAR-381
nohjunh Oct 11, 2023
1a48b35
feat : MyPage에서 기록 조회 수행 시 ModeType 분기를 위한 enum 정의 #PAR-381
nohjunh Oct 11, 2023
268a522
feat : MyPage에서 싱글 기록 조회 수행 #PAR-381
nohjunh Oct 11, 2023
99c909a
refactor : Rename this parameter to match the regular expression #PAR…
nohjunh Oct 11, 2023
f8320d5
refactor : 임시 Battle block of code #PAR-381
nohjunh Oct 11, 2023
1c2386b
refactor : Rename this parameter to match the regular expression #PAR…
nohjunh Oct 11, 2023
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 @@ -109,6 +109,13 @@ fun SetUpMainNavGraph(
navigateToProfile = {
navController.navigate(MainNavRoutes.Profile.route)
},
navigateToSingleResult = {
navController.navigate(MainNavRoutes.SingleResult.route) {
popUpTo(MainNavRoutes.MyPage.route) {
inclusive = false
}
}
},
onShowSnackbar = onShowSnackbar
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import kotlinx.coroutines.flow.Flow
import online.partyrun.partyrunapplication.core.model.running_result.battle.BattleResult
import online.partyrun.partyrunapplication.core.common.result.Result
import online.partyrun.partyrunapplication.core.model.my_page.ComprehensiveRunRecord
import online.partyrun.partyrunapplication.core.model.my_page.SingleRunningHistory
import online.partyrun.partyrunapplication.core.model.running_result.single.SingleResult

interface ResultRepository {
suspend fun getBattleResults(): Flow<Result<BattleResult>>
suspend fun getSingleResults(): Flow<Result<SingleResult>>
suspend fun getComprehensiveRunRecord(): Flow<Result<ComprehensiveRunRecord>>
suspend fun getSingleHistory(): Flow<Result<SingleRunningHistory>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import online.partyrun.partyrunapplication.core.common.result.Result
import online.partyrun.partyrunapplication.core.common.result.mapResultModel
import online.partyrun.partyrunapplication.core.datastore.datasource.SinglePreferencesDataSource
import online.partyrun.partyrunapplication.core.model.my_page.ComprehensiveRunRecord
import online.partyrun.partyrunapplication.core.model.my_page.SingleRunningHistory
import online.partyrun.partyrunapplication.core.model.running_result.single.SingleResult
import javax.inject.Inject

Expand Down Expand Up @@ -40,4 +41,10 @@ class ResultRepositoryImpl @Inject constructor(
}.mapResultModel { it.toDomainModel() }
}

override suspend fun getSingleHistory(): Flow<Result<SingleRunningHistory>> {
return apiRequestFlow {
resultDataSource.getSingleHistory()
}.mapResultModel { it.toDomainModel() }
}

}
Original file line number Diff line number Diff line change
@@ -1,50 +1,41 @@
package online.partyrun.partyrunapplication.core.designsystem.component

import androidx.compose.animation.core.animateFloat
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.rememberInfiniteTransition
import androidx.compose.animation.core.tween
import androidx.compose.animation.core.*
import androidx.compose.foundation.background
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.unit.IntSize
import online.partyrun.partyrunapplication.core.designsystem.theme.Purple50
import online.partyrun.partyrunapplication.core.designsystem.theme.Purple60
import online.partyrun.partyrunapplication.core.designsystem.theme.*

private const val shimmerAnimationDuration = 1000
private const val SHIMMER_ANIMATION_DURATION = 1000

fun Modifier.shimmerEffect(): Modifier = composed {
var size by remember {
mutableStateOf(IntSize.Zero)
}
private val DarkThemeColors = listOf(Gray20, Gray10, Gray20)
private val PartyRunThemeColors = listOf(Purple60, Purple50, Purple60)

fun Modifier.shimmerEffect(isDarkTheme: Boolean): Modifier = composed {
val colors = if (isDarkTheme) DarkThemeColors else PartyRunThemeColors

var size by remember { mutableStateOf(IntSize.Zero) }
val transition = rememberInfiniteTransition()
val startOffsetX by transition.animateFloat(
initialValue = -2 * size.width.toFloat(),
targetValue = 2 * size.width.toFloat(),
animationSpec = infiniteRepeatable(
animation = tween(shimmerAnimationDuration)
animation = tween(SHIMMER_ANIMATION_DURATION)
)
)

background(
brush = Brush.linearGradient(
colors = listOf(
Purple60,
Purple50,
Purple60,
),
colors = colors,
start = Offset(startOffsetX, 0f),
end = Offset(startOffsetX + size.width.toFloat(), size.height.toFloat())
)
)
.onGloballyPositioned {
size = it.size
}
}
).onGloballyPositioned {
size = it.size
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package online.partyrun.partyrunapplication.core.domain.my_page

import online.partyrun.partyrunapplication.core.data.repository.ResultRepository
import javax.inject.Inject

class GetSingleHistoryUseCase @Inject constructor(
private val resultRepository: ResultRepository
) {
suspend operator fun invoke() = resultRepository.getSingleHistory()

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package online.partyrun.partyrunapplication.core.model.my_page

data class RunningHistoryDetail(
val id: String,
val date: String,
val runningTime: String,
val distanceFormatted: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package online.partyrun.partyrunapplication.core.model.my_page

data class SingleRunningHistory(
val history: List<RunningHistoryDetail>
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ fun NavGraphBuilder.myPageRoute(
navigateToSettings: () -> Unit,
navigateToMyPage: () -> Unit,
navigateToProfile: () -> Unit,
navigateToSingleResult: () -> Unit,
onShowSnackbar: (String) -> Unit
) {
composable(route = MainNavRoutes.MyPage.route) {
MyPageScreen(
navigateToSettings = navigateToSettings,
navigateToProfile = navigateToProfile,
navigateToSingleResult = navigateToSingleResult,
onShowSnackbar = onShowSnackbar
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package online.partyrun.partyrunapplication.core.network.datasource
import online.partyrun.partyrunapplication.core.common.network.ApiResponse
import online.partyrun.partyrunapplication.core.network.model.response.BattleResultResponse
import online.partyrun.partyrunapplication.core.network.model.response.ComprehensiveRunRecordResponse
import online.partyrun.partyrunapplication.core.network.model.response.SingleHistoryResponse
import online.partyrun.partyrunapplication.core.network.model.response.SingleResultResponse

interface ResultDataSource {
suspend fun getBattleResults(battleId: String): ApiResponse<BattleResultResponse>
suspend fun getSingleResults(singleId: String): ApiResponse<SingleResultResponse>
suspend fun getComprehensiveRunRecord(): ApiResponse<ComprehensiveRunRecordResponse>
suspend fun getSingleHistory(): ApiResponse<SingleHistoryResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package online.partyrun.partyrunapplication.core.network.datasource
import online.partyrun.partyrunapplication.core.common.network.ApiResponse
import online.partyrun.partyrunapplication.core.network.model.response.BattleResultResponse
import online.partyrun.partyrunapplication.core.network.model.response.ComprehensiveRunRecordResponse
import online.partyrun.partyrunapplication.core.network.model.response.SingleHistoryResponse
import online.partyrun.partyrunapplication.core.network.model.response.SingleResultResponse
import online.partyrun.partyrunapplication.core.network.service.ResultApiService
import javax.inject.Inject
Expand All @@ -19,4 +20,7 @@ class ResultDataSourceImpl @Inject constructor(
override suspend fun getComprehensiveRunRecord(): ApiResponse<ComprehensiveRunRecordResponse> =
resultApi.getComprehensiveRunRecord()

override suspend fun getSingleHistory(): ApiResponse<SingleHistoryResponse> =
resultApi.getSingleHistory()

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package online.partyrun.partyrunapplication.core.network.model.response

import com.google.gson.annotations.SerializedName
import online.partyrun.partyrunapplication.core.model.my_page.RunningHistoryDetail
import online.partyrun.partyrunapplication.core.model.running.RunningTime
import online.partyrun.partyrunapplication.core.model.running.toElapsedTimeString
import online.partyrun.partyrunapplication.core.model.util.DateTimeUtils
import online.partyrun.partyrunapplication.core.network.model.util.formatDate
import online.partyrun.partyrunapplication.core.network.model.util.formatDistanceWithComma
import java.time.LocalDateTime

data class SingleHistoryDetailResponse(
@SerializedName("id")
val id: String?,
@SerializedName("startTime")
val startTime: String?,
@SerializedName("runningTime")
val runningTime: RunningTime?,
@SerializedName("distance")
val distance: Double?
)

fun SingleHistoryDetailResponse.toDomainModel(): RunningHistoryDetail {
val parsedDate = startTime?.let {
LocalDateTime.parse(
it,
DateTimeUtils.localDateTimeFormatter
)
}

return RunningHistoryDetail(
id = this.id ?: "",
date = parsedDate?.let { formatDate(it) } ?: "",
runningTime = this.runningTime?.toElapsedTimeString() ?: "00:00:00",
distanceFormatted = formatDistanceWithComma(this.distance?.toInt() ?: 0)
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package online.partyrun.partyrunapplication.core.network.model.response

import com.google.gson.annotations.SerializedName
import online.partyrun.partyrunapplication.core.model.my_page.SingleRunningHistory

data class SingleHistoryResponse(
@SerializedName("history")
val history: List<SingleHistoryDetailResponse>?
)

fun SingleHistoryResponse.toDomainModel(): SingleRunningHistory {
val transformedHistory = history?.map { it.toDomainModel() }?.reversed() ?: emptyList()
return SingleRunningHistory(history = transformedHistory)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package online.partyrun.partyrunapplication.core.network.service
import online.partyrun.partyrunapplication.core.common.network.ApiResponse
import online.partyrun.partyrunapplication.core.network.model.response.BattleResultResponse
import online.partyrun.partyrunapplication.core.network.model.response.ComprehensiveRunRecordResponse
import online.partyrun.partyrunapplication.core.network.model.response.SingleHistoryResponse
import online.partyrun.partyrunapplication.core.network.model.response.SingleResultResponse
import retrofit2.http.GET
import retrofit2.http.Path
Expand All @@ -21,4 +22,8 @@ interface ResultApiService {

@GET("/api/mypage/total")
suspend fun getComprehensiveRunRecord(): ApiResponse<ComprehensiveRunRecordResponse>

@GET("/api/mypage/singles")
suspend fun getSingleHistory(): ApiResponse<SingleHistoryResponse>

}
Loading