Page MenuHomeGitPull.it

No OneTemporary

Authored By
Unknown
Size
160 KB
Referenced Files
None
Subscribers
None
diff --git a/app/src/main/java/it/reyboz/bustorino/adapters/AdapterClickListener.java b/app/src/main/java/it/reyboz/bustorino/adapters/AdapterClickListener.java
new file mode 100644
index 0000000..089d756
--- /dev/null
+++ b/app/src/main/java/it/reyboz/bustorino/adapters/AdapterClickListener.java
@@ -0,0 +1,6 @@
+package it.reyboz.bustorino.adapters;
+
+public interface AdapterClickListener<T> {
+
+ void onAdapterClickListener(T element);
+}
diff --git a/app/src/main/java/it/reyboz/bustorino/adapters/PalinaAdapter.java b/app/src/main/java/it/reyboz/bustorino/adapters/PalinaAdapter.java
index 3ec8ccf..9a9735c 100644
--- a/app/src/main/java/it/reyboz/bustorino/adapters/PalinaAdapter.java
+++ b/app/src/main/java/it/reyboz/bustorino/adapters/PalinaAdapter.java
@@ -1,242 +1,242 @@
/*
BusTO (backend components)
Copyright (C) 2016 Ludovico Pavesi
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package it.reyboz.bustorino.adapters;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager;
import android.content.SharedPreferences;
import android.os.Build;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.ArrayAdapter;
import android.widget.TextView;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Locale;
+import java.util.*;
+import androidx.recyclerview.widget.RecyclerView;
import it.reyboz.bustorino.R;
import it.reyboz.bustorino.backend.Palina;
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;
+import org.jetbrains.annotations.NotNull;
/**
* This once was a ListView Adapter for BusLine[].
*
* Thanks to Framentos developers for the guide:
* http://www.framentos.com/en/android-tutorial/2012/07/16/listview-in-android-using-custom-listadapter-and-viewcache/#
*
* @author Valerio Bozzolan
* @author Ludovico Pavesi
*/
-public class PalinaAdapter extends ArrayAdapter<Route> implements SharedPreferences.OnSharedPreferenceChangeListener {
- private LayoutInflater li;
- private static int row_layout = R.layout.entry_bus_line_passage;
+public class PalinaAdapter extends RecyclerView.Adapter<PalinaAdapter.PalinaViewHolder> implements SharedPreferences.OnSharedPreferenceChangeListener {
+
+ private static final int ROW_LAYOUT = R.layout.entry_bus_line_passage;
private static final int metroBg = R.drawable.route_background_metro;
private static final int busBg = R.drawable.route_background_bus;
private static final int extraurbanoBg = R.drawable.route_background_bus_long_distance;
private static final int busIcon = R.drawable.bus;
private static final int trainIcon = R.drawable.subway;
private static final int tramIcon = R.drawable.tram;
private final String KEY_CAPITALIZE;
private Capitalize capit;
- //private static final int cityIcon = R.drawable.city;
-
- // hey look, a pattern!
- private static class ViewHolder {
- TextView rowStopIcon;
- TextView rowRouteDestination;
- TextView rowRouteTimetable;
- }
- private static Capitalize getCapitalize(SharedPreferences shPr, String key){
- String capitalize = shPr.getString(key, "");
-
- switch (capitalize.trim()){
- case "KEEP":
- return Capitalize.DO_NOTHING;
- case "CAPITALIZE_ALL":
- return Capitalize.ALL;
-
- case "CAPITALIZE_FIRST":
- return Capitalize.FIRST;
- }
- return Capitalize.DO_NOTHING;
- }
-
- public PalinaAdapter(Context context, Palina p) {
- super(context, row_layout, p.queryAllRoutes());
- li = LayoutInflater.from(context);
- Comparator<Passaggio> 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<Route>() {
-
- @Override
- public int compare(Route route, Route t1) {
- LinesNameSorter sorter = new LinesNameSorter();
- if(route.getNameForDisplay()!= null){
- if(t1.getNameForDisplay()!=null){
- return sorter.compare(route.getNameForDisplay(), t1.getNameForDisplay());
- }
- else return -1;
- } else if(t1.getNameForDisplay()!=null){
- return +1;
- }
- else return 0;
- }
- });
-
- */
- KEY_CAPITALIZE = context.getString(R.string.pref_arrival_times_capit);
- SharedPreferences defSharPref = PreferenceManager.getDefaultSharedPreferences(context);
- defSharPref.registerOnSharedPreferenceChangeListener(this);
- this.capit = getCapitalize(defSharPref, KEY_CAPITALIZE);
- }
+ private final List<Route> mRoutes;
+ private final AdapterClickListener<Route> mRouteListener;
- /**
- * Some parts taken from the AdapterBusLines class.<br>
- * Some parts inspired by these enlightening tutorials:<br>
- * http://www.simplesoft.it/android/guida-agli-adapter-e-le-listview-in-android.html<br>
- * https://www.codeofaninja.com/2013/09/android-viewholder-pattern-example.html<br>
- * And some other bits and bobs TIRATI FUORI DAL NULLA CON L'INTUIZIONE INTELLETTUALE PERCHÉ
- * SEMBRA CHE NESSUNO ABBIA LA MINIMA IDEA DI COME FUNZIONA UN ADAPTER SU ANDROID.
- */
@NonNull
+ @NotNull
@Override
- public View getView(int position, View convertView, @NonNull ViewGroup parent) {
- ViewHolder vh;
-
- if(convertView == null) {
- // INFLATE!
- // setting a parent here is not supported and causes a fatal exception, apparently.
- convertView = li.inflate(row_layout, null);
-
- // STORE TEXTVIEWS!
- vh = new ViewHolder();
- vh.rowStopIcon = (TextView) convertView.findViewById(R.id.routeID);
- vh.rowRouteDestination = (TextView) convertView.findViewById(R.id.routeDestination);
- vh.rowRouteTimetable = (TextView) convertView.findViewById(R.id.routesThatStopHere);
+ public PalinaViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
+ View view = LayoutInflater.from(parent.getContext())
+ .inflate(ROW_LAYOUT, parent, false);
+ return new PalinaViewHolder(view);
+ }
- // STORE VIEWHOLDER IN\ON\OVER\UNDER\ABOVE\BESIDE THE VIEW!
- convertView.setTag(vh);
- } else {
- // RECOVER THIS STUFF!
- vh = (ViewHolder) convertView.getTag();
- }
+ @Override
+ public void onBindViewHolder(@NonNull @NotNull PalinaViewHolder vh, int position) {
+ final Route route = mRoutes.get(position);
- Route route = getItem(position);
vh.rowStopIcon.setText(route.getNameForDisplay());
if(route.destinazione==null || route.destinazione.length() == 0) {
vh.rowRouteDestination.setVisibility(View.GONE);
// move around the route timetable
final ViewGroup.MarginLayoutParams pars = (ViewGroup.MarginLayoutParams) vh.rowRouteTimetable.getLayoutParams();
if (pars!=null){
pars.topMargin = 16;
if(Build.VERSION.SDK_INT >= 17)
pars.setMarginStart(20);
pars.leftMargin = 20;
}
} else {
// View Holder Pattern(R) renders each element from a previous one: if the other one had an invisible rowRouteDestination, we need to make it visible.
vh.rowRouteDestination.setVisibility(View.VISIBLE);
String dest = route.destinazione;
switch (capit){
case ALL:
dest = route.destinazione.toUpperCase(Locale.ROOT);
break;
case FIRST:
dest = utils.toTitleCase(route.destinazione, true);
break;
case DO_NOTHING:
default:
}
vh.rowRouteDestination.setText(dest);
+
+ //set click listener
+ vh.itemView.setOnClickListener(view -> {
+ mRouteListener.onAdapterClickListener(route);
+ });
}
switch (route.type) {
//UNKNOWN = BUS for the moment
case UNKNOWN:
case BUS:
default:
// convertView could contain another background, reset it
vh.rowStopIcon.setBackgroundResource(busBg);
vh.rowRouteDestination.setCompoundDrawablesWithIntrinsicBounds(busIcon, 0, 0, 0);
break;
case LONG_DISTANCE_BUS:
vh.rowStopIcon.setBackgroundResource(extraurbanoBg);
vh.rowRouteDestination.setCompoundDrawablesWithIntrinsicBounds(busIcon, 0, 0, 0);
break;
case METRO:
vh.rowStopIcon.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
vh.rowStopIcon.setBackgroundResource(metroBg);
vh.rowRouteDestination.setCompoundDrawablesWithIntrinsicBounds(trainIcon, 0, 0, 0);
break;
case RAILWAY:
vh.rowStopIcon.setBackgroundResource(busBg);
vh.rowRouteDestination.setCompoundDrawablesWithIntrinsicBounds(trainIcon, 0, 0, 0);
break;
case TRAM: // never used but whatever.
vh.rowStopIcon.setBackgroundResource(busBg);
vh.rowRouteDestination.setCompoundDrawablesWithIntrinsicBounds(tramIcon, 0, 0, 0);
break;
}
List<Passaggio> passaggi = route.passaggi;
//TODO: Sort the passaggi with realtime first if source is GTTJSONFetcher
if(passaggi.size() == 0) {
vh.rowRouteTimetable.setText(R.string.no_passages);
} else {
vh.rowRouteTimetable.setText(route.getPassaggiToString());
}
- return convertView;
}
+ @Override
+ public int getItemCount() {
+ return mRoutes.size();
+ }
+
+ //private static final int cityIcon = R.drawable.city;
+
+ // hey look, a pattern!
+ public static class PalinaViewHolder extends RecyclerView.ViewHolder {
+ final TextView rowStopIcon;
+ final TextView rowRouteDestination;
+ final TextView rowRouteTimetable;
+
+ public PalinaViewHolder(@NonNull @NotNull View view) {
+ super(view);
+ /*
+ convertView.findViewById(R.id.routeID);
+ vh.rowRouteDestination = (TextView) convertView.findViewById(R.id.routeDestination);
+ vh.rowRouteTimetable = (TextView) convertView.findViewById(R.id.routesThatStopHere);
+ */
+ rowStopIcon = view.findViewById(R.id.routeID);
+ rowRouteDestination = view.findViewById(R.id.routeDestination);
+ rowRouteTimetable = view.findViewById(R.id.routesThatStopHere);
+ }
+ }
+ private static Capitalize getCapitalize(SharedPreferences shPr, String key){
+ String capitalize = shPr.getString(key, "");
+
+ switch (capitalize.trim()){
+ case "KEEP":
+ return Capitalize.DO_NOTHING;
+ case "CAPITALIZE_ALL":
+ return Capitalize.ALL;
+
+ case "CAPITALIZE_FIRST":
+ return Capitalize.FIRST;
+ }
+ return Capitalize.DO_NOTHING;
+ }
+
+ public PalinaAdapter(Context context, Palina p, AdapterClickListener<Route> listener, boolean hideEmptyRoutes) {
+ Comparator<Passaggio> sorter = null;
+ if (p.getPassaggiSourceIfAny()== Passaggio.Source.GTTJSON){
+ sorter = new PassaggiSorter();
+ }
+ final List<Route> routes;
+ if (hideEmptyRoutes){
+ // build the routes by filtering them
+ routes = new ArrayList<>();
+ for(Route r: p.queryAllRoutes()){
+ //add only if there is at least one passage
+ if (r.numPassaggi()>0){
+ routes.add(r);
+ }
+ }
+ } else
+ routes = p.queryAllRoutes();
+ for(Route r: routes){
+ if (sorter==null) Collections.sort(r.passaggi);
+ else Collections.sort(r.passaggi, sorter);
+ }
+
+ Collections.sort(routes,new RouteSorterByArrivalTime());
+
+ mRoutes = routes;
+ KEY_CAPITALIZE = context.getString(R.string.pref_arrival_times_capit);
+ SharedPreferences defSharPref = PreferenceManager.getDefaultSharedPreferences(context);
+ defSharPref.registerOnSharedPreferenceChangeListener(this);
+ this.capit = getCapitalize(defSharPref, KEY_CAPITALIZE);
+
+ this.mRouteListener = listener;
+ }
+
+
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if(key.equals(KEY_CAPITALIZE)){
capit = getCapitalize(sharedPreferences, KEY_CAPITALIZE);
notifyDataSetChanged();
}
}
enum Capitalize{
DO_NOTHING, ALL, FIRST
}
}
diff --git a/app/src/main/java/it/reyboz/bustorino/adapters/RouteOnlyLineAdapter.kt b/app/src/main/java/it/reyboz/bustorino/adapters/RouteOnlyLineAdapter.kt
new file mode 100644
index 0000000..c780291
--- /dev/null
+++ b/app/src/main/java/it/reyboz/bustorino/adapters/RouteOnlyLineAdapter.kt
@@ -0,0 +1,48 @@
+package it.reyboz.bustorino.adapters
+
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.widget.TextView
+import androidx.recyclerview.widget.RecyclerView
+import it.reyboz.bustorino.R
+import it.reyboz.bustorino.backend.Palina
+
+class RouteOnlyLineAdapter (val routeNames: List<String>) :
+ RecyclerView.Adapter<RouteOnlyLineAdapter.ViewHolder>() {
+
+ /**
+ * Provide a reference to the type of views that you are using
+ * (custom ViewHolder)
+ */
+ class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
+ val textView: TextView
+
+ init {
+ // Define click listener for the ViewHolder's View
+ textView = view.findViewById(R.id.routeBallID)
+ }
+ }
+ constructor(palina: Palina, showOnlyEmpty: Boolean): this(palina.routesNamesWithNoPassages)
+
+ // Create new views (invoked by the layout manager)
+ override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): ViewHolder {
+ // Create a new view, which defines the UI of the list item
+ val view = LayoutInflater.from(viewGroup.context)
+ .inflate(R.layout.round_line_header, viewGroup, false)
+
+ return ViewHolder(view)
+ }
+
+ // Replace the contents of a view (invoked by the layout manager)
+ override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
+
+ // Get element from your dataset at this position and replace the
+ // contents of the view with that element
+ viewHolder.textView.text = routeNames[position]
+ }
+
+ // Return the size of your dataset (invoked by the layout manager)
+ override fun getItemCount() = routeNames.size
+
+}
diff --git a/app/src/main/java/it/reyboz/bustorino/backend/Palina.java b/app/src/main/java/it/reyboz/bustorino/backend/Palina.java
index 902f00e..b25393d 100644
--- a/app/src/main/java/it/reyboz/bustorino/backend/Palina.java
+++ b/app/src/main/java/it/reyboz/bustorino/backend/Palina.java
@@ -1,404 +1,417 @@
/*
BusTO (backend components)
Copyright (C) 2016 Ludovico Pavesi
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package it.reyboz.bustorino.backend;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import it.reyboz.bustorino.util.LinesNameSorter;
/**
* Timetable for multiple routes.<br>
* <br>
* Apparently "palina" and a bunch of other terms can't really be translated into English.<br>
* Not in a way that makes sense and keeps the code readable, at least.
*/
public class Palina extends Stop {
private ArrayList<Route> routes = new ArrayList<>();
private boolean routesModified = false;
private Passaggio.Source allSource = null;
public Palina(String stopID) {
super(stopID);
}
public Palina(Stop s){
super(s.ID,s.getStopDefaultName(),s.getStopUserName(),s.location,s.type,
s.getRoutesThatStopHere(),s.getLatitude(),s.getLongitude(), null);
}
public Palina(@NonNull String ID, @Nullable String name, @Nullable String userName,
@Nullable String location,
@Nullable Double lat, @Nullable Double lon, @Nullable String gtfsID) {
super(ID, name, userName, location, null, null, lat, lon, gtfsID);
}
public Palina(@Nullable String name, @NonNull String ID, @Nullable String location, @Nullable Route.Type type, @Nullable List<String> routesThatStopHere) {
super(name, ID, location, type, routesThatStopHere);
}
/**
* Adds a timetable entry to a route.
*
* @param TimeGTT time in GTT format (e.g. "11:22*")
* @param arrayIndex position in the array for this route (returned by addRoute)
*/
public void addPassaggio(String TimeGTT, Passaggio.Source src,int arrayIndex) {
this.routes.get(arrayIndex).addPassaggio(TimeGTT,src);
routesModified = true;
}
/**
* Count routes with missing directions
* @return number
*/
public int countRoutesWithMissingDirections(){
int i = 0;
for (Route r : routes){
if(r.destinazione==null||r.destinazione.equals(""))
i++;
}
return i;
}
/**
* Adds a route to the timetable.
*
* @param routeID name
* @param type bus, underground, railway, ...
* @param destinazione end of line\terminus (underground stations have the same ID for both directions)
* @return array index for this route
*/
public int addRoute(String routeID, String destinazione, Route.Type type) {
return addRoute(new Route(routeID, destinazione, type, new ArrayList<>(6)));
}
public int addRoute(Route r){
this.routes.add(r);
routesModified = true;
buildRoutesString();
return this.routes.size()-1; // last inserted element and pray that direct access to ArrayList elements really is direct
}
public void setRoutes(List<Route> routeList){
routes = new ArrayList<>(routeList);
}
@Nullable
@Override
protected String buildRoutesString() {
// no routes => no string
if(routes == null || routes.size() == 0) {
return "";
}
/*final StringBuilder sb = new StringBuilder();
final LinesNameSorter nameSorter = new LinesNameSorter();
Collections.sort(routes, (o1, o2) -> nameSorter.compare(o1.getName().trim(), o2.getName().trim()));
int i, lenMinusOne = routes.size() - 1;
for (i = 0; i < lenMinusOne; i++) {
sb.append(routes.get(i).getName().trim()).append(", ");
}
// last one:
sb.append(routes.get(i).getName());
*/
ArrayList<String> names = new ArrayList<>();
for (Route r: routes){
names.add(r.getName());
}
final String routesThatStopHere = buildRoutesStringFromNames(names);
setRoutesThatStopHereString(routesThatStopHere);
return routesThatStopHereToString();
}
/**
* Sort the names of the routes for the string "routes stopping here" and make the string
* @param names of the Routes that pass in the stop
* @return the full string of routes stopping (eg, "10, 13, 42" ecc)
*/
public static String buildRoutesStringFromNames(List<String> names){
final StringBuilder sb = new StringBuilder();
final LinesNameSorter nameSorter = new LinesNameSorter();
Collections.sort(names, nameSorter);
int i, lenMinusOne = names.size() - 1;
for (i = 0; i < lenMinusOne; i++) {
sb.append(names.get(i).trim()).append(", ");
}
//last one
sb.append(names.get(i).trim());
return sb.toString();
}
protected void checkPassaggi(){
Passaggio.Source mSource = null;
for (Route r: routes){
for(Passaggio pass: r.passaggi){
if (mSource == null) {
mSource = pass.source;
} else if (mSource != pass.source){
Log.w("BusTO-CheckPassaggi",
"Cannot determine the source, have got "+mSource +" so far, the next one is "+pass.source );
mSource = Passaggio.Source.UNDETERMINED;
break;
}
}
if(mSource == Passaggio.Source.UNDETERMINED)
break;
}
// if the Source is still null, set undetermined
if (mSource == null) mSource = Passaggio.Source.UNDETERMINED;
//finished with the check, setting flags
routesModified = false;
allSource = mSource;
}
@NonNull
public Passaggio.Source getPassaggiSourceIfAny(){
if(allSource==null || routesModified){
checkPassaggi();
}
assert allSource != null;
return allSource;
}
/**
* Gets every route and its timetable.
*
* @return routes and timetables.
*/
public List<Route> queryAllRoutes() {
return this.routes;
}
public void sortRoutes() {
Collections.sort(this.routes);
}
/**
* Add info about the routes already found from another source
* @param additionalRoutes ArrayList of routes to get the info from
* @return the number of routes modified
*/
public int addInfoFromRoutes(List<Route> additionalRoutes){
if(routes == null || routes.size()==0) {
this.routes = new ArrayList<>(additionalRoutes);
buildRoutesString();
return routes.size();
}
int count=0;
final Calendar c = Calendar.getInstance();
final int todaysInt = c.get(Calendar.DAY_OF_WEEK);
for(Route r:routes) {
int j = 0;
boolean correct = false;
Route selected = null;
//TODO: rewrite this as a simple loop
//MADNESS begins here
while (!correct) {
//find the correct route to merge to
// scan routes and find the first which has the same name
while (j < additionalRoutes.size() && !r.getName().equals(additionalRoutes.get(j).getName())) {
j++;
}
if (j == additionalRoutes.size()) break; //no match has been found
//should have found the first occurrence of the line
selected = additionalRoutes.get(j);
//move forward
j++;
if (selected.serviceDays != null && selected.serviceDays.length > 0) {
//check if it is in service
for (int d : selected.serviceDays) {
if (d == todaysInt) {
correct = true;
break;
}
}
} else if (r.festivo != null) {
switch (r.festivo) {
case FERIALE:
//Domenica = 1 --> Saturday=7
if (todaysInt <= 7 && todaysInt > 1) correct = true;
break;
case FESTIVO:
if (todaysInt == 1) correct = true; //TODO: implement way to recognize all holidays
break;
case UNKNOWN:
correct = true;
}
} else {
//case a: there is no info because the line is always active
//case b: there is no info because the information is missing
correct = true;
}
}
if (!correct || selected == null) {
Log.w("Palina_mergeRoutes","Cannot match the route with name "+r.getName());
continue; //we didn't find any match
}
//found the correct correspondance
//MERGE INFO
if(r.mergeRouteWithAnother(selected)) count++;
}
if (count> 0) buildRoutesString();
return count;
}
// /**
// * Route with terminus (destinazione) and timetables (passaggi), internal implementation.
// *
// * Contains mostly the same data as the Route public class, but methods are quite different and extending Route doesn't really work, here.
// */
// private final class RouteInternal {
// public final String name;
// public final String destinazione;
// private boolean updated;
// private List<Passaggio> passaggi;
//
// /**
// * Creates a new route and marks it as "updated", since it's new.
// *
// * @param routeID name
// * @param destinazione end of line\terminus
// */
// public RouteInternal(String routeID, String destinazione) {
// this.name = routeID;
// this.destinazione = destinazione;
// this.passaggi = new LinkedList<>();
// this.updated = true;
// }
//
// /**
// * Adds a time (passaggio) to the timetable for this route
// *
// * @param TimeGTT time in GTT format (e.g. "11:22*")
// */
// public void addPassaggio(String TimeGTT) {
// this.passaggi.add(new Passaggio(TimeGTT));
// }
//
// /**
// * Deletes al times (passaggi) from the timetable.
// */
// public void deletePassaggio() {
// this.passaggi = new LinkedList<>();
// this.updated = true;
// }
//
// /**
// * Sets the "updated" flag to false.
// *
// * @return previous state
// */
// public boolean unupdateFlag() {
// if(this.updated) {
// this.updated = false;
// return true;
// } else {
// return false;
// }
// }
//
// /**
// * Sets the "updated" flag to true.
// *
// * @return previous state
// */
// public boolean updateFlag() {
// if(this.updated) {
// return true;
// } else {
// this.updated = true;
// return false;
// }
// }
//
// /**
// * Exactly what it says on the tin.
// *
// * @return times from the timetable
// */
// public List<Passaggio> getPassaggi() {
// return this.passaggi;
// }
// }
//remove duplicates
public void mergeDuplicateRoutes(int startidx){
//ArrayList<Route> routesCopy = new ArrayList<>(routes);
//for
if(routes.size()<=1|| startidx >= routes.size()) //we have finished
return;
Route routeCheck = routes.get(startidx);
boolean found = false;
for(int i=startidx+1; i<routes.size(); i++){
final Route r = routes.get(i);
if(routeCheck.equals(r)){
//we have found a match, merge
routes.remove(routeCheck);
r.mergeRouteWithAnother(routeCheck);
found=true;
break;
}
}
if (found) mergeDuplicateRoutes(startidx);
else mergeDuplicateRoutes(startidx+1);
}
public int getTotalNumberOfPassages(){
int tot = 0;
if(routes==null)
return tot;
for(Route r: routes){
tot += r.numPassaggi();
}
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());
}
if (min == Integer.MAX_VALUE) return 0;
else return min;
}
+
+ public ArrayList<String> getRoutesNamesWithNoPassages(){
+ ArrayList<String> mList = new ArrayList<>();
+ if(routes==null || routes.size() == 0){
+ return mList;
+ }
+ for(Route r: routes){
+ if(r.numPassaggi()==0)
+ mList.add(r.getNameForDisplay());
+ }
+
+ return mList;
+ }
//private void mergeRoute
}
\ No newline at end of file
diff --git a/app/src/main/java/it/reyboz/bustorino/fragments/ArrivalsFragment.java b/app/src/main/java/it/reyboz/bustorino/fragments/ArrivalsFragment.java
index f4e1068..b5c0653 100644
--- a/app/src/main/java/it/reyboz/bustorino/fragments/ArrivalsFragment.java
+++ b/app/src/main/java/it/reyboz/bustorino/fragments/ArrivalsFragment.java
@@ -1,559 +1,659 @@
/*
BusTO - Fragments components
Copyright (C) 2018 Fabio Mazza
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package it.reyboz.bustorino.fragments;
+import android.annotation.SuppressLint;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
+import android.widget.*;
import androidx.annotation.Nullable;
import androidx.annotation.NonNull;
+import androidx.core.widget.NestedScrollView;
import androidx.loader.app.LoaderManager;
import androidx.loader.content.CursorLoader;
import androidx.loader.content.Loader;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.ImageButton;
-import android.widget.ListAdapter;
-import android.widget.TextView;
-import android.widget.Toast;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import androidx.recyclerview.widget.DividerItemDecoration;
+import androidx.recyclerview.widget.GridLayoutManager;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
import it.reyboz.bustorino.R;
+import it.reyboz.bustorino.adapters.AdapterClickListener;
import it.reyboz.bustorino.adapters.PalinaAdapter;
+import it.reyboz.bustorino.adapters.RouteOnlyLineAdapter;
import it.reyboz.bustorino.backend.ArrivalsFetcher;
import it.reyboz.bustorino.backend.DBStatusManager;
import it.reyboz.bustorino.backend.Fetcher;
import it.reyboz.bustorino.backend.FiveTNormalizer;
import it.reyboz.bustorino.backend.Palina;
import it.reyboz.bustorino.backend.Passaggio;
import it.reyboz.bustorino.backend.Route;
import it.reyboz.bustorino.backend.Stop;
import it.reyboz.bustorino.backend.utils;
import it.reyboz.bustorino.data.AppDataProvider;
import it.reyboz.bustorino.data.NextGenDB;
import it.reyboz.bustorino.data.UserDB;
import it.reyboz.bustorino.middleware.AsyncStopFavoriteAction;
+import it.reyboz.bustorino.util.LinesNameSorter;
+import it.reyboz.bustorino.util.ViewUtils;
-public class ArrivalsFragment extends ResultListFragment implements LoaderManager.LoaderCallbacks<Cursor> {
+public class ArrivalsFragment extends ResultBaseFragment implements LoaderManager.LoaderCallbacks<Cursor> {
private final static String KEY_STOP_ID = "stopid";
private final static String KEY_STOP_NAME = "stopname";
private final static String DEBUG_TAG_ALL = "BUSTOArrivalsFragment";
private String DEBUG_TAG = DEBUG_TAG_ALL;
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;
private DBStatusManager.OnDBUpdateStatusChangeListener listener;
private boolean justCreated = false;
private Palina lastUpdatedPalina = null;
private boolean needUpdateOnAttach = false;
private boolean fetchersChangeRequestPending = false;
private boolean stopIsInFavorites = false;
//Views
protected ImageButton addToFavorites;
protected TextView timesSourceTextView;
+ protected TextView messageTextView;
+ protected RecyclerView arrivalsRecyclerView;
+ private PalinaAdapter mListAdapter = null;
+
+ //private NestedScrollView theScrollView;
+ protected RecyclerView noArrivalsRecyclerView;
+ private RouteOnlyLineAdapter noArrivalsAdapter;
+ private TextView noArrivalsTitleView;
+ private GridLayoutManager layoutManager;
+
+ //private View canaryEndView;
private List<ArrivalsFetcher> fetchers = null; //new ArrayList<>(Arrays.asList(utils.getDefaultArrivalsFetchers()));
private boolean reloadOnResume = true;
+ private final AdapterClickListener<Route> mRouteClickListener = route -> {
+ String routeName;
+
+ routeName = FiveTNormalizer.routeInternalToDisplay(route.getNameForDisplay());
+ if (routeName == null) {
+ routeName = route.getNameForDisplay();
+ }
+ if(getContext()==null)
+ Log.e(DEBUG_TAG, "Touched on a route but Context is null");
+ else if (route.destinazione == null || route.destinazione.length() == 0) {
+ Toast.makeText(getContext(),
+ getString(R.string.route_towards_unknown, routeName), Toast.LENGTH_SHORT).show();
+ } else {
+ Toast.makeText(getContext(),
+ getString(R.string.route_towards_destination, routeName, route.destinazione), Toast.LENGTH_SHORT).show();
+ }
+
+ };
+
public static ArrivalsFragment newInstance(String stopID){
return newInstance(stopID, null);
}
public static ArrivalsFragment newInstance(@NonNull String stopID, @Nullable String stopName){
ArrivalsFragment fragment = new ArrivalsFragment();
Bundle args = new Bundle();
args.putString(KEY_STOP_ID,stopID);
//parameter for ResultListFragmentrequestArrivalsForStopID
- args.putSerializable(LIST_TYPE,FragmentKind.ARRIVALS);
+ //args.putSerializable(LIST_TYPE,FragmentKind.ARRIVALS);
if (stopName != null){
args.putString(KEY_STOP_NAME,stopName);
}
fragment.setArguments(args);
return fragment;
}
+ public static String getFragmentTag(Palina p) {
+ return "palina_"+p.ID;
+ }
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
stopID = getArguments().getString(KEY_STOP_ID);
DEBUG_TAG = DEBUG_TAG_ALL+" "+stopID;
//this might really be null
stopName = getArguments().getString(KEY_STOP_NAME);
final ArrivalsFragment arrivalsFragment = this;
listener = new DBStatusManager.OnDBUpdateStatusChangeListener() {
@Override
public void onDBStatusChanged(boolean updating) {
if(!updating){
getLoaderManager().restartLoader(loaderFavId,getArguments(),arrivalsFragment);
} else {
final LoaderManager lm = getLoaderManager();
lm.destroyLoader(loaderFavId);
lm.destroyLoader(loaderStopId);
}
}
@Override
public boolean defaultStatusValue() {
return true;
}
};
prefs = new DBStatusManager(getContext().getApplicationContext(),listener);
justCreated = true;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_arrivals, container, false);
messageTextView = root.findViewById(R.id.messageTextView);
addToFavorites = root.findViewById(R.id.addToFavorites);
- resultsListView = root.findViewById(R.id.resultsListView);
+ //theScrollView = root.findViewById(R.id.arrivalsScrollView);
+ // recyclerview holding the arrival times
+ arrivalsRecyclerView = root.findViewById(R.id.arrivalsRecyclerView);
+ final LinearLayoutManager manager = new LinearLayoutManager(getContext());
+ arrivalsRecyclerView.setLayoutManager(manager);
+ final DividerItemDecoration mDividerItemDecoration = new DividerItemDecoration(arrivalsRecyclerView.getContext(),
+ manager.getOrientation());
+ arrivalsRecyclerView.addItemDecoration(mDividerItemDecoration);
timesSourceTextView = root.findViewById(R.id.timesSourceTextView);
timesSourceTextView.setOnLongClickListener(view -> {
if(!fetchersChangeRequestPending){
rotateFetchers();
//Show we are changing provider
timesSourceTextView.setText(R.string.arrival_source_changing);
mListener.requestArrivalsForStopID(stopID);
fetchersChangeRequestPending = true;
return true;
}
return false;
});
timesSourceTextView.setOnClickListener(view -> {
Toast.makeText(getContext(), R.string.change_arrivals_source_message, Toast.LENGTH_SHORT)
.show();
});
//Button
addToFavorites.setClickable(true);
addToFavorites.setOnClickListener(v -> {
// add/remove the stop in the favorites
toggleLastStopToFavorites();
});
- resultsListView.setOnItemClickListener((parent, view, position, id) -> {
- String routeName;
-
- Route r = (Route) parent.getItemAtPosition(position);
- routeName = FiveTNormalizer.routeInternalToDisplay(r.getNameForDisplay());
- if (routeName == null) {
- routeName = r.getNameForDisplay();
- }
- if (r.destinazione == null || r.destinazione.length() == 0) {
- Toast.makeText(getContext(),
- getString(R.string.route_towards_unknown, routeName), Toast.LENGTH_SHORT).show();
- } else {
- Toast.makeText(getContext(),
- getString(R.string.route_towards_destination, routeName, r.destinazione), Toast.LENGTH_SHORT).show();
- }
- });
String displayName = getArguments().getString(STOP_TITLE);
if(displayName!=null)
- setTextViewMessage(String.format(
+ setTextViewMessage(String.format(
getString(R.string.passages), displayName));
String probablemessage = getArguments().getString(MESSAGE_TEXT_VIEW);
if (probablemessage != null) {
//Log.d("BusTO fragment " + this.getTag(), "We have a possible message here in the savedInstaceState: " + probablemessage);
messageTextView.setText(probablemessage);
messageTextView.setVisibility(View.VISIBLE);
}
+ //no arrivals stuff
+ noArrivalsRecyclerView = root.findViewById(R.id.noArrivalsRecyclerView);
+ layoutManager = new GridLayoutManager(getContext(),60);
+ layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
+ @Override
+ public int getSpanSize(int position) {
+ return 12;
+ }
+ });
+ noArrivalsRecyclerView.setLayoutManager(layoutManager);
+ noArrivalsTitleView = root.findViewById(R.id.noArrivalsMessageTextView);
+
+ //canaryEndView = root.findViewById(R.id.canaryEndView);
/*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;
}
@Override
public void onResume() {
super.onResume();
LoaderManager loaderManager = getLoaderManager();
- Log.d(DEBUG_TAG, "OnResume, justCreated "+justCreated);
+ Log.d(DEBUG_TAG, "OnResume, justCreated "+justCreated+", lastUpdatedPalina is: "+lastUpdatedPalina);
/*if(needUpdateOnAttach){
updateFragmentData(null);
needUpdateOnAttach=false;
}*/
+ /*if(lastUpdatedPalina!=null){
+ updateFragmentData(null);
+ showArrivalsSources(lastUpdatedPalina);
+ }*/
+ if (mListAdapter!=null)
+ resetListAdapter(mListAdapter);
+ if(noArrivalsAdapter!=null){
+ noArrivalsRecyclerView.setAdapter(noArrivalsAdapter);
+
+ }
+
if(stopID!=null){
- //refresh the arrivals
if(!justCreated){
fetchers = utils.getDefaultArrivalsFetchers(getContext());
adjustFetchersToSource();
if (reloadOnResume)
mListener.requestArrivalsForStopID(stopID);
}
else justCreated = false;
//start the loader
if(prefs.isDBUpdating(true)){
prefs.registerListener();
} else {
Log.d(DEBUG_TAG, "Restarting loader for stop");
loaderManager.restartLoader(loaderFavId, getArguments(), this);
}
updateMessage();
}
}
@Override
public void onStart() {
super.onStart();
if (needUpdateOnAttach){
updateFragmentData(null);
needUpdateOnAttach = false;
}
}
@Override
public void onPause() {
if(listener!=null)
prefs.unregisterListener();
super.onPause();
LoaderManager loaderManager = getLoaderManager();
Log.d(DEBUG_TAG, "onPause, have running loaders: "+loaderManager.hasRunningLoaders());
loaderManager.destroyLoader(loaderFavId);
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
//get fetchers
fetchers = utils.getDefaultArrivalsFetchers(context);
}
@Nullable
public String getStopID() {
return stopID;
}
public boolean reloadsOnResume() {
return reloadOnResume;
}
public void setReloadOnResume(boolean reloadOnResume) {
this.reloadOnResume = reloadOnResume;
}
/**
* Give the fetchers
* @return the list of the fetchers
*/
public ArrayList<Fetcher> getCurrentFetchers(){
return new ArrayList<>(this.fetchers);
}
public ArrivalsFetcher[] getCurrentFetchersAsArray(){
ArrivalsFetcher[] arr = new ArrivalsFetcher[fetchers.size()];
fetchers.toArray(arr);
return arr;
}
private void rotateFetchers(){
Log.d(DEBUG_TAG, "Rotating fetchers, before: "+fetchers);
Collections.rotate(fetchers, -1);
Log.d(DEBUG_TAG, "Rotating fetchers, afterwards: "+fetchers);
}
/**
* Update the UI with the new data
* @param p the full Palina
*/
public void updateFragmentData(@Nullable Palina p){
if (p!=null)
lastUpdatedPalina = p;
if (!isAdded()){
//defer update at next show
if (p==null)
Log.w(DEBUG_TAG, "Asked to update the data, but we're not attached and the data is null");
else needUpdateOnAttach = true;
} else {
- final PalinaAdapter adapter = new PalinaAdapter(getContext(), lastUpdatedPalina);
+ final PalinaAdapter adapter = new PalinaAdapter(getContext(), lastUpdatedPalina, mRouteClickListener, true);
showArrivalsSources(lastUpdatedPalina);
- super.resetListAdapter(adapter);
+ resetListAdapter(adapter);
+
+ final ArrayList<String> routesWithNoPassages = lastUpdatedPalina.getRoutesNamesWithNoPassages();
+ Collections.sort(routesWithNoPassages, new LinesNameSorter());
+ noArrivalsAdapter = new RouteOnlyLineAdapter(routesWithNoPassages);
+ if(noArrivalsRecyclerView!=null){
+ noArrivalsRecyclerView.setAdapter(noArrivalsAdapter);
+ //hide the views if there are no empty routes
+ if(routesWithNoPassages.isEmpty()){
+ noArrivalsRecyclerView.setVisibility(View.GONE);
+ noArrivalsTitleView.setVisibility(View.GONE);
+ } else {
+ noArrivalsRecyclerView.setVisibility(View.VISIBLE);
+ noArrivalsTitleView.setVisibility(View.VISIBLE);
+ }
+ }
+
+ //canaryEndView.setVisibility(View.VISIBLE);
+ //check if canaryEndView is visible
+ //boolean isCanaryVisibile = ViewUtils.Companion.isViewPartiallyVisibleInScroll(canaryEndView, theScrollView);
+ //Log.d(DEBUG_TAG, "Canary view fully visibile: "+isCanaryVisibile);
+
}
}
+
+
/**
* Set the message of the arrival times source
* @param p Palina with the arrival times
*/
protected void showArrivalsSources(Palina p){
final Passaggio.Source source = p.getPassaggiSourceIfAny();
if (source == null){
Log.e(DEBUG_TAG, "NULL SOURCE");
return;
}
String source_txt;
switch (source){
case GTTJSON:
source_txt = getString(R.string.gttjsonfetcher);
break;
case FiveTAPI:
source_txt = getString(R.string.fivetapifetcher);
break;
case FiveTScraper:
source_txt = getString(R.string.fivetscraper);
break;
case MatoAPI:
source_txt = getString(R.string.source_mato);
break;
case UNDETERMINED:
//Don't show the view
source_txt = getString(R.string.undetermined_source);
break;
default:
throw new IllegalStateException("Unexpected value: " + source);
}
//
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);
+ timesSourceTextView.setVisibility(View.VISIBLE);
+
if (p.getTotalNumberOfPassages() > 0) {
timesSourceTextView.setVisibility(View.VISIBLE);
} else {
timesSourceTextView.setVisibility(View.INVISIBLE);
}
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();
- }
-
/**
* Update the message in the fragment
*
* It may eventually change the "Add to Favorite" icon
*/
private void updateMessage(){
String message = null;
if (stopName != null && stopID != null && stopName.length() > 0) {
message = (stopID.concat(" - ").concat(stopName));
} else if(stopID!=null) {
message = stopID;
} else {
Log.e("ArrivalsFragm"+getTag(),"NO ID FOR THIS FRAGMENT - something went horribly wrong");
}
if(message!=null) {
setTextViewMessage(getString(R.string.passages,message));
}
// whatever is the case, update the star icon
//updateStarIconFromLastBusStop();
}
@NonNull
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
if(args.getString(KEY_STOP_ID)==null) return null;
final String stopID = args.getString(KEY_STOP_ID);
final Uri.Builder builder = AppDataProvider.getUriBuilderToComplete();
CursorLoader cl;
switch (id){
case loaderFavId:
builder.appendPath("favorites").appendPath(stopID);
cl = new CursorLoader(getContext(),builder.build(),UserDB.getFavoritesColumnNamesAsArray,null,null,null);
break;
case loaderStopId:
builder.appendPath("stop").appendPath(stopID);
cl = new CursorLoader(getContext(),builder.build(),new String[]{NextGenDB.Contract.StopsTable.COL_NAME},
null,null,null);
break;
default:
return null;
}
cl.setUpdateThrottle(500);
return cl;
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
switch (loader.getId()){
case loaderFavId:
final int colUserName = data.getColumnIndex(UserDB.getFavoritesColumnNamesAsArray[1]);
if(data.getCount()>0){
// IT'S IN FAVORITES
data.moveToFirst();
final String probableName = data.getString(colUserName);
stopIsInFavorites = true;
stopName = probableName;
//update the message in the textview
updateMessage();
} else {
stopIsInFavorites =false;
}
updateStarIcon();
if(stopName == null){
//stop is not inside the favorites and wasn't provided
Log.d("ArrivalsFragment"+getTag(),"Stop wasn't in the favorites and has no name, looking in the DB");
getLoaderManager().restartLoader(loaderStopId,getArguments(),this);
}
break;
case loaderStopId:
if(data.getCount()>0){
data.moveToFirst();
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");
}
}
}
@Override
public void onLoaderReset(Loader<Cursor> loader) {
//NOTHING TO DO
}
+ protected void resetListAdapter(PalinaAdapter adapter) {
+ mListAdapter = adapter;
+ if (arrivalsRecyclerView != null) {
+ arrivalsRecyclerView.setAdapter(adapter);
+ arrivalsRecyclerView.setVisibility(View.VISIBLE);
+ }
+ }
+ /**
+ * Set the message textView
+ * @param message the whole message to write in the textView
+ */
+ public void setTextViewMessage(String message) {
+ messageTextView.setText(message);
+ messageTextView.setVisibility(View.VISIBLE);
+ }
public void toggleLastStopToFavorites() {
Stop stop = lastUpdatedPalina;
if (stop != null) {
// toggle the status in background
new AsyncStopFavoriteAction(getContext().getApplicationContext(), AsyncStopFavoriteAction.Action.TOGGLE,
v->updateStarIconFromLastBusStop(v)).execute(stop);
} else {
// this case have no sense, but just immediately update the favorite icon
updateStarIconFromLastBusStop(true);
}
}
/**
* Update the star "Add to favorite" icon
*/
public void updateStarIconFromLastBusStop(Boolean toggleDone) {
if (stopIsInFavorites)
stopIsInFavorites = !toggleDone;
else stopIsInFavorites = toggleDone;
updateStarIcon();
// check if there is a last Stop
/*
if (stopID == null) {
addToFavorites.setVisibility(View.INVISIBLE);
} else {
// filled or outline?
if (isStopInFavorites(stopID)) {
addToFavorites.setImageResource(R.drawable.ic_star_filled);
} else {
addToFavorites.setImageResource(R.drawable.ic_star_outline);
}
addToFavorites.setVisibility(View.VISIBLE);
}
*/
}
/**
* Update the star icon according to `stopIsInFavorites`
*/
public void updateStarIcon() {
// no favorites no party!
// check if there is a last Stop
if (stopID == null) {
addToFavorites.setVisibility(View.INVISIBLE);
} else {
// filled or outline?
if (stopIsInFavorites) {
addToFavorites.setImageResource(R.drawable.ic_star_filled);
} else {
addToFavorites.setImageResource(R.drawable.ic_star_outline);
}
addToFavorites.setVisibility(View.VISIBLE);
}
}
@Override
public void onDestroyView() {
- getArguments().putString(SOURCES_TEXT, timesSourceTextView.getText().toString());
+ arrivalsRecyclerView = null;
+ if(getArguments()!=null) {
+ getArguments().putString(SOURCES_TEXT, timesSourceTextView.getText().toString());
+ getArguments().putString(MESSAGE_TEXT_VIEW, messageTextView.getText().toString());
+ }
super.onDestroyView();
}
+
+ public boolean isFragmentForTheSameStop(Palina p) {
+ if (getTag() != null)
+ return getTag().equals(getFragmentTag(p));
+ else return false;
+ }
}
diff --git a/app/src/main/java/it/reyboz/bustorino/fragments/FragmentHelper.java b/app/src/main/java/it/reyboz/bustorino/fragments/FragmentHelper.java
index d86349f..444934b 100644
--- a/app/src/main/java/it/reyboz/bustorino/fragments/FragmentHelper.java
+++ b/app/src/main/java/it/reyboz/bustorino/fragments/FragmentHelper.java
@@ -1,285 +1,285 @@
/*
BusTO (fragments)
Copyright (C) 2018 Fabio Mazza
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package it.reyboz.bustorino.fragments;
import android.content.Context;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.Toast;
import it.reyboz.bustorino.R;
import it.reyboz.bustorino.backend.Fetcher;
import it.reyboz.bustorino.backend.Palina;
import it.reyboz.bustorino.backend.Stop;
import it.reyboz.bustorino.backend.utils;
import it.reyboz.bustorino.middleware.*;
import java.lang.ref.WeakReference;
import java.util.List;
/**
* Helper class to manage the fragments and their needs
*/
public class FragmentHelper {
//GeneralActivity act;
private final FragmentListenerMain listenerMain;
private final WeakReference<FragmentManager> managerWeakRef;
private Stop lastSuccessfullySearchedBusStop;
//support for multiple frames
private final int secondaryFrameLayout;
private final int primaryFrameLayout;
private final Context context;
public static final int NO_FRAME = -3;
private static final String DEBUG_TAG = "BusTO FragmHelper";
private WeakReference<AsyncTask> lastTaskRef;
private boolean shouldHaltAllActivities=false;
public FragmentHelper(FragmentListenerMain listener, FragmentManager framan, Context context, int mainFrame) {
this(listener,framan, context,mainFrame,NO_FRAME);
}
public FragmentHelper(FragmentListenerMain listener, FragmentManager fraMan, Context context, int primaryFrameLayout, int secondaryFrameLayout) {
this.listenerMain = listener;
this.managerWeakRef = new WeakReference<>(fraMan);
this.primaryFrameLayout = primaryFrameLayout;
this.secondaryFrameLayout = secondaryFrameLayout;
this.context = context.getApplicationContext();
}
/**
* Get the last successfully searched bus stop or NULL
*
* @return the stop
*/
public Stop getLastSuccessfullySearchedBusStop() {
return lastSuccessfullySearchedBusStop;
}
public void setLastSuccessfullySearchedBusStop(Stop stop) {
this.lastSuccessfullySearchedBusStop = stop;
}
public void setLastTaskRef(AsyncTask task) {
this.lastTaskRef = new WeakReference<>(task);
}
/**
* Called when you need to create a fragment for a specified Palina
* @param p the Stop that needs to be displayed
*/
public void createOrUpdateStopFragment(Palina p, boolean addToBackStack){
boolean sameFragment;
ArrivalsFragment arrivalsFragment = null;
if(managerWeakRef.get()==null || shouldHaltAllActivities) {
//SOMETHING WENT VERY WRONG
Log.e(DEBUG_TAG, "We are asked for a new stop but we can't show anything");
return;
}
FragmentManager fm = managerWeakRef.get();
if(fm.findFragmentById(primaryFrameLayout) instanceof ArrivalsFragment) {
arrivalsFragment = (ArrivalsFragment) fm.findFragmentById(primaryFrameLayout);
//Log.d(DEBUG_TAG, "Arrivals are for fragment with same stop?");
if (arrivalsFragment == null) sameFragment = false;
else sameFragment = arrivalsFragment.isFragmentForTheSameStop(p);
} else {
sameFragment = false;
Log.d(DEBUG_TAG, "We aren't showing an ArrivalsFragment");
}
setLastSuccessfullySearchedBusStop(p);
if (sameFragment){
Log.d("BusTO", "Same bus stop, accessing existing fragment");
arrivalsFragment = (ArrivalsFragment) fm.findFragmentById(primaryFrameLayout);
if (arrivalsFragment == null) sameFragment = false;
}
if(!sameFragment) {
//set the String to be displayed on the fragment
String displayName = p.getStopDisplayName();
if (displayName != null && displayName.length() > 0) {
arrivalsFragment = ArrivalsFragment.newInstance(p.ID,displayName);
} else {
arrivalsFragment = ArrivalsFragment.newInstance(p.ID);
}
- String probableTag = ResultListFragment.getFragmentTag(p);
+ String probableTag = ArrivalsFragment.getFragmentTag(p);
attachFragmentToContainer(fm,arrivalsFragment,new AttachParameters(probableTag, true, addToBackStack));
}
// DO NOT CALL `setListAdapter` ever on arrivals fragment
arrivalsFragment.updateFragmentData(p);
// enable fragment auto refresh
arrivalsFragment.setReloadOnResume(true);
listenerMain.hideKeyboard();
toggleSpinner(false);
}
/**
* Called when you need to display the results of a search of stops
* @param resultList the List of stops found
* @param query String queried
*/
public void createStopListFragment(List<Stop> resultList, String query, boolean addToBackStack){
listenerMain.hideKeyboard();
StopListFragment listfragment = StopListFragment.newInstance(query);
if(managerWeakRef.get()==null || shouldHaltAllActivities) {
//SOMETHING WENT VERY WRONG
Log.e(DEBUG_TAG, "We are asked for a new stop but we can't show anything");
return;
}
attachFragmentToContainer(managerWeakRef.get(),listfragment,
new AttachParameters("search_"+query, false,addToBackStack));
listfragment.setStopList(resultList);
listenerMain.readyGUIfor(FragmentKind.STOPS);
toggleSpinner(false);
}
/**
* Wrapper for toggleSpinner in Activity
* @param on new status of spinner system
*/
public void toggleSpinner(boolean on){
listenerMain.toggleSpinner(on);
}
/**
* Attach a new fragment to a cointainer
* @param fm the FragmentManager
* @param fragment the Fragment
* @param parameters attach parameters
*/
protected void attachFragmentToContainer(FragmentManager fm,Fragment fragment, AttachParameters parameters){
if(shouldHaltAllActivities) //nothing to do
return;
FragmentTransaction ft = fm.beginTransaction();
int frameID;
if(parameters.attachToSecondaryFrame && secondaryFrameLayout!=NO_FRAME)
// ft.replace(secondaryFrameLayout,fragment,tag);
frameID = secondaryFrameLayout;
else frameID = primaryFrameLayout;
switch (parameters.transaction){
case REPLACE:
ft.replace(frameID,fragment,parameters.tag);
}
if (parameters.addToBackStack)
ft.addToBackStack("state_"+parameters.tag);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
if(!fm.isDestroyed() && !shouldHaltAllActivities)
ft.commit();
//fm.executePendingTransactions();
}
public synchronized void setBlockAllActivities(boolean shouldI) {
this.shouldHaltAllActivities = shouldI;
}
public void stopLastRequestIfNeeded(boolean interruptIfRunning){
if(lastTaskRef == null) return;
AsyncTask task = lastTaskRef.get();
if(task!=null){
task.cancel(interruptIfRunning);
}
}
/**
* Wrapper to show the errors/status that happened
* @param res result from Fetcher
*/
public void showErrorMessage(Fetcher.Result res, SearchRequestType type){
//TODO: implement a common set of errors for all fragments
if (res==null){
Log.e(DEBUG_TAG, "Asked to show result with null result");
return;
}
Log.d(DEBUG_TAG, "Showing result for "+res);
switch (res){
case OK:
break;
case CLIENT_OFFLINE:
showToastMessage(R.string.network_error, true);
break;
case SERVER_ERROR:
if (utils.isConnected(context)) {
showToastMessage(R.string.parsing_error, true);
} else {
showToastMessage(R.string.network_error, true);
}
case PARSER_ERROR:
default:
showShortToast(R.string.internal_error);
break;
case QUERY_TOO_SHORT:
showShortToast(R.string.query_too_short);
break;
case EMPTY_RESULT_SET:
if (type == SearchRequestType.STOPS)
showShortToast(R.string.no_bus_stop_have_this_name);
else if(type == SearchRequestType.ARRIVALS){
showShortToast(R.string.no_arrivals_stop);
}
break;
case NOT_FOUND:
showShortToast(R.string.no_bus_stop_have_this_name);
break;
}
}
public void showToastMessage(int messageID, boolean short_lenght) {
final int length = short_lenght ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG;
if (context != null)
Toast.makeText(context, messageID, length).show();
}
private void showShortToast(int messageID){
showToastMessage(messageID, true);
}
enum Transaction{
REPLACE,
}
static final class AttachParameters {
String tag;
boolean attachToSecondaryFrame;
Transaction transaction;
boolean addToBackStack;
public AttachParameters(String tag, boolean attachToSecondaryFrame, Transaction transaction, boolean addToBackStack) {
this.tag = tag;
this.attachToSecondaryFrame = attachToSecondaryFrame;
this.transaction = transaction;
this.addToBackStack = addToBackStack;
}
public AttachParameters(String tag, boolean attachToSecondaryFrame, boolean addToBackStack) {
this.tag = tag;
this.attachToSecondaryFrame = attachToSecondaryFrame;
this.addToBackStack = addToBackStack;
this.transaction = Transaction.REPLACE;
}
}
}
diff --git a/app/src/main/java/it/reyboz/bustorino/fragments/MainScreenFragment.java b/app/src/main/java/it/reyboz/bustorino/fragments/MainScreenFragment.java
index 3859c30..f30fd70 100644
--- a/app/src/main/java/it/reyboz/bustorino/fragments/MainScreenFragment.java
+++ b/app/src/main/java/it/reyboz/bustorino/fragments/MainScreenFragment.java
@@ -1,882 +1,882 @@
package it.reyboz.bustorino.fragments;
import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Criteria;
import android.location.Location;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageButton;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.util.List;
import java.util.Map;
import it.reyboz.bustorino.R;
import it.reyboz.bustorino.backend.*;
import it.reyboz.bustorino.middleware.AppLocationManager;
import it.reyboz.bustorino.middleware.AsyncArrivalsSearcher;
import it.reyboz.bustorino.middleware.AsyncStopsSearcher;
import it.reyboz.bustorino.middleware.BarcodeScanContract;
import it.reyboz.bustorino.middleware.BarcodeScanOptions;
import it.reyboz.bustorino.middleware.BarcodeScanUtils;
import it.reyboz.bustorino.util.LocationCriteria;
import it.reyboz.bustorino.util.Permissions;
import static it.reyboz.bustorino.backend.utils.getBusStopIDFromUri;
import static it.reyboz.bustorino.util.Permissions.LOCATION_PERMISSIONS;
/**
* A simple {@link Fragment} subclass.
* Use the {@link MainScreenFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class MainScreenFragment extends ScreenBaseFragment implements FragmentListenerMain{
private static final String OPTION_SHOW_LEGEND = "show_legend";
private static final String SAVED_FRAGMENT="saved_fragment";
private static final String DEBUG_TAG = "BusTO - MainFragment";
public static final String PENDING_STOP_SEARCH="PendingStopSearch";
public final static String FRAGMENT_TAG = "MainScreenFragment";
/// UI ELEMENTS //
private ImageButton addToFavorites;
private FragmentHelper fragmentHelper;
private SwipeRefreshLayout swipeRefreshLayout;
private EditText busStopSearchByIDEditText;
private EditText busStopSearchByNameEditText;
private ProgressBar progressBar;
private TextView howDoesItWorkTextView;
private Button hideHintButton;
private MenuItem actionHelpMenuItem;
private FloatingActionButton floatingActionButton;
private FrameLayout resultFrameLayout;
private boolean setupOnStart = true;
private boolean suppressArrivalsReload = false;
private boolean instanceStateSaved = false;
//private Snackbar snackbar;
/*
* Search mode
*/
private static final int SEARCH_BY_NAME = 0;
private static final int SEARCH_BY_ID = 1;
private static final int SEARCH_BY_ROUTE = 2; // TODO: implement this -- https://gitpull.it/T12
private int searchMode;
//private ImageButton addToFavorites;
//// HIDDEN BUT IMPORTANT ELEMENTS ////
FragmentManager fragMan;
Handler mainHandler;
private final Runnable refreshStop = new Runnable() {
public void run() {
if(getContext() == null) return;
List<ArrivalsFetcher> 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){
//we create a new fragment, which is WRONG
Log.e("BusTO-RefreshStop", "Asking for refresh when there is no fragment");
// AsyncDataDownload(fragmentHelper, arrivalsFetchers,getContext()).execute();
} else{
String stopName = fragment.getStopID();
new AsyncArrivalsSearcher(fragmentHelper, fragment.getCurrentFetchersAsArray(), getContext()).execute(stopName);
}
} else //we create a new fragment, which is WRONG
new AsyncArrivalsSearcher(fragmentHelper, arrivalsFetchers, getContext()).execute();
}
};
//
private final ActivityResultLauncher<BarcodeScanOptions> barcodeLauncher = registerForActivityResult(new BarcodeScanContract(),
result -> {
if(result!=null && result.getContents()!=null) {
//Toast.makeText(MyActivity.this, "Cancelled", Toast.LENGTH_LONG).show();
Uri uri;
try {
uri = Uri.parse(result.getContents()); // this apparently prevents NullPointerException. Somehow.
} catch (NullPointerException e) {
if (getContext()!=null)
- Toast.makeText(getContext().getApplicationContext(),
+ Toast.makeText(getContext().getApplicationContext(),
R.string.no_qrcode, Toast.LENGTH_SHORT).show();
return;
}
String busStopID = getBusStopIDFromUri(uri);
busStopSearchByIDEditText.setText(busStopID);
requestArrivalsForStopID(busStopID);
} else {
//Toast.makeText(MyActivity.this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
if (getContext()!=null)
Toast.makeText(getContext().getApplicationContext(),
R.string.no_qrcode, Toast.LENGTH_SHORT).show();
}
});
/// LOCATION STUFF ///
boolean pendingNearbyStopsRequest = false;
boolean locationPermissionGranted, locationPermissionAsked = false;
AppLocationManager locationManager;
private final ActivityResultLauncher<String[]> requestPermissionLauncher =
registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback<Map<String, Boolean>>() {
@Override
public void onActivityResult(Map<String, Boolean> result) {
if(result==null || result.get(Manifest.permission.ACCESS_COARSE_LOCATION) == null
||result.get(Manifest.permission.ACCESS_FINE_LOCATION) == null) return;
if(result.get(Manifest.permission.ACCESS_COARSE_LOCATION) == null ||
result.get(Manifest.permission.ACCESS_FINE_LOCATION) == null)
return;
boolean resCoarse = result.get(Manifest.permission.ACCESS_COARSE_LOCATION);
boolean resFine = result.get(Manifest.permission.ACCESS_FINE_LOCATION);
Log.d(DEBUG_TAG, "Permissions for location are: "+result);
if(result.get(Manifest.permission.ACCESS_COARSE_LOCATION) && result.get(Manifest.permission.ACCESS_FINE_LOCATION)){
locationPermissionGranted = true;
Log.w(DEBUG_TAG, "Starting position");
if (mListener!= null && getContext()!=null){
if (locationManager==null)
locationManager = AppLocationManager.getInstance(getContext());
locationManager.addLocationRequestFor(requester);
}
// show nearby fragment
//showNearbyStopsFragment();
Log.d(DEBUG_TAG, "We have location permission");
if(pendingNearbyStopsRequest){
showNearbyFragmentIfNeeded(cr);
pendingNearbyStopsRequest = false;
}
}
if(pendingNearbyStopsRequest) pendingNearbyStopsRequest=false;
}
});
private final LocationCriteria cr = new LocationCriteria(2000, 10000);
//Location
private AppLocationManager.LocationRequester requester = new AppLocationManager.LocationRequester() {
@Override
public void onLocationChanged(Location loc) {
}
@Override
public void onLocationStatusChanged(int status) {
if(status == AppLocationManager.LOCATION_GPS_AVAILABLE && !isNearbyFragmentShown() && checkLocationPermission()){
//request Stops
//pendingNearbyStopsRequest = false;
if (getContext()!= null && !isNearbyFragmentShown())
//mainHandler.post(new NearbyStopsRequester(getContext(), cr));
showNearbyFragmentIfNeeded(cr);
}
}
@Override
public long getLastUpdateTimeMillis() {
return 50;
}
@Override
public LocationCriteria getLocationCriteria() {
return cr;
}
@Override
public void onLocationProviderAvailable() {
//Log.w(DEBUG_TAG, "pendingNearbyStopRequest: "+pendingNearbyStopsRequest);
if(!isNearbyFragmentShown() && getContext()!=null){
// we should have the location permission
if(!checkLocationPermission())
Log.e(DEBUG_TAG, "Asking to show nearbystopfragment when " +
"we have no location permission");
pendingNearbyStopsRequest = true;
//mainHandler.post(new NearbyStopsRequester(getContext(), cr));
showNearbyFragmentIfNeeded(cr);
}
}
@Override
public void onLocationDisabled() {
}
};
//// ACTIVITY ATTACHED (LISTENER ///
private CommonFragmentListener mListener;
private String pendingStopID = null;
private CoordinatorLayout coordLayout;
public MainScreenFragment() {
// Required empty public constructor
}
public static MainScreenFragment newInstance() {
return new MainScreenFragment();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
//do nothing
Log.d(DEBUG_TAG, "ARGS ARE NOT NULL: "+getArguments());
if (getArguments().getString(PENDING_STOP_SEARCH)!=null)
pendingStopID = getArguments().getString(PENDING_STOP_SEARCH);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View root = inflater.inflate(R.layout.fragment_main_screen, container, false);
addToFavorites = root.findViewById(R.id.addToFavorites);
busStopSearchByIDEditText = root.findViewById(R.id.busStopSearchByIDEditText);
busStopSearchByNameEditText = root.findViewById(R.id.busStopSearchByNameEditText);
progressBar = root.findViewById(R.id.progressBar);
howDoesItWorkTextView = root.findViewById(R.id.howDoesItWorkTextView);
hideHintButton = root.findViewById(R.id.hideHintButton);
swipeRefreshLayout = root.findViewById(R.id.listRefreshLayout);
floatingActionButton = root.findViewById(R.id.floatingActionButton);
resultFrameLayout = root.findViewById(R.id.resultFrame);
busStopSearchByIDEditText.setSelectAllOnFocus(true);
busStopSearchByIDEditText
.setOnEditorActionListener((v, actionId, event) -> {
// IME_ACTION_SEARCH alphabetical option
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
onSearchClick(v);
return true;
}
return false;
});
busStopSearchByNameEditText
.setOnEditorActionListener((v, actionId, event) -> {
// IME_ACTION_SEARCH alphabetical option
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
onSearchClick(v);
return true;
}
return false;
});
swipeRefreshLayout
.setOnRefreshListener(() -> mainHandler.post(refreshStop));
swipeRefreshLayout.setColorSchemeResources(R.color.blue_500, R.color.orange_500);
coordLayout = root.findViewById(R.id.coord_layout);
floatingActionButton.setOnClickListener((this::onToggleKeyboardLayout));
hideHintButton.setOnClickListener(this::onHideHint);
AppCompatImageButton qrButton = root.findViewById(R.id.QRButton);
qrButton.setOnClickListener(this::onQRButtonClick);
AppCompatImageButton searchButton = root.findViewById(R.id.searchButton);
searchButton.setOnClickListener(this::onSearchClick);
// Fragment stuff
fragMan = getChildFragmentManager();
fragMan.addOnBackStackChangedListener(() -> Log.d("BusTO Main Fragment", "BACK STACK CHANGED"));
fragmentHelper = new FragmentHelper(this, getChildFragmentManager(), getContext(), R.id.resultFrame);
setSearchModeBusStopID();
cr.setAccuracy(Criteria.ACCURACY_FINE);
cr.setAltitudeRequired(false);
cr.setBearingRequired(false);
cr.setCostAllowed(true);
cr.setPowerRequirement(Criteria.NO_REQUIREMENT);
locationManager = AppLocationManager.getInstance(getContext());
Log.d(DEBUG_TAG, "OnCreateView, savedInstanceState null: "+(savedInstanceState==null));
return root;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Log.d(DEBUG_TAG, "onViewCreated, SwipeRefreshLayout visible: "+(swipeRefreshLayout.getVisibility()==View.VISIBLE));
Log.d(DEBUG_TAG, "Saved instance state is: "+savedInstanceState);
//Restore instance state
/*if (savedInstanceState!=null){
Fragment fragment = getChildFragmentManager().getFragment(savedInstanceState, SAVED_FRAGMENT);
if (fragment!=null){
getChildFragmentManager().beginTransaction().add(R.id.resultFrame, fragment).commit();
setupOnStart = false;
}
}
*/
if (getChildFragmentManager().findFragmentById(R.id.resultFrame)!= null){
swipeRefreshLayout.setVisibility(View.VISIBLE);
}
instanceStateSaved = false;
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
Log.d(DEBUG_TAG, "Saving instance state");
Fragment fragment = getChildFragmentManager().findFragmentById(R.id.resultFrame);
if (fragment!=null)
getChildFragmentManager().putFragment(outState, SAVED_FRAGMENT, fragment);
if (fragmentHelper!=null) fragmentHelper.setBlockAllActivities(true);
instanceStateSaved = true;
}
public void setSuppressArrivalsReload(boolean value){
suppressArrivalsReload = value;
// we have to suppress the reloading of the (possible) ArrivalsFragment
/*if(value) {
Fragment fragment = getChildFragmentManager().findFragmentById(R.id.resultFrame);
if (fragment instanceof ArrivalsFragment) {
ArrivalsFragment frag = (ArrivalsFragment) fragment;
frag.setReloadOnResume(false);
}
}
*/
}
/**
* Cancel the reload of the arrival times
* because we are going to pop the fragment
*/
public void cancelReloadArrivalsIfNeeded(){
if(getContext()==null) return; //we are not attached
//Fragment fr = getChildFragmentManager().findFragmentById(R.id.resultFrame);
fragmentHelper.stopLastRequestIfNeeded(true);
toggleSpinner(false);
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
Log.d(DEBUG_TAG, "OnAttach called, setupOnAttach: "+ setupOnStart);
mainHandler = new Handler();
if (context instanceof CommonFragmentListener) {
mListener = (CommonFragmentListener) context;
} else {
throw new RuntimeException(context
+ " must implement CommonFragmentListener");
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
// setupOnAttached = true;
}
@Override
public void onStart() {
super.onStart();
Log.d(DEBUG_TAG, "onStart called, setupOnStart: "+setupOnStart);
if (setupOnStart) {
if (pendingStopID==null){
//We want the nearby bus stops!
//mainHandler.post(new NearbyStopsRequester(getContext(), cr));
Log.d(DEBUG_TAG, "Showing nearby stops");
if(!checkLocationPermission()){
requestLocationPermission();
pendingNearbyStopsRequest = true;
}
else {
showNearbyFragmentIfNeeded(cr);
}
}
else{
///TODO: if there is a stop displayed, we need to hold the update
}
setupOnStart = false;
}
}
@Override
public void onResume() {
final Context con = getContext();
Log.w(DEBUG_TAG, "OnResume called, setupOnStart: "+ setupOnStart);
if (con != null) {
if(locationManager==null)
locationManager = AppLocationManager.getInstance(con);
if(Permissions.locationPermissionGranted(con)){
Log.d(DEBUG_TAG, "Location permission OK");
if(!locationManager.isRequesterRegistered(requester))
locationManager.addLocationRequestFor(requester);
} //don't request permission
}
else {
Log.w(DEBUG_TAG, "Context is null at onResume");
}
super.onResume();
// if we have a pending stopID request, do it
Log.d(DEBUG_TAG, "Pending stop ID for arrivals: "+pendingStopID);
//this is the second time we are attaching this fragment
Log.d(DEBUG_TAG, "Waiting for new stop request: "+ suppressArrivalsReload);
if (suppressArrivalsReload){
// we have to suppress the reloading of the (possible) ArrivalsFragment
Fragment fragment = getChildFragmentManager().findFragmentById(R.id.resultFrame);
if (fragment instanceof ArrivalsFragment){
ArrivalsFragment frag = (ArrivalsFragment) fragment;
frag.setReloadOnResume(false);
}
suppressArrivalsReload = false;
}
if(pendingStopID!=null){
Log.d(DEBUG_TAG, "Re-requesting arrivals for pending stop "+pendingStopID);
requestArrivalsForStopID(pendingStopID);
pendingStopID = null;
}
mListener.readyGUIfor(FragmentKind.MAIN_SCREEN_FRAGMENT);
fragmentHelper.setBlockAllActivities(false);
}
@Override
public void onPause() {
//mainHandler = null;
locationManager.removeLocationRequestFor(requester);
super.onPause();
fragmentHelper.setBlockAllActivities(true);
fragmentHelper.stopLastRequestIfNeeded(true);
}
/*
GUI METHODS
*/
/**
* QR scan button clicked
*
* @param v View QRButton clicked
*/
public void onQRButtonClick(View v) {
BarcodeScanOptions scanOptions = new BarcodeScanOptions();
Intent intent = scanOptions.createScanIntent();
if(!BarcodeScanUtils.checkTargetPackageExists(getContext(), intent)){
BarcodeScanUtils.showDownloadDialog(null, this);
}else {
barcodeLauncher.launch(scanOptions);
}
}
public void onHideHint(View v) {
hideHints();
setOption(OPTION_SHOW_LEGEND, false);
}
/**
* OK this is pure shit
*
* @param v View clicked
*/
public void onSearchClick(View v) {
final StopsFinderByName[] stopsFinderByNames = new StopsFinderByName[]{new GTTStopsFetcher(), new FiveTStopsFetcher()};
if (searchMode == SEARCH_BY_ID) {
String busStopID = busStopSearchByIDEditText.getText().toString();
fragmentHelper.stopLastRequestIfNeeded(true);
requestArrivalsForStopID(busStopID);
} else { // searchMode == SEARCH_BY_NAME
String query = busStopSearchByNameEditText.getText().toString();
query = query.trim();
if(getContext()!=null) {
if (query.length() < 1) {
Toast.makeText(getContext(), R.string.insert_bus_stop_name_error, Toast.LENGTH_SHORT).show();
} else if(query.length()< 2){
Toast.makeText(getContext(), R.string.query_too_short, Toast.LENGTH_SHORT).show();
}
else {
fragmentHelper.stopLastRequestIfNeeded(true);
new AsyncStopsSearcher(fragmentHelper, stopsFinderByNames).execute(query);
}
}
}
}
public void onToggleKeyboardLayout(View v) {
if (searchMode == SEARCH_BY_NAME) {
setSearchModeBusStopID();
if (busStopSearchByIDEditText.requestFocus()) {
showKeyboard();
}
} else { // searchMode == SEARCH_BY_ID
setSearchModeBusStopName();
if (busStopSearchByNameEditText.requestFocus()) {
showKeyboard();
}
}
}
@Override
public void enableRefreshLayout(boolean yes) {
swipeRefreshLayout.setEnabled(yes);
}
////////////////////////////////////// GUI HELPERS /////////////////////////////////////////////
public void showKeyboard() {
if(getActivity() == null) return;
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
View view = searchMode == SEARCH_BY_ID ? busStopSearchByIDEditText : busStopSearchByNameEditText;
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
}
private void setSearchModeBusStopID() {
searchMode = SEARCH_BY_ID;
busStopSearchByNameEditText.setVisibility(View.GONE);
busStopSearchByNameEditText.setText("");
busStopSearchByIDEditText.setVisibility(View.VISIBLE);
floatingActionButton.setImageResource(R.drawable.alphabetical);
}
private void setSearchModeBusStopName() {
searchMode = SEARCH_BY_NAME;
busStopSearchByIDEditText.setVisibility(View.GONE);
busStopSearchByIDEditText.setText("");
busStopSearchByNameEditText.setVisibility(View.VISIBLE);
floatingActionButton.setImageResource(R.drawable.numeric);
}
protected boolean isNearbyFragmentShown(){
Fragment fragment = getChildFragmentManager().findFragmentByTag(NearbyStopsFragment.FRAGMENT_TAG);
return (fragment!= null && fragment.isVisible());
}
/**
* Having that cursor at the left of the edit text makes me cancer.
*
* @param busStopID bus stop ID
*/
private void setBusStopSearchByIDEditText(String busStopID) {
busStopSearchByIDEditText.setText(busStopID);
busStopSearchByIDEditText.setSelection(busStopID.length());
}
private void showHints() {
howDoesItWorkTextView.setVisibility(View.VISIBLE);
hideHintButton.setVisibility(View.VISIBLE);
//actionHelpMenuItem.setVisible(false);
}
private void hideHints() {
howDoesItWorkTextView.setVisibility(View.GONE);
hideHintButton.setVisibility(View.GONE);
//actionHelpMenuItem.setVisible(true);
}
@Nullable
@org.jetbrains.annotations.Nullable
@Override
public View getBaseViewForSnackBar() {
return coordLayout;
}
@Override
public void toggleSpinner(boolean enable) {
if (enable) {
//already set by the RefreshListener when needed
//swipeRefreshLayout.setRefreshing(true);
progressBar.setVisibility(View.VISIBLE);
} else {
swipeRefreshLayout.setRefreshing(false);
progressBar.setVisibility(View.GONE);
}
}
private void prepareGUIForBusLines() {
swipeRefreshLayout.setEnabled(true);
swipeRefreshLayout.setVisibility(View.VISIBLE);
//actionHelpMenuItem.setVisible(true);
}
private void prepareGUIForBusStops() {
swipeRefreshLayout.setEnabled(false);
swipeRefreshLayout.setVisibility(View.VISIBLE);
//actionHelpMenuItem.setVisible(false);
}
private void actuallyShowNearbyStopsFragment(){
swipeRefreshLayout.setVisibility(View.VISIBLE);
final Fragment existingFrag = fragMan.findFragmentById(R.id.resultFrame);
// fragment;
if (!(existingFrag instanceof NearbyStopsFragment)){
Log.d(DEBUG_TAG, "actually showing Nearby Stops Fragment");
//there is no fragment showing
final NearbyStopsFragment fragment = NearbyStopsFragment.newInstance(NearbyStopsFragment.TYPE_STOPS);
FragmentTransaction ft = fragMan.beginTransaction();
ft.replace(R.id.resultFrame, fragment, NearbyStopsFragment.FRAGMENT_TAG);
if (getActivity()!=null && !getActivity().isFinishing() &&!instanceStateSaved)
ft.commit();
else Log.e(DEBUG_TAG, "Not showing nearby fragment because we saved instanceState");
}
}
@Override
public void showFloatingActionButton(boolean yes) {
mListener.showFloatingActionButton(yes);
}
/**
* This provides a temporary fix to make the transition
* to a single asynctask go smoother
*
* @param fragmentType the type of fragment created
*/
@Override
public void readyGUIfor(FragmentKind fragmentType) {
//if we are getting results, already, stop waiting for nearbyStops
if (fragmentType == FragmentKind.ARRIVALS || fragmentType == FragmentKind.STOPS) {
hideKeyboard();
if (pendingNearbyStopsRequest) {
locationManager.removeLocationRequestFor(requester);
pendingNearbyStopsRequest = false;
}
}
if (fragmentType == null) Log.e("ActivityMain", "Problem with fragmentType");
else
switch (fragmentType) {
case ARRIVALS:
prepareGUIForBusLines();
if (getOption(OPTION_SHOW_LEGEND, true)) {
showHints();
}
break;
case STOPS:
prepareGUIForBusStops();
break;
default:
Log.d(DEBUG_TAG, "Fragment type is unknown");
return;
}
// Shows hints
}
@Override
public void showMapCenteredOnStop(Stop stop) {
if(mListener!=null) mListener.showMapCenteredOnStop(stop);
}
/**
* Main method for stops requests
* @param ID the Stop ID
*/
@Override
public void requestArrivalsForStopID(String ID) {
if (!isResumed()){
//defer request
pendingStopID = ID;
Log.d(DEBUG_TAG, "Deferring update for stop "+ID+ " saved: "+pendingStopID);
return;
}
final boolean delayedRequest = !(pendingStopID==null);
final FragmentManager framan = getChildFragmentManager();
if (getContext()==null){
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);
toggleSpinner(false);
} else if (framan.findFragmentById(R.id.resultFrame) instanceof ArrivalsFragment) {
ArrivalsFragment fragment = (ArrivalsFragment) framan.findFragmentById(R.id.resultFrame);
if (fragment != null && fragment.getStopID() != null && fragment.getStopID().equals(ID)){
// Run with previous fetchers
//fragment.getCurrentFetchers().toArray()
new AsyncArrivalsSearcher(fragmentHelper,fragment.getCurrentFetchersAsArray(), getContext()).execute(ID);
} else{
new AsyncArrivalsSearcher(fragmentHelper, fetchers, getContext()).execute(ID);
}
}
else {
new AsyncArrivalsSearcher(fragmentHelper,fetchers, getContext()).execute(ID);
Log.d(DEBUG_TAG, "Started search for arrivals of stop " + ID);
}
}
private boolean checkLocationPermission(){
final Context context = getContext();
if(context==null) return false;
final boolean isOldVersion = Build.VERSION.SDK_INT < Build.VERSION_CODES.M;
final boolean noPermission = ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED;
return isOldVersion || !noPermission;
}
private void requestLocationPermission(){
requestPermissionLauncher.launch(LOCATION_PERMISSIONS);
}
private void showNearbyFragmentIfNeeded(Criteria cr){
if(isNearbyFragmentShown()) {
//nothing to do
Log.w(DEBUG_TAG, "launched nearby fragment request but we already are showing");
return;
}
if(getContext()==null){
Log.e(DEBUG_TAG, "Wanting to show nearby fragment but context is null");
return;
}
AppLocationManager appLocationManager = AppLocationManager.getInstance(getContext());
final boolean haveProviders = appLocationManager.anyLocationProviderMatchesCriteria(cr);
if (haveProviders
&& fragmentHelper.getLastSuccessfullySearchedBusStop() == null
&& !fragMan.isDestroyed()) {
//Go ahead with the request
Log.d("mainActivity", "Recreating stop fragment");
actuallyShowNearbyStopsFragment();
pendingNearbyStopsRequest = false;
} else if(!haveProviders){
Log.e(DEBUG_TAG, "NO PROVIDERS FOR POSITION");
}
}
/////////// LOCATION METHODS //////////
/*
private void startStopRequest(String provider) {
Log.d(DEBUG_TAG, "Provider " + provider + " got enabled");
if (locmgr != null && mainHandler != null && pendingNearbyStopsRequest && locmgr.getProvider(provider).meetsCriteria(cr)) {
}
}
*/
/*
* Run location requests separately and asynchronously
class NearbyStopsRequester implements Runnable {
Context appContext;
Criteria cr;
public NearbyStopsRequester(Context appContext, Criteria criteria) {
this.appContext = appContext.getApplicationContext();
this.cr = criteria;
}
@Override
public void run() {
if(isNearbyFragmentShown()) {
//nothing to do
Log.w(DEBUG_TAG, "launched nearby fragment request but we already are showing");
return;
}
final boolean isOldVersion = Build.VERSION.SDK_INT < Build.VERSION_CODES.M;
final boolean noPermission = ActivityCompat.checkSelfPermission(appContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(appContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED;
//if we don't have the permission, we have to ask for it, if we haven't
// asked too many times before
if (noPermission) {
if (!isOldVersion) {
pendingNearbyStopsRequest = true;
//Permissions.assertLocationPermissions(appContext,getActivity());
requestPermissionLauncher.launch(LOCATION_PERMISSIONS);
Log.w(DEBUG_TAG, "Cannot get position: Asking permission, noPositionFromSys: " + noPermission);
return;
} else {
Toast.makeText(appContext, "Asked for permission position too many times", Toast.LENGTH_LONG).show();
}
} else setOption(LOCATION_PERMISSION_GIVEN, true);
AppLocationManager appLocationManager = AppLocationManager.getInstance(appContext);
final boolean haveProviders = appLocationManager.anyLocationProviderMatchesCriteria(cr);
if (haveProviders
&& fragmentHelper.getLastSuccessfullySearchedBusStop() == null
&& !fragMan.isDestroyed()) {
//Go ahead with the request
Log.d("mainActivity", "Recreating stop fragment");
showNearbyStopsFragment();
pendingNearbyStopsRequest = false;
} else if(!haveProviders){
Log.e(DEBUG_TAG, "NO PROVIDERS FOR POSITION");
}
}
}
*/
}
\ No newline at end of file
diff --git a/app/src/main/java/it/reyboz/bustorino/fragments/ResultBaseFragment.java b/app/src/main/java/it/reyboz/bustorino/fragments/ResultBaseFragment.java
new file mode 100644
index 0000000..a36a550
--- /dev/null
+++ b/app/src/main/java/it/reyboz/bustorino/fragments/ResultBaseFragment.java
@@ -0,0 +1,33 @@
+package it.reyboz.bustorino.fragments;
+
+import android.content.Context;
+import androidx.annotation.NonNull;
+import androidx.fragment.app.Fragment;
+
+public abstract class ResultBaseFragment extends Fragment {
+
+ protected FragmentListenerMain mListener;
+ protected static final String MESSAGE_TEXT_VIEW = "message_text_view";
+
+
+ public ResultBaseFragment() {
+ }
+ @Override
+ public void onAttach(@NonNull Context context) {
+ super.onAttach(context);
+ if (context instanceof FragmentListenerMain) {
+ mListener = (FragmentListenerMain) context;
+ } else {
+ throw new RuntimeException(context.toString()
+ + " must implement FragmentListenerMain");
+ }
+
+ }
+
+ @Override
+ public void onDetach() {
+ mListener.showFloatingActionButton(false);
+ mListener = null;
+ super.onDetach();
+ }
+}
diff --git a/app/src/main/java/it/reyboz/bustorino/fragments/ResultListFragment.java b/app/src/main/java/it/reyboz/bustorino/fragments/ResultListFragment.java
index faf6ceb..b80d22b 100644
--- a/app/src/main/java/it/reyboz/bustorino/fragments/ResultListFragment.java
+++ b/app/src/main/java/it/reyboz/bustorino/fragments/ResultListFragment.java
@@ -1,300 +1,297 @@
/*
BusTO - Fragments components
Copyright (C) 2016 Fabio Mazza
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package it.reyboz.bustorino.fragments;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.os.Parcelable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import it.reyboz.bustorino.R;
import it.reyboz.bustorino.backend.FiveTNormalizer;
import it.reyboz.bustorino.backend.Palina;
import it.reyboz.bustorino.backend.Route;
import it.reyboz.bustorino.backend.Stop;
import it.reyboz.bustorino.data.UserDB;
/**
* This is a generalized fragment that can be used both for
*
*
*/
public class ResultListFragment extends Fragment{
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
static final String LIST_TYPE = "list-type";
protected static final String LIST_STATE = "list_state";
protected static final String MESSAGE_TEXT_VIEW = "message_text_view";
private FragmentKind adapterKind;
protected FragmentListenerMain mListener;
protected TextView messageTextView;
protected ListView resultsListView;
private ListAdapter mListAdapter = null;
boolean listShown;
private Parcelable mListInstanceState = null;
public ResultListFragment() {
// Required empty public constructor
}
public ListView getResultsListView() {
return resultsListView;
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param listType whether the list is used for STOPS or LINES (Orari)
* @return A new instance of fragment ResultListFragment.
*/
public static ResultListFragment newInstance(FragmentKind listType, String eventualStopTitle) {
ResultListFragment fragment = new ResultListFragment();
Bundle args = new Bundle();
args.putSerializable(LIST_TYPE, listType);
if (eventualStopTitle != null) {
args.putString(ArrivalsFragment.STOP_TITLE, eventualStopTitle);
}
fragment.setArguments(args);
return fragment;
}
public static ResultListFragment newInstance(FragmentKind listType) {
return newInstance(listType, null);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
adapterKind = (FragmentKind) getArguments().getSerializable(LIST_TYPE);
}
}
/**
* Check if the last Bus Stop is in the favorites
* @return true if it iss
*/
public boolean isStopInFavorites(String busStopId) {
boolean found = false;
// no stop no party
if(busStopId != null) {
SQLiteDatabase userDB = new UserDB(getContext()).getReadableDatabase();
found = UserDB.isStopInFavorites(userDB, busStopId);
}
return found;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_list_view, container, false);
messageTextView = (TextView) root.findViewById(R.id.messageTextView);
if (adapterKind != null) {
resultsListView = (ListView) root.findViewById(R.id.resultsListView);
switch (adapterKind) {
case STOPS:
resultsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
/*
* Casting because of Javamerda
* @url http://stackoverflow.com/questions/30549485/androids-list-view-parameterized-type-in-adapterview-onitemclicklistener
*/
Stop busStop = (Stop) parent.getItemAtPosition(position);
mListener.requestArrivalsForStopID(busStop.ID);
}
});
// set the textviewMessage
setTextViewMessage(getString(R.string.results));
break;
case ARRIVALS:
resultsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String routeName;
Route r = (Route) parent.getItemAtPosition(position);
routeName = FiveTNormalizer.routeInternalToDisplay(r.getNameForDisplay());
if (routeName == null) {
routeName = r.getNameForDisplay();
}
if (r.destinazione == null || r.destinazione.length() == 0) {
Toast.makeText(getContext(),
getString(R.string.route_towards_unknown, routeName), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getContext(),
getString(R.string.route_towards_destination, routeName, r.destinazione), Toast.LENGTH_SHORT).show();
}
}
});
String displayName = getArguments().getString(ArrivalsFragment.STOP_TITLE);
setTextViewMessage(String.format(
getString(R.string.passages), displayName));
break;
default:
throw new IllegalStateException("Argument passed was not of a supported type");
}
String probablemessage = getArguments().getString(MESSAGE_TEXT_VIEW);
if (probablemessage != null) {
//Log.d("BusTO fragment " + this.getTag(), "We have a possible message here in the savedInstaceState: " + probablemessage);
messageTextView.setText(probablemessage);
messageTextView.setVisibility(View.VISIBLE);
}
} else
Log.d(getString(R.string.list_fragment_debug), "No content root for fragment");
return root;
}
public boolean isFragmentForTheSameStop(Palina 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) {
return "palina_"+p.ID;
}
@Override
public void onResume() {
super.onResume();
//Log.d(getString(R.string.list_fragment_debug),"Fragment restored, saved listAdapter is "+(mListAdapter));
if (mListAdapter != null) {
ListAdapter adapter = mListAdapter;
mListAdapter = null;
resetListAdapter(adapter);
}
if (mListInstanceState != null) {
Log.d("resultsListView", "trying to restore instance state");
resultsListView.onRestoreInstanceState(mListInstanceState);
}
switch (adapterKind) {
case ARRIVALS:
resultsListView.setOnScrollListener(new CommonScrollListener(mListener, true));
mListener.showFloatingActionButton(true);
break;
case STOPS:
resultsListView.setOnScrollListener(new CommonScrollListener(mListener, false));
break;
default:
//NONE
}
mListener.readyGUIfor(adapterKind);
}
@Override
public void onPause() {
if (adapterKind.equals(FragmentKind.ARRIVALS)) {
SwipeRefreshLayout reflay = getActivity().findViewById(R.id.listRefreshLayout);
reflay.setEnabled(false);
Log.d("BusTO Fragment " + this.getTag(), "RefreshLayout disabled");
}
super.onPause();
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
if (context instanceof FragmentListenerMain) {
mListener = (FragmentListenerMain) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement ResultFragmentListener");
}
}
@Override
public void onDetach() {
mListener.showFloatingActionButton(false);
mListener = null;
super.onDetach();
}
@Override
public void onDestroyView() {
resultsListView = null;
//Log.d(getString(R.string.list_fragment_debug), "called onDestroyView");
getArguments().putString(MESSAGE_TEXT_VIEW, messageTextView.getText().toString());
super.onDestroyView();
}
@Override
public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
super.onViewStateRestored(savedInstanceState);
Log.d("ResultListFragment", "onViewStateRestored");
if (savedInstanceState != null) {
mListInstanceState = savedInstanceState.getParcelable(LIST_STATE);
Log.d("ResultListFragment", "listInstanceStatePresent :" + mListInstanceState);
}
}
protected void resetListAdapter(ListAdapter adapter) {
boolean hadAdapter = mListAdapter != null;
mListAdapter = adapter;
if (resultsListView != null) {
resultsListView.setAdapter(adapter);
resultsListView.setVisibility(View.VISIBLE);
}
}
- public void setNewListAdapter(ListAdapter adapter){
- resetListAdapter(adapter);
- }
/**
* Set the message textView
* @param message the whole message to write in the textView
*/
public void setTextViewMessage(String message) {
messageTextView.setText(message);
messageTextView.setVisibility(View.VISIBLE);
}
}
\ No newline at end of file
diff --git a/app/src/main/java/it/reyboz/bustorino/util/ViewUtils.kt b/app/src/main/java/it/reyboz/bustorino/util/ViewUtils.kt
new file mode 100644
index 0000000..ad693d8
--- /dev/null
+++ b/app/src/main/java/it/reyboz/bustorino/util/ViewUtils.kt
@@ -0,0 +1,33 @@
+package it.reyboz.bustorino.util
+
+import android.graphics.Rect
+import android.util.Log
+
+import android.view.View
+import androidx.core.widget.NestedScrollView
+
+
+class ViewUtils {
+
+ companion object{
+ const val DEBUG_TAG="BusTO:ViewUtils"
+ fun isViewFullyVisibleInScroll(view: View, scrollView: NestedScrollView): Boolean {
+ val scrollBounds = Rect()
+ scrollView.getDrawingRect(scrollBounds)
+ val top = view.y
+ val bottom = top + view.height
+ Log.d(DEBUG_TAG, "Scroll bounds are $scrollBounds, top:${view.y}, bottom $bottom")
+ return (scrollBounds.top < top && scrollBounds.bottom > bottom)
+ }
+ fun isViewPartiallyVisibleInScroll(view: View, scrollView: NestedScrollView): Boolean{
+ val scrollBounds = Rect()
+ scrollView.getHitRect(scrollBounds)
+ Log.d(DEBUG_TAG, "Scroll bounds are $scrollBounds")
+ if (view.getLocalVisibleRect(scrollBounds)) {
+ return true
+ } else {
+ return false
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/res/layout/entry_bus_line_passage.xml b/app/src/main/res/layout/entry_bus_line_passage.xml
index 5431b72..4906347 100644
--- a/app/src/main/res/layout/entry_bus_line_passage.xml
+++ b/app/src/main/res/layout/entry_bus_line_passage.xml
@@ -1,53 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="8dip"
android:paddingBottom="8dip"
android:paddingLeft="16dip"
android:paddingRight="16dip">
+
<TextView
android:id="@+id/routeID"
android:layout_width="54dip"
android:layout_height="54dip"
android:background="@drawable/route_background_bus"
android:gravity="center"
android:textColor="@color/grey_100"
android:textSize="21sp"
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp">
</TextView>
<!--the icon comes from setCompoundDrawables in PalinaAdapter -->
<!--android:drawableLeft="@drawable/bus"
android:drawableStart="@drawable/bus" -->
<TextView
android:id="@+id/routeDestination"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/grey_600"
android:layout_height="30dp"
android:layout_width="match_parent"
android:layout_toEndOf="@id/routeID"
android:layout_toRightOf="@id/routeID"
android:layout_alignTop="@+id/routeID"
android:maxLines="1"
android:drawablePadding="0dp"
android:singleLine="true">
</TextView>
<!-- this can hold 3-4 timetable entries before overflowing into a second line. It's ugly but at least doesn't lose any information. -->
<TextView
android:id="@+id/routesThatStopHere"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/blue_500"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginLeft="5dip"
android:layout_marginStart="5dip"
android:layout_toEndOf="@id/routeID"
android:layout_toRightOf="@id/routeID"
android:layout_below="@id/routeDestination">
</TextView>
</RelativeLayout>
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_arrivals.xml b/app/src/main/res/layout/fragment_arrivals.xml
index e003e4c..d94d80d 100644
--- a/app/src/main/res/layout/fragment_arrivals.xml
+++ b/app/src/main/res/layout/fragment_arrivals.xml
@@ -1,98 +1,147 @@
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:fab="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
+<RelativeLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical"
+ android:paddingTop="8dp">
<androidx.cardview.widget.CardView
- android:id="@+id/messageCardView"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginStart="16dp"
- android:layout_marginLeft="16dp"
- android:layout_marginTop="16dp"
- android:layout_marginEnd="16dp"
- android:layout_marginRight="16dp"
- android:layout_marginBottom="10dp"
- fab:cardCornerRadius="5dp"
- fab:cardElevation="2dp">
+ android:id="@+id/messageCardView"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ app:cardCornerRadius="5dp"
+ app:cardElevation="2dp"
+ >
<TextView
- android:id="@+id/messageTextView"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginStart="8dp"
- android:layout_marginLeft="8dp"
- android:layout_toStartOf="@+id/addToFavorites"
- android:layout_toLeftOf="@+id/addToFavorites"
-
- android:foreground="?attr/selectableItemBackground"
- android:gravity="center_vertical"
- android:minHeight="40dp"
- android:textAppearance="?android:attr/textAppearanceMedium" />
+ android:id="@+id/messageTextView"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="8dp"
+ android:layout_marginLeft="8dp"
+ android:layout_toStartOf="@+id/addToFavorites"
+ android:layout_toLeftOf="@+id/addToFavorites"
+
+ android:foreground="?attr/selectableItemBackground"
+ android:gravity="center_vertical"
+ android:minHeight="40dp"
+ android:textAppearance="?android:attr/textAppearanceMedium"/>
<ImageButton
- android:id="@+id/addToFavorites"
- android:layout_width="45dp"
- android:layout_height="match_parent"
- android:layout_gravity="end"
- android:background="@android:color/transparent"
- android:foreground="?attr/selectableItemBackground"
- fab:srcCompat="@drawable/ic_star_outline"
- tools:ignore="OnClick" />
+ android:id="@+id/addToFavorites"
+ android:layout_width="45dp"
+ android:layout_height="match_parent"
+ android:layout_gravity="end"
+ android:background="@android:color/transparent"
+ android:foreground="?attr/selectableItemBackground"
+ app:srcCompat="@drawable/ic_star_outline"
+ tools:ignore="OnClick"/>
</androidx.cardview.widget.CardView>
-
<LinearLayout
- android:layout_width="match_parent"
- android:layout_below="@+id/messageCardView"
- android:orientation="vertical"
-
- android:layout_height="wrap_content">
-
- <ListView
- android:id="@+id/resultsListView"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="9"
- android:clickable="true"
- android:descendantFocusability="blocksDescendants"
- android:focusable="true"
- android:scrollbars="vertical"
- android:visibility="visible">
-
- </ListView>
-
- <View
- android:id="@+id/divider_arr"
- android:layout_width="match_parent"
- android:layout_height="1dp"
- android:background="@color/grey_100"
- />
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_below="@+id/messageCardView"
+ android:orientation="vertical">
+
+ <androidx.core.widget.NestedScrollView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:id="@+id/arrivalsScrollView"
+ android:layout_weight="12"
+ >
<LinearLayout
- android:id="@+id/theLinearLayout"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:layout_width="match_parent" android:layout_height="wrap_content">
+ <androidx.recyclerview.widget.RecyclerView
+ android:id="@+id/arrivalsRecyclerView"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:clickable="true"
+ android:descendantFocusability="blocksDescendants"
+ android:focusable="true"
+
+ android:visibility="visible"
+ android:nestedScrollingEnabled="false"
+
+ android:layout_marginTop="8dp"/>
+
+ <TextView android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/no_passages_title"
+ android:textAppearance="@style/TextAppearance.AppCompat.Display1"
+ android:textSize="22sp"
+ android:id="@+id/noArrivalsMessageTextView"
+ android:minHeight="0dp"
+ android:layout_marginLeft="12dp"
+ android:layout_marginStart="12dp"
+ android:layout_marginEnd="12dp"
+ android:layout_marginRight="12dp"
+
+ />
+
+ <androidx.recyclerview.widget.RecyclerView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:id="@+id/noArrivalsRecyclerView"
+ android:nestedScrollingEnabled="false"
+ android:layout_marginLeft="@dimen/margin_arr"
+ android:layout_marginStart="@dimen/margin_arr"
+ android:layout_marginEnd="@dimen/margin_arr"
+ android:layout_marginRight="@dimen/margin_arr"
+
+ />
+ <!--
+ <View
+ android:id="@+id/canaryEndView"
+ android:layout_height="2dp"
+ android:layout_width="match_parent"
+ android:layout_marginLeft="@dimen/margin_arr"
+ android:layout_marginStart="@dimen/margin_arr"
+ android:layout_marginEnd="@dimen/margin_arr"
+ android:layout_marginRight="@dimen/margin_arr"
+ android:background="@color/orange_500"
+ />
+ -->
- android:layout_marginTop="5dp"
+ </LinearLayout>
+
+ </androidx.core.widget.NestedScrollView>
+
+
+ <LinearLayout android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:id="@+id/bottomLinearLayout"
+ android:gravity="top"
+ >
+ <View
+ android:id="@+id/divider_arr"
+ android:layout_width="match_parent"
+ android:layout_height="1dp"
+ android:background="@color/grey_200"
+
+ />
- android:layout_marginBottom="5dp"
- android:orientation="horizontal">
<TextView
- android:id="@+id/timesSourceTextView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginStart="15dp"
- android:layout_marginLeft="15dp"
- android:text=""
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:textSize="19sp"
-
- />
- </LinearLayout>
+ android:id="@+id/timesSourceTextView"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="10dp"
+ android:text=""
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:textSize="20sp"
+
+ android:gravity="center_vertical"
+ android:paddingBottom="5dp"
+ android:layout_marginStart="10dp"
+ android:layout_marginTop="5dp"
+ />
+ </LinearLayout>
</LinearLayout>
-
</RelativeLayout>
\ No newline at end of file
diff --git a/app/src/main/res/layout/round_line_header.xml b/app/src/main/res/layout/round_line_header.xml
new file mode 100644
index 0000000..450c228
--- /dev/null
+++ b/app/src/main/res/layout/round_line_header.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+
+ android:background="@color/orange_500"
+ app:cardCornerRadius="54sp"
+ app:cardElevation="0sp"
+ android:layout_gravity="center_vertical"
+ android:layout_margin="5dp"
+ android:padding="3dp"
+ app:cardBackgroundColor="@color/orange_500"
+>
+ <RelativeLayout
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:gravity="center"
+ android:minHeight="54sp"
+ android:minWidth="54sp"
+ >
+ <TextView
+ android:id="@+id/routeBallID"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:gravity="center"
+ android:textColor="@color/grey_100"
+ android:textSize="21sp"
+ android:text="231"
+ android:paddingStart="4sp"
+ android:paddingLeft="4sp"
+ android:paddingRight="4sp"
+ android:paddingEnd="4sp"
+ >
+ </TextView>
+ </RelativeLayout>
+</androidx.cardview.widget.CardView>
\ No newline at end of file
diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml
index 01a93c8..dcebc67 100644
--- a/app/src/main/res/values-it/strings.xml
+++ b/app/src/main/res/values-it/strings.xml
@@ -1,206 +1,208 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_description">Stai utilizzando l\'ultimo ritrovato in materia di rispetto della tua privacy.</string>
<string name="search">Cerca</string>
<string name="qrcode">QR Code</string>
<string name="yes">Si</string>
<string name="no">No</string>
<string name="title_barcode_scanner_install">Installare Barcode Scanner?</string>
<string name="message_install_barcode_scanner">Questa azione richiede un\'altra app per scansionare i codici QR. Vuoi installare Barcode Scanner?</string>
<string name="insert_bus_stop_number">Numero fermata</string>
<string name="insert_bus_stop_name">Nome fermata</string>
<string name="insert_bus_stop_number_error">Inserisci il numero della fermata</string>
<string name="insert_bus_stop_name_error">Inserisci il nome della fermata</string>
<string name="network_error">Verifica l\'accesso ad Internet!</string>
<string name="no_bus_stop_have_this_name">Sembra che nessuna fermata abbia questo nome</string>
<string name="no_arrivals_stop">Nessun passaggio trovato alla fermata</string>
<string name="parsing_error">Errore di lettura del sito 5T/GTT (dannato sito!)</string>
<string name="passages">Fermata: %1$s</string>
<string name="line">Linea</string>
<string name="lines">Linee</string>
<string name="line_fill">Linea: %1$s</string>
<string name="lines_fill">Linee: %1$s</string>
<string name="results">Scegli la fermata…</string>
<string name="no_passages">Nessun passaggio</string>
<string name="no_qrcode">Nessun QR code trovato, prova ad usare un\'altra app</string>
<string name="action_favorites">Preferiti</string>
<string name="action_help">Aiuto</string>
<string name="action_about">Informazioni</string>
<string name="action_about_more">Più informazioni</string>
<string name="action_wiki">Contribuisci</string>
<string name="hack_url">https://gitpull.it/w/librebusto/it/</string>
<string name="action_source">Codice sorgente</string>
<string name="action_licence">Licenza</string>
<string name="action_author">Incontra l\'autore</string>
<string name="added_in_favorites">Fermata aggiunta ai preferiti</string>
<string name="cant_add_to_favorites">Impossibile aggiungere ai preferiti (memoria piena o database corrotto?)!</string>
<string name="title_activity_favorites">Preferiti</string>
<string name="title_activity_map">Mappa</string>
<string name="tip_add_favorite">Nessun preferito? Arghh!\nSchiaccia sulla stella di una fermata per aggiungerla a questa lista!</string>
<string name="action_remove_from_favourites">Rimuovi</string>
<string name="action_rename_bus_stop_username">Rinomina</string>
<string name="dialog_rename_bus_stop_username_title">Rinomina fermata</string>
<string name="dialog_rename_bus_stop_username_reset_button">Reset</string>
<string name="about">Informazioni</string>
<string name="howDoesItWork"><b>Tocca la stella</b> per aggiungere la fermata ai preferiti\n\n<b>Come leggere gli orari:</b>
\n<b>&#160;&#160;&#160;12:56*</b> Orario in tempo reale\n<b>&#160;&#160;&#160;12:56</b> &#160; Orario programmato\n\n<b>Trascina giù per aggiornare</b> l\'orario.
\n<b>Tocca a lungo</b> su <b>Fonte Orari</b> per cambiare sorgente degli orari di arrivo.
</string>
<string name="hint_button">OK!</string>
<string name="about_history">
<![CDATA[
<h1>Benvenuto!</h1>
<p>Grazie per aver scelto BusTO, un\'app <b>indipendente</b> da GTT/5T, per spostarsi a Torino attraverso <b>software libero</b>:</p>
<p>Perché usare BusTO?</p>
<p>
- Non sei <b>monitorato</b><br>
- Non ci sono <b>pubblicità</b><br>
- La tua <b>privacy</b> è al sicuro<br>
- Inoltre l\'app è molto leggera!<br>
</p>
<h2>Come Funziona?</h2>
<p>Quest\'app ottiene i passaggi dei bus in tempo reale filtrando i dati forniti pubblicamente sul sito <b>www.gtt.to.it</b> o <i>www.5t.torino.it</i> "per uso personale".</p>
<p>Ingredienti:<br>
- <b>Fabio Mazza</b> attuale rockstar developer anziano.<br>
- <b>Andrea Ugo</b> attuale rockstar developer in formazione.<br>
- <b>Silviu Chiriac</b> designer del logo 2021.<br>
- <b>Marco M</b> formidabile tester e cacciatore di bug.<br>
- <b>Ludovico Pavesi</b> ex rockstar developer anziano asd.<br>
- <b>Valerio Bozzolan</b> attuale manutentore.<br>
- <b>Marco Gagino</b> apprezzato ex collaboratore, ideatore icona e grafica.<br>
- <b>JSoup</b> libreria per "<i>web scaping</i>".<br>
- <b>Google</b> icone e libreria di supporto per il Material Design.<br>
- Tutti i contributori!
</p>
<h2>Licenze</h2>
<p>L\'app e il relativo codice sorgente sono distribuiti sotto la licenza <i>GNU General Public License v3+</i>.
Ciò <b>significa</b> che puoi usare, studiare, migliorare e ricondividere quest\'app con <b>qualunque mezzo</b> e per <b>qualsiasi scopo</b>: a patto di mantenere sempre questi diritti a tua volta e di dare credito a Valerio Bozzolan.
</p>
<h2>Note</h2>
<p>Quest\'applicazione è rilasciata <b>nella speranza che sia utile a tutti</b> ma senza NESSUNA garanzia.</p>
<p>Buon utilizzo! :)</p>
]]>
</string>
<string name="query_too_short">Nome troppo corto, digita più caratteri e riprova</string>
<string name="route_towards_destination">%1$s verso %2$s</string>
<string name="route_towards_unknown">%s (destinazione sconosciuta)</string>
<string name="internal_error">Errore interno inaspettato, impossibile estrarre dati dal sito GTT/5T</string>
<string name="action_view_on_map">Visualizza sulla mappa</string>
<string name="cannot_show_on_map_no_activity">Non trovo un\'applicazione dove mostrarla</string>
<string name="cannot_show_on_map_no_position">Posizione della fermata non trovata</string>
<string name="nearby_stops_message">Fermate vicine</string>
<string name="position_searching_message">Ricerca della posizione in corso&#8230;</string>
<string name="no_stops_nearby">Nessuna fermata nei dintorni</string>
<string name="main_menu_pref">Preferenze</string>
<string name="database_update_msg_inapp">Aggiornamento del database&#8230;</string>
<string name="database_update_msg_notif">Aggiornamento del database</string>
<string name="database_update_req">Aggiornamento database forzato</string>
<string name="database_update_req_descr">Tocca per aggiornare ora il database</string>
<string name="pref_num_elements">Numero minimo di fermate</string>
<string name="num_stops_nearby_not_number">Il numero di fermate da ricercare non è valido</string>
<string name="invalid_number">Valore errato, inserisci un numero</string>
<string name="title_activity_settings">Impostazioni</string>
<string name="settings_search_radius">Distanza massima di ricerca (m)</string>
<string name="settings_experimental">Funzionalità sperimentali</string>
<string name="action_settings">Impostazioni</string>
<string name="general_settings">Generali</string>
<string name="pref_recents_group_title">Fermate recenti</string>
<string name="settings_group_general">Impostazioni generali</string>
<string name="settings_group_database">Gestione del database</string>
<string name="settings_reset_database">Comincia aggiornamento manuale del database</string>
<string name="enable_position_message_map">Consenti l\'accesso alla posizione per mostrarla sulla mappa</string>
<string name="enableGpsText">Abilitare il GPS</string>
<string name="bus_arriving_at">arriva alle</string>
<string name="arrivals_card_at_the_stop">alla fermata</string>
<string name="show_arrivals">Mostra arrivi</string>
<string name="show_stops">Mostra fermate</string>
<string name="nearby_arrivals_message">Arrivi qui vicino</string>
<string name="removed_from_favorites">Fermata rimossa dai preferiti</string>
<!--
Mixed button strings
!-->
<string name="open_telegram">Entra nel canale Telegram</string>
<!--
Map view buttons strings
!-->
<string name="bt_center_map_description">La mia posizione</string>
<string name="bt_follow_me_description">Segui posizione</string>
<!--
Arrival times sources
!-->
<string name="times_source_fmt">Fonte orari: %1$s</string>
<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="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>
<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>
+ <string name="no_passages_title">Nessun passaggio per le linee:</string>
+
<string name="default_notification_channel_description">Canale unico delle notifiche</string>
<string name="database_notification_channel">Database</string>
<string name="database_notification_channel_desc">Informazioni sul database (aggiornamento)</string>
<string name="db_trips_download_message">Downloading trips from MaTO server</string>
<string name="too_many_permission_asks">Chiesto troppe volte per il permesso %1$s</string>
<string name="permission_storage_maps_msg">Non si può usare questa funzionalità senza il permesso di archivio</string>
<string name="storage_permission">di archivio</string>
<string name="message_crash">Un bug ha fatto crashare l\'app!
\nPremi \"OK\" per inviare il report agli sviluppatori via email, così potranno scovare e risolvere il tuo bug!
\nIl report contiene piccole informazioni non sensibili sulla configurazione del tuo telefono e sullo stato dell\'app al momento del crash.
</string>
<string name="acra_email_message">L\'applicazione è crashata, e il crash report è stato messo negli allegati. Se vuoi, descrivi cosa stavi facendo prima che si interrompesse: \n</string>
<string name="nav_arrivals_text">Arrivi</string>
<string name="nav_map_text">Mappa</string>
<string name="nav_favorites_text">Preferiti</string>
<string name="drawer_open">Apri drawer</string>
<string name="drawer_close">Chiudi drawer</string>
<string name="experiments">Esperimenti</string>
<string name="donate_now">Offrici un caffè</string>
<string name="map">Mappa</string>
<string name="stop_search_view_title">Ricerca fermate</string>
<string name="app_version">Versione app</string>
<string name="arrival_times">Orari di arrivo</string>
<!-- Preferences -->
<string name="requesting_db_update">Richiesto aggiornamento del database</string>
<string name="pref_directions_capitalize">Mostra direzioni in maiuscolo</string>
<string-array name="directions_capitalize">
<item>Non cambiare</item>
<item>Tutto in maiuscolo</item>
<item>Solo la prima lettera maiuscola</item>
</string-array>
<string name="pref_lines_click_msg">Mostra arrivi quando tocchi una fermata</string>
<string name="pref_experimental_msg">Abilita esperimenti</string>
<string name="pref_shown_startup">Schermata da mostrare all\'avvio</string>
<string name="pref_shown_startup_def_desc">Tocca per cambiare</string>
<!-- lines -->
<string name="long_press_stop_4_options">Tocca a lungo la fermata per le opzioni</string>
</resources>
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index 9602d1e..254055f 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -1,33 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="orange_500">#ff9800</color>
<color name="orange_700">#F57C00</color>
<color name="orange_700_40light"> #cc6600</color>
<color name="orange_700_30light">#994d00</color>
<color name="blue_500">#2196F3</color>
<color name="blue_620">#2a65e8</color>
<color name="blue_700">#2060dd</color> <!-- #1976D2 -->
<color name="blue_mid_2">#2378e8</color>
<color name="blue_c_or_700">#0079f5</color>
<color name="teal_dark">#2a968b</color>
<color name="blue_comp_500">#0067ff</color>
<color name="teal_500">#009688</color>
<color name="teal_300">#4DB6AC</color>
<color name="teal_200">#80cbc4</color>
<color name="grey_100">#F5F5F5</color>
+ <color name="grey_200">#dddddd</color>
<color name="grey_050">#f8f8f8</color>
<color name="grey_600">#757575</color>
<!--<color name="white">#FFFFFF</color>
<color name="accent">#009688</color>-->
<color name="metro_red">#DE0908</color>
<color name="red_darker">#b30000</color>
<color name="blue_extraurbano">#2060DD</color>
<color name="white">#FFFFFF</color>
<color name="black">#000000</color>
<color name="black_900">#1c1c1c</color>
<color name="line_pattern_color">@color/blue_mid_2</color><!-- 2e8df0-->
</resources>
\ No newline at end of file
diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml
index e4f2b1c..d5562a9 100644
--- a/app/src/main/res/values/dimens.xml
+++ b/app/src/main/res/values/dimens.xml
@@ -1,12 +1,14 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="fab_margin">16dp</dimen>
<dimen name="text_size_nearby">18sp</dimen>
<dimen name="text_size_nearby_indicate">16sp</dimen>
<dimen name="default_textView_margin">6dp</dimen>
+ <dimen name="margin_arr">5dp</dimen>
+
</resources>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 3eed7a5..d38cc87 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,242 +1,243 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name" translatable="false">BusTO</string>
<string name="app_name_full" translatable="false">Libre BusTO</string>
<string name="app_name_debug" translatable="false">BusTO dev</string>
<string name="app_name_gitpull" translatable="false">BusTO git</string>
<string name="app_description">You\'re using the latest in technology when it comes to respecting your privacy.
</string>
<string name="search">Search</string>
<string name="qrcode">Scan QR Code</string>
<string name="yes">Yes</string>
<string name="no">No</string>
<string name="title_barcode_scanner_install">Install Barcode Scanner?</string>
<string name="message_install_barcode_scanner">This application requires an app to scan the QR codes. Would you like
to install Barcode Scanner now?
</string>
<string name="insert_bus_stop_number">Bus stop number</string>
<string name="insert_bus_stop_name">Bus stop name</string>
<string name="insert_bus_stop_number_error">Insert bus stop number</string>
<string name="insert_bus_stop_name_error">Insert bus stop name</string>
<string name="route_towards_destination">%1$s towards %2$s</string>
<string name="route_towards_unknown">%s (unknown destination)</string>
<string name="network_error">Verify your Internet connection!</string>
<string name="no_bus_stop_have_this_name">Seems that no bus stop have this name</string>
<string name="no_arrivals_stop">No arrivals found for this stop</string>
<string name="parsing_error">Error parsing the 5T/GTT website (damn site!)</string>
<string name="query_too_short">Name too short, type more characters and retry
</string> <!-- TODO: carry out experiments to determine the best wording for this message and publish a paper with the findings -->
<string name="passages">Arrivals at: %1$s</string>
<string name="results">Choose the bus stop…</string>
<string name="line">Line</string>
<string name="lines">Lines</string>
<string name="lines_fill">Lines: %1$s</string>
<string name="line_fill">Line: %1$s</string>
<string name="no_passages">No timetable found</string>
<string name="no_qrcode">No QR code found, try using another app to scan</string>
<string name="internal_error">Unexpected internal error, cannot extract data from GTT/5T website</string>
<string name="action_help">Help</string>
<string name="action_about">About</string>
<string name="action_about_more">More about</string>
<string name="action_wiki">Contribute</string>
<string name="hack_url">https://gitpull.it/w/librebusto/en/</string>
<string name="action_source">Source code</string>
<string name="action_licence">Licence</string>11
<string name="action_author">Meet the author</string>
<string name="added_in_favorites">Bus stop is now in your favorites</string>
<string name="removed_from_favorites">Bus stop removed from your favorites</string>
<string name="action_favorites">Favorites</string>
<string name="title_activity_favorites">Favorites</string>
<string name="title_activity_map">Map</string>
<string name="tip_add_favorite">No favorites? Arghh! Press on a bus stop star to populate this list!</string>
<string name="action_remove_from_favourites">Delete</string>
<string name="action_rename_bus_stop_username">Rename</string>
<string name="dialog_rename_bus_stop_username_title">Rename the bus stop</string>
<string name="dialog_rename_bus_stop_username_reset_button">Reset</string>
<string name="about">About</string>
<string name="howDoesItWork">
<b>Tap the star</b>
to add the bus stop to the favourites\n\n<b>How to read timelines:</b>\n<b>&#160;&#160;&#160;12:56*</b> Real-time
arrivals\n<b>&#160;&#160;&#160;12:56</b> &#160; Scheduled arrivals\n\n<b>Pull down to refresh</b> the timetable
\n <b>Long press on Arrivals source</b> to change the source of the arrival times
</string>
<string name="hint_button">GOT IT!</string>
<string name="arrival_times">Arrival times</string>
+ <string name="no_passages_title">No arrivals found for lines:</string>
<string name="about_history">
<![CDATA[
<h1>Welcome!</h1>
<p>Thanks for using BusTO, a "politically" <b>independent</b> app useful to move around Torino using a <b>Free/Libre software</b>.</p>
<p>Why use this app?</p>
<p>
- You\'ll never be <b>tracked</b><br>
- You\'ll never see boring <b>ads</b><br>
- We\'ll always respect your <b>privacy</b><br>
- Moreover, it\'s lightweight!<br>
</p>
<h2>How does it work?</h2>
<p>This app will show you bus timetables gathering data from <b>www.gtt.to.it</b> or <b>www.5t.torino.it</b> "for personal use".</p>
<p>Who worked on BusTO:<br>
- <b>Fabio Mazza</b> current senior rockstar developer.<br>
- <b>Andrea Ugo</b> current junior rockstar developer.<br>
- <b>Silviu Chiriac</b> designer of the 2021 logo.<br>
- <b>Marco M</b> rockstar tester and bug hunter.<br>
- <b>Ludovico Pavesi</b> previous senior rockstar developer asd.<br>
- <b>Valerio Bozzolan</b> maintainer and infrastructure sponsor.<br>
- <b>Marco Gagino</b> contributor and icon creator.<br>
- <b>JSoup</b> web scraper library.<br>
- <b>makovkastar</b> floating buttons.<br>
- <b>Google</b> Material Design icons.<br>
- All the contributors!
</p>
<h2>Licenses</h2>
<p>The app and the related source code are released by Valerio Bozzolan under the terms of the <i>GNU General Public License v3+</i>).
So everyone is allowed to use, to study, to improve and to share this app by <b>any kind of means</b> and for <b>any purpose</b>: under the conditions of maintaining this rights and of attributing the original work to Valerio Bozzolan.</p>
<h2>Notes</h2>
<p>This app has been developed <b>hoping to be useful to everyone</b> but without ANY warranty.</p>
<p>This translation is kindly provided by Riccardo Caniato and Marco Gagino.</p>
<p>Get involved! :)</p>
]]>
</string>
<string name="cant_add_to_favorites">Cannot add to favorites (storage full or corrupted database?)!</string>
<string name="action_view_on_map">View on a map</string>
<string name="cannot_show_on_map_no_activity">Cannot find any application to show it in</string>
<string name="cannot_show_on_map_no_position">Cannot find the position of the stop</string>
<string name="list_fragment_debug" translatable="false">ListFragment - BusTO</string>
<string name="mainSharedPreferences" translatable="false">it.reyboz.bustorino.preferences</string>
<string name="databaseUpdatingPref" translatable="false">db_is_updating</string>
<!-- Settings -->
<string name="nearby_stops_message">Nearby stops</string>
<string name="nearby_arrivals_message">Nearby connections</string>
<string name="app_version">App version</string>
<string name="num_stops_nearby_not_number">The number of stops to show in the recents is invalid</string>
<string name="invalid_number">Invalid value, put a valid number</string>
<string name="position_searching_message">Finding the position&#8230;</string>
<string name="no_stops_nearby">No stops nearby</string>
<string name="pref_num_elements">Minimum number of stops</string>
<string name="main_menu_pref">Preferences</string>
<string name="title_activity_settings">Settings</string>
<string name="action_settings">Settings</string>
<string name="general_settings">General</string>
<string name="settings_experimental">Experimental features</string>
<string name="settings_search_radius">Maximum distance (meters)</string>
<string name="pref_recents_group_title">Recent stops</string>
<string name="settings_group_general">General settings</string>
<string name="settings_group_database">Database management</string>
<string name="settings_reset_database">Launch manual database update</string>
<string name="enable_position_message_map">Allow access to position to show it on the map</string>
<string name="enableGpsText">Please enable GPS</string>
<string name="database_update_msg_inapp">Database update in progress&#8230;</string>
<string name="database_update_msg_notif">Updating the database</string>
<string name="database_update_req">Force database update</string>
<string name="database_update_req_descr">Touch to update the app database now</string>
<string name="bus_arriving_at">is arriving at</string>
<string name="arrivals_card_at_the_stop">at the stop</string>
<string name="two_strings_format" translatable="false">%1$s - %2$s</string>
<string name="show_arrivals">Show arrivals</string>
<string name="show_stops">Show stops</string>
<!--
Mixed button strings
!-->
<string name="open_telegram">Join Telegram channel</string>
<!--
Map view buttons strings
!-->
<string name="bt_center_map_description">Center on my location</string>
<string name="bt_follow_me_description">Follow me</string>
<!--
Arrival times sources
!-->
<string name="times_source_fmt">Arrivals source: %1$s</string>
<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="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>
<string-array name="arrival_times_source_list">
<item>@string/source_mato</item>
<item>@string/fivetapifetcher</item>
<item>@string/gttjsonfetcher</item>
<item>@string/fivetscraper</item>
</string-array>
<string name="arrival_times_choice_title">Sources of arrival times</string>
<string name="arrival_times_choice_explanation">Select which sources of arrival times to use</string>
<!--
Notifications
-->
<string name="default_notification_channel" translatable="false">Default</string>
<string name="default_notification_channel_description">Default channel for notifications</string>
<string name="database_notification_channel">Database</string>
<string name="database_notification_channel_desc">Notifications on the update of the database</string>
<string name="db_trips_download_message">Downloading trips from MaTO server</string>
<string name="too_many_permission_asks">Asked for %1$s permission too many times</string>
<string name="permission_storage_maps_msg">Cannot use the map with the storage permission!</string>
<string name="storage_permission">storage</string>
<string name="message_crash">The application has crashed because you encountered a bug.
\nIf you want, you can help the developers by sending the crash report via email.
\nNote that no sensitive data is contained in the report, just small bits of info on your phone and app
configuration/state.
</string>
<string name="acra_email_message">The application crashed and the crash report is in the attachments. Please
describe what you were doing before the crash: \n
</string>
<string name="nav_arrivals_text">Arrivals</string>
<string name="nav_map_text">Map</string>
<string name="nav_favorites_text">Favorites</string>
<string name="drawer_open">Open navigation drawer</string>
<string name="drawer_close">Close navigation drawer</string>
<string name="experiments">Experiments</string>
<string name="donate_now">Buy us a coffee</string>
<string name="map">Map</string>
<string name="stop_search_view_title">Search by stop</string>
<string name="requesting_db_update">Launching database update</string>
<!-- preferences -->
<string name="pref_directions_capitalize">Capitalize directions</string>
<string-array name="directions_capitalize">
<item>Do not change arrivals directions</item>
<item>Capitalize everything</item>
<item>Capitalize only first letter</item>
</string-array>
<array name="directions_capitalize_keys">
<item>KEEP</item>
<item>CAPITALIZE_ALL</item>
<item>CAPITALIZE_FIRST</item>
</array>
<string name="pref_shown_startup">Section to show on startup</string>
<string name="pref_shown_startup_def_desc">Touch to change it</string>
<string name="pref_lines_click_msg">Show arrivals touching on stop</string>
<string name="pref_experimental_msg">Enable experiments</string>
<!-- lines -->
<string name="long_press_stop_4_options">Long press the stop for options</string>
<array name="first_screen_shown">
<item>@string/nav_arrivals_text</item>
<item>@string/nav_favorites_text</item>
<item>@string/nav_map_text</item>
<item>@string/lines</item>
</array>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>

File Metadata

Mime Type
text/x-diff
Expires
Thu, Nov 19, 00:09 (1 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2263504
Default Alt Text
(160 KB)

Event Timeline