Skip to content

Commit 68b8bcf

Browse files
authored
Merge #50 -> develop
[Mod/#50] walk review 부분 completion 부분 수정
2 parents 4b7efed + 885e987 commit 68b8bcf

37 files changed

+660
-302
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.paw.key.core.util
2+
3+
import android.content.Context
4+
import androidx.datastore.preferences.core.edit
5+
import androidx.datastore.preferences.core.floatPreferencesKey
6+
import androidx.datastore.preferences.core.intPreferencesKey
7+
import androidx.datastore.preferences.core.longPreferencesKey
8+
import androidx.datastore.preferences.core.stringPreferencesKey
9+
import androidx.datastore.preferences.preferencesDataStore
10+
import com.kakao.vectormap.LatLng
11+
import kotlinx.coroutines.flow.Flow
12+
import kotlinx.coroutines.flow.map
13+
14+
private val Context.summaryStore by preferencesDataStore(name = "summaryStore_pref")
15+
16+
private val POINTS_KEY = stringPreferencesKey("points")
17+
private val TOTAL_DISTANCE_KEY = floatPreferencesKey("total_distance")
18+
private val TOTAL_TIME_KEY = longPreferencesKey("total_time")
19+
private val TOTAL_STEPS_KEY = intPreferencesKey("total_steps")
20+
21+
private fun List<LatLng>.toPreferenceString(): String =
22+
joinToString(";") { "${it.latitude},${it.longitude}" }
23+
24+
private fun String.toLatLngList(): List<LatLng> =
25+
split(";").mapNotNull {
26+
val parts = it.split(",")
27+
if (parts.size == 2) {
28+
LatLng.from(parts[0].toDoubleOrNull() ?: return@mapNotNull null, parts[1].toDoubleOrNull() ?: return@mapNotNull null)
29+
}
30+
else null
31+
}
32+
33+
object PreferenceDataStore {
34+
suspend fun saveWalkSummary(
35+
context: Context,
36+
points: List<LatLng>,
37+
totalDistance: Float,
38+
totalTime: Long,
39+
totalSteps: Int,
40+
) {
41+
context.summaryStore.edit { preferences ->
42+
preferences[POINTS_KEY] = points.toPreferenceString()
43+
preferences[TOTAL_DISTANCE_KEY] = totalDistance
44+
preferences[TOTAL_TIME_KEY] = totalTime
45+
preferences[TOTAL_STEPS_KEY] = totalSteps
46+
}
47+
}
48+
49+
fun getPoints(context: Context): Flow<List<LatLng>> {
50+
return context.summaryStore.data.map { preferences ->
51+
preferences[POINTS_KEY]?.toLatLngList() ?: emptyList()
52+
}
53+
}
54+
55+
fun getTotalDistance(context: Context): Flow<Float> {
56+
return context.summaryStore.data.map { preferences ->
57+
preferences[TOTAL_DISTANCE_KEY] ?: 0f
58+
}
59+
}
60+
61+
fun getTotalTime(context: Context): Flow<Long> {
62+
return context.summaryStore.data.map { preferences ->
63+
preferences[TOTAL_TIME_KEY] ?: 0L
64+
}
65+
}
66+
67+
fun getTotalSteps(context: Context): Flow<Int> {
68+
return context.summaryStore.data.map { preferences ->
69+
preferences[TOTAL_STEPS_KEY] ?: 0
70+
}
71+
}
72+
73+
suspend fun clearWalkSummary(context: Context) {
74+
context.summaryStore.edit { preferences ->
75+
preferences.clear() // 모든 데이터 삭제
76+
}
77+
}
78+
}
Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
package com.paw.key.data.di
22

3-
import android.content.Context
4-
import androidx.datastore.core.DataStore
5-
import androidx.datastore.preferences.core.Preferences
6-
import androidx.datastore.preferences.preferencesDataStore
73
import com.paw.key.BuildConfig
84
import dagger.Module
95
import dagger.Provides
106
import dagger.hilt.InstallIn
11-
import dagger.hilt.android.qualifiers.ApplicationContext
127
import dagger.hilt.components.SingletonComponent
138
import javax.inject.Named
14-
import javax.inject.Singleton
15-
16-
val Context.bitmapDataStore: DataStore<Preferences> by preferencesDataStore(name = "captured_bitmap_prefs")
179

1810
@Module
1911
@InstallIn(SingletonComponent::class)
@@ -24,10 +16,4 @@ object AppModule {
2416
fun provideKakaoNativeKey(): String {
2517
return BuildConfig.KAKAO_NATIVE_KEY
2618
}
27-
28-
@Singleton
29-
@Provides
30-
fun provideBitmapDataStore(@ApplicationContext context: Context): DataStore<Preferences> {
31-
return context.bitmapDataStore
32-
}
3319
}
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package com.paw.key.data.di
22

3-
import com.paw.key.data.repositoryimpl.BitmapRepositoryImpl
43
import com.paw.key.data.repositoryimpl.DummyRepositoryImpl
5-
import com.paw.key.domain.repository.BitmapRepository
4+
import com.paw.key.data.repositoryimpl.WalkSharedResultRepositoryImpl
65
import com.paw.key.domain.repository.DummyRepository
6+
import com.paw.key.domain.repository.WalkSharedResultRepository
77
import dagger.Binds
88
import dagger.Module
99
import dagger.hilt.InstallIn
1010
import dagger.hilt.components.SingletonComponent
11+
import javax.inject.Singleton
1112

1213
@Module
1314
@InstallIn(SingletonComponent::class)
@@ -19,8 +20,9 @@ interface RepositoryModule {
1920
): DummyRepository
2021

2122
@Binds
22-
fun bindsBitmapRepository(
23-
bitmapRepositoryImpl: BitmapRepositoryImpl
24-
): BitmapRepository
23+
@Singleton
24+
fun bindsSharedWalkResultRepository(
25+
walkSharedResultRepositoryImpl: WalkSharedResultRepositoryImpl
26+
): WalkSharedResultRepository
2527

2628
}

