Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/fragments/LinesViewModel.kt
Show All 17 Lines | class LinesViewModel(application: Application) : AndroidViewModel(application) { | ||||
private val oldRepo: OldDataRepository | private val oldRepo: OldDataRepository | ||||
//val patternsByRouteLiveData: LiveData<List<MatoPattern>> | //val patternsByRouteLiveData: LiveData<List<MatoPattern>> | ||||
private val routeIDToSearch = MutableLiveData<String>() | private val routeIDToSearch = MutableLiveData<String>() | ||||
private var lastShownPatternStops = ArrayList<String>() | private var lastShownPatternStops = ArrayList<String>() | ||||
val stopsForPatternLiveData = MutableLiveData<List<Stop>>() | val stopsForPatternLiveData = MutableLiveData<List<Stop>>() | ||||
val executor = Executors.newFixedThreadPool(2) | private val executor = Executors.newFixedThreadPool(2) | ||||
init { | init { | ||||
val gtfsDao = GtfsDatabase.getGtfsDatabase(application).gtfsDao() | val gtfsDao = GtfsDatabase.getGtfsDatabase(application).gtfsDao() | ||||
gtfsRepo = GtfsRepository(gtfsDao) | gtfsRepo = GtfsRepository(gtfsDao) | ||||
oldRepo = OldDataRepository(executor, NextGenDB.getInstance(application)) | oldRepo = OldDataRepository(executor, NextGenDB.getInstance(application)) | ||||
} | } | ||||
Show All 10 Lines | fun setRouteIDQuery(routeID: String){ | ||||
routeIDToSearch.value = routeID | routeIDToSearch.value = routeID | ||||
} | } | ||||
fun getRouteIDQueried(): String?{ | fun getRouteIDQueried(): String?{ | ||||
return routeIDToSearch.value | return routeIDToSearch.value | ||||
} | } | ||||
var shouldShowMessage = true | var shouldShowMessage = true | ||||
/** | |||||
* Find the | |||||
*/ | |||||
private fun requestStopsForGTFSIDs(gtfsIDs: List<String>){ | private fun requestStopsForGTFSIDs(gtfsIDs: List<String>){ | ||||
if (gtfsIDs.equals(lastShownPatternStops)){ | if (gtfsIDs.equals(lastShownPatternStops)){ | ||||
//nothing to do | //nothing to do | ||||
return | return | ||||
} | } | ||||
oldRepo.requestStopsWithGtfsIDs(gtfsIDs) { | oldRepo.requestStopsWithGtfsIDs(gtfsIDs) { | ||||
if (it.isSuccess) { | if (it.isSuccess) { | ||||
stopsForPatternLiveData.postValue(it.result) | stopsForPatternLiveData.postValue(it.result) | ||||
Show All 20 Lines | /*fun getLinesGTT(): MutableLiveData<List<GtfsRoute>> { | ||||
val routesData = MutableLiveData<List<GtfsRoute>>() | val routesData = MutableLiveData<List<GtfsRoute>>() | ||||
viewModelScope.launch { | viewModelScope.launch { | ||||
val routes=gtfsRepo.getLinesForFeed("gtt") | val routes=gtfsRepo.getLinesForFeed("gtt") | ||||
routesData.postValue(routes) | routesData.postValue(routes) | ||||
} | } | ||||
return routesData | return routesData | ||||
}*/ | }*/ | ||||
} | } | ||||
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