Skip to content

Commit

Permalink
fix : 대결에 참여한 러너 중 빈 기록이 있는 경우 별도 처리
Browse files Browse the repository at this point in the history
1. RunningRecordCalculation에서 각 계산함수에 records의 empty 여부 판단
2. empty인 경우 스크린 다르게 처리
  • Loading branch information
nohjunh committed Oct 16, 2023
1 parent 8d9ff9a commit ad0b4d8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ fun calculateAverageAltitude(runnerStatus: RunnerStatus): Double {
}

fun calculateCumulativePacePerMinute(records: List<RunnerRecord>): List<Pair<String, Double>> {
if (records.isEmpty()) return emptyList()

val startTime = records.first().time
return records.drop(1).mapNotNull { record ->
val timeElapsed = Duration.between(startTime, record.time)
Expand All @@ -74,17 +76,19 @@ fun calculateCumulativePacePerMinute(records: List<RunnerRecord>): List<Pair<Str
}

fun calculateDistanceOverTime(records: List<RunnerRecord>): List<Pair<String, Double>> {
val startTime = records.first().time
if (records.isEmpty()) return emptyList()

val startTime = records.first().time
return records.map { record ->
val timeElapsed = Duration.between(startTime, record.time)
Pair(formatDurationToTimeString(timeElapsed), record.distance)
}
}

fun calculateAltitudeOverTime(records: List<RunnerRecord>): List<Pair<String, Double>> {
val startTime = records.first().time
if (records.isEmpty()) return emptyList()

val startTime = records.first().time
return records.map { record ->
val timeElapsed = Duration.between(startTime, record.time)
Pair(formatDurationToTimeString(timeElapsed), record.altitude.roundToInt().toDouble())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import online.partyrun.partyrunapplication.core.model.running_result.ui.BattleRe
import online.partyrun.partyrunapplication.core.model.running_result.ui.RunnerStatusUiModel
import online.partyrun.partyrunapplication.feature.running_result.R
import online.partyrun.partyrunapplication.feature.running_result.component.ChartScreen
import online.partyrun.partyrunapplication.feature.running_result.component.EmptyMapWidget
import online.partyrun.partyrunapplication.feature.running_result.component.FixedBottomNavigationSheet
import online.partyrun.partyrunapplication.feature.running_result.component.ResultLoadFailedBody
import online.partyrun.partyrunapplication.feature.running_result.component.MapWidget
Expand Down Expand Up @@ -133,11 +134,15 @@ private fun BattleResultBody(
.fillMaxWidth()
.heightIn(400.dp) // 지도의 높이는 400dp
) {
MapWidget(
isFromMyPage = isFromMyPage,
targetDistanceFormatted = battleResult.targetDistanceFormatted,
records = selectedRunner?.records
)
if (selectedRunner?.records.isNullOrEmpty()) {
EmptyMapWidget()
} else {
MapWidget(
isFromMyPage = isFromMyPage,
targetDistanceFormatted = battleResult.targetDistanceFormatted,
records = selectedRunner?.records
)
}
}

// 프레임 컴포넌트
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package online.partyrun.partyrunapplication.feature.running_result.component

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
Expand All @@ -14,6 +17,7 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
Expand All @@ -22,6 +26,7 @@ import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.asAndroidBitmap
import androidx.compose.ui.res.imageResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.google.android.gms.maps.model.BitmapDescriptor
import com.google.android.gms.maps.model.BitmapDescriptorFactory
Expand All @@ -37,6 +42,7 @@ import com.google.maps.android.compose.Marker
import com.google.maps.android.compose.MarkerState
import com.google.maps.android.compose.Polyline
import com.google.maps.android.compose.rememberCameraPositionState
import online.partyrun.partyrunapplication.core.designsystem.component.LottieImage
import online.partyrun.partyrunapplication.core.designsystem.icon.PartyRunIcons
import online.partyrun.partyrunapplication.core.model.running_result.ui.RunnerRecordUiModel
import online.partyrun.partyrunapplication.feature.running_result.R
Expand Down Expand Up @@ -187,3 +193,29 @@ private fun DistanceBox(targetDistance: String) {
)
}
}

@Composable
fun EmptyMapWidget() {
Column(
modifier = Modifier
.fillMaxSize()
.background(color = MaterialTheme.colorScheme.onPrimary),
verticalArrangement = Arrangement.Top,
horizontalAlignment = Alignment.CenterHorizontally
) {
LottieImage(
modifier = Modifier
.size(250.dp)
.padding(top = 70.dp),
rawAnimation = R.raw.no_records
)
}
Box(
modifier = Modifier
.padding(10.dp)
.clip(RoundedCornerShape(15.dp))
.background(color = MaterialTheme.colorScheme.primary)
) {
DistanceBox(stringResource(id = R.string.empty_records))
}
}

0 comments on commit ad0b4d8

Please sign in to comment.