Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality to show steady location on map #160

Merged
merged 3 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,18 @@ fun JourneyMap(
val boundsBuilder = LatLngBounds.builder()
.apply {
include(fromLatLang)
include(toLatLang)
if (location?.to_latitude != null && location.to_longitude != null) {
include(toLatLang)
}
routePoints.forEach { latLng ->
this.include(latLng)
}
}.build()
val update = CameraUpdateFactory.newLatLngBounds(boundsBuilder, 50)
cameraPositionState.move(update)
if (location?.to_latitude == null && location?.to_longitude == null) {
cameraPositionState.move(CameraUpdateFactory.newLatLngZoom(fromLatLang, 18f))
}
} catch (e: Exception) {
e.printStackTrace()
}
Expand Down Expand Up @@ -135,8 +140,9 @@ fun JourneyMap(
) {
location?.let {
LocationMarker(fromLatLang, anchor, fromMarkerContent)

LocationMarker(toLatLang, anchor, toMarkerContent)
if (location.to_latitude != null && location.to_longitude != null) {
LocationMarker(toLatLang, anchor, toMarkerContent)
}

Polyline(
points = if (shouldAnimate) animatedPoints else routePoints,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.location.Address
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -72,7 +73,7 @@ fun LocationHistoryItem(
selectedMapStyle: String
) {
if (location.isSteady()) {
SteadyLocationItem(location, isFirstItem, isLastItem, journeyList) {
SteadyLocationItem(location, isFirstItem, isLastItem, journeyList, showJourneyDetails) {
addPlaceTap(location.from_latitude, location.from_longitude)
}
} else {
Expand Down Expand Up @@ -155,6 +156,7 @@ fun SteadyLocationItem(
isFirstItem: Boolean,
isLastItem: Boolean,
journeyList: List<LocationJourney>,
onTap: () -> Unit,
addPlace: () -> Unit
) {
val context = LocalContext.current
Expand Down Expand Up @@ -209,6 +211,7 @@ fun SteadyLocationItem(

Column(
modifier = Modifier
.clickable { onTap() }
.padding(start = 16.dp)
.weight(1f)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
Expand All @@ -38,6 +40,8 @@ import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import com.canopas.yourspace.R
Expand Down Expand Up @@ -139,43 +143,84 @@ private fun JourneyInfo(journey: LocationJourney) {
val distance = getDistanceString(journey.route_distance ?: 0.0)
val duration = getRouteDurationString(journey.route_duration ?: 0)

Text(
text = "$distance - $duration",
color = AppTheme.colorScheme.textPrimary,
style = AppTheme.appTypography.header2,
modifier = Modifier
.padding(top = 8.dp, bottom = 24.dp)
.padding(horizontal = 16.dp)
)
if (toAddress != null) {
Text(
text = "$distance - $duration",
color = AppTheme.colorScheme.textPrimary,
style = AppTheme.appTypography.header2,
modifier = Modifier
.padding(top = 8.dp, bottom = 24.dp)
.padding(horizontal = 16.dp)
)

Row(
verticalAlignment = Alignment.Top,
modifier = Modifier
.height(90.dp)
) {
DottedTimeline(isSteadyLocation = false, isLastItem = false, isJourneyDetail = true)
Column(
Row(
verticalAlignment = Alignment.Top,
modifier = Modifier
.padding(start = 16.dp)
.weight(1f)
.height(90.dp)
) {
PlaceInfo(fromAddressStr, getFormattedLocationTime(journey.created_at!!))
DottedTimeline(isSteadyLocation = false, isLastItem = false, isJourneyDetail = true)
Column(
modifier = Modifier
.padding(start = 16.dp)
.weight(1f)
) {
PlaceInfo(fromAddressStr, getFormattedLocationTime(journey.created_at))
}
}
}

Row(
verticalAlignment = Alignment.Top,
modifier = Modifier
.height(90.dp)
) {
DottedTimeline(isSteadyLocation = true, isLastItem = true, isJourneyDetail = true)
Column(
Row(
verticalAlignment = Alignment.Top,
modifier = Modifier
.padding(start = 16.dp)
.weight(1f)
.height(90.dp)
) {
journey.updated_at?.let { getFormattedLocationTime(it) }
?.let { PlaceInfo(toAddressStr, it) }
DottedTimeline(isSteadyLocation = true, isLastItem = true, isJourneyDetail = true)
Column(
modifier = Modifier
.padding(start = 16.dp)
.weight(1f)
) {
PlaceInfo(toAddressStr, getFormattedLocationTime(journey.updated_at))
}
}
} else {
Row(
verticalAlignment = Alignment.Top,
modifier = Modifier
.wrapContentHeight()
.padding(4.dp)
) {
Icon(
painter = painterResource(R.drawable.ic_journey_destination),
contentDescription = "",
tint = AppTheme.colorScheme.primary,
modifier = Modifier
.padding(start = 8.dp)
.background(AppTheme.colorScheme.secondaryInverseVariant, CircleShape)
.size(30.dp)
.padding(4.dp)
)
Column(
modifier = Modifier
.padding(start = 16.dp)
.weight(1f)
) {
Text(
text = fromAddressStr,
style = AppTheme.appTypography.body2.copy(
color = AppTheme.colorScheme.textPrimary,
fontWeight = FontWeight.Medium
),
overflow = TextOverflow.Ellipsis,
modifier = Modifier.padding(end = 16.dp)
)

Spacer(modifier = Modifier.size(8.dp))

Text(
text = getFormattedLocationTime(journey.created_at),
style = AppTheme.appTypography.caption.copy(color = AppTheme.colorScheme.textDisabled)
)
}
}
}
}
Expand Down
Loading