Differential D161 Diff 503 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
| Show All 14 Lines | BusTO - View Models components | ||||
| You should have received a copy of the GNU General Public License | You should have received a copy of the GNU General Public License | ||||
| along with this program. If not, see <http://www.gnu.org/licenses/>. | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
| */ | */ | ||||
| package it.reyboz.bustorino.viewmodels | package it.reyboz.bustorino.viewmodels | ||||
| import android.app.Application | import android.app.Application | ||||
| import android.util.Log | import android.util.Log | ||||
| import androidx.lifecycle.* | import androidx.lifecycle.* | ||||
| import androidx.work.OneTimeWorkRequest | |||||
| import com.android.volley.Response | import com.android.volley.Response | ||||
| import it.reyboz.bustorino.backend.NetworkVolleyManager | import it.reyboz.bustorino.backend.NetworkVolleyManager | ||||
| import it.reyboz.bustorino.backend.gtfs.LivePositionUpdate | import it.reyboz.bustorino.backend.gtfs.LivePositionUpdate | ||||
| import it.reyboz.bustorino.backend.gtfs.GtfsRtPositionsRequest | import it.reyboz.bustorino.backend.gtfs.GtfsRtPositionsRequest | ||||
| 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 | ||||
| ▲ Show 20 Lines • Show All 130 Lines • ▼ Show 20 Lines | class GtfsPositionsViewModel(application: Application): AndroidViewModel(application) { | ||||
| /* | /* | ||||
| There are two strategies for the queries, since we cannot query a bunch of tripIDs all together | There are two strategies for the queries, since we cannot query a bunch of tripIDs all together | ||||
| to Mato API -> we need to query each separately: | to Mato API -> we need to query each separately: | ||||
| 1 -> wait until they are all queried to insert in the DB | 1 -> wait until they are all queried to insert in the DB | ||||
| 2 -> after each request finishes, insert it into the DB | 2 -> after each request finishes, insert it into the DB | ||||
| Keep in mind that trips DO CHANGE often, and so do the Patterns | Keep in mind that trips DO CHANGE often, and so do the Patterns | ||||
| */ | */ | ||||
| fun downloadTripsFromMato(trips: List<String>): Boolean{ | fun downloadTripsFromMato(trips: List<String>): OneTimeWorkRequest?{ | ||||
| return MatoTripsDownloadWorker.downloadTripsFromMato(trips,getApplication(), DEBUG_TI) | return MatoTripsDownloadWorker.requestMatoTripsDownload(trips,getApplication(), "BusTO-MatoTripsDown") | ||||
| } | } | ||||
| private fun downloadMissingPatterns(routeIds: List<String>): Boolean{ | private fun downloadMissingPatterns(routeIds: List<String>): Boolean{ | ||||
| return MatoPatternsDownloadWorker.downloadPatternsForRoutes(routeIds, getApplication()) | return MatoPatternsDownloadWorker.downloadPatternsForRoutes(routeIds, getApplication()) | ||||
| } | } | ||||
| init { | init { | ||||
| Log.d(DEBUG_TI, "MapViewModel created") | Log.d(DEBUG_TI, "MapViewModel created") | ||||
| Show All 16 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