app/src/main/java/com/paw/key/data/repositoryimpl/BitmapRepositoryImpl.kt

Lines changed: 0 additions & 59 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.paw.key.data.repositoryimpl
2+
3+
import android.graphics.Bitmap
4+
import android.util.Log
5+
import com.kakao.vectormap.LatLng
6+
import com.paw.key.domain.model.entity.sharedresult.WalkResult
7+
import com.paw.key.domain.repository.WalkSharedResultRepository
8+
import kotlinx.coroutines.flow.Flow
9+
import kotlinx.coroutines.flow.MutableSharedFlow
10+
import kotlinx.coroutines.flow.MutableStateFlow
11+
import kotlinx.coroutines.flow.StateFlow
12+
import kotlinx.coroutines.flow.asStateFlow
13+
import javax.inject.Inject
14+
import javax.inject.Singleton
15+
16+
@Singleton
17+
class WalkSharedResultRepositoryImpl @Inject constructor(
18+
) : WalkSharedResultRepository {
19+
private val _walkResult = MutableStateFlow<WalkResult?>(null)
20+
21+
override suspend fun saveResult(
22+
bitmap: Bitmap?,
23+
totalTime: Long,
24+
distance: Float,
25+
steps: Int,
26+
points: List<LatLng>
27+
) {
28+
_walkResult.value = WalkResult(bitmap, totalTime, distance, steps, points)
29+
Log.d("WalkSharedResultRepositoryImpl", "Result saved: $bitmap")
30+
Log.d("WalkSharedResultRepositoryImpl", "Result saved: $totalTime")
31+
Log.d("WalkSharedResultRepositoryImpl", "Result saved: $distance")
32+
Log.d("WalkSharedResultRepositoryImpl", "Result saved: $steps")
33+
}
34+
35+
override fun getResult(): Flow<WalkResult?> = _walkResult.asStateFlow()
36+
37+
override fun clear() {
38+
_walkResult.value = null
39+
}
40+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.paw.key.domain.model.entity.sharedresult
2+
3+
import android.graphics.Bitmap
4+
import com.kakao.vectormap.LatLng
5+
6+
data class WalkResult(
7+
val bitmap: Bitmap?,
8+
val totalTime: Long,
9+
val distance: Float,
10+
val steps: Int,
11+
val points : List<LatLng>
12+
)

app/src/main/java/com/paw/key/domain/repository/BitmapRepository.kt

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.paw.key.domain.repository
2+
3+
import android.graphics.Bitmap
4+
import com.kakao.vectormap.LatLng
5+
import com.paw.key.domain.model.entity.sharedresult.WalkResult
6+
import kotlinx.coroutines.flow.Flow
7+
8+
interface WalkSharedResultRepository {
9+
suspend fun saveResult(bitmap: Bitmap?, totalTime: Long, distance: Float, steps: Int, points : List<LatLng>)
10+
fun getResult(): Flow<WalkResult?>
11+
fun clear()
12+
}

app/src/main/java/com/paw/key/presentation/animation/FootprintAnimationScreen.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ import androidx.compose.ui.unit.Dp
2222
import androidx.compose.ui.unit.dp
2323
import com.paw.key.R
2424
import com.paw.key.presentation.ui.main.state.MainContract
25+
import kotlinx.collections.immutable.PersistentList
2526
import kotlinx.coroutines.delay
2627
import kotlinx.coroutines.launch
2728

2829
@Composable
2930
fun FootprintAnimationScreen(
30-
footprints: List<MainContract.Footprint>,
31+
footprints: PersistentList<MainContract.Footprint>,
3132
onAnimationFinished: (MainContract.Footprint) -> Unit,
3233
modifier: Modifier = Modifier
3334
) {

app/src/main/java/com/paw/key/presentation/ui/course/entire/tab/map/TapMapScreen.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ fun TapMapRoute(
8787

8888
LaunchedEffect(isGranted) {
8989
if (isGranted) {
90-
Log.e("TapMapRoute", "isGranted: $isGranted")
9190
val currentLocation = getCurrentLocation(
9291
context,
9392
fusedLocationClient,
@@ -101,11 +100,7 @@ fun TapMapRoute(
101100
currentLocation = currentLocation
102101
)
103102
}
104-
}
105-
}
106103

107-
LaunchedEffect(isGranted) {
108-
if (isGranted) {
109104
val locationRequest = LocationRequest.Builder(Priority.PRIORITY_HIGH_ACCURACY, 1000) // 1초마다, 높은 정확도
110105
.setWaitForAccurateLocation(true)
111106
.build()
@@ -141,7 +136,7 @@ fun TapMapRoute(
141136
context = context,
142137
currentUserLocation = state.currentLocation,
143138
isTrackingEnabled = state.isTrackingEnabled,
144-
onDispose = {
139+
onDisposeCallback = {
145140
fusedLocationClient.removeLocationUpdates(locationCallback)
146141
}
147142
)

0 commit comments

Comments
 (0)