Differential D133 Diff 422 app/src/main/java/it/reyboz/bustorino/fragments/TestRealtimeGtfsFragment.kt
Changeset View
Changeset View
Standalone View
Standalone View
app/src/main/java/it/reyboz/bustorino/fragments/TestRealtimeGtfsFragment.kt
| package it.reyboz.bustorino.fragments | package it.reyboz.bustorino.fragments | ||||
| import android.os.Bundle | import android.os.Bundle | ||||
| import android.util.Log | import android.util.Log | ||||
| import androidx.fragment.app.Fragment | import androidx.fragment.app.Fragment | ||||
| 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.widget.Button | import android.widget.Button | ||||
| import android.widget.EditText | import android.widget.EditText | ||||
| import android.widget.TextView | import android.widget.TextView | ||||
| import androidx.fragment.app.viewModels | import androidx.fragment.app.viewModels | ||||
| import it.reyboz.bustorino.R | import it.reyboz.bustorino.R | ||||
| import it.reyboz.bustorino.backend.mato.MQTTMatoClient | import it.reyboz.bustorino.backend.mato.MQTTMatoClient | ||||
| import it.reyboz.bustorino.viewmodels.MQTTPositionsViewModel | import it.reyboz.bustorino.viewmodels.LivePositionsViewModel | ||||
| /** | /** | ||||
| * A simple [Fragment] subclass. | * A simple [Fragment] subclass. | ||||
| * Use the [TestRealtimeGtfsFragment.newInstance] factory method to | * Use the [TestRealtimeGtfsFragment.newInstance] factory method to | ||||
| * create an instance of this fragment. | * create an instance of this fragment. | ||||
| */ | */ | ||||
| class TestRealtimeGtfsFragment : Fragment() { | class TestRealtimeGtfsFragment : Fragment() { | ||||
| private lateinit var buttonLaunch: Button | private lateinit var buttonLaunch: Button | ||||
| private lateinit var messageTextView: TextView | private lateinit var messageTextView: TextView | ||||
| private var subscribed = false | private var subscribed = false | ||||
| private lateinit var mqttMatoClient: MQTTMatoClient | private lateinit var mqttMatoClient: MQTTMatoClient | ||||
| private lateinit var lineEditText: EditText | private lateinit var lineEditText: EditText | ||||
| private val mqttViewModel: MQTTPositionsViewModel by viewModels() | private val mqttViewModel: LivePositionsViewModel by viewModels() | ||||
| /*private val requestListener = object: GtfsRtPositionsRequest.Companion.RequestListener{ | /*private val requestListener = object: GtfsRtPositionsRequest.Companion.RequestListener{ | ||||
| override fun onResponse(response: ArrayList<GtfsPositionUpdate>?) { | override fun onResponse(response: ArrayList<GtfsPositionUpdate>?) { | ||||
| if (response == null) return | if (response == null) return | ||||
| if (response.size == 0) { | if (response.size == 0) { | ||||
| messageTextView.text = "No entities in the message" | messageTextView.text = "No entities in the message" | ||||
| return | return | ||||
| ▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | ): View? { | ||||
| Response.ErrorListener { Toast.makeText(cont, "Error: ${it.message}",Toast.LENGTH_SHORT) }, | Response.ErrorListener { Toast.makeText(cont, "Error: ${it.message}",Toast.LENGTH_SHORT) }, | ||||
| requestListener | requestListener | ||||
| ) | ) | ||||
| NetworkVolleyManager.getInstance(cont).addToRequestQueue(req) | NetworkVolleyManager.getInstance(cont).addToRequestQueue(req) | ||||
| */ | */ | ||||
| subscribed = if(subscribed){ | subscribed = if(subscribed){ | ||||
| //mqttMatoClient.desubscribe(listener) | //mqttMatoClient.desubscribe(listener) | ||||
| mqttViewModel.stopPositionsListening() | mqttViewModel.stopMatoUpdates() | ||||
| buttonLaunch.text="Start" | buttonLaunch.text="Start" | ||||
| false | false | ||||
| } else{ | } else{ | ||||
| //mqttMatoClient.startAndSubscribe(lineEditText.text.trim().toString(), listener) | //mqttMatoClient.startAndSubscribe(lineEditText.text.trim().toString(), listener) | ||||
| mqttViewModel.requestPosUpdates(lineEditText.text.trim().toString()) | mqttViewModel.requestMatoPosUpdates(lineEditText.text.trim().toString()) | ||||
| buttonLaunch.text="Stop" | buttonLaunch.text="Stop" | ||||
| true | true | ||||
| } | } | ||||
| } | } | ||||
| Show All 9 Lines | companion object { | ||||
| * @return A new instance of fragment TestRealtimeGtfsFragment. | * @return A new instance of fragment TestRealtimeGtfsFragment. | ||||
| */ | */ | ||||
| @JvmStatic | @JvmStatic | ||||
| fun newInstance() = | fun newInstance() = | ||||
| TestRealtimeGtfsFragment().apply { | TestRealtimeGtfsFragment().apply { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| 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