Page MenuHomeGitPull.it

D76.1729597559.diff
No OneTemporary

Size
9 KB
Referenced Files
None
Subscribers
None

D76.1729597559.diff

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 @@
<string name="gttjsonfetcher">Sito GTT</string>
<string name="fivetscraper">Sito 5T Torino</string>
<string name="source_mato">App Muoversi a Torino</string>
+ <string name="undetermined_source">Sconosciuta</string>
<string name="arrival_source_changing">Cambiamento sorgente orari…</string>
<string name="change_arrivals_source_message">Premi a lungo per cambiare la sorgente degli orari</string>
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 @@
<string name="gttjsonfetcher">GTT Website</string>
<string name="fivetscraper">5T Torino website</string>
<string name="source_mato">Muoversi a Torino app</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>
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 @@
-->
<androidx.preference.SeekBarPreference
android:title="@string/pref_num_elements" android:key="@string/pref_key_num_recents"
- android:defaultValue="4"
+ android:defaultValue="6"
android:max="40"
app:min="1"
android:layout_width="match_parent"
diff --git a/src/it/reyboz/bustorino/backend/Palina.java b/src/it/reyboz/bustorino/backend/Palina.java
--- a/src/it/reyboz/bustorino/backend/Palina.java
+++ b/src/it/reyboz/bustorino/backend/Palina.java
@@ -358,15 +358,23 @@
}
return tot;
}
+
+ /**
+ * Compute the minimum number of passages per route
+ * Ignoring empty routes
+ * @return the minimum, or 0 if there are no passages/routes
+ */
public int getMinNumberOfPassages(){
if (routes == null) return 0;
int min = Integer.MAX_VALUE;
if( routes.size() == 0) min = 0;
else for (Route r : routes){
+ if(r.numPassaggi()>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<Fetcher.Result>?): Palina {
stopID!!
val future = RequestFuture.newFuture<Palina>()
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<Fetcher> getCurrentFetchers(){
- ArrayList<Fetcher> v = new ArrayList<Fetcher>();
- 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<Fetcher.Result> res;
+ private final AtomicReference<Fetcher.Result> finalResultRef;
private String query;
WeakReference<FragmentHelper> helperRef;
private final ArrayList<Thread> 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;
@@ -160,7 +156,7 @@
}
publishProgress(resRef.get());
//TODO: find a way to avoid overloading the user with toasts
- if (result == null){
+ if (result == null && f instanceof MatoAPIFetcher){
result = p;
}
//find if it went well
@@ -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,9 +183,12 @@
break;
}
}
+
+ */
//at this point, we are sure that the result has been negative
failedAll=true;
+
return result;
}
@@ -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);

File Metadata

Mime Type
text/plain
Expires
Tue, Oct 22, 13:45 (7 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
639177
Default Alt Text
D76.1729597559.diff (9 KB)

Event Timeline