diff --git a/app/src/main/java/it/reyboz/bustorino/backend/gtfs/LivePositionUpdate.kt b/app/src/main/java/it/reyboz/bustorino/backend/gtfs/LivePositionUpdate.kt --- a/app/src/main/java/it/reyboz/bustorino/backend/gtfs/LivePositionUpdate.kt +++ b/app/src/main/java/it/reyboz/bustorino/backend/gtfs/LivePositionUpdate.kt @@ -61,6 +61,11 @@ fun getLineGTFSFormat(): String{ return "gtt:$routeID" } + + fun hasTripId(): Boolean{ + val r = tripID.isEmpty() || tripID == "null" + return !r + } } diff --git a/app/src/main/java/it/reyboz/bustorino/fragments/GeneralMapLibreFragment.kt b/app/src/main/java/it/reyboz/bustorino/fragments/GeneralMapLibreFragment.kt --- a/app/src/main/java/it/reyboz/bustorino/fragments/GeneralMapLibreFragment.kt +++ b/app/src/main/java/it/reyboz/bustorino/fragments/GeneralMapLibreFragment.kt @@ -57,6 +57,7 @@ import it.reyboz.bustorino.backend.LivePositionTripPattern import it.reyboz.bustorino.backend.LivePositionsServiceStatus import it.reyboz.bustorino.backend.Stop +import it.reyboz.bustorino.backend.VehicleClassInfo import it.reyboz.bustorino.backend.VehicleUtils import it.reyboz.bustorino.backend.gtfs.GtfsUtils import it.reyboz.bustorino.backend.gtfs.LivePositionUpdate @@ -178,6 +179,8 @@ protected lateinit var locationComponent: LocationComponent protected lateinit var busPositionsIconButton: ImageButton protected lateinit var vehicleIcon: ImageView + protected lateinit var warningTripIcon: ImageView + private lateinit var loadingTripIcon: ImageView protected var lastLocation : Location? = null @@ -273,11 +276,18 @@ arrivalsCard = view.findViewById(R.id.arrivalsCardButton) directionsCard = view.findViewById(R.id.directionsCardButton) vehicleIcon = view.findViewById(R.id.vehicleIcon) + loadingTripIcon = view.findViewById(R.id.downloadingIcon) + warningTripIcon = view.findViewById(R.id.warningIconTrip) linesBottomTextView = view.findViewById(R.id.linesBottomTextView) linesBottomTextView.text = getString(R.string.lines_fill, "") bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet) bottomSheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN + //set onclick listener for warning trip icon + warningTripIcon.setOnClickListener { + showToastMessage(R.string.no_trip_info_warning, true) + } + loadingTripIcon.setOnClickListener { showToastMessage(R.string.downloading_trip_info, true) } } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -523,6 +533,11 @@ locationEngine?.removeLocationUpdates(mapLibreLocationCallback) } + protected fun showVehClassInfo(vehInfo: VehicleClassInfo){ + val print = "${vehInfo.type.getName()}: ${vehInfo.name}" + makeToast(print) + } + /** * Update function for the bus positions @@ -538,6 +553,7 @@ hasVehicleTracking: Boolean = true, trackVehicleCallback: ((String) -> Unit)? = null ) { + //TODO: Eventually change this (incomingData should be keyed by vehicle) val vehsNew = HashSet(incomingData.values.map { up -> up.first.vehicle }) val vehsOld = HashSet(updatesByVehDict.keys) @@ -670,13 +686,17 @@ GtfsUtils.getLineNameFromGtfsID(data.posUpdate.routeID), false ) val pat = data.pattern + val update = data.posUpdate + if (pat != null) { stopTitleTextView.text = pat.headsign stopTitleTextView.visibility = View.VISIBLE stopNumberTextView.text = getString(R.string.line_fill_towards, lineName) + loadingTripIcon.visibility = View.GONE } else { stopTitleTextView.visibility = View.GONE stopNumberTextView.text = getString(R.string.line_fill, lineName) + loadingTripIcon.visibility = if (update.hasTripId()) View.VISIBLE else View.GONE } directionsCard.setOnClickListener { onDirectionsClick(pat?.code ?: "", veh) @@ -695,10 +715,10 @@ extraBottomTextView.text = getString(R.string.updated_fill, utils.unixTimestampToLocalTime(data.posUpdate.timestamp)) extraBottomTextView.visibility = View.VISIBLE - val update = data.posUpdate val vehInfo = VehicleUtils.getTypeForLabel(update.vehicle) if(vehInfo == null){ vehicleIcon.visibility = View.GONE + linesPassingTextView.setOnClickListener { } //empty click listener } else{ val ico = when(vehInfo.type){ VehicleUtils.VehicleType.BUS -> R.drawable.ic_bus @@ -709,9 +729,14 @@ vehicleIcon.visibility = View.VISIBLE vehicleIcon.setOnClickListener { - val print = "${vehInfo.type.getName()}: ${vehInfo.name}" - makeToast(print) + showVehClassInfo(vehInfo) } + linesPassingTextView.setOnClickListener { showVehClassInfo(vehInfo) } + } + if (!update.hasTripId()){ + warningTripIcon.visibility = View.VISIBLE + } else{ + warningTripIcon.visibility = View.GONE } } @@ -866,6 +891,8 @@ else stop.routesThatStopHereToString() //requireContext().getString(R.string.lines_fill, stop.routesThatStopHereToString()) linesPassingTextView.text = string_show linesPassingTextView.visibility = View.VISIBLE + linesPassingTextView.setOnClickListener { } //empty click listener (needed when switching from vehicle) + linesPassingTextView.gravity = Gravity.TOP linesBottomTextView.visibility =View.VISIBLE @@ -880,14 +907,17 @@ directionsCard.setOnClickListener { ViewUtils.openStopInOutsideApp(stop, context) } + context?.let { val colorIcon = ViewUtils.getColorFromTheme(it, R.attr.colorAccent)//ResourcesCompat.getColor(resources,R.attr.colorAccent,activity?.theme) ViewCompat.setBackgroundTintList(directionsCard, ColorStateList.valueOf(colorIcon)) } bottomrightImage.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.navigation_right, activity?.theme)) - + // icons for the vehicles vehicleIcon.visibility = View.GONE + warningTripIcon.visibility = View.GONE + loadingTripIcon.visibility = View.GONE } //add stop marker diff --git a/app/src/main/java/it/reyboz/bustorino/viewmodels/LivePositionsViewModel.kt b/app/src/main/java/it/reyboz/bustorino/viewmodels/LivePositionsViewModel.kt --- a/app/src/main/java/it/reyboz/bustorino/viewmodels/LivePositionsViewModel.kt +++ b/app/src/main/java/it/reyboz/bustorino/viewmodels/LivePositionsViewModel.kt @@ -207,15 +207,22 @@ * This livedata object contains the final updates with patterns present in the DB */ val updatesWithTripAndPatterns = gtfsTripsPatternsInDB.map { tripPatterns-> - //TODO: Change the mapping in the final updates, I don't know why the key is the tripID and not the vehicle ID - Log.i(DEBUG_TI, "Mapping trips and patterns") - val mdict = HashMap() + //Integrate trips and patterns + //Log.i(DEBUG_TI, "Mapping trips and patterns") + //val mdict = HashMap() + val upsByVeh = HashMap() //missing patterns val routesToDownload = HashSet() if(positionsToBeMatchedLiveData.value!=null) for(update in positionsToBeMatchedLiveData.value!!){ + if(!update.hasTripId()){ + //when there is no trip information + upsByVeh[update.vehicle] = Pair(update, null) + continue + } - val trID:String = update.tripID + val trID = update.tripID + val veh = update.vehicle var found = false for(trip in tripPatterns){ if (trip.pattern == null){ @@ -226,14 +233,14 @@ if (trip.trip.tripID == "gtt:$trID"){ found = true //insert directly - mdict[trID] = Pair(update,trip) + upsByVeh[veh] = Pair(update,trip) break } } if (!found){ //Log.d(DEBUG_TI, "Cannot find pattern ${tr}") //give the update anyway - mdict[trID] = Pair(update,null) + upsByVeh[veh] = Pair(update,null) } } //have to request download of missing Patterns @@ -243,7 +250,7 @@ MatoPatternsDownloadWorker.downloadPatternsForRoutes(routesToDownload.toList(), getApplication()) } - return@map mdict + return@map upsByVeh } fun clearOldPositionsUpdates(){ @@ -297,14 +304,14 @@ Pair, List>{ val gtfsLineId = linePatt.first val pattern = linePatt.second - val updsForTripId = HashMap>() + val updsByVeh = HashMap>() val vehicleOnWrongDirection = mutableListOf() //supporting the eventual null case when there is no need to filter if (gtfsLineId == "ALL"){ //copy the dict - for ((tripId, pair) in updates.entries) { - updsForTripId[tripId] = pair + for ((vehicle, pair) in updates.entries) { + updsByVeh[vehicle] = pair } } else { @@ -318,11 +325,11 @@ ) // cannot understand where this is used //val patternsDirections = HashMap() - for ((tripId, pair) in updates.entries) { + for ((veh, pair) in updates.entries) { //remove trips with wrong line val posUp = pair.first val vehicle = pair.first.vehicle - if (pair.first.routeID != filtdLineID) + if (posUp.routeID != filtdLineID) continue if (directionId != -100 && pair.second != null && pair.second?.pattern != null) { @@ -330,22 +337,22 @@ if (dir == directionId) { //add the trip - updsForTripId[tripId] = pair + updsByVeh[veh] = pair //Log.d(DEBUG_TI, "Add vehicle ${pair.first.vehicle}, route ${pair.first.routeID}") } else { vehicleOnWrongDirection.add(vehicle) } - //patternsDirections[tripId] = dir ?: -10 + //patternsDirections[veh] = dir ?: -10 } else { - updsForTripId[tripId] = pair - //Log.d(DEBUG_TAG, "No pattern for tripID: $tripId") - //patternsDirections[tripId] = -10 + updsByVeh[veh] = pair + //Log.d(DEBUG_TAG, "No pattern for tripID: $veh") + //patternsDirections[veh] = -10 } } } - Log.d(DEBUG_TI, "Filtered updates are ${updsForTripId.keys.size}") // Original updates directs: $patternsDirections\n + Log.d(DEBUG_TI, "Filtered updates are ${updsByVeh.keys.size}") // Original updates directs: $patternsDirections\n - return Pair(updsForTripId, vehicleOnWrongDirection) + return Pair(updsByVeh, vehicleOnWrongDirection) } diff --git a/app/src/main/res/drawable/ic_round_downloading.xml b/app/src/main/res/drawable/ic_round_downloading.xml new file mode 100644 --- /dev/null +++ b/app/src/main/res/drawable/ic_round_downloading.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_round_warning_larger.xml b/app/src/main/res/drawable/ic_round_warning_larger.xml new file mode 100644 --- /dev/null +++ b/app/src/main/res/drawable/ic_round_warning_larger.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/include_map_bottom_sheet.xml b/app/src/main/res/layout/include_map_bottom_sheet.xml --- a/app/src/main/res/layout/include_map_bottom_sheet.xml +++ b/app/src/main/res/layout/include_map_bottom_sheet.xml @@ -60,9 +60,8 @@ android:layout_marginTop="5dp" app:layout_constraintTop_toBottomOf="@id/stopTitleTextView" android:id="@+id/bottomLinearLayout" - app:layout_constraintEnd_toStartOf="@id/arrivalsCardButton" + app:layout_constraintEnd_toStartOf="@id/arrivalsCardButton" android:layout_marginEnd="10dp" - > - + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -266,4 +266,7 @@ Segui il sistema Imposta tema scuro o chiaro + + Nessuna informazione trasmessa sulla direzione o sul viaggio del veicolo. + Download in corso delle informazioni sul viaggio diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -99,4 +99,5 @@ @color/blue_700 @color/light_blue_900 + #fbb504 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -417,4 +417,6 @@ Press back again to close the app Donate + No information on the direction or trip of the vehicle was transmitted. + Downloading trip information…