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
@@ -150,6 +150,9 @@
App Muoversi a Torino
Sconosciuta
+ Fonti orari di arrivo
+ Scegli le fonti di orari da usare
+
Cambiamento sorgente orari…
Premi a lungo per cambiare la sorgente degli orari
diff --git a/res/values/keys.xml b/res/values/keys.xml
--- a/res/values/keys.xml
+++ b/res/values/keys.xml
@@ -10,4 +10,17 @@
- map
- lines
+
+
+ - matofetcher
+ - fivetapifetcher
+ - gttjsonfetcher
+ - fivetscraper
+
+
+
+ - matofetcher
+ - gttjsonfetcher
+ - fivetscraper
+
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -164,6 +164,15 @@
Undetermined
Changing arrival times source…
Long press to change the source of arrivals
+
+ - @string/source_mato
+ - @string/fivetapifetcher
+ - @string/gttjsonfetcher
+ - @string/fivetscraper
+
+ Sources of arrival times
+ Select which sources of arrival times to use
+
+
+
setSelected = mainSharedPref.getStringSet(SettingsFragment.KEY_ARRIVALS_FETCHERS_USE, new HashSet<>());
+ if (setSelected.isEmpty()){
+ String[] defaultVals = getResources().getStringArray(R.array.arrivals_sources_values_default);
+ editor.putStringSet(SettingsFragment.KEY_ARRIVALS_FETCHERS_USE, utils.convertArrayToSet(defaultVals));
+ edit=true;
+ }
+ if (edit){
+ editor.commit();
+ }
+
+
+ }
}
diff --git a/src/it/reyboz/bustorino/adapters/PalinaAdapter.java b/src/it/reyboz/bustorino/adapters/PalinaAdapter.java
--- a/src/it/reyboz/bustorino/adapters/PalinaAdapter.java
+++ b/src/it/reyboz/bustorino/adapters/PalinaAdapter.java
@@ -30,6 +30,8 @@
import android.widget.ArrayAdapter;
import android.widget.TextView;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
import java.util.Locale;
@@ -38,6 +40,7 @@
import it.reyboz.bustorino.backend.Passaggio;
import it.reyboz.bustorino.backend.Route;
import it.reyboz.bustorino.backend.utils;
+import it.reyboz.bustorino.util.PassaggiSorter;
import it.reyboz.bustorino.util.RouteSorterByArrivalTime;
/**
@@ -88,6 +91,14 @@
public PalinaAdapter(Context context, Palina p) {
super(context, row_layout, p.queryAllRoutes());
li = LayoutInflater.from(context);
+ Comparator sorter = null;
+ if (p.getPassaggiSourceIfAny()== Passaggio.Source.GTTJSON){
+ sorter = new PassaggiSorter();
+ }
+ for(Route r: p.queryAllRoutes()){
+ if (sorter==null) Collections.sort(r.passaggi);
+ else Collections.sort(r.passaggi, sorter);
+ }
sort(new RouteSorterByArrivalTime());
/*
sort(new Comparator() {
diff --git a/src/it/reyboz/bustorino/backend/GTTJSONFetcher.java b/src/it/reyboz/bustorino/backend/GTTJSONFetcher.java
--- a/src/it/reyboz/bustorino/backend/GTTJSONFetcher.java
+++ b/src/it/reyboz/bustorino/backend/GTTJSONFetcher.java
@@ -95,8 +95,9 @@
} catch (JSONException ignored) { // if "Bacino" gets removed...
bacino = "U";
}
-
- pos = p.addRoute(routename, thisroute.getString("Direzione"), FiveTNormalizer.decodeType(routename, bacino));
+ final Route r = new Route(routename, thisroute.getString("Direzione"),
+ "",
+ FiveTNormalizer.decodeType(routename, bacino));
passaggi = thisroute.getJSONArray("PassaggiRT");
howManyPassaggi = passaggi.length();
@@ -105,17 +106,20 @@
if (mPassaggio.contains("__")){
mPassaggio = mPassaggio.replace("_", "");
}
- p.addPassaggio(mPassaggio.concat("*"), Passaggio.Source.GTTJSON, pos);
+ r.addPassaggio(mPassaggio.concat("*"), Passaggio.Source.GTTJSON);
}
+
passaggi = thisroute.getJSONArray("PassaggiPR"); // now the non-real-time ones
howManyPassaggi = passaggi.length();
for(j = 0; j < howManyPassaggi; j++) {
- p.addPassaggio(passaggi.getString(j), Passaggio.Source.GTTJSON, pos);
+ r.addPassaggio(passaggi.getString(j), Passaggio.Source.GTTJSON);
}
+ p.addRoute(r);
}
} catch (JSONException e) {
res.set(Result.PARSER_ERROR);
+ e.printStackTrace();
return p;
}
diff --git a/src/it/reyboz/bustorino/backend/Passaggio.java b/src/it/reyboz/bustorino/backend/Passaggio.java
--- a/src/it/reyboz/bustorino/backend/Passaggio.java
+++ b/src/it/reyboz/bustorino/backend/Passaggio.java
@@ -144,17 +144,7 @@
if(this.hh == UNKNOWN_TIME || other.hh == UNKNOWN_TIME)
return 0;
else {
- int diff = this.hh - other.hh;
- // an attempt to correctly sort arrival times around midnight (e.g. 23.59 should come before 00.01)
- if (diff > 12) { // untested
- diff -= 24;
- } else if (diff < -12) {
- diff += 24;
- }
-
- diff *= 60;
-
- diff += this.mm - other.mm;
+ int diff = getMinutesDiff(other);
// we should take into account if one is in real time and the other isn't, shouldn't we?
if (other.isInRealTime) {
@@ -167,6 +157,20 @@
return diff;
}
}
+ public int getMinutesDiff(Passaggio other){
+ int diff = this.hh - other.hh;
+ // an attempt to correctly sort arrival times around midnight (e.g. 23.59 should come before 00.01)
+ if (diff > 12) { // untested
+ diff -= 24;
+ } else if (diff < -12) {
+ diff += 24;
+ }
+
+ diff *= 60;
+
+ diff += this.mm - other.mm;
+ return diff;
+ }
//
diff --git a/src/it/reyboz/bustorino/backend/Route.java b/src/it/reyboz/bustorino/backend/Route.java
--- a/src/it/reyboz/bustorino/backend/Route.java
+++ b/src/it/reyboz/bustorino/backend/Route.java
@@ -18,6 +18,8 @@
package it.reyboz.bustorino.backend;
+import android.util.Log;
+
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -136,6 +138,15 @@
public Route(String name,Type t,String description){
this(name,null,new ArrayList<>(),t,description);
}
+ /**
+ * Constructor used by the FiveTAPIFetcher
+ * @param name stop Name
+ * @param t optional type
+ * @param description line rough description
+ */
+ public Route(String name,String destinazione, String description, Type t){
+ this(name,destinazione,new ArrayList<>(),t,description);
+ }
/**
* Exactly what it says on the tin.
@@ -248,6 +259,23 @@
return 0;
return passaggi.size();
}
+ public Passaggio.Source getPassaggiSource(){
+ Passaggio.Source mSource = null;
+
+ for(Passaggio pass: passaggi){
+ if (mSource == null) {
+ mSource = pass.source;
+ } else if (mSource != pass.source){
+ Log.w("BusTO-CheckPassaggi",
+ "Cannot determine the source for route "+this.name+", have got "+mSource +" so far, the next one is "+pass.source );
+ mSource = Passaggio.Source.UNDETERMINED;
+
+ break;
+ }
+ }
+ if (mSource == null) mSource = Passaggio.Source.UNDETERMINED;
+ return mSource;
+ }
@Override
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
@@ -72,10 +72,10 @@
try {
val palinaResult = future.get(5, TimeUnit.SECONDS)
if (palinaResult!=null) {
- if (BuildConfig.DEBUG)
+ /*if (BuildConfig.DEBUG)
for (r in palinaResult.queryAllRoutes()){
Log.d(DEBUG_TAG, "route " + r.gtfsId + " has " + r.passaggi.size + " passaggi: "+ r.passaggiToString)
- }
+ }*/
palina = palinaResult
numPassaggi = palina.minNumberOfPassages
} else{
diff --git a/src/it/reyboz/bustorino/backend/utils.java b/src/it/reyboz/bustorino/backend/utils.java
--- a/src/it/reyboz/bustorino/backend/utils.java
+++ b/src/it/reyboz/bustorino/backend/utils.java
@@ -19,6 +19,7 @@
import android.content.Context;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
@@ -26,16 +27,21 @@
import android.util.TypedValue;
import android.view.View;
import androidx.annotation.Nullable;
+import androidx.preference.PreferenceManager;
import java.io.PrintWriter;
import java.io.StringWriter;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashSet;
import java.util.List;
import java.util.Locale;
+import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import it.reyboz.bustorino.backend.mato.MatoAPIFetcher;
+import it.reyboz.bustorino.fragments.SettingsFragment;
public abstract class utils {
private static final double EarthRadius = 6371e3;
@@ -213,9 +219,67 @@
}
}
+ /**
+ * Get the default list of fetchers for arrival times
+ * @return array of ArrivalsFetchers to use
+ */
public static ArrivalsFetcher[] getDefaultArrivalsFetchers(){
return new ArrivalsFetcher[]{ new MatoAPIFetcher(),
- new FiveTAPIFetcher(), new GTTJSONFetcher(), new FiveTScraperFetcher()};
+ new GTTJSONFetcher(), new FiveTScraperFetcher()};
+ }
+ /**
+ * Get the default list of fetchers for arrival times
+ * @return array of ArrivalsFetchers to use
+ */
+ public static List getDefaultArrivalsFetchers(Context context){
+ SharedPreferences defSharPref = PreferenceManager.getDefaultSharedPreferences(context);
+ final Set setSelected = new HashSet<>(defSharPref.getStringSet(SettingsFragment.KEY_ARRIVALS_FETCHERS_USE,
+ new HashSet<>()));
+ if (setSelected.isEmpty()) {
+ return Arrays.asList(new MatoAPIFetcher(),
+ new GTTJSONFetcher(), new FiveTScraperFetcher());
+ }else{
+ ArrayList outFetchers = new ArrayList<>(4);
+ /*for(String s: setSelected){
+ switch (s){
+ case "matofetcher":
+ outFetchers.add(new MatoAPIFetcher());
+ break;
+ case "fivetapifetcher":
+ outFetchers.add(new FiveTAPIFetcher());
+ break;
+ case "gttjsonfetcher":
+ outFetchers.add(new GTTJSONFetcher());
+ break;
+ case "fivetscraper":
+ outFetchers.add(new FiveTScraperFetcher());
+ break;
+ default:
+ throw new IllegalArgumentException();
+ }
+ }*/
+ if (setSelected.contains("matofetcher")) {
+ outFetchers.add(new MatoAPIFetcher());
+ setSelected.remove("matofetcher");
+ }
+ if (setSelected.contains("fivetapifetcher")) {
+ outFetchers.add(new FiveTAPIFetcher());
+ setSelected.remove("fivetapifetcher");
+ }
+ if (setSelected.contains("gttjsonfetcher")){
+ outFetchers.add(new GTTJSONFetcher());
+ setSelected.remove("gttjsonfetcher");
+ }
+ if (setSelected.contains("fivetscraper")) {
+ outFetchers.add(new FiveTScraperFetcher());
+ setSelected.remove("fivetscraper");
+ }
+ if(!setSelected.isEmpty()){
+ Log.e("BusTO-Utils","Getting some fetchers values which are not contemplated: "+setSelected);
+ }
+
+ return outFetchers;
+ }
}
/**
* Print the first i lines of the the trace of an exception
@@ -253,4 +317,25 @@
}
return sb.toString();
}
+
+ public static Set convertArrayToSet(T[] array)
+ {
+ // Create an empty Set
+ Set set = new HashSet<>();
+ // Add each element into the set
+ set.addAll(Arrays.asList(array));
+
+ // Return the converted Set
+ return set;
+ }
+
+ public static String giveClassesForArray(T[] array){
+ StringBuilder sb = new StringBuilder();
+ for (T f: array){
+ sb.append("");
+ sb.append(f.getClass().getSimpleName());
+ sb.append("; ");
+ }
+ return sb.toString();
+ }
}
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
@@ -18,6 +18,7 @@
package it.reyboz.bustorino.fragments;
+import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
@@ -34,12 +35,10 @@
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ListAdapter;
-import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -48,10 +47,7 @@
import it.reyboz.bustorino.backend.ArrivalsFetcher;
import it.reyboz.bustorino.backend.DBStatusManager;
import it.reyboz.bustorino.backend.Fetcher;
-import it.reyboz.bustorino.backend.FiveTAPIFetcher;
import it.reyboz.bustorino.backend.FiveTNormalizer;
-import it.reyboz.bustorino.backend.FiveTScraperFetcher;
-import it.reyboz.bustorino.backend.GTTJSONFetcher;
import it.reyboz.bustorino.backend.Palina;
import it.reyboz.bustorino.backend.Passaggio;
import it.reyboz.bustorino.backend.Route;
@@ -71,6 +67,7 @@
private final static int loaderFavId = 2;
private final static int loaderStopId = 1;
static final String STOP_TITLE = "messageExtra";
+ private final static String SOURCES_TEXT="sources_textview_message";
private @Nullable String stopID,stopName;
private DBStatusManager prefs;
@@ -85,7 +82,7 @@
protected ImageButton addToFavorites;
protected TextView timesSourceTextView;
- private List fetchers = new ArrayList<>(Arrays.asList(utils.getDefaultArrivalsFetchers()));
+ private List fetchers = null; //new ArrayList<>(Arrays.asList(utils.getDefaultArrivalsFetchers()));
private boolean reloadOnResume = true;
@@ -196,6 +193,14 @@
messageTextView.setText(probablemessage);
messageTextView.setVisibility(View.VISIBLE);
}
+
+ /*String sourcesTextViewData = getArguments().getString(SOURCES_TEXT);
+ if (sourcesTextViewData!=null){
+ timesSourceTextView.setText(sourcesTextViewData);
+ }*/
+ //need to do this when we recreate the fragment but we haven't updated the arrival times
+ if (lastUpdatedPalina!=null)
+ showArrivalsSources(lastUpdatedPalina);
return root;
}
@@ -211,6 +216,9 @@
if(stopID!=null){
//refresh the arrivals
if(!justCreated){
+ fetchers = utils.getDefaultArrivalsFetchers(getContext());
+ adjustFetchersToSource();
+
if (reloadOnResume)
mListener.requestArrivalsForStopID(stopID);
}
@@ -224,6 +232,8 @@
}
updateMessage();
}
+
+
}
@@ -247,6 +257,14 @@
}
+ @Override
+ public void onAttach(@NonNull Context context) {
+ super.onAttach(context);
+
+ //get fetchers
+ fetchers = utils.getDefaultArrivalsFetchers(context);
+ }
+
@Nullable
public String getStopID() {
return stopID;
@@ -274,7 +292,10 @@
}
private void rotateFetchers(){
+ Log.d(DEBUG_TAG, "Rotating fetchers, before: "+fetchers);
Collections.rotate(fetchers, -1);
+ Log.d(DEBUG_TAG, "Rotating fetchers, afterwards: "+fetchers);
+
}
@@ -330,14 +351,9 @@
default:
throw new IllegalStateException("Unexpected value: " + source);
}
- int count = 0;
- if (source!= Passaggio.Source.UNDETERMINED)
- while (source != fetchers.get(0).getSourceForFetcher() && count < 100){
- //we need to update the fetcher that is requested
- rotateFetchers();
- count++;
- }
- if (count>10)
+ //
+ final boolean updatedFetchers = adjustFetchersToSource(source);
+ if(!updatedFetchers)
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.setText(base_message);
@@ -349,6 +365,23 @@
fetchersChangeRequestPending = false;
}
+ protected boolean adjustFetchersToSource(Passaggio.Source source){
+ if (source == null) return false;
+ int count = 0;
+ if (source!= Passaggio.Source.UNDETERMINED)
+ while (source != fetchers.get(0).getSourceForFetcher() && count < 200){
+ //we need to update the fetcher that is requested
+ rotateFetchers();
+ count++;
+ }
+ return count < 200;
+ }
+ protected boolean adjustFetchersToSource(){
+ if (lastUpdatedPalina == null) return false;
+ final Passaggio.Source source = lastUpdatedPalina.getPassaggiSourceIfAny();
+ return adjustFetchersToSource(source);
+ }
+
@Override
public void setNewListAdapter(ListAdapter adapter) {
throw new UnsupportedOperationException();
@@ -431,9 +464,13 @@
case loaderStopId:
if(data.getCount()>0){
data.moveToFirst();
- stopName = data.getString(data.getColumnIndex(
+ int index = data.getColumnIndex(
NextGenDB.Contract.StopsTable.COL_NAME
- ));
+ );
+ if (index == -1){
+ Log.e(DEBUG_TAG, "Index is -1, column not present. App may explode now...");
+ }
+ stopName = data.getString(index);
updateMessage();
} else {
Log.w("ArrivalsFragment"+getTag(),"Stop is not inside the database... CLOISTER BELL");
@@ -513,4 +550,9 @@
}
+ @Override
+ public void onDestroyView() {
+ getArguments().putString(SOURCES_TEXT, timesSourceTextView.getText().toString());
+ super.onDestroyView();
+ }
}
diff --git a/src/it/reyboz/bustorino/fragments/MainScreenFragment.java b/src/it/reyboz/bustorino/fragments/MainScreenFragment.java
--- a/src/it/reyboz/bustorino/fragments/MainScreenFragment.java
+++ b/src/it/reyboz/bustorino/fragments/MainScreenFragment.java
@@ -41,6 +41,7 @@
import com.google.android.material.floatingactionbutton.FloatingActionButton;
+import java.util.List;
import java.util.Map;
import it.reyboz.bustorino.R;
@@ -100,13 +101,16 @@
private static final int SEARCH_BY_ROUTE = 2; // TODO: implement this -- https://gitpull.it/T12
private int searchMode;
//private ImageButton addToFavorites;
- private final ArrivalsFetcher[] arrivalsFetchers = utils.getDefaultArrivalsFetchers();
//// HIDDEN BUT IMPORTANT ELEMENTS ////
FragmentManager fragMan;
Handler mainHandler;
private final Runnable refreshStop = new Runnable() {
public void run() {
if(getContext() == null) return;
+ List fetcherList = utils.getDefaultArrivalsFetchers(getContext());
+ ArrivalsFetcher[] arrivalsFetchers = new ArrivalsFetcher[fetcherList.size()];
+ arrivalsFetchers = fetcherList.toArray(arrivalsFetchers);
+
if (fragMan.findFragmentById(R.id.resultFrame) instanceof ArrivalsFragment) {
ArrivalsFragment fragment = (ArrivalsFragment) fragMan.findFragmentById(R.id.resultFrame);
if (fragment == null){
@@ -715,6 +719,7 @@
Log.e(DEBUG_TAG, "Asked for arrivals with null context");
return;
}
+ ArrivalsFetcher[] fetchers = utils.getDefaultArrivalsFetchers(getContext()).toArray(new ArrivalsFetcher[0]);
if (ID == null || ID.length() <= 0) {
// we're still in UI thread, no need to mess with Progress
showToastMessage(R.string.insert_bus_stop_number_error, true);
@@ -726,11 +731,11 @@
//fragment.getCurrentFetchers().toArray()
new AsyncArrivalsSearcher(fragmentHelper,fragment.getCurrentFetchersAsArray(), getContext()).execute(ID);
} else{
- new AsyncArrivalsSearcher(fragmentHelper, arrivalsFetchers, getContext()).execute(ID);
+ new AsyncArrivalsSearcher(fragmentHelper, fetchers, getContext()).execute(ID);
}
}
else {
- new AsyncArrivalsSearcher(fragmentHelper,arrivalsFetchers, getContext()).execute(ID);
+ new AsyncArrivalsSearcher(fragmentHelper,fetchers, getContext()).execute(ID);
Log.d(DEBUG_TAG, "Started search for arrivals of stop " + ID);
}
}
diff --git a/src/it/reyboz/bustorino/fragments/ResultListFragment.java b/src/it/reyboz/bustorino/fragments/ResultListFragment.java
--- a/src/it/reyboz/bustorino/fragments/ResultListFragment.java
+++ b/src/it/reyboz/bustorino/fragments/ResultListFragment.java
@@ -186,7 +186,10 @@
}
public boolean isFragmentForTheSameStop(Palina p) {
- return adapterKind.equals(FragmentKind.ARRIVALS) && getTag().equals(getFragmentTag(p));
+ if (!adapterKind.equals(FragmentKind.ARRIVALS)) return false;
+ if (getTag() != null)
+ return getTag().equals(getFragmentTag(p));
+ else return false;
}
public static String getFragmentTag(Palina p) {
diff --git a/src/it/reyboz/bustorino/fragments/SettingsFragment.java b/src/it/reyboz/bustorino/fragments/SettingsFragment.java
--- a/src/it/reyboz/bustorino/fragments/SettingsFragment.java
+++ b/src/it/reyboz/bustorino/fragments/SettingsFragment.java
@@ -34,6 +34,7 @@
import it.reyboz.bustorino.data.DatabaseUpdate;
import java.lang.ref.WeakReference;
+import java.util.HashSet;
public class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
private static final String TAG = SettingsFragment.class.getName();
@@ -43,6 +44,8 @@
//private static final
Handler mHandler;
public final static String PREF_KEY_STARTUP_SCREEN="startup_screen_to_show";
+ public final static String KEY_ARRIVALS_FETCHERS_USE = "arrivals_fetchers_use_setting";
+
private boolean setSummaryStartupPref = false;
@Override
@@ -102,6 +105,10 @@
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Preference pref = findPreference(key);
Log.d(TAG,"Preference key "+key+" changed");
+ if (key.equals(SettingsFragment.KEY_ARRIVALS_FETCHERS_USE)){
+ Log.d(TAG, "New value is: "+sharedPreferences.getStringSet(key, new HashSet<>()));
+ }
+
//sometimes this happens
if(getContext()==null) return;
if(key.equals(PREF_KEY_STARTUP_SCREEN) && setSummaryStartupPref && pref !=null){
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
@@ -82,6 +82,13 @@
FragmentHelper fh = helperRef.get();
ArrayList results = new ArrayList<>(theFetchers.length);
//If the FragmentHelper is null, that means the activity doesn't exist anymore
+ StringBuilder sb = new StringBuilder();
+ for (ArrivalsFetcher f: theFetchers){
+ sb.append("");
+ sb.append(f.getClass().getSimpleName());
+ sb.append("; ");
+ }
+ Log.d(DEBUG_TAG, "Using fetchers: "+sb.toString());
if (fh == null){
return null;
}
diff --git a/src/it/reyboz/bustorino/util/PassaggiSorter.java b/src/it/reyboz/bustorino/util/PassaggiSorter.java
new file mode 100644
--- /dev/null
+++ b/src/it/reyboz/bustorino/util/PassaggiSorter.java
@@ -0,0 +1,38 @@
+package it.reyboz.bustorino.util;
+
+import java.util.Comparator;
+
+import it.reyboz.bustorino.backend.Passaggio;
+
+/**
+ * Sorter of passaggi, giving the arrival times that are in real time first
+ */
+public class PassaggiSorter implements Comparator {
+
+ @Override
+ public int compare(Passaggio p1, Passaggio p2) {
+ if (p1.isInRealTime){
+ if(p2.isInRealTime){
+ //compare times
+ return p1.getMinutesDiff(p2);
+ }
+ else {
+ return -2;
+ }
+ } else{
+ if(p2.isInRealTime){
+ // other should come first
+ return 2;
+ } else return p1.getMinutesDiff(p2);
+ }
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ boolean equal= this.equals(o);
+ if (equal) return true;
+ else{
+ return o instanceof PassaggiSorter;
+ }
+ }
+}
diff --git a/src/it/reyboz/bustorino/util/RouteSorterByArrivalTime.kt b/src/it/reyboz/bustorino/util/RouteSorterByArrivalTime.kt
--- a/src/it/reyboz/bustorino/util/RouteSorterByArrivalTime.kt
+++ b/src/it/reyboz/bustorino/util/RouteSorterByArrivalTime.kt
@@ -20,10 +20,10 @@
} else if (passaggi2 == null || passaggi2.size == 0){
return -2
}
- passaggi1.sort()
- passaggi2.sort()
+ //passaggi1.sort()
+ //passaggi2.sort()
return passaggi1[0].compareTo(passaggi2[0])
}
}
\ No newline at end of file