diff --git a/res/values-it/strings.xml b/res/values-it/strings.xml --- a/res/values-it/strings.xml +++ b/res/values-it/strings.xml @@ -133,6 +133,7 @@ Sito GTT Sito 5T Torino App Muoversi a Torino + Sconosciuta Cambiamento sorgente orari… Premi a lungo per cambiare la sorgente degli orari diff --git a/res/values/strings.xml b/res/values/strings.xml --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -147,6 +147,7 @@ GTT Website 5T Torino website Muoversi a Torino app + Undetermined Changing arrival times source… Long press to change the source of arrivals diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -22,7 +22,7 @@ --> 0) min = Math.min(min,r.numPassaggi()); } - return min; + if (min == Integer.MAX_VALUE) return 0; + else return min; } //private void mergeRoute } \ No newline at end of file diff --git a/src/it/reyboz/bustorino/backend/mato/MatoAPIFetcher.kt b/src/it/reyboz/bustorino/backend/mato/MatoAPIFetcher.kt --- a/src/it/reyboz/bustorino/backend/mato/MatoAPIFetcher.kt +++ b/src/it/reyboz/bustorino/backend/mato/MatoAPIFetcher.kt @@ -37,22 +37,23 @@ set(value) { field = value!!.applicationContext } - constructor(): this(3) + constructor(): this(2) override fun ReadArrivalTimesAll(stopID: String?, res: AtomicReference?): Palina { stopID!! val future = RequestFuture.newFuture() val now = Calendar.getInstance().time - var numMinutes = 30 + var numMinutes = 15 var palina = Palina(stopID) var numPassaggi = 0 var trials = 0 + var numDepartures = 5 while (numPassaggi < minNumPassaggi && trials < 4) { - + numDepartures+=5 numMinutes += 15 - val request = MapiArrivalRequest(stopID, now, numMinutes * 60, 10, res, future, future) + val request = MapiArrivalRequest(stopID, now, numMinutes * 60, numDepartures, res, future, future) if (appContext == null || res == null) { Log.e("BusTO:MatoAPIFetcher", "ERROR: Given null context or null result ref") return Palina(stopID) @@ -65,7 +66,7 @@ val palinaResult = future.get(5, TimeUnit.SECONDS) if (palinaResult!=null) { palina = palinaResult - numPassaggi = palina.totalNumberOfPassages + numPassaggi = palina.minNumberOfPassages } } catch (e: InterruptedException) { e.printStackTrace() diff --git a/src/it/reyboz/bustorino/fragments/ArrivalsFragment.java b/src/it/reyboz/bustorino/fragments/ArrivalsFragment.java --- a/src/it/reyboz/bustorino/fragments/ArrivalsFragment.java +++ b/src/it/reyboz/bustorino/fragments/ArrivalsFragment.java @@ -141,10 +141,10 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View root = inflater.inflate(R.layout.fragment_arrivals, container, false); - messageTextView = (TextView) root.findViewById(R.id.messageTextView); - addToFavorites = (ImageButton) root.findViewById(R.id.addToFavorites); - resultsListView = (ListView) root.findViewById(R.id.resultsListView); - timesSourceTextView = (TextView) root.findViewById(R.id.timesSourceTextView); + messageTextView = root.findViewById(R.id.messageTextView); + addToFavorites = root.findViewById(R.id.addToFavorites); + resultsListView = root.findViewById(R.id.resultsListView); + timesSourceTextView = root.findViewById(R.id.timesSourceTextView); timesSourceTextView.setOnLongClickListener(view -> { if(!fetchersChangeRequestPending){ rotateFetchers(); @@ -265,11 +265,7 @@ * @return the list of the fetchers */ public ArrayList getCurrentFetchers(){ - ArrayList v = new ArrayList(); - for (ArrivalsFetcher fetcher: fetchers){ - v.add(fetcher); - } - return v; + return new ArrayList<>(this.fetchers); } public ArrivalsFetcher[] getCurrentFetchersAsArray(){ ArrivalsFetcher[] arr = new ArrivalsFetcher[fetchers.size()]; @@ -329,7 +325,7 @@ break; case UNDETERMINED: //Don't show the view - source_txt = ""; + source_txt = getString(R.string.undetermined_source); break; default: throw new IllegalStateException("Unexpected value: " + source); @@ -344,8 +340,12 @@ if (count>10) Log.w(DEBUG_TAG, "Tried to update the source fetcher but it didn't work"); final String base_message = getString(R.string.times_source_fmt, source_txt); - timesSourceTextView.setVisibility(View.VISIBLE); timesSourceTextView.setText(base_message); + if (p.getTotalNumberOfPassages() > 0) { + timesSourceTextView.setVisibility(View.VISIBLE); + } else { + timesSourceTextView.setVisibility(View.INVISIBLE); + } fetchersChangeRequestPending = false; } diff --git a/src/it/reyboz/bustorino/middleware/AsyncArrivalsSearcher.java b/src/it/reyboz/bustorino/middleware/AsyncArrivalsSearcher.java --- a/src/it/reyboz/bustorino/middleware/AsyncArrivalsSearcher.java +++ b/src/it/reyboz/bustorino/middleware/AsyncArrivalsSearcher.java @@ -26,12 +26,9 @@ import android.os.AsyncTask; import androidx.annotation.NonNull; -import androidx.core.content.ContextCompat; import android.util.Log; -import android.widget.Toast; -import it.reyboz.bustorino.R; import it.reyboz.bustorino.backend.*; import it.reyboz.bustorino.backend.mato.MatoAPIFetcher; import it.reyboz.bustorino.data.AppDataProvider; @@ -41,7 +38,6 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.concurrent.atomic.AtomicReference; import java.util.Calendar; @@ -55,7 +51,7 @@ private static final String DEBUG_TAG = TAG; private boolean failedAll = false; - private final AtomicReference res; + private final AtomicReference finalResultRef; private String query; WeakReference helperRef; private final ArrayList otherActivities = new ArrayList<>(); @@ -68,7 +64,7 @@ public AsyncArrivalsSearcher(FragmentHelper fh, @NonNull ArrivalsFetcher[] fetchers, Context context) { helperRef = new WeakReference<>(fh); fh.setLastTaskRef(this); - res = new AtomicReference<>(); + finalResultRef = new AtomicReference<>(); this.context = context.getApplicationContext(); this.replaceFragment = true; @@ -82,7 +78,7 @@ @Override protected Palina doInBackground(String... params) { RecursionHelper r = new RecursionHelper<>(theFetchers); - Palina result = null; + Palina resultPalina = null; FragmentHelper fh = helperRef.get(); ArrayList results = new ArrayList<>(theFetchers.length); //If the FragmentHelper is null, that means the activity doesn't exist anymore @@ -160,8 +156,8 @@ } publishProgress(resRef.get()); //TODO: find a way to avoid overloading the user with toasts - if (result == null){ - result = p; + if (resultPalina == null && f instanceof MatoAPIFetcher && p.queryAllRoutes().size() > 0){ + resultPalina = p; } //find if it went well results.add(resRef.get()); @@ -177,7 +173,9 @@ return p; } + finalResultRef.set(resRef.get()); } + /* boolean emptyResults = true; for (Fetcher.Result re: results){ if (!re.equals(Fetcher.Result.EMPTY_RESULT_SET)) { @@ -185,10 +183,13 @@ break; } } + + */ //at this point, we are sure that the result has been negative failedAll=true; - return result; + + return resultPalina; } @Override @@ -208,7 +209,7 @@ protected void onPostExecute(Palina p) { FragmentHelper fh = helperRef.get(); - if(failedAll || p == null || fh == null){ + if(p == null || fh == null){ //everything went bad if(fh!=null) fh.toggleSpinner(false); cancel(true);