Differential D249 Diff 801 app/src/main/java/it/reyboz/bustorino/fragments/GeneralMapLibreFragment.kt
Changeset View
Changeset View
Standalone View
Standalone View
app/src/main/java/it/reyboz/bustorino/fragments/GeneralMapLibreFragment.kt
| Show All 23 Lines | |||||
| import android.content.Context.LOCATION_SERVICE | import android.content.Context.LOCATION_SERVICE | ||||
| import android.content.SharedPreferences | import android.content.SharedPreferences | ||||
| import android.content.res.ColorStateList | import android.content.res.ColorStateList | ||||
| import android.graphics.Color | import android.graphics.Color | ||||
| import android.location.Location | import android.location.Location | ||||
| import android.location.LocationManager | import android.location.LocationManager | ||||
| import android.os.Bundle | import android.os.Bundle | ||||
| import android.util.Log | import android.util.Log | ||||
| import android.view.Gravity | |||||
| import android.view.LayoutInflater | import android.view.LayoutInflater | ||||
| import android.view.View | import android.view.View | ||||
| import android.view.ViewGroup | import android.view.ViewGroup | ||||
| import android.view.animation.LinearInterpolator | import android.view.animation.LinearInterpolator | ||||
| import android.widget.ImageButton | import android.widget.ImageButton | ||||
| import android.widget.ImageView | import android.widget.ImageView | ||||
| import android.widget.TextView | import android.widget.TextView | ||||
| import android.widget.Toast | import android.widget.Toast | ||||
| ▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | protected val positionRequestResponder = registerForActivityResult( | ||||
| } | } | ||||
| ) | ) | ||||
| //Bottom sheet behavior in GeneralMapLibreFragment | //Bottom sheet behavior in GeneralMapLibreFragment | ||||
| protected var bottomLayout: ConstraintLayout? = null | protected var bottomLayout: ConstraintLayout? = null | ||||
| protected lateinit var stopTitleTextView: TextView | protected lateinit var stopTitleTextView: TextView | ||||
| protected lateinit var stopNumberTextView: TextView | protected lateinit var stopNumberTextView: TextView | ||||
| protected lateinit var linesPassingTextView: TextView | protected lateinit var linesPassingTextView: TextView | ||||
| protected lateinit var extraBottomTextView: TextView | protected lateinit var extraBottomTextView: TextView | ||||
| protected lateinit var linesBottomTextView: TextView | |||||
| protected lateinit var arrivalsCard: CardView | protected lateinit var arrivalsCard: CardView | ||||
| protected lateinit var directionsCard: CardView | protected lateinit var directionsCard: CardView | ||||
| protected lateinit var bottomrightImage: ImageView | protected lateinit var bottomrightImage: ImageView | ||||
| protected lateinit var locationComponent: LocationComponent | protected lateinit var locationComponent: LocationComponent | ||||
| protected lateinit var busPositionsIconButton: ImageButton | protected lateinit var busPositionsIconButton: ImageButton | ||||
| protected lateinit var vehicleIcon: ImageView | protected lateinit var vehicleIcon: ImageView | ||||
| protected var lastLocation : Location? = null | protected var lastLocation : Location? = null | ||||
| ▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | protected fun initBottomSheet(view: View){ | ||||
| val bottomSheet = view.findViewById<ConstraintLayout>(R.id.bottom_sheet) | val bottomSheet = view.findViewById<ConstraintLayout>(R.id.bottom_sheet) | ||||
| bottomLayout = bottomSheet | bottomLayout = bottomSheet | ||||
| stopTitleTextView = view.findViewById(R.id.stopTitleTextView) | stopTitleTextView = view.findViewById(R.id.stopTitleTextView) | ||||
| stopNumberTextView = view.findViewById(R.id.stopNumberTextView) | stopNumberTextView = view.findViewById(R.id.stopNumberTextView) | ||||
| linesPassingTextView = view.findViewById(R.id.descriptionTextView) | linesPassingTextView = view.findViewById(R.id.descriptionTextView) | ||||
| arrivalsCard = view.findViewById(R.id.arrivalsCardButton) | arrivalsCard = view.findViewById(R.id.arrivalsCardButton) | ||||
| directionsCard = view.findViewById(R.id.directionsCardButton) | directionsCard = view.findViewById(R.id.directionsCardButton) | ||||
| vehicleIcon = view.findViewById(R.id.vehicleIcon) | vehicleIcon = view.findViewById(R.id.vehicleIcon) | ||||
| linesBottomTextView = view.findViewById(R.id.linesBottomTextView) | |||||
| linesBottomTextView.text = getString(R.string.lines_fill, "") | |||||
| bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet) | bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet) | ||||
| bottomSheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN | bottomSheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN | ||||
| } | } | ||||
| override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||||
| super.onViewCreated(view, savedInstanceState) | super.onViewCreated(view, savedInstanceState) | ||||
| ▲ Show 20 Lines • Show All 395 Lines • ▼ Show 20 Lines | ) { | ||||
| directionsCard.setOnClickListener { | directionsCard.setOnClickListener { | ||||
| onDirectionsClick(pat?.code ?: "", veh) | onDirectionsClick(pat?.code ?: "", veh) | ||||
| } | } | ||||
| directionsCard.visibility = View.VISIBLE | directionsCard.visibility = View.VISIBLE | ||||
| bottomrightImage.setImageDrawable( | bottomrightImage.setImageDrawable( | ||||
| ResourcesCompat.getDrawable(resources, R.drawable.ic_magnifying_glass, activity?.theme) | ResourcesCompat.getDrawable(resources, R.drawable.ic_magnifying_glass, activity?.theme) | ||||
| ) | ) | ||||
| // if you change this, remember to change the color of the vehicleIcon | // if you change this, remember to change the color of the vehicleIcon | ||||
| val colorBlue = ResourcesCompat.getColor(resources, R.color.blue_500, activity?.theme) | val colorBlue = ResourcesCompat.getColor(resources, R.color.bus_marker_color_selected, activity?.theme) | ||||
| ViewCompat.setBackgroundTintList(directionsCard, ColorStateList.valueOf(colorBlue)) | ViewCompat.setBackgroundTintList(directionsCard, ColorStateList.valueOf(colorBlue)) | ||||
| linesPassingTextView.text = getString(R.string.vehicle_fill, data.posUpdate.vehicle) | linesPassingTextView.text = getString(R.string.vehicle_fill, data.posUpdate.vehicle) | ||||
| linesPassingTextView.gravity = Gravity.CENTER_VERTICAL | |||||
| linesBottomTextView.visibility = View.GONE | |||||
| arrivalsCard.visibility = View.GONE | arrivalsCard.visibility = View.GONE | ||||
| extraBottomTextView.text = getString(R.string.updated_fill, utils.unixTimestampToLocalTime(data.posUpdate.timestamp)) | extraBottomTextView.text = getString(R.string.updated_fill, utils.unixTimestampToLocalTime(data.posUpdate.timestamp)) | ||||
| extraBottomTextView.visibility = View.VISIBLE | extraBottomTextView.visibility = View.VISIBLE | ||||
| val update = data.posUpdate | val update = data.posUpdate | ||||
| val vehInfo = VehicleUtils.getTypeForLabel(update.vehicle) | val vehInfo = VehicleUtils.getTypeForLabel(update.vehicle) | ||||
| if(vehInfo == null){ | if(vehInfo == null){ | ||||
| vehicleIcon.visibility = View.GONE | vehicleIcon.visibility = View.GONE | ||||
| ▲ Show 20 Lines • Show All 148 Lines • ▼ Show 20 Lines | protected fun openStopInBottomSheet(stop: Stop){ | ||||
| //lay.findViewById<TextView>(R.id.stopTitleTextView).text ="${stop.ID} - ${stop.stopDefaultName}" | //lay.findViewById<TextView>(R.id.stopTitleTextView).text ="${stop.ID} - ${stop.stopDefaultName}" | ||||
| val stopName = stop.stopUserName ?: stop.stopDefaultName | val stopName = stop.stopUserName ?: stop.stopDefaultName | ||||
| stopTitleTextView.text = stopName//stop.stopDefaultName | stopTitleTextView.text = stopName//stop.stopDefaultName | ||||
| stopNumberTextView.text = getString(R.string.stop_fill,stop.ID) | stopNumberTextView.text = getString(R.string.stop_fill,stop.ID) | ||||
| stopTitleTextView.visibility = View.VISIBLE | stopTitleTextView.visibility = View.VISIBLE | ||||
| val string_show = if (stop.numRoutesStopping==0) "" | val string_show = if (stop.numRoutesStopping==0) "" | ||||
| else requireContext().getString(R.string.lines_fill, stop.routesThatStopHereToString()) | else stop.routesThatStopHereToString() //requireContext().getString(R.string.lines_fill, stop.routesThatStopHereToString()) | ||||
| linesPassingTextView.text = string_show | linesPassingTextView.text = string_show | ||||
| linesPassingTextView.visibility = View.VISIBLE | linesPassingTextView.visibility = View.VISIBLE | ||||
| linesPassingTextView.gravity = Gravity.TOP | |||||
| linesBottomTextView.visibility =View.VISIBLE | |||||
| //SET ON CLICK LISTENER | //SET ON CLICK LISTENER | ||||
| arrivalsCard.setOnClickListener{ | arrivalsCard.setOnClickListener{ | ||||
| fragmentListener?.requestArrivalsForStopID(stop.ID) | fragmentListener?.requestArrivalsForStopID(stop.ID) | ||||
| } | } | ||||
| arrivalsCard.visibility = View.VISIBLE | arrivalsCard.visibility = View.VISIBLE | ||||
| directionsCard.visibility = View.VISIBLE | directionsCard.visibility = View.VISIBLE | ||||
| directionsCard.setOnClickListener { | directionsCard.setOnClickListener { | ||||
| ViewUtils.openStopInOutsideApp(stop, context) | ViewUtils.openStopInOutsideApp(stop, context) | ||||
| } | } | ||||
| context?.let { | context?.let { | ||||
| val colorIcon = ViewUtils.getColorFromTheme(it, android.R.attr.colorAccent)//ResourcesCompat.getColor(resources,R.attr.colorAccent,activity?.theme) | val colorIcon = ViewUtils.getColorFromTheme(it, R.attr.colorAccent)//ResourcesCompat.getColor(resources,R.attr.colorAccent,activity?.theme) | ||||
| ViewCompat.setBackgroundTintList(directionsCard, ColorStateList.valueOf(colorIcon)) | ViewCompat.setBackgroundTintList(directionsCard, ColorStateList.valueOf(colorIcon)) | ||||
| } | } | ||||
| bottomrightImage.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.navigation_right, activity?.theme)) | bottomrightImage.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.navigation_right, activity?.theme)) | ||||
| vehicleIcon.visibility = View.GONE | vehicleIcon.visibility = View.GONE | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | protected fun addImagesStyle(style: Style){ | ||||
| style.addImage(BUS_SEL_IMAGE_ID, ResourcesCompat.getDrawable(resources, R.drawable.map_bus_position_icon_sel, activity?.theme)!!) | style.addImage(BUS_SEL_IMAGE_ID, ResourcesCompat.getDrawable(resources, R.drawable.map_bus_position_icon_sel, activity?.theme)!!) | ||||
| val polyIconArrow = ResourcesCompat.getDrawable(resources, R.drawable.arrow_up_box_fill, activity?.theme)!! | val polyIconArrow = ResourcesCompat.getDrawable(resources, R.drawable.arrow_up_box_fill, activity?.theme)!! | ||||
| style.addImage(POLY_ARROW, polyIconArrow) | style.addImage(POLY_ARROW, polyIconArrow) | ||||
| } | } | ||||
| protected fun initStopsLayer(style: Style, stopsFeatures: FeatureCollection?){ | protected fun initStopsLayer(style: Style, stopsFeatures: FeatureCollection?){ | ||||
| //determine default layer | //determine default layer | ||||
| var layerAbove = "" | |||||
| if (lastMapStyle == MapLibreUtils.STYLE_OSM_RASTER){ | val layerAbove = if (lastMapStyle == MapLibreUtils.STYLE_OSM_RASTER){ | ||||
| layerAbove = "osm-raster" | "osm-raster" | ||||
| } else if (lastMapStyle == MapLibreUtils.STYLE_VECTOR){ | } else// if (lastMapStyle == MapLibreUtils.STYLE_VERSATILES_ECLIPSE_JSON){ | ||||
| layerAbove = "symbol-transit-airfield" | "symbol-transit-airfield" | ||||
| /*} else { | |||||
| // | |||||
| "poi_park" | |||||
| } | } | ||||
| */ | |||||
| initStopsLayer(style, stopsFeatures, layerAbove) | initStopsLayer(style, stopsFeatures, layerAbove) | ||||
| } | } | ||||
| protected fun initStopsLayer(style: Style, stopsFeatures: FeatureCollection?, stopsLayerAbove: String){ | protected fun initStopsLayer(style: Style, stopsFeatures: FeatureCollection?, stopsLayerAbove: String){ | ||||
| stopsSource = GeoJsonSource(STOPS_SOURCE_ID,stopsFeatures ?: FeatureCollection.fromFeatures(ArrayList<Feature>())) | stopsSource = GeoJsonSource(STOPS_SOURCE_ID,stopsFeatures ?: FeatureCollection.fromFeatures(ArrayList<Feature>())) | ||||
| style.addSource(stopsSource) | style.addSource(stopsSource) | ||||
| ▲ Show 20 Lines • Show All 262 Lines • ▼ Show 20 Lines | companion object{ | ||||
| private const val PERM_LOC_COARSE = Manifest.permission.ACCESS_COARSE_LOCATION | private const val PERM_LOC_COARSE = Manifest.permission.ACCESS_COARSE_LOCATION | ||||
| private const val PERM_LOC_FINE = Manifest.permission.ACCESS_FINE_LOCATION | private const val PERM_LOC_FINE = Manifest.permission.ACCESS_FINE_LOCATION | ||||
| //TODO: this is hardcoded, make it modifiable by the user | //TODO: this is hardcoded, make it modifiable by the user | ||||
| protected const val MAX_DIST_KM = 90.0 | protected const val MAX_DIST_KM = 90.0 | ||||
| } | } | ||||
| } | } | ||||
| No newline at end of file | No newline at end of file | ||||
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register