Page MenuHomeGitPull.it

D248.1792522667.diff
No OneTemporary

Authored By
Unknown
Size
8 KB
Referenced Files
None
Subscribers
None

D248.1792522667.diff

diff --git a/app/src/main/java/it/reyboz/bustorino/backend/VehicleUtils.kt b/app/src/main/java/it/reyboz/bustorino/backend/VehicleUtils.kt
--- a/app/src/main/java/it/reyboz/bustorino/backend/VehicleUtils.kt
+++ b/app/src/main/java/it/reyboz/bustorino/backend/VehicleUtils.kt
@@ -46,8 +46,8 @@
VehicleClassInfo(9000, "BYD K9", "E-Bus", 9120, 9121),
VehicleClassInfo(9200, "Citymood", "Bus", 9200, 9251),
VehicleClassInfo(9200, "Citymood", "Bus", 9252, 9261),
- VehicleClassInfo(9400, "E-Way", "E-Bus", 9400, 9599),
- VehicleClassInfo(9600, "E-Way 18m", "E-Bus", 9600, 9699)
+ VehicleClassInfo(9400, "Iveco E-Way", "E-Bus", 9400, 9599),
+ VehicleClassInfo(9600, "Iveco E-Way 18m", "E-Bus", 9600, 9699)
)
fun getTypeForLabel(label: String): VehicleClassInfo? {
diff --git a/app/src/main/java/it/reyboz/bustorino/data/MatoTripsDownloadWorker.kt b/app/src/main/java/it/reyboz/bustorino/data/MatoTripsDownloadWorker.kt
--- a/app/src/main/java/it/reyboz/bustorino/data/MatoTripsDownloadWorker.kt
+++ b/app/src/main/java/it/reyboz/bustorino/data/MatoTripsDownloadWorker.kt
@@ -28,6 +28,7 @@
class MatoTripsDownloadWorker(appContext: Context, workerParams: WorkerParameters)
: CoroutineWorker(appContext, workerParams) {
+ private val DOWNLOAD_STEP = 50
override suspend fun doWork(): Result {
@@ -41,7 +42,7 @@
var i = 0
var totDown = 0
while (i <numTrips){
- val res = downloadGtfsTrips(tripsList.copyOfRange(i, min(i+100, numTrips)))
+ val res = downloadGtfsTrips(tripsList.copyOfRange(i, min(i+DOWNLOAD_STEP, numTrips)))
if (res < 0){
return Result.failure();
}
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
@@ -35,7 +35,6 @@
import android.view.animation.LinearInterpolator
import android.widget.ImageButton
import android.widget.ImageView
-import android.widget.RelativeLayout
import android.widget.TextView
import android.widget.Toast
import androidx.activity.result.ActivityResultCallback
@@ -47,6 +46,7 @@
import androidx.core.view.ViewCompat
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
+import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.gson.JsonObject
@@ -69,6 +69,7 @@
import it.reyboz.bustorino.util.ViewUtils
import it.reyboz.bustorino.viewmodels.LivePositionsViewModel
import it.reyboz.bustorino.viewmodels.MapStateViewModel
+import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.maplibre.android.MapLibre
@@ -119,7 +120,7 @@
protected lateinit var bottomSheetBehavior: BottomSheetBehavior<ConstraintLayout>
protected var locationEngine: MapLibreLocationEngine? = null
- protected lateinit var locationProvider: FusedNativeLocationProvider
+ protected var locationProvider: FusedNativeLocationProvider? = null
protected var shownToastNoPosition = false
protected var locationEnabledOnDevice = true
@@ -185,8 +186,9 @@
protected val animatorsByVeh = HashMap<String, ValueAnimator>()
protected var vehShowing = ""
protected var lastUpdateTime:Long = -2
+ protected var jobUpdate: Job? = null
- private val lifecycleOwnerLiveData = getViewLifecycleOwnerLiveData()
+ //private val lifecycleOwnerLiveData = viewLifecycleOwnerLiveData
//extra items to use the LibreMap
@@ -253,6 +255,7 @@
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
+ //TODO: Re-create map when this preference changes
lastMapStyle = PreferencesHolder.getMapLibreStyleFile(requireContext())
Log.d(DEBUG_TAG, "onCreateView lastMapStyle: $lastMapStyle")
return super.onCreateView(inflater, container, savedInstanceState)
@@ -311,6 +314,7 @@
}
override fun onStop() {
+ locationProvider?.removeListener(deviceLocationStatusListener)
mapView?.onStop()
super.onStop()
}
@@ -323,7 +327,6 @@
override fun onDestroyView() {
bottomLayout = null
- locationProvider.removeListener(deviceLocationStatusListener)
mapInitialized = false
locationInitialized = false
super.onDestroyView()
@@ -478,9 +481,10 @@
mStyle?.let{ style ->
locationComponent = map.locationComponent
- locationProvider = FusedNativeLocationProvider(context)
- locationProvider.addListener(deviceLocationStatusListener)
- locationEngine = MapLibreLocationEngine(locationProvider)
+ val locProvider = FusedNativeLocationProvider(context)
+ locProvider.addListener(deviceLocationStatusListener)
+ locationEngine = MapLibreLocationEngine(locProvider)
+ locationProvider = locProvider
val options = LocationComponentActivationOptions.builder(context, style)
.useDefaultLocationEngine(false)
.locationEngine(locationEngine)
@@ -709,20 +713,30 @@
/**
* Update the bus positions displayed on the map, from the existing data
*
- * @param forced If true, forces immediate update ignoring the 60ms throttle
+ * @param forced If true, forces immediate update ignoring the 100ms throttle
*/
protected fun updatePositionsIcons(forced: Boolean) {
// Avoid frequent updates - throttle to max once per 60ms
val currentTime = System.currentTimeMillis()
- if (!forced && currentTime - lastUpdateTime < 60) {
+ val isStarted = (lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED))
+ if(forced){
+ // if we're running a forced update, cancel the pending one
+ jobUpdate?.cancel()
+ }
+ else if (currentTime - lastUpdateTime < 100) {
// Schedule delayed update
- if(lifecycleOwnerLiveData.value != null)
- viewLifecycleOwner.lifecycleScope.launch {
- delay(200.milliseconds)
- updatePositionsIcons(forced)
+ if(viewLifecycleOwnerLiveData.value != null) {
+ jobUpdate?.cancel()
+ jobUpdate = viewLifecycleOwner.lifecycleScope.launch {
+ delay(100.milliseconds)
+ updatePositionsIcons(false)
}
+ }
return
}
+ if(!isStarted){
+ Log.w(DEBUG_TAG, "fragment is not started, ")
+ }
val busFeatures = ArrayList<Feature>()
val selectedBusFeatures = ArrayList<Feature>()
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
@@ -46,6 +46,7 @@
import kotlin.collections.HashSet
import androidx.core.content.edit
import androidx.lifecycle.MutableLiveData
+import kotlin.text.contains
typealias FullPositionUpdatesMap = HashMap<String, Pair<LivePositionUpdate, TripAndPatternWithStops?>>
typealias FullPositionUpdate = Pair<LivePositionUpdate, TripAndPatternWithStops?>
@@ -177,7 +178,9 @@
//find the trip IDs in the updates
private val tripsIDsInUpdates = positionsToBeMatchedLiveData.map { it ->
//Log.d(DEBUG_TI, "Updates map has keys ${upMap.keys}")
- it.map { pos -> "gtt:"+pos.tripID }
+ it.map { pos -> "gtt:"+pos.tripID }.filter{ s->
+ !(s.contains("null") || s.trim() =="gtt:")
+ }
}
// get the trip IDs in the DB
@@ -191,7 +194,9 @@
val tripNames=tripswithPatterns.map { twp-> twp.trip.tripID }
Log.i(DEBUG_TI, "Have ${tripswithPatterns.size} trips in the DB")
if (tripsIDsInUpdates.value!=null)
- return@map tripsIDsInUpdates.value!!.filter { !(tripNames.contains(it) || it.contains("null"))}
+ return@map tripsIDsInUpdates.value!!.filter { !(
+ tripNames.contains(it) || it.contains("null") || it =="gtt:"
+ )}.distinct()
else {
Log.e(DEBUG_TI,"Got results for gtfsTripsInDB but not tripsIDsInUpdates??")
return@map ArrayList<String>()

File Metadata

Mime Type
text/plain
Expires
Tue, Oct 20, 20:57 (12 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2258415
Default Alt Text
D248.1792522667.diff (8 KB)

Event Timeline