Skip to content

Commit f0b5514

Browse files
committed
Add functionality to show steady location on map.
1 parent cd11194 commit f0b5514

File tree

3 files changed

+87
-34
lines changed

3 files changed

+87
-34
lines changed

app/src/main/java/com/canopas/yourspace/ui/flow/journey/components/JourneyMap.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,18 @@ fun JourneyMap(
9191
val boundsBuilder = LatLngBounds.builder()
9292
.apply {
9393
include(fromLatLang)
94-
include(toLatLang)
94+
if (location?.to_latitude != null && location.to_longitude != null) {
95+
include(toLatLang)
96+
}
9597
routePoints.forEach { latLng ->
9698
this.include(latLng)
9799
}
98100
}.build()
99101
val update = CameraUpdateFactory.newLatLngBounds(boundsBuilder, 50)
100102
cameraPositionState.move(update)
103+
if (location?.to_latitude == null && location?.to_longitude == null) {
104+
cameraPositionState.move(CameraUpdateFactory.newLatLngZoom(fromLatLang, 18f))
105+
}
101106
} catch (e: Exception) {
102107
e.printStackTrace()
103108
}
@@ -135,8 +140,9 @@ fun JourneyMap(
135140
) {
136141
location?.let {
137142
LocationMarker(fromLatLang, anchor, fromMarkerContent)
138-
139-
LocationMarker(toLatLang, anchor, toMarkerContent)
143+
if (location.to_latitude != null && location.to_longitude != null) {
144+
LocationMarker(toLatLang, anchor, toMarkerContent)
145+
}
140146

141147
Polyline(
142148
points = if (shouldAnimate) animatedPoints else routePoints,

app/src/main/java/com/canopas/yourspace/ui/flow/journey/components/LocationHistory.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import android.location.Address
55
import androidx.compose.foundation.Image
66
import androidx.compose.foundation.background
77
import androidx.compose.foundation.border
8+
import androidx.compose.foundation.clickable
89
import androidx.compose.foundation.layout.Arrangement
910
import androidx.compose.foundation.layout.Box
1011
import androidx.compose.foundation.layout.Column
@@ -72,7 +73,7 @@ fun LocationHistoryItem(
7273
selectedMapStyle: String
7374
) {
7475
if (location.isSteady()) {
75-
SteadyLocationItem(location, isFirstItem, isLastItem, journeyList) {
76+
SteadyLocationItem(location, isFirstItem, isLastItem, journeyList, showJourneyDetails) {
7677
addPlaceTap(location.from_latitude, location.from_longitude)
7778
}
7879
} else {
@@ -155,6 +156,7 @@ fun SteadyLocationItem(
155156
isFirstItem: Boolean,
156157
isLastItem: Boolean,
157158
journeyList: List<LocationJourney>,
159+
onTap: () -> Unit,
158160
addPlace: () -> Unit
159161
) {
160162
val context = LocalContext.current
@@ -209,6 +211,7 @@ fun SteadyLocationItem(
209211

210212
Column(
211213
modifier = Modifier
214+
.clickable { onTap() }
212215
.padding(start = 16.dp)
213216
.weight(1f)
214217
) {

app/src/main/java/com/canopas/yourspace/ui/flow/journey/detail/UserJourneyDetailScreen.kt

Lines changed: 74 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ import androidx.compose.foundation.layout.BoxScope
88
import androidx.compose.foundation.layout.Column
99
import androidx.compose.foundation.layout.ColumnScope
1010
import androidx.compose.foundation.layout.Row
11+
import androidx.compose.foundation.layout.Spacer
1112
import androidx.compose.foundation.layout.fillMaxSize
1213
import androidx.compose.foundation.layout.fillMaxWidth
1314
import androidx.compose.foundation.layout.height
1415
import androidx.compose.foundation.layout.heightIn
1516
import androidx.compose.foundation.layout.padding
1617
import androidx.compose.foundation.layout.size
18+
import androidx.compose.foundation.layout.wrapContentHeight
1719
import androidx.compose.foundation.shape.CircleShape
1820
import androidx.compose.material.icons.Icons
1921
import androidx.compose.material.icons.automirrored.filled.ArrowBack
@@ -38,6 +40,8 @@ import androidx.compose.ui.geometry.Offset
3840
import androidx.compose.ui.graphics.Color
3941
import androidx.compose.ui.platform.LocalContext
4042
import androidx.compose.ui.res.painterResource
43+
import androidx.compose.ui.text.font.FontWeight
44+
import androidx.compose.ui.text.style.TextOverflow
4145
import androidx.compose.ui.unit.dp
4246
import androidx.hilt.navigation.compose.hiltViewModel
4347
import com.canopas.yourspace.R
@@ -139,43 +143,83 @@ private fun JourneyInfo(journey: LocationJourney) {
139143
val distance = getDistanceString(journey.route_distance ?: 0.0)
140144
val duration = getRouteDurationString(journey.route_duration ?: 0)
141145

142-
Text(
143-
text = "$distance - $duration",
144-
color = AppTheme.colorScheme.textPrimary,
145-
style = AppTheme.appTypography.header2,
146-
modifier = Modifier
147-
.padding(top = 8.dp, bottom = 24.dp)
148-
.padding(horizontal = 16.dp)
149-
)
146+
if (toAddress != null) {
147+
Text(
148+
text = "$distance - $duration",
149+
color = AppTheme.colorScheme.textPrimary,
150+
style = AppTheme.appTypography.header2,
151+
modifier = Modifier
152+
.padding(top = 8.dp, bottom = 24.dp)
153+
.padding(horizontal = 16.dp)
154+
)
150155

151-
Row(
152-
verticalAlignment = Alignment.Top,
153-
modifier = Modifier
154-
.height(90.dp)
155-
) {
156-
DottedTimeline(isSteadyLocation = false, isLastItem = false, isJourneyDetail = true)
157-
Column(
156+
Row(
157+
verticalAlignment = Alignment.Top,
158158
modifier = Modifier
159-
.padding(start = 16.dp)
160-
.weight(1f)
159+
.height(90.dp)
161160
) {
162-
PlaceInfo(fromAddressStr, getFormattedLocationTime(journey.created_at!!))
161+
DottedTimeline(isSteadyLocation = false, isLastItem = false, isJourneyDetail = true)
162+
Column(
163+
modifier = Modifier
164+
.padding(start = 16.dp)
165+
.weight(1f)
166+
) {
167+
PlaceInfo(fromAddressStr, getFormattedLocationTime(journey.created_at!!))
168+
}
163169
}
164-
}
165170

166-
Row(
167-
verticalAlignment = Alignment.Top,
168-
modifier = Modifier
169-
.height(90.dp)
170-
) {
171-
DottedTimeline(isSteadyLocation = true, isLastItem = true, isJourneyDetail = true)
172-
Column(
171+
Row(
172+
verticalAlignment = Alignment.Top,
173173
modifier = Modifier
174-
.padding(start = 16.dp)
175-
.weight(1f)
174+
.height(90.dp)
176175
) {
177-
journey.update_at?.let { getFormattedLocationTime(it) }
178-
?.let { PlaceInfo(toAddressStr, it) }
176+
DottedTimeline(isSteadyLocation = true, isLastItem = true, isJourneyDetail = true)
177+
Column(
178+
modifier = Modifier
179+
.padding(start = 16.dp)
180+
.weight(1f)
181+
) {
182+
journey.update_at?.let { getFormattedLocationTime(it) }
183+
?.let { PlaceInfo(toAddressStr, it) }
184+
}
185+
}
186+
} else {
187+
Row(
188+
verticalAlignment = Alignment.Top,
189+
modifier = Modifier.wrapContentHeight().padding(4.dp)
190+
) {
191+
Icon(
192+
painter = painterResource(R.drawable.ic_journey_destination),
193+
contentDescription = "",
194+
tint = AppTheme.colorScheme.primary,
195+
modifier = Modifier
196+
.padding(start = 8.dp)
197+
.background(AppTheme.colorScheme.secondaryInverseVariant, CircleShape)
198+
.size(30.dp)
199+
.padding(4.dp)
200+
)
201+
Column(
202+
modifier = Modifier
203+
.padding(start = 16.dp)
204+
.weight(1f)
205+
) {
206+
Text(
207+
text = fromAddressStr,
208+
style = AppTheme.appTypography.body2.copy(
209+
color = AppTheme.colorScheme.textPrimary,
210+
fontWeight = FontWeight.Medium
211+
),
212+
overflow = TextOverflow.Ellipsis,
213+
modifier = Modifier.padding(end = 16.dp)
214+
)
215+
216+
Spacer(modifier = Modifier.size(8.dp))
217+
218+
Text(
219+
text = getFormattedLocationTime(journey.created_at!!),
220+
style = AppTheme.appTypography.caption.copy(color = AppTheme.colorScheme.textDisabled)
221+
)
222+
}
179223
}
180224
}
181225
}

0 commit comments

Comments
 (0)