Skip to content

Commit 4a630e6

Browse files
committed
chore/#100: 카메라 조정 및 datastore context 세팅
1 parent f0d7356 commit 4a630e6

File tree

3 files changed

+97
-102
lines changed

3 files changed

+97
-102
lines changed

app/src/main/java/com/paw/key/core/util/PreferenceDataStore.kt

Lines changed: 72 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -38,135 +38,115 @@ private fun String.toLatLngList(): List<LatLng> =
3838
}
3939

4040
object PreferenceDataStore {
41+
42+
private lateinit var appContext: Context
43+
44+
fun init(context: Context) {
45+
appContext = context.applicationContext
46+
}
47+
48+
private val summaryStore
49+
get() = appContext.summaryStore
50+
51+
4152
suspend fun saveWalkSummary(
42-
context: Context,
4353
points: List<LatLng>,
4454
totalDistance: Float,
4555
totalTime: Long,
4656
totalSteps: Int,
4757
) {
48-
context.summaryStore.edit { preferences ->
58+
summaryStore.edit { preferences ->
4959
preferences[POINTS_KEY] = points.toPreferenceString()
5060
preferences[TOTAL_DISTANCE_KEY] = totalDistance
5161
preferences[TOTAL_TIME_KEY] = totalTime
5262
preferences[TOTAL_STEPS_KEY] = totalSteps
5363
}
5464
}
5565

56-
fun getPoints(context: Context): Flow<List<LatLng>> {
57-
return context.summaryStore.data.map { preferences ->
58-
preferences[POINTS_KEY]?.toLatLngList() ?: emptyList()
59-
}
66+
fun getPoints(): Flow<List<LatLng>> = summaryStore.data.map {
67+
it[POINTS_KEY]?.toLatLngList() ?: emptyList()
6068
}
6169

62-
fun getTotalDistance(context: Context): Flow<Float> {
63-
return context.summaryStore.data.map { preferences ->
64-
preferences[TOTAL_DISTANCE_KEY] ?: 0f
65-
}
70+
fun getTotalDistance(): Flow<Float> = summaryStore.data.map {
71+
it[TOTAL_DISTANCE_KEY] ?: 0f
6672
}
6773

68-
fun getTotalTime(context: Context): Flow<Long> {
69-
return context.summaryStore.data.map { preferences ->
70-
preferences[TOTAL_TIME_KEY] ?: 0L
71-
}
74+
fun getTotalTime(): Flow<Long> = summaryStore.data.map {
75+
it[TOTAL_TIME_KEY] ?: 0L
7276
}
7377

74-
fun getTotalSteps(context: Context): Flow<Int> {
75-
return context.summaryStore.data.map { preferences ->
76-
preferences[TOTAL_STEPS_KEY] ?: 0
77-
}
78+
fun getTotalSteps(): Flow<Int> = summaryStore.data.map {
79+
it[TOTAL_STEPS_KEY] ?: 0
7880
}
7981

80-
suspend fun clearWalkSummary(context: Context) {
81-
context.summaryStore.edit { preferences ->
82-
preferences.remove(POINTS_KEY)
83-
preferences.remove(TOTAL_DISTANCE_KEY)
84-
preferences.remove(TOTAL_TIME_KEY)
85-
preferences.remove(TOTAL_STEPS_KEY)
82+
suspend fun clearWalkSummary() {
83+
summaryStore.edit {
84+
it.remove(POINTS_KEY)
85+
it.remove(TOTAL_DISTANCE_KEY)
86+
it.remove(TOTAL_TIME_KEY)
87+
it.remove(TOTAL_STEPS_KEY)
8688
}
8789
}
8890

89-
suspend fun saveLoginInfo(
90-
context: Context,
91-
email: String,
92-
password: String
93-
) {
94-
context.summaryStore.edit { preferences ->
95-
preferences[LOGIN_EMAIL_KEY] = email
96-
preferences[LOGIN_PASSWORD_KEY] = password
91+
suspend fun saveLoginInfo(email: String, password: String) {
92+
summaryStore.edit {
93+
it[LOGIN_EMAIL_KEY] = email
94+
it[LOGIN_PASSWORD_KEY] = password
9795
}
9896
}
9997

100-
fun getLoginEmail(context: Context): Flow<String> {
101-
return context.summaryStore.data.map { preferences ->
102-
preferences[LOGIN_EMAIL_KEY] ?: ""
103-
}
98+
fun getLoginEmail(): Flow<String> = summaryStore.data.map {
99+
it[LOGIN_EMAIL_KEY] ?: ""
104100
}
105101

106-
fun getLoginPassword(context: Context): Flow<String> {
107-
return context.summaryStore.data.map { preferences ->
108-
preferences[LOGIN_PASSWORD_KEY] ?: ""
109-
}
102+
fun getLoginPassword(): Flow<String> = summaryStore.data.map {
103+
it[LOGIN_PASSWORD_KEY] ?: ""
110104
}
111105

112-
data class LoginInfo(
113-
val email: String,
114-
val password: String
115-
)
106+
data class LoginInfo(val email: String, val password: String)
116107

117-
fun getLoginInfo(context: Context): Flow<LoginInfo> {
118-
return context.summaryStore.data.map { preferences ->
119-
LoginInfo(
120-
email = preferences[LOGIN_EMAIL_KEY] ?: "",
121-
password = preferences[LOGIN_PASSWORD_KEY] ?: ""
122-
)
123-
}
108+
fun getLoginInfo(): Flow<LoginInfo> = summaryStore.data.map {
109+
LoginInfo(
110+
email = it[LOGIN_EMAIL_KEY] ?: "",
111+
password = it[LOGIN_PASSWORD_KEY] ?: ""
112+
)
124113
}
125114

126-
suspend fun clearLoginInfo(context: Context) {
127-
context.summaryStore.edit { preferences ->
128-
preferences.remove(LOGIN_EMAIL_KEY)
129-
preferences.remove(LOGIN_PASSWORD_KEY)
115+
suspend fun clearLoginInfo() {
116+
summaryStore.edit {
117+
it.remove(LOGIN_EMAIL_KEY)
118+
it.remove(LOGIN_PASSWORD_KEY)
130119
}
131120
}
132121

133122
suspend fun saveUserInfo(
134-
context: Context,
135123
userId: Int,
136124
userName: String,
137125
petId: Int,
138126
petName: String
139127
) {
140-
context.summaryStore.edit { preferences ->
141-
preferences[USER_ID_KEY] = userId
142-
preferences[USER_NAME_KEY] = userName
143-
preferences[PET_ID_KEY] = petId
144-
preferences[PET_NAME_KEY] = petName
128+
summaryStore.edit {
129+
it[USER_ID_KEY] = userId
130+
it[USER_NAME_KEY] = userName
131+
it[PET_ID_KEY] = petId
132+
it[PET_NAME_KEY] = petName
145133
}
146134
}
147135

148-
fun getUserId(context: Context): Flow<Int> {
149-
return context.summaryStore.data.map { preferences ->
150-
preferences[USER_ID_KEY] ?: 0
151-
}
136+
fun getUserId(): Flow<Int> = summaryStore.data.map {
137+
it[USER_ID_KEY] ?: 0
152138
}
153139

154-
fun getUserName(context: Context): Flow<String> {
155-
return context.summaryStore.data.map { preferences ->
156-
preferences[USER_NAME_KEY] ?: ""
157-
}
140+
fun getUserName(): Flow<String> = summaryStore.data.map {
141+
it[USER_NAME_KEY] ?: ""
158142
}
159143

160-
fun getPetId(context: Context): Flow<Int> {
161-
return context.summaryStore.data.map { preferences ->
162-
preferences[PET_ID_KEY] ?: 0
163-
}
144+
fun getPetId(): Flow<Int> = summaryStore.data.map {
145+
it[PET_ID_KEY] ?: 0
164146
}
165147

166-
fun getPetName(context: Context): Flow<String> {
167-
return context.summaryStore.data.map { preferences ->
168-
preferences[PET_NAME_KEY] ?: ""
169-
}
148+
fun getPetName(): Flow<String> = summaryStore.data.map {
149+
it[PET_NAME_KEY] ?: ""
170150
}
171151

172152
data class UserInfo(
@@ -176,29 +156,25 @@ object PreferenceDataStore {
176156
val petName: String
177157
)
178158

179-
fun getUserInfo(context: Context): Flow<UserInfo> {
180-
return context.summaryStore.data.map { preferences ->
181-
UserInfo(
182-
userId = preferences[USER_ID_KEY] ?: 0,
183-
userName = preferences[USER_NAME_KEY] ?: "",
184-
petId = preferences[PET_ID_KEY] ?: 0,
185-
petName = preferences[PET_NAME_KEY] ?: ""
186-
)
187-
}
159+
fun getUserInfo(): Flow<UserInfo> = summaryStore.data.map {
160+
UserInfo(
161+
userId = it[USER_ID_KEY] ?: 0,
162+
userName = it[USER_NAME_KEY] ?: "",
163+
petId = it[PET_ID_KEY] ?: 0,
164+
petName = it[PET_NAME_KEY] ?: ""
165+
)
188166
}
189167

190-
suspend fun clearUserInfo(context: Context) {
191-
context.summaryStore.edit { preferences ->
192-
preferences.remove(USER_ID_KEY)
193-
preferences.remove(USER_NAME_KEY)
194-
preferences.remove(PET_ID_KEY)
195-
preferences.remove(PET_NAME_KEY)
168+
suspend fun clearUserInfo() {
169+
summaryStore.edit {
170+
it.remove(USER_ID_KEY)
171+
it.remove(USER_NAME_KEY)
172+
it.remove(PET_ID_KEY)
173+
it.remove(PET_NAME_KEY)
196174
}
197175
}
198176

199-
suspend fun clearAllData(context: Context) {
200-
context.summaryStore.edit { preferences ->
201-
preferences.clear()
202-
}
177+
suspend fun clearAllData() {
178+
summaryStore.edit { it.clear() }
203179
}
204180
}

app/src/main/java/com/paw/key/presentation/ui/course/sharedwalk/sharedroute/component/sharedCourseMapView.kt

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import com.kakao.vectormap.camera.CameraUpdateFactory
2525
import com.kakao.vectormap.label.Label
2626
import com.kakao.vectormap.label.LabelOptions
2727
import com.kakao.vectormap.label.LabelStyle
28+
import com.kakao.vectormap.label.TrackingManager
2829
import com.kakao.vectormap.route.RouteLine
2930
import com.kakao.vectormap.route.RouteLineOptions
3031
import com.kakao.vectormap.route.RouteLineSegment
@@ -63,6 +64,10 @@ fun sharedWalkCourseMapView(
6364
// ------------------------------------------------
6465
// 트래킹
6566

67+
var trackingManager by remember {
68+
mutableStateOf<TrackingManager?>(null)
69+
}
70+
6671
var dimScreenLayer by remember {
6772
mutableStateOf<DimScreenLayer?>(null)
6873
}
@@ -159,6 +164,7 @@ fun sharedWalkCourseMapView(
159164
object : KakaoMapReadyCallback() {
160165
override fun onMapReady(kakaoMap: KakaoMap) {
161166
kakaoMapState = kakaoMap
167+
trackingManager = kakaoMap.trackingManager
162168
dimScreenLayer = kakaoMap.dimScreenManager?.dimScreenLayer
163169

164170
centerLabel = kakaoMap.labelManager?.layer?.addLabel(
@@ -193,10 +199,21 @@ fun sharedWalkCourseMapView(
193199

194200
override fun onResume(owner: LifecycleOwner) {
195201
mapView.resume()
202+
203+
kakaoMapState?.moveCamera(
204+
CameraUpdateFactory.newCenterPosition(
205+
currentUserLocation, 19
206+
)
207+
)
196208
}
197209

198210
override fun onPause(owner: LifecycleOwner) {
199211
mapView.pause()
212+
kakaoMapState?.moveCamera(
213+
CameraUpdateFactory.fitMapPoints(
214+
poiPoints.toTypedArray(), 150, 15
215+
)
216+
)
200217
}
201218
}
202219

@@ -213,21 +230,21 @@ fun sharedWalkCourseMapView(
213230
LaunchedEffect(currentUserLocation, isTrackingEnabled, centerLabel, kakaoMapState) {
214231
if (currentUserLocation != null && centerLabel != null && kakaoMapState != null) {
215232
centerLabel?.moveTo(currentUserLocation)
216-
217-
kakaoMapState?.moveCamera(
218-
CameraUpdateFactory.newCenterPosition(
219-
currentUserLocation, 18
220-
)
221-
)
222233
}
223234
}
224235

236+
LaunchedEffect(Unit) {
237+
trackingManager?.startTracking(centerLabel)
238+
}
239+
225240
LaunchedEffect(isPauseTracking) {
226241
if (!isPauseTracking) {
242+
trackingManager?.stopTracking()
227243
mapView.isClickable = false
228244
dimScreenLayer?.setColor(Color.Black.copy(alpha = 0.5f).toArgb())
229245
dimScreenLayer?.setVisible(true)
230246
} else {
247+
trackingManager?.stopTracking()
231248
mapView.isClickable = true
232249
dimScreenLayer?.setVisible(false)
233250
}

app/src/main/java/com/paw/key/presentation/ui/main/MainActivity.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import androidx.activity.enableEdgeToEdge
88
import androidx.annotation.RequiresApi
99
import androidx.core.view.WindowCompat
1010
import com.paw.key.core.designsystem.theme.PawKeyTheme
11+
import com.paw.key.core.util.PreferenceDataStore
1112
import dagger.hilt.android.AndroidEntryPoint
1213

1314
@AndroidEntryPoint
@@ -16,6 +17,7 @@ class MainActivity : ComponentActivity() {
1617
override fun onCreate(savedInstanceState: Bundle?) {
1718
super.onCreate(savedInstanceState)
1819
enableEdgeToEdge()
20+
PreferenceDataStore.init(this)
1921

2022
WindowCompat.getInsetsController(window, window.decorView).apply {
2123
isAppearanceLightStatusBars = true

0 commit comments

Comments
 (0)