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 @@ -169,6 +169,19 @@ } ) } + protected fun isPointInsideVisibleRegion(p: LatLng, other: Boolean): Boolean{ + val bounds = map?.projection?.visibleRegion?.latLngBounds + var inside = other + bounds?.let { inside = it.contains(p) } + return inside + } + + protected fun isPointInsideVisibleRegion(lat: Double, lon: Double, other: Boolean): Boolean{ + val p = LatLng(lat, lon) + return isPointInsideVisibleRegion(p, other) + } + + companion object{ private const val DEBUG_TAG="GeneralMapLibreFragment" diff --git a/app/src/main/java/it/reyboz/bustorino/fragments/LinesDetailFragment.kt b/app/src/main/java/it/reyboz/bustorino/fragments/LinesDetailFragment.kt --- a/app/src/main/java/it/reyboz/bustorino/fragments/LinesDetailFragment.kt +++ b/app/src/main/java/it/reyboz/bustorino/fragments/LinesDetailFragment.kt @@ -196,6 +196,7 @@ private lateinit var locationComponent: LocationComponent private lateinit var polylineSource: GeoJsonSource private lateinit var polyArrowSource: GeoJsonSource + private lateinit var selectedBusSource: GeoJsonSource private var savedCameraPosition: CameraPosition? = null private var vehShowing = "" @@ -699,8 +700,6 @@ stopTitleTextView.visibility = View.VISIBLE val string_show = if (stop.numRoutesStopping==0) "" - else if (stop.numRoutesStopping <= 1) - requireContext().getString(R.string.line_fill, stop.routesThatStopHereToString()) else requireContext().getString(R.string.lines_fill, stop.routesThatStopHereToString()) linesPassingTextView.text = string_show @@ -710,6 +709,7 @@ } arrivalsCard.visibility = View.VISIBLE + directionsCard.visibility = View.VISIBLE directionsCard.setOnClickListener { ViewUtils.openStopInOutsideApp(stop, context) @@ -750,7 +750,11 @@ //reset states shownStopInBottomSheet = null - vehShowing = "" + if (vehShowing!=""){ + //we are hiding a vehicle + vehShowing = "" + updatePositionsIcons(true) + } } @@ -764,39 +768,48 @@ bottomLayout?.let { val lineName = FiveTNormalizer.fixShortNameForDisplay( GtfsUtils.getLineNameFromGtfsID(data.posUpdate.routeID), true) - stopNumberTextView.text = requireContext().getString(R.string.line_fill, lineName) val pat = data.pattern if (pat!=null){ + //WE HAVE THE DIRECTIONS DATA stopTitleTextView.text = pat.headsign stopTitleTextView.visibility = View.VISIBLE Log.d(DEBUG_TAG, "Showing headsign ${pat.headsign} for vehicle $veh") + stopNumberTextView.text = requireContext().getString(R.string.line_fill_towards, lineName) + + bottomrightImage.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ic_magnifying_glass, activity?.theme)) + directionsCard.setOnClickListener { + data.pattern?.let { + + if(patternShown?.pattern?.code == it.code){ + context?.let { c->Toast.makeText(c, R.string.showing_same_direction, Toast.LENGTH_SHORT).show() } + }else + showPatternWithCode(it.code) + } //TODO + // ?: { + // context?.let { ctx -> Toast.makeText(ctx,"") } + //} + } + //set color + val colorBlue = ResourcesCompat.getColor(resources,R.color.blue_500,activity?.theme) + ViewCompat.setBackgroundTintList(directionsCard, ColorStateList.valueOf(colorBlue)) + directionsCard.visibility = View.VISIBLE } else { //stopTitleTextView.text = "NN" stopTitleTextView.visibility = View.GONE + stopNumberTextView.text = requireContext().getString(R.string.line_fill, lineName) + directionsCard.visibility = View.GONE + } - linesPassingTextView.text = data.posUpdate.vehicle + linesPassingTextView.text = requireContext().getString(R.string.vehicle_fill, data.posUpdate.vehicle) } arrivalsCard.visibility=View.GONE - bottomrightImage.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ic_magnifying_glass, activity?.theme)) - directionsCard.setOnClickListener { - data.pattern?.let { - - if(patternShown?.pattern?.code == it.code){ - context?.let { c->Toast.makeText(c, R.string.showing_same_direction, Toast.LENGTH_SHORT).show() } - }else - showPatternWithCode(it.code) - } //TODO - // ?: { - // context?.let { ctx -> Toast.makeText(ctx,"") } - //} - } - //set color - val colorBlue = ResourcesCompat.getColor(resources,R.color.blue_620,activity?.theme) - ViewCompat.setBackgroundTintList(directionsCard, ColorStateList.valueOf(colorBlue)) vehShowing = veh bottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED + + //call update position to color the bus special + updatePositionsIcons(true) //isBottomSheetShowing = true Log.d(DEBUG_TAG, "Shown vehicle $veh in bottom layout") } @@ -878,6 +891,10 @@ style.addSource(busesSource) style.addImage("bus_symbol",ResourcesCompat.getDrawable(resources, R.drawable.map_bus_position_icon, activity?.theme)!!) + selectedBusSource = GeoJsonSource("sel_bus_source") + style.addSource(selectedBusSource) + style.addImage("sel_bus_symbol", ResourcesCompat.getDrawable(resources, R.drawable.map_bus_position_icon_sel, activity?.theme)!!) + // Buses layer val busesLayer = SymbolLayer(BUSES_LAYER_ID, BUSES_SOURCE_ID).apply { withProperties( @@ -892,6 +909,17 @@ } style.addLayerAbove(busesLayer, STOPS_LAYER_ID) + val selectedBusLayer = SymbolLayer("sel_bus_layer", "sel_bus_source").withProperties( + PropertyFactory.iconImage("sel_bus_symbol"), + //PropertyFactory.iconSize(1.2f), + PropertyFactory.iconAllowOverlap(true), + PropertyFactory.iconIgnorePlacement(true), + PropertyFactory.iconRotate(Expression.get("bearing")), + PropertyFactory.iconRotationAlignment(ICON_ROTATION_ALIGNMENT_MAP) + + ) + style.addLayerAbove(selectedBusLayer, BUSES_LAYER_ID) + } override fun onAttach(context: Context) { @@ -1198,9 +1226,9 @@ var countUpds = 0 //val symbolsToUpdate = ArrayList() for (upsWithTrp in incomingData.values){ - val pos = upsWithTrp.first + val newPos = upsWithTrp.first val patternStops = upsWithTrp.second - val vehID = pos.vehicle + val vehID = newPos.vehicle var animate = false if (vehsOld.contains(vehID)){ //changing the location of an existing bus @@ -1210,10 +1238,10 @@ var avoidShowingUpdateBecauseIsImpossible = false oldPos?.let{ - if(it.routeID!=pos.routeID) { - val dist = LatLng(it.latitude, it.longitude).distanceTo(LatLng(pos.latitude, pos.longitude)) - val speed = dist*3.6 / (pos.timestamp - it.timestamp) //this should be in km/h - Log.w(DEBUG_TAG, "Vehicle $vehID changed route from ${oldPos.routeID} to ${pos.routeID}, distance: $dist, speed: $speed") + if(it.routeID!=newPos.routeID) { + val dist = LatLng(it.latitude, it.longitude).distanceTo(LatLng(newPos.latitude, newPos.longitude)) + val speed = dist*3.6 / (newPos.timestamp - it.timestamp) //this should be in km/h + Log.w(DEBUG_TAG, "Vehicle $vehID changed route from ${oldPos.routeID} to ${newPos.routeID}, distance: $dist, speed: $speed") if (speed > 120 || speed < 0){ avoidShowingUpdateBecauseIsImpossible = true } @@ -1225,26 +1253,25 @@ continue } - val samePosition = oldPos?.let { (it.latitude==pos.latitude)&&(it.longitude == pos.longitude) }?:false + val samePosition = oldPos?.let { (it.latitude==newPos.latitude)&&(it.longitude == newPos.longitude) }?:false val setPattern = (oldPattern==null) && (patternStops!=null) if((!samePosition)|| setPattern) { - //THIS PART C - /*val isPositionInBounds = isInsideVisibleRegion( - pos.latitude, pos.longitude, true - ) || (oldPos?.let { isInsideVisibleRegion(it.latitude,it.longitude,true) } ?: false) - */ - val skip = true - if (skip) { - //animate = true - // set the pattern data too - updatesByVehDict[vehID]!!.pattern = patternStops!!.pattern + val newOrOldPosInBounds = isPointInsideVisibleRegion( + newPos.latitude, newPos.longitude, true + ) || (oldPos?.let { isPointInsideVisibleRegion(it.latitude,it.longitude,true) } ?: false) + + + //val skip = true + if (newOrOldPosInBounds) { + // update the pattern data, the position will be updated with the animation + patternStops?.let { updatesByVehDict[vehID]!!.pattern = it.pattern} //this moves both the icon and the label - animateNewPositionMove(pos) + animateNewPositionMove(newPos) } else { //update - updatesByVehDict[vehID] = LivePositionTripPattern(pos,patternStops!!.pattern) + updatesByVehDict[vehID] = LivePositionTripPattern(newPos,patternStops?.pattern) /*busLabelSymbolsByVeh[vehID]?.let { it.latLng = LatLng(pos.latitude, pos.longitude) symbolsToUpdate.add(it) @@ -1259,7 +1286,7 @@ else{ //not inside // update it simply - updatesByVehDict[vehID] = LivePositionTripPattern(pos, patternStops?.pattern) + updatesByVehDict[vehID] = LivePositionTripPattern(newPos, patternStops?.pattern) //createLabelForVehicle(pos) //if(vehShowing==vehID) // map?.animateCamera(CameraUpdateFactory.newLatLng(LatLng(pos.latitude, pos.longitude)),500) @@ -1379,24 +1406,26 @@ return } - val features = ArrayList()//stops.mapNotNull { stop -> - //stop.latitude?.let { lat -> - // stop.longitude?.let { lon -> + val busFeatures = ArrayList() + val selectedBusFeatures = ArrayList() for (dat in updatesByVehDict.values){ //if (s.latitude!=null && s.longitude!=null) val pos = dat.posUpdate val point = Point.fromLngLat(pos.longitude, pos.latitude) - features.add( - Feature.fromGeometry( - point, - JsonObject().apply { - addProperty("veh", pos.vehicle) - addProperty("trip", pos.tripID) - addProperty("bearing", pos.bearing ?:0.0f) - addProperty("line", pos.routeID) - } - ) + + val newFeature = Feature.fromGeometry( + point, + JsonObject().apply { + addProperty("veh", pos.vehicle) + addProperty("trip", pos.tripID) + addProperty("bearing", pos.bearing ?:0.0f) + addProperty("line", pos.routeID) + } ) + if (vehShowing == dat.posUpdate.vehicle) + selectedBusFeatures.add(newFeature) + else + busFeatures.add(newFeature) /*busLabelSymbolsByVeh[pos.vehicle]?.let { it.latLng = LatLng(pos.latitude, pos.longitude) symbolsToUpdate.add(it) @@ -1404,7 +1433,8 @@ */ } - busesSource.setGeoJson(FeatureCollection.fromFeatures(features)) + busesSource.setGeoJson(FeatureCollection.fromFeatures(busFeatures)) + selectedBusSource.setGeoJson(FeatureCollection.fromFeatures(selectedBusFeatures)) //update labels, clear cache to be used //symbolManager.update(symbolsToUpdate) //symbolsToUpdate.clear() diff --git a/app/src/main/java/it/reyboz/bustorino/fragments/MapLibreFragment.kt b/app/src/main/java/it/reyboz/bustorino/fragments/MapLibreFragment.kt --- a/app/src/main/java/it/reyboz/bustorino/fragments/MapLibreFragment.kt +++ b/app/src/main/java/it/reyboz/bustorino/fragments/MapLibreFragment.kt @@ -518,8 +518,6 @@ stopTitleTextView.text = stopName//stop.stopDefaultName stopNumberTextView.text = getString(R.string.stop_fill,stop.ID) val string_show = if (stop.numRoutesStopping==0) "" - else if (stop.numRoutesStopping <= 1) - requireContext().getString(R.string.line_fill, stop.routesThatStopHereToString()) else requireContext().getString(R.string.lines_fill, stop.routesThatStopHereToString()) linesPassingTextView.text = string_show diff --git a/app/src/main/res/drawable/map_bus_position_icon_sel.xml b/app/src/main/res/drawable/map_bus_position_icon_sel.xml new file mode 100644 --- /dev/null +++ b/app/src/main/res/drawable/map_bus_position_icon_sel.xml @@ -0,0 +1,8 @@ + + + diff --git a/app/src/main/res/font/lato_bold.ttf b/app/src/main/res/font/lato_bold.ttf new file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@ @@ -267,7 +267,7 @@ android:layout_height="30sp" app:srcCompat="@drawable/baseline_close_16" android:id="@+id/btnClose" - android:layout_marginTop="15dp" + android:layout_marginTop="10dp" android:layout_marginEnd="15dp" android:layout_marginBottom="5dp" android:layout_marginStart="10dp" diff --git a/app/src/main/res/layout/fragment_map_libre.xml b/app/src/main/res/layout/fragment_map_libre.xml --- a/app/src/main/res/layout/fragment_map_libre.xml +++ b/app/src/main/res/layout/fragment_map_libre.xml @@ -21,56 +21,57 @@ android:layout_height="wrap_content" android:layout_marginStart="10dp" android:layout_marginEnd="10dp" + android:paddingTop="3dp" android:orientation="vertical" android:background="@drawable/bottom_sheet_background" android:elevation="8dp" - android:padding="10dp" + android:padding="13dp" app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior" app:behavior_hideable="true" app:behavior_peekHeight="4dp" android:clickable="true" android:focusable="true"> + @@ -126,11 +127,11 @@ android:layout_width="30sp" android:layout_height="30sp" app:srcCompat="@drawable/baseline_close_16" - android:tint="@color/red_darker" + app:tint="@color/red_darker" android:id="@+id/btnClose" android:layout_marginTop="10dp" - android:layout_marginEnd="10dp" - android:layout_marginBottom="10dp" + android:layout_marginEnd="15dp" + android:layout_marginBottom="5dp" android:layout_marginStart="10dp" android:layout_below="@id/directionsCardButton" android:layout_alignParentEnd="true" diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -102,7 +102,8 @@ À propos de l\'application Aucune ligne trouvée dans cette catégorie Aucune ligne ne correspond à la recherche - Ligne: %1$s + Ligne %1$s + Ligne %1$s, direction: Erreur interne inattendue, impossible d\'extraire les données depuis le site GTT/5T Favoris Carte 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 @@ -28,10 +28,12 @@ Nessuna linea in questa categoria Nessuna linea corrisponde alla ricerca Filtra per nome - Linea: %1$s + Linea %1$s Linee: %1$s + Linea %1$s, direzione: Fermata %1$s Scegli la fermata… + Matricola %1$s Nessun passaggio Nessun QR code trovato, prova ad usare un\'altra app Preferiti diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -48,7 +48,7 @@ Geen lijnen gevonden in deze categorie Geen lijnen gevonden met deze naam Bestemming: - Lijn: %1$s + Lijn %1$s Geen rooster gevonden Geen QR code gevonden, probeer het met een andere app Onverwachte interne fout, kan geen data halen van de GTT/5T website 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 @@ -44,6 +44,7 @@ #FFFFFF #000000 #1c1c1c + #3f3f3f @color/blue_mid_2 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 @@ -44,8 +44,10 @@ Destination: Lines: %1$s - Line: %1$s + Line %1$s + Line %1$s towards: Stop %1$s + Vehicle %1$s No timetable found No QR code found, try using another app to scan Unexpected internal error, cannot extract data from GTT/5T website diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -31,6 +31,8 @@ @style/PreferenceThemeOverlay + @color/grey_700 +