Page Menu
Home
GitPull.it
Search
Configure Global Search
Log In
Files
F2442530
D76.1729597699.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
10 KB
Referenced Files
None
Subscribers
None
D76.1729597699.diff
View Options
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;
@@ -82,7 +78,7 @@
@Override
protected Palina doInBackground(String... params) {
RecursionHelper<ArrivalsFetcher> r = new RecursionHelper<>(theFetchers);
- Palina result = null;
+ Palina resultPalina = null;
FragmentHelper fh = helperRef.get();
ArrayList<Fetcher.Result> 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);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Oct 22, 13:48 (7 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
639179
Default Alt Text
D76.1729597699.diff (10 KB)
Attached To
Mode
D76: Show the stop when there are no passages
Attached
Detach File
Event Timeline
Log In to Comment