Skip to content

Commit

Permalink
Merge pull request #225 from SWM-KAWAI-MANS/PAR-381
Browse files Browse the repository at this point in the history
#PAR-381 : 싱글 모드 단일 조회 API 연동 + Shimmer Effect 적용
  • Loading branch information
nohjunh authored Oct 11, 2023
2 parents 8a299ed + 1c2386b commit a41725c
Show file tree
Hide file tree
Showing 18 changed files with 362 additions and 109 deletions.
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

0 comments on commit a41725c

Please sign in to comment.