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

510 create and show end ride if distance is less than 100 meters #511

Closed
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
2 changes: 1 addition & 1 deletion .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ object MappingConstants {
const val SELECTION_RESCUEE_TYPE = "rescuee_type"

const val NEAREST_METERS = 70.00
const val METERS_TO_END_RIDE = 1200
const val DEFAULT_RADIUS = 7000.00
const val API_CALL_RETRY_COUNT: Long = 7

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,9 @@ class TrackingStateHandler(
state.update { it.copy(speedometerState = it.speedometerState.copy(currentSpeedKph = currentSpeedKph)) }
}

fun setTravelledDistance(distance: String){
fun setTravelledDistance(distance: Double){

state.update { it.copy(speedometerState = it.speedometerState.copy(travelledDistance = distance)) }
state.update { it.copy(speedometerState = it.speedometerState.copy(travelledDistance = distance.formatToDistanceKm())) }
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,14 @@ fun MappingScreen(
}
}

is MappingEvent.AbleToEndRide -> {
uiState = uiState.copy(ableToEndRide = true)
}

is MappingEvent.AbleToCancelRide -> {
uiState = uiState.copy(ableToEndRide = false)
}

else -> {}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.cyclistance.core.utils.constants.MappingConstants.DEFAULT_RADIUS
import com.example.cyclistance.core.utils.constants.MappingConstants.MAPPING_VM_STATE_KEY
import com.example.cyclistance.core.utils.constants.MappingConstants.METERS_TO_END_RIDE
import com.example.cyclistance.core.utils.constants.MappingConstants.NEAREST_METERS
import com.example.cyclistance.core.utils.formatter.FormatterUtils
import com.example.cyclistance.core.utils.formatter.FormatterUtils.formatToDistanceKm
Expand Down Expand Up @@ -717,6 +718,8 @@ class MappingViewModel @Inject constructor(
destinationLocation = LocationModel(location.latitude, location.longitude)
).toInt()

_eventFlow.emit(value = if (distance <= METERS_TO_END_RIDE) MappingEvent.AbleToEndRide else MappingEvent.AbleToCancelRide)


if (distance <= NEAREST_METERS) {
_eventFlow.emit(value = MappingEvent.DestinationReached)
Expand Down Expand Up @@ -746,7 +749,7 @@ class MappingViewModel @Inject constructor(
longitude = this.longitude
),
destinationLocation = userLocation)
_state.update { it.copy(rescueETA = eta, rescueDistance = distance.formatToDistanceKm()) }
_state.update { it.copy(rescueETA = eta, rescueDistance = distance) }
}

private fun getETABetweenTwoPoints(
Expand Down Expand Up @@ -814,7 +817,7 @@ class MappingViewModel @Inject constructor(
it.copy(
rescueTransaction = rescueTransaction,
rescueETA = estimatedTimeArrival ?: "",
rescueDistance = distance?.formatToDistanceKm() ?: "",
rescueDistance = distance,
rescuer = rescuer
)
}
Expand Down Expand Up @@ -1010,24 +1013,34 @@ class MappingViewModel @Inject constructor(
trackingHandler.updateLocation(location)
broadcastRescueTransactionToRespondent(location)
updateSpeedometer(location)
if (state.value.nearbyCyclist == null) {
broadcastToNearbyCyclists()
}
broadcastToAllCyclists()

}.launchIn(this@launch).invokeOnCompletion {
savedStateHandle[MAPPING_VM_STATE_KEY] = state.value
}
}
}

private suspend fun broadcastToAllCyclists(){
if (state.value.nearbyCyclist == null) {
broadcastToNearbyCyclists()
}
}



private fun updateSpeedometer(location: LocationModel) {
val isUserRescuer = state.value.user.isRescuer()
location.latitude ?: return
location.longitude ?: return
travelledPath.add(element = GoogleLatLng(location.latitude, location.longitude))
val travelledDistance = SphericalUtil.computeLength(travelledPath)


if (isUserRescuer) {
trackingHandler.setSpeed(location.speed)
trackingHandler.getTopSpeed(location.speed)
travelledPath.add(element = GoogleLatLng(location.latitude!!, location.longitude!!))
val distance = SphericalUtil.computeLength(travelledPath).formatToDistanceKm()
trackingHandler.setTravelledDistance(distance)
trackingHandler.setTravelledDistance(travelledDistance)
}
}

