Page MenuHomeGitPull.it

D223.1781404479.diff
No OneTemporary

Authored By
Unknown
Size
21 KB
Referenced Files
None
Subscribers
None

D223.1781404479.diff

diff --git a/app/src/main/java/it/reyboz/bustorino/backend/Palina.java b/app/src/main/java/it/reyboz/bustorino/backend/Palina.java
--- a/app/src/main/java/it/reyboz/bustorino/backend/Palina.java
+++ b/app/src/main/java/it/reyboz/bustorino/backend/Palina.java
@@ -42,7 +42,7 @@
* Not in a way that makes sense and keeps the code readable, at least.
*/
public class Palina extends Stop implements Parcelable {
- private ArrayList<Route> routes = new ArrayList<>();
+ private ArrayList<Route> routes = new ArrayList<>(); // the routes with arrival times
private boolean routesModified = false;
private Passaggio.Source allSource = null;
@@ -52,7 +52,7 @@
public Palina(Stop s){
super(s.ID,s.getStopDefaultName(),s.getStopUserName(),s.location,s.type,
- s.getRoutesThatStopHere(),s.getLatitude(),s.getLongitude(), null);
+ s.getRoutesThatStopHere(),s.getLatitude(),s.getLongitude(), s.gtfsID);
}
public Palina(@NonNull String ID, @Nullable String name, @Nullable String userName,
@@ -111,6 +111,21 @@
routes = new ArrayList<>(routeList);
}
+ /**
+ * Remove all arrivals from this Palina
+ */
+ public void clearRoutes(){
+ routes.clear();
+ }
+
+ /**
+ * Check how many routes (from arrival times) we have
+ * @return the number of routes
+ */
+ public int getNumRoutesWithArrivals(){
+ return routes.size();
+ }
+
@Nullable
@Override
protected String buildRoutesString() {
diff --git a/app/src/main/java/it/reyboz/bustorino/backend/mato/MatoAPIFetcher.kt b/app/src/main/java/it/reyboz/bustorino/backend/mato/MatoAPIFetcher.kt
--- a/app/src/main/java/it/reyboz/bustorino/backend/mato/MatoAPIFetcher.kt
+++ b/app/src/main/java/it/reyboz/bustorino/backend/mato/MatoAPIFetcher.kt
@@ -57,10 +57,10 @@
var numPassaggi = 0
var trials = 0
val numDepartures = 8
- while (numPassaggi < minNumPassaggi && trials < 2) {
+ while (numPassaggi < minNumPassaggi && trials <5) {
//numDepartures+=2
- numMinutes += 20
+ numMinutes *= 2 //duplicate time
val future = RequestFuture.newFuture<Palina>()
val request = MapiArrivalRequest(stopID, now, numMinutes * 60, numDepartures, res, future, future)
if (appContext == null || res == null) {
@@ -79,7 +79,7 @@
Log.d(DEBUG_TAG, "route " + r.gtfsId + " has " + r.passaggi.size + " passaggi: "+ r.passaggiToString)
}*/
palina = palinaResult
- numPassaggi = palina.minNumberOfPassages
+ numPassaggi = palina.totalNumberOfPassages
} else{
Log.d(DEBUG_TAG, "Result palina is null")
}
@@ -109,7 +109,7 @@
const val VOLLEY_TAG = "MatoAPIFetcher"
const val DEBUG_TAG = "BusTO:MatoAPIFetcher"
- const val DEF_MIN_NUMPASSAGGI=2
+ const val DEF_MIN_NUMPASSAGGI = 5
val REQ_PARAMETERS = mapOf(
"Content-Type" to "application/json; charset=utf-8",
diff --git a/app/src/main/java/it/reyboz/bustorino/fragments/ArrivalsFragment.kt b/app/src/main/java/it/reyboz/bustorino/fragments/ArrivalsFragment.kt
--- a/app/src/main/java/it/reyboz/bustorino/fragments/ArrivalsFragment.kt
+++ b/app/src/main/java/it/reyboz/bustorino/fragments/ArrivalsFragment.kt
@@ -66,7 +66,7 @@
//Views
protected lateinit var addToFavorites: ImageButton
protected lateinit var openInMapButton: ImageButton
- protected lateinit var timesSourceTextView: TextView
+ protected lateinit var arrivalsSourceTextView: TextView
private lateinit var messageTextView: TextView
private lateinit var preMessageTextView: TextView // this hold the "Arrivals at: " text
protected lateinit var arrivalsRecyclerView: RecyclerView
@@ -187,12 +187,12 @@
manager.orientation
)
arrivalsRecyclerView.addItemDecoration(mDividerItemDecoration)
- timesSourceTextView = root.findViewById(R.id.timesSourceTextView)
- timesSourceTextView.setOnLongClickListener { view: View? ->
+ arrivalsSourceTextView = root.findViewById(R.id.timesSourceTextView)
+ arrivalsSourceTextView.setOnLongClickListener { view: View? ->
if (!fetchersChangeRequestPending) {
rotateFetchers()
//Show we are changing provider
- timesSourceTextView.setText(R.string.arrival_source_changing)
+ arrivalsSourceTextView.setText(R.string.arrival_source_changing)
//mListener.requestArrivalsForStopID(stopID)
requestArrivalsForTheFragment()
@@ -201,7 +201,7 @@
}
false
}
- timesSourceTextView.setOnClickListener(View.OnClickListener { view: View? ->
+ arrivalsSourceTextView.setOnClickListener(View.OnClickListener { view: View? ->
Toast.makeText(
context, R.string.change_arrivals_source_message, Toast.LENGTH_SHORT
)
@@ -255,26 +255,45 @@
*/
-
+ arrivalsViewModel.arrivalsRequestRunningLiveData.observe(viewLifecycleOwner, { running ->
+ //UI CHANGES TO APPLY WHEN THE REQUEST IS RUNNING
+ if(running){
+ //different way of setting this flag
+ if(lastUpdatedPalina == null || lastUpdatedPalina?.totalNumberOfPassages==0) {
+ showLoadingMessageForFirstTime()
+ }
+ mListener.toggleSpinner(true)
+ } else{
+ //stopped running, we can show the palina
+ //val uname = lastUpdatedPalina?.stopDisplayName
+ if (lastUpdatedPalina == null || lastUpdatedPalina?.numRoutesWithArrivals == 0) {
+ //no passages and result is not valid
+ setUIForNoStopFound()
+ }
+ mListener.toggleSpinner(false)
+ }
+ })
arrivalsViewModel.palinaLiveData.observe(viewLifecycleOwner){
mListener.toggleSpinner(false)
- Log.d(DEBUG_TAG, "New result palina observed, has coords: ${it.hasCoords()}")
- if(arrivalsViewModel.resultLiveData.value==Fetcher.Result.OK){
- //the result is true
- changeUIFirstSearchActive(false)
+ Log.d(DEBUG_TAG, "New result palina observed, has coords: ${it.hasCoords()}, title ${it?.stopDisplayName}, number of passages: ${it.totalNumberOfPassages}")
+
+ val palinaIsValid = it!=null && (it.totalNumberOfPassages>0 || it.stopDisplayName!=null)
+ if (palinaIsValid){
updateFragmentData(it)
- } else{
- progressBar.visibility=View.INVISIBLE
- // Avoid showing this ugly message if we have found the stop, clearly it exists but GTT doesn't provide arrival times
- if (stopName==null)
- loadingMessageTextView.text = getString(R.string.no_bus_stop_have_this_name)
- else
- loadingMessageTextView.text = getString(R.string.no_arrivals_stop)
+ }
+ if(arrivalsViewModel.arrivalsRequestRunningLiveData.value ==false) {
+ //finished loading
+ if (palinaIsValid) {
+ //the result is true
+ hideLoadingMessageAndShowResults()
+ } else {
+ setUIForNoStopFound()
+ }
}
}
-
+ // this is only for the progress
arrivalsViewModel.sourcesLiveData.observe(viewLifecycleOwner){
Log.d(DEBUG_TAG, "Using arrivals source: $it")
val srcString = getDisplayArrivalsSource(it,requireContext())
@@ -282,24 +301,25 @@
}
arrivalsViewModel.resultLiveData.observe(viewLifecycleOwner){res ->
+ val src = arrivalsViewModel.sourcesLiveData.value
when (res) {
Fetcher.Result.OK -> {}
- Fetcher.Result.CLIENT_OFFLINE -> showToastMessage(R.string.network_error, true)
+ Fetcher.Result.CLIENT_OFFLINE -> showFetcherMessage(R.string.network_error, src)
Fetcher.Result.SERVER_ERROR -> {
if (utils.isConnected(context)) {
- showToastMessage(R.string.parsing_error, true)
+ showFetcherMessage(R.string.parsing_error, src)
} else {
- showToastMessage(R.string.network_error, true)
+ showFetcherMessage(R.string.network_error, src)
}
- showToastMessage(R.string.internal_error,true)
+ showFetcherMessage(R.string.internal_error,src)
}
- Fetcher.Result.PARSER_ERROR -> showShortToast(R.string.internal_error)
- Fetcher.Result.QUERY_TOO_SHORT -> showShortToast(R.string.query_too_short)
- Fetcher.Result.EMPTY_RESULT_SET -> showShortToast(R.string.no_arrivals_stop)
+ Fetcher.Result.PARSER_ERROR -> showFetcherMessage(R.string.internal_error, src)
+ Fetcher.Result.QUERY_TOO_SHORT -> showFetcherMessage(R.string.query_too_short, src)
+ Fetcher.Result.EMPTY_RESULT_SET -> showFetcherMessage(R.string.no_arrivals_stop, src)
- Fetcher.Result.NOT_FOUND -> showShortToast(R.string.no_bus_stop_have_this_name)
- else -> showShortToast(R.string.internal_error)
+ Fetcher.Result.NOT_FOUND -> showFetcherMessage(R.string.no_bus_stop_have_this_name, src)
+ else -> showFetcherMessage(R.string.internal_error, src)
}
}
return root
@@ -308,8 +328,18 @@
private fun showShortToast(id: Int) = showToastMessage(id,true)
+ private fun showFetcherMessage(id: Int, source: Source?){
+ val srcString = source?.let{ getDisplayArrivalsSource(it,requireContext())}
+ if (srcString!=null){
+ Toast.makeText(requireContext(), id, Toast.LENGTH_SHORT).show()
+ } else{
+ val message = getString(id)
+
+ Toast.makeText(requireContext(), "$srcString : $message", Toast.LENGTH_SHORT).show()
+ }
+ }
- private fun changeUIFirstSearchActive(yes: Boolean){
+ /*private fun changeUIFirstSearchActive(yes: Boolean){
if(yes){
resultsLayout.visibility = View.GONE
progressBar.visibility = View.VISIBLE
@@ -321,18 +351,32 @@
}
}
+ */
+ private fun showLoadingMessageForFirstTime(){
+ resultsLayout.visibility = View.GONE
+ progressBar.visibility = View.VISIBLE
+ loadingMessageTextView.visibility = View.VISIBLE
+ }
+ private fun hideLoadingMessageAndShowResults(){
+ resultsLayout.visibility = View.VISIBLE
+ progressBar.visibility = View.GONE
+ loadingMessageTextView.visibility = View.GONE
+ }
+
+ private fun setUIForNoStopFound(){
+ progressBar.visibility=View.INVISIBLE
+ // Avoid showing this ugly message if we have found the stop, clearly it exists but GTT doesn't provide arrival times
+ if (stopName==null)
+ loadingMessageTextView.text = getString(R.string.no_bus_stop_have_this_name)
+ else
+ loadingMessageTextView.text = getString(R.string.no_arrivals_stop)
+ }
+
override fun onResume() {
super.onResume()
val loaderManager = loaderManager
Log.d(DEBUG_TAG, "OnResume, justCreated $justCreated, lastUpdatedPalina is: $lastUpdatedPalina")
- /*if(needUpdateOnAttach){
- updateFragmentData(null);
- needUpdateOnAttach=false;
- }*/
- /*if(lastUpdatedPalina!=null){
- updateFragmentData(null);
- showArrivalsSources(lastUpdatedPalina);
- }*/
+
mListener.readyGUIfor(FragmentKind.ARRIVALS)
//fix bug when the list adapter is null
@@ -350,7 +394,7 @@
} else {
//start first search
requestArrivalsForTheFragment()
- changeUIFirstSearchActive(true)
+ showLoadingMessageForFirstTime()
justCreated = false
}
//start the loader
@@ -421,15 +465,6 @@
setOption(requireContext(), OPTION_SHOW_LEGEND, false)
}
- /*val currentFetchersAsArray: Array<ArrivalsFetcher?>
- get() {
- val arr = arrayOfNulls<ArrivalsFetcher>(fetchers!!.size)
- fetchers!!.toArray<ArrivalsFetcher>(arr)
- return arr
- }
-
- */
-
fun getCurrentFetchersAsArray(): Array<out ArrivalsFetcher?> {
val r= fetchers.toTypedArray()
//?: emptyArray<ArrivalsFetcher>()
@@ -462,7 +497,11 @@
}
val adapter = PalinaAdapter(context, lastUpdatedPalina, palinaClickListener, true)
- showArrivalsSources(lastUpdatedPalina!!)
+ p?.let {
+ //only update the sources if we have actual passaggi
+ if (it.numRoutesWithArrivals >0)
+ showArrivalsSources(lastUpdatedPalina!!)
+ }
resetListAdapter(adapter)
lastUpdatedPalina?.let{ pal ->
openInMapButton.setOnClickListener {
@@ -508,13 +547,13 @@
val updatedFetchers = adjustFetchersToSource(source)
if (!updatedFetchers) Log.w(DEBUG_TAG, "Tried to update the source fetcher but it didn't work")
val base_message = getString(R.string.times_source_fmt, source_txt)
- timesSourceTextView.text = base_message
- timesSourceTextView.visibility = View.VISIBLE
+ arrivalsSourceTextView.text = base_message
+ arrivalsSourceTextView.visibility = View.VISIBLE
if (p.totalNumberOfPassages > 0) {
- timesSourceTextView.visibility = View.VISIBLE
+ arrivalsSourceTextView.visibility = View.VISIBLE
} else {
- timesSourceTextView.visibility = View.INVISIBLE
+ arrivalsSourceTextView.visibility = View.INVISIBLE
}
fetchersChangeRequestPending = false
}
@@ -716,7 +755,7 @@
override fun onDestroyView() {
//arrivalsRecyclerView = null
if (arguments != null) {
- requireArguments().putString(SOURCES_TEXT, timesSourceTextView.text.toString())
+ requireArguments().putString(SOURCES_TEXT, arrivalsSourceTextView.text.toString())
requireArguments().putString(MESSAGE_TEXT_VIEW, messageTextView.text.toString())
}
super.onDestroyView()
@@ -738,8 +777,7 @@
fun requestArrivalsForTheFragment(){
// Run with previous fetchers
- //fragment.getCurrentFetchers().toArray()
- //AsyncArrivalsSearcher(, getCurrentFetchersAsArray(), context).execute(stopID)
+
context?.let {
mListener.toggleSpinner(true)
val fetcherSources = fetchers.map { f-> f?.sourceForFetcher?.name ?: "" }
diff --git a/app/src/main/java/it/reyboz/bustorino/viewmodels/ArrivalsViewModel.kt b/app/src/main/java/it/reyboz/bustorino/viewmodels/ArrivalsViewModel.kt
--- a/app/src/main/java/it/reyboz/bustorino/viewmodels/ArrivalsViewModel.kt
+++ b/app/src/main/java/it/reyboz/bustorino/viewmodels/ArrivalsViewModel.kt
@@ -25,7 +25,7 @@
val palinaLiveData = MediatorLiveData<Palina>()
val sourcesLiveData = MediatorLiveData<Passaggio.Source>()
- val resultLiveData = MediatorLiveData<Fetcher.Result>()
+ val resultLiveData = MutableLiveData<Fetcher.Result>()
val currentFetchers = MediatorLiveData<List<ArrivalsFetcher>>()
@@ -35,6 +35,9 @@
private var stopIdRequested = ""
private val stopFromDB = MutableLiveData<Stop>()
+
+ val arrivalsRequestRunningLiveData = MutableLiveData(false)
+
private val oldRepoStopCallback = OldDataRepository.Callback<List<Stop>>{ stopListRes ->
if(stopIdRequested.isEmpty()) return@Callback
@@ -53,23 +56,33 @@
init {
appContext = application.applicationContext
+
palinaLiveData.addSource(stopFromDB){
s ->
val hasSource = palinaLiveData.value?.passaggiSourceIfAny
Log.d(DEBUG_TAG, "Have current palina ${palinaLiveData.value!=null}, source passaggi $hasSource, new incoming stop $s from database")
- val newp = Palina.mergePaline(palinaLiveData.value, Palina(s))
- newp?.let { palinaLiveData.value = it }
+ val newp = if(palinaLiveData.value == null) Palina(s) else Palina.mergePaline(palinaLiveData.value, Palina(s))
+ Log.d(DEBUG_TAG, "Merged palina: $newp, num passages: ${newp?.totalNumberOfPassages}, has coords: ${newp?.hasCoords()}")
+ newp?.let { pal -> palinaLiveData.postValue(pal) }
}
+
}
+ fun clearPalinaArrivals(palina: Palina) : Palina{
+ palina.clearRoutes()
+ return palina
+ }
fun requestArrivalsForStop(stopId: String, fetchers: List<ArrivalsFetcher>){
val context = appContext //application.applicationContext
currentFetchers.value = fetchers
+ palinaLiveData.value?.let{
+ palinaLiveData.value = clearPalinaArrivals(it)
+ }
//request stop from the DB
stopIdRequested = stopId
oldRepo.requestStopsWithGtfsIDs(listOf("gtt:$stopId"), oldRepoStopCallback)
-
+ arrivalsRequestRunningLiveData.value = true
viewModelScope.launch(Dispatchers.IO){
runArrivalsFetching(stopId, fetchers, context)
}
@@ -84,6 +97,7 @@
if (fetchers.isEmpty()) {
//do nothing
+ arrivalsRequestRunningLiveData.postValue(false)
return
}
@@ -166,7 +180,7 @@
// Se abbiamo un risultato OK, restituiamo la palina
if (resultRef.get() == Fetcher.Result.OK) {
setResultAndPalinaFromFetchers(palina, Fetcher.Result.OK)
- //TODO: Rotate the fetchers appropriately
+
return
}
//end Fetchers loop
@@ -179,10 +193,13 @@
resultPalina?.let {
setResultAndPalinaFromFetchers(it, resultRef.get())
}
-
+ //in ogni caso, settiamo la richiesta come conclusa
+ arrivalsRequestRunningLiveData.postValue(false)
+ Log.d(DEBUG_TAG, "Finished fetchers available to search arrivals for palina stop $stopId")
}
private fun setResultAndPalinaFromFetchers(palina: Palina, fetcherResult: Fetcher.Result) {
+ arrivalsRequestRunningLiveData.postValue(false)
resultLiveData.postValue(fetcherResult)
Log.d(DEBUG_TAG, "Have new result palina for stop ${palina.ID}, source ${palina.passaggiSourceIfAny} has coords: ${palina.hasCoords()}")
Log.d(DEBUG_TAG, "Old palina liveData is: ${palinaLiveData.value?.stopDisplayName}, has Coords ${palinaLiveData.value?.hasCoords()}")
diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml
--- a/app/src/main/res/values-fr/strings.xml
+++ b/app/src/main/res/values-fr/strings.xml
@@ -67,7 +67,7 @@
<string name="database_update_req">Forcer la mise à jour de la base de données</string>
<string name="arrivals_card_at_the_stop">à l\'arrêt</string>
<string name="show_arrivals">Afficher les arrivées</string>
- <string name="source_mato">Appli Muoversi a Torino</string>
+ <string name="source_mato">Muoversi a Torino</string>
<string name="mqtt_notification_text">Le service de localisation en temps réel MaTO live bus est en cours d\'exécution</string>
<string name="storage_permission">stockage</string>
<string name="stop_search_view_title">Rechercher par arrêt</string>
diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml
--- a/app/src/main/res/values-it/strings.xml
+++ b/app/src/main/res/values-it/strings.xml
@@ -166,7 +166,7 @@
<string name="fivetapifetcher">App GTT</string>
<string name="gttjsonfetcher">Sito GTT</string>
<string name="fivetscraper">Sito 5T Torino</string>
- <string name="source_mato">App Muoversi a Torino</string>
+ <string name="source_mato">Muoversi a Torino</string>
<string name="undetermined_source">Sconosciuta</string>
<string name="arrival_times_choice_title">Fonti orari di arrivo</string>
<string name="arrival_times_choice_explanation">Scegli le fonti di orari da usare</string>
diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml
--- a/app/src/main/res/values-nl/strings.xml
+++ b/app/src/main/res/values-nl/strings.xml
@@ -104,7 +104,7 @@
<string name="fivetapifetcher">GTT Applicatie</string>
<string name="gttjsonfetcher">GTT Website</string>
<string name="fivetscraper">5T Torino website</string>
- <string name="source_mato">Muoversi a Torino app</string>
+ <string name="source_mato">Muoversi a Torino</string>
<string name="undetermined_source">Onbepaald</string>
<string name="change_arrivals_source_message">Ingedrukt houden om aankomsten bron te veranderen</string>
<string name="arrival_times_choice_title">Bronnen van aankomsttijden</string>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -207,7 +207,7 @@
<string name="fivetapifetcher">GTT App</string>
<string name="gttjsonfetcher">GTT Website</string>
<string name="fivetscraper">5T Torino website</string>
- <string name="source_mato">Muoversi a Torino app</string>
+ <string name="source_mato">Muoversi a Torino</string>
<string name="undetermined_source">Undetermined</string>
<string name="arrival_source_changing">Changing arrival times source…</string>
<string name="change_arrivals_source_message">Long press to change the source of arrivals</string>

File Metadata

Mime Type
text/plain
Expires
Sun, Jun 14, 04:34 (6 h, 30 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1958617
Default Alt Text
D223.1781404479.diff (21 KB)

Event Timeline