Differential D133 Diff 422 app/src/main/java/it/reyboz/bustorino/viewmodels/GtfsPositionsViewModel.kt
Changeset View
Changeset View
Standalone View
Standalone View
app/src/main/java/it/reyboz/bustorino/viewmodels/GtfsPositionsViewModel.kt
- This file was moved from app/src/main/java/it/reyboz/bustorino/viewmodels/GTFSPositionsViewModel.kt.
| Show All 26 Lines | |||||
| import it.reyboz.bustorino.data.* | import it.reyboz.bustorino.data.* | ||||
| import it.reyboz.bustorino.data.gtfs.TripAndPatternWithStops | import it.reyboz.bustorino.data.gtfs.TripAndPatternWithStops | ||||
| import kotlinx.coroutines.delay | import kotlinx.coroutines.delay | ||||
| import kotlinx.coroutines.launch | import kotlinx.coroutines.launch | ||||
| /** | /** | ||||
| * View Model for the map. For containing the stops, the trips and whatever | * View Model for the map. For containing the stops, the trips and whatever | ||||
| */ | */ | ||||
| class GTFSPositionsViewModel(application: Application): AndroidViewModel(application) { | class GtfsPositionsViewModel(application: Application): AndroidViewModel(application) { | ||||
| private val gtfsRepo = GtfsRepository(application) | private val gtfsRepo = GtfsRepository(application) | ||||
| private val netVolleyManager = NetworkVolleyManager.getInstance(application) | private val netVolleyManager = NetworkVolleyManager.getInstance(application) | ||||
| val positionsLiveData = MutableLiveData<ArrayList<LivePositionUpdate>>() | val positionsLiveData = MutableLiveData<ArrayList<LivePositionUpdate>>() | ||||
| private val positionsRequestRunning = MutableLiveData<Boolean>() | private val positionsRequestRunning = MutableLiveData<Boolean>() | ||||
| Show All 13 Lines | private val positionRequestListener = object: GtfsRtPositionsRequest.Companion.RequestListener{ | ||||
| } | } | ||||
| } | } | ||||
| //whatever the result, launch again the update TODO | //whatever the result, launch again the update TODO | ||||
| } | } | ||||
| } | } | ||||
| private val positionRequestErrorListener = Response.ErrorListener { | private val positionRequestErrorListener = Response.ErrorListener { | ||||
| //error listener, it->VolleyError | |||||
| Log.e(DEBUG_TI, "Could not download the update, error:\n"+it.stackTrace) | Log.e(DEBUG_TI, "Could not download the update, error:\n"+it.stackTrace) | ||||
| //TODO: launch again if needed | |||||
| } | } | ||||
| fun requestUpdates(){ | fun requestUpdates(){ | ||||
| if(positionsRequestRunning.value == null || !positionsRequestRunning.value!!) { | if(positionsRequestRunning.value == null || !positionsRequestRunning.value!!) { | ||||
| val request = GtfsRtPositionsRequest(positionRequestErrorListener, positionRequestListener) | val request = GtfsRtPositionsRequest(positionRequestErrorListener, positionRequestListener) | ||||
| netVolleyManager.requestQueue.add(request) | netVolleyManager.requestQueue.add(request) | ||||
| Log.i(DEBUG_TI, "Requested GTFS realtime position updates") | Log.i(DEBUG_TI, "Requested GTFS realtime position updates") | ||||
| positionsRequestRunning.value = true | positionsRequestRunning.value = true | ||||
| ▲ Show 20 Lines • Show All 121 Lines • ▼ Show 20 Lines | class GtfsPositionsViewModel(application: Application): AndroidViewModel(application) { | ||||
| companion object{ | companion object{ | ||||
| private const val DEBUG_TI="BusTO-GTFSRTViewModel" | private const val DEBUG_TI="BusTO-GTFSRTViewModel" | ||||
| const val DEFAULT_DELAY_REQUESTS: Long=4000 | const val DEFAULT_DELAY_REQUESTS: Long=4000 | ||||
| } | } | ||||
| } | } | ||||
| 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