Expand All @@ -1044,7 +1057,6 @@ class MappingViewModel @Inject constructor(
}.onEach {
it.filterUser()
it.updateNearbyCyclists()
Timber.v("Receiving from subscribeToNearbyUsersChanges")
trackingHandler.updateClient()
}.launchIn(this).invokeOnCompletion {
savedStateHandle[MAPPING_VM_STATE_KEY] = state.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.example.cyclistance.R
import com.example.cyclistance.feature_mapping.domain.model.Role
import com.example.cyclistance.feature_mapping.domain.model.ui.bottomSheet.OnGoingRescueModel
import com.example.cyclistance.theme.Black440
import com.example.cyclistance.theme.Blue600
import com.example.cyclistance.theme.CyclistanceTheme
import com.example.cyclistance.theme.Red900

Expand All @@ -38,6 +39,7 @@ fun BottomSheetOnGoingRescue(
onClickChatButton: () -> Unit,
onClickCancelButton: () -> Unit,
role: String,
ableToEndRide: Boolean,
onGoingRescueModel: OnGoingRescueModel,
) {

Expand Down Expand Up @@ -165,6 +167,7 @@ fun BottomSheetOnGoingRescue(
start.linkTo(parent.start)
bottom.linkTo(parent.bottom, margin = 10.dp)
},
ableToEndRide = ableToEndRide,
onClickCallButton = onClickCallButton,
onClickChatButton = onClickChatButton,
onClickCancelButton = onClickCancelButton)
Expand Down Expand Up @@ -286,6 +289,7 @@ fun RowScope.ItemSpeed(modifier: Modifier, title: String, content: String) {
@Composable
private fun RoundButtonSection(
modifier: Modifier = Modifier,
ableToEndRide: Boolean ,
onClickCallButton: () -> Unit,
onClickChatButton: () -> Unit,
onClickCancelButton: () -> Unit) {
Expand Down Expand Up @@ -314,12 +318,24 @@ private fun RoundButtonSection(
buttonSubtitle = "Chat", onClick = onClickChatButton)


RoundedButtonItem(
modifier = Modifier.weight(1f),
backgroundColor = Red900,
contentColor = Color.White,
imageId = R.drawable.ic_cancel_1,
buttonSubtitle = "Cancel", onClick = onClickCancelButton)
if(ableToEndRide){
RoundedButtonItem(
modifier = Modifier.weight(1f),
backgroundColor = Blue600,
contentColor = Color.White,
imageId = R.drawable.ic_end_ride,
buttonSubtitle = "End Ride",
onClick = {}
)
}else{
RoundedButtonItem(
modifier = Modifier.weight(1f),
backgroundColor = Red900,
contentColor = Color.White,
imageId = R.drawable.ic_cancel_1,
buttonSubtitle = "Cancel", onClick = onClickCancelButton)

}
}
}

Expand Down Expand Up @@ -401,7 +417,7 @@ private fun PreviewBottomSheetOnGoingRescueDark() {
estimatedDistance = "9.0 km",
estimatedTime = "1h 20m",
),
role = Role.Rescuer.name)
role = Role.Rescuer.name, ableToEndRide = true)
}, content = {
Box(
contentAlignment = Alignment.BottomCenter,
Expand Down Expand Up @@ -442,6 +458,7 @@ private fun PreviewBottomSheetOnGoingRescueLight() {
estimatedDistance = "9.0 km",
estimatedTime = "1h 20m",
),
ableToEndRide = false,
role = Role.Rescuee.name)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.unit.dp
import com.example.cyclistance.core.utils.formatter.FormatterUtils.formatToDistanceKm
import com.example.cyclistance.core.utils.formatter.IconFormatter.toHazardousLaneIconMarker
import com.example.cyclistance.feature_mapping.domain.model.ui.bottomSheet.OnGoingRescueModel
import com.example.cyclistance.feature_mapping.presentation.mapping_main_screen.event.MappingUiEvent
Expand Down Expand Up @@ -107,12 +108,13 @@ fun MappingBottomSheet(
role = state.user.transaction?.role ?: "",
onGoingRescueModel = OnGoingRescueModel(
estimatedTime = state.rescueETA,
estimatedDistance = state.rescueDistance,
estimatedDistance = state.rescueDistance?.formatToDistanceKm() ?: "",
currentSpeed = String.format(
"%.2f",
state.speedometerState.currentSpeedKph),
ridingDistance = state.speedometerState.travelledDistance,
maxSpeed = String.format("%.2f", state.speedometerState.topSpeed)))
maxSpeed = String.format("%.2f", state.speedometerState.topSpeed)),
ableToEndRide = uiState.ableToEndRide)

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ sealed class MappingEvent{
data class RespondToHelpSuccess(val reason:String = "Rescue request sent"): MappingEvent()
data class AddressFailed(val reason: String? = "Rescue transaction not found"): MappingEvent()
data object NoInternetConnection: MappingEvent()

data object AbleToEndRide: MappingEvent()
data object AbleToCancelRide: MappingEvent()

data class NewSelectedRescuee(val selectedRescuee: MapSelectedRescuee): MappingEvent()
data class NewBottomSheetType(val bottomSheetType: String): MappingEvent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ data class MappingState(
val respondedToHelp: Boolean = false,
val transactionLocation: LocationModel? = null,
val rescueETA: String = "",
val rescueDistance: String = "",
val rescueDistance: Double? = 0.0,
val newRescueRequest: NewRescueRequestsModel? = null,
val speedometerState: SpeedometerState = SpeedometerState(),
val nearbyCyclist: NearbyCyclist? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ data class MappingUiState(
val generateRouteFailed: Boolean = false,
val cancelSearchDialogVisible: Boolean = false,
val cancelOnGoingRescueDialogVisible: Boolean = false,
val notificationPermissionVisible: Boolean = false
val notificationPermissionVisible: Boolean = false,
val ableToEndRide: Boolean = false



Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/ic_end_ride.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="26dp"
android:height="18dp"
android:viewportWidth="26"
android:viewportHeight="18">
<path
android:strokeWidth="1"
android:pathData="M25.081,0.913L25.081,0.913C25.351,1.176 25.5,1.528 25.5,1.892C25.5,2.256 25.351,2.608 25.081,2.87C25.081,2.871 25.081,2.871 25.081,2.871L10.457,17.05L10.457,17.05C10.311,17.192 10.136,17.305 9.943,17.382C9.75,17.46 9.543,17.5 9.333,17.5C9.123,17.5 8.916,17.46 8.723,17.382C8.53,17.305 8.356,17.192 8.209,17.05L8.209,17.05L0.944,10.006L0.944,10.006L0.937,10C0.799,9.871 0.69,9.717 0.616,9.549C0.541,9.38 0.502,9.199 0.5,9.016C0.498,8.834 0.534,8.652 0.606,8.482C0.678,8.313 0.784,8.157 0.92,8.026C1.055,7.894 1.217,7.79 1.397,7.718C1.576,7.647 1.769,7.611 1.964,7.613C2.159,7.614 2.351,7.654 2.529,7.728C2.707,7.802 2.867,7.909 3,8.043L3,8.043L3.006,8.049L8.984,13.845L9.333,14.183L9.681,13.845L23.017,0.913L23.017,0.913C23.151,0.783 23.311,0.679 23.488,0.608C23.666,0.537 23.856,0.5 24.049,0.5C24.241,0.5 24.432,0.537 24.609,0.608C24.787,0.679 24.947,0.783 25.081,0.913Z"
android:fillColor="#ffffff"
android:strokeColor="#ffffff"/>
</vector>