Page Menu
Home
GitPull.it
Search
Configure Global Search
Log In
Files
F11398368
D84.1773220557.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
16 KB
Referenced Files
None
Subscribers
None
D84.1773220557.diff
View Options
diff --git a/res/drawable-xxxhdpi/bus_stop_background.xml b/res/drawable/bus_stop_background.xml
rename from res/drawable-xxxhdpi/bus_stop_background.xml
rename to res/drawable/bus_stop_background.xml
diff --git a/res/drawable-xxxhdpi/bus_stop_background.xml b/res/drawable/bus_stop_background_pattern.xml
rename from res/drawable-xxxhdpi/bus_stop_background.xml
rename to res/drawable/bus_stop_background_pattern.xml
--- a/res/drawable-xxxhdpi/bus_stop_background.xml
+++ b/res/drawable/bus_stop_background_pattern.xml
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
- <solid android:color="@color/blue_500" />
+ <solid android:color="@color/line_pattern_color" />
<corners android:radius="100dp" />
</shape>
\ No newline at end of file
diff --git a/res/layout/bus_stop_line_elmt.xml b/res/layout/bus_stop_line_elmt.xml
--- a/res/layout/bus_stop_line_elmt.xml
+++ b/res/layout/bus_stop_line_elmt.xml
@@ -10,7 +10,7 @@
android:layout_height="60dp"
android:layout_centerVertical="true"
- android:background="@drawable/bus_stop_background"
+ android:background="@drawable/bus_stop_background_pattern"
android:gravity="center"
android:textColor="@color/grey_100"
android:textSize="20sp"
@@ -22,22 +22,22 @@
<View
android:layout_width="8dp"
android:layout_height="16dp" android:id="@+id/topStub"
- android:background="@color/blue_500"
+ android:background="@color/line_pattern_color"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="@id/busStopID"
- android:layout_marginLeft="25dp"
- android:layout_marginStart="25dp"/>
+ android:layout_marginLeft="26dp"
+ android:layout_marginStart="26dp"/>
<View
android:layout_width="8dp"
android:layout_height="0dp" android:id="@+id/bottomStub"
- android:background="@color/blue_500"
+ android:background="@color/line_pattern_color"
app:layout_constraintTop_toBottomOf="@id/busStopID"
app:layout_constraintStart_toStartOf="@id/busStopID"
app:layout_constraintBottom_toBottomOf="parent"
- android:layout_marginLeft="25dp"
- android:layout_marginStart="25dp"/>
+ android:layout_marginLeft="26dp"
+ android:layout_marginStart="26dp"/>
<TextView
android:id="@+id/busStopName"
@@ -47,7 +47,7 @@
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textAppearance="?android:attr/textAppearanceMedium"
- android:textColor="@color/blue_500"
+ android:textColor="@color/line_pattern_color"
app:layout_constraintStart_toEndOf="@id/busStopID"
app:layout_constraintTop_toTopOf="@id/busStopID"
android:layout_marginStart="10dp"
diff --git a/res/values/colors.xml b/res/values/colors.xml
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -4,7 +4,12 @@
<color name="orange_500">#ff9800</color>
<color name="orange_700">#F57C00</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_500">#009688</color>
<color name="teal_300">#4DB6AC</color>
<color name="teal_200">#80cbc4</color>
@@ -16,5 +21,6 @@
<color name="blue_extraurbano">#2060DD</color>
<color name="white">#FFFFFF</color>
<color name="black">#000000</color>
+ <color name="line_pattern_color">@color/blue_mid_2</color><!-- 2e8df0-->
</resources>
\ No newline at end of file
diff --git a/src/it/reyboz/bustorino/backend/utils.java b/src/it/reyboz/bustorino/backend/utils.java
--- a/src/it/reyboz/bustorino/backend/utils.java
+++ b/src/it/reyboz/bustorino/backend/utils.java
@@ -1,3 +1,20 @@
+/*
+ BusTO (backend components)
+ Copyright (C) 2019 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.backend;
import android.content.Context;
@@ -146,13 +163,26 @@
sb.append(subs);
continue;
}
- sb.append(Character.toUpperCase(subs.charAt(0)));
+ //SPLIT ON ', check if contains "D'"
+ if(subs.toLowerCase(Locale.ROOT).startsWith("d'")){
+ sb.append("D'");
+ subs = subs.substring(2);
+ }
+ int index = 0;
+ char c = subs.charAt(index);
+ if(subs.length() > 1 && c=='('){
+ sb.append(c);
+ index += 1;
+ c = subs.charAt(index);
+ }
+ sb.append(Character.toUpperCase(c));
if (lowercaseRest)
- sb.append(subs.substring(1).toLowerCase(Locale.ROOT));
+ sb.append(subs.substring(index+1).toLowerCase(Locale.ROOT));
else
- sb.append(subs.substring(1));
+ sb.append(subs.substring(index+1));
}
+ if(addPoint && allsubs.length == 1) sb.append('.');
sb.append(" ");
/*sb.append(Character.toUpperCase(arr[i].charAt(0)));
if (lowercaseRest)
diff --git a/src/it/reyboz/bustorino/fragments/LinesFragment.kt b/src/it/reyboz/bustorino/fragments/LinesFragment.kt
--- a/src/it/reyboz/bustorino/fragments/LinesFragment.kt
+++ b/src/it/reyboz/bustorino/fragments/LinesFragment.kt
@@ -36,6 +36,7 @@
import it.reyboz.bustorino.data.gtfs.MatoPatternWithStops
import it.reyboz.bustorino.data.gtfs.PatternStop
import it.reyboz.bustorino.util.LinesNameSorter
+import it.reyboz.bustorino.util.PatternWithStopsSorter
class LinesFragment : ScreenBaseFragment() {
@@ -45,6 +46,8 @@
}
const val DEBUG_TAG="BusTO-LinesFragment"
const val FRAGMENT_TAG="LinesFragment"
+
+ val patternStopsComparator = PatternWithStopsSorter()
}
@@ -93,16 +96,6 @@
routeDescriptionTextView = rootView.findViewById(R.id.routeDescriptionTextView)
stopsRecyclerView = rootView.findViewById(R.id.patternStopsRecyclerView)
- /*
- Stop busStop = (Stop) parent.getItemAtPosition(position);
-
- if(mListener!=null){
- mListener.requestArrivalsForStopID(busStop.ID);
- }
-
- });
-
- */
val llManager = LinearLayoutManager(context)
llManager.orientation = LinearLayoutManager.VERTICAL
@@ -122,8 +115,13 @@
val selRoute = currentRoutes.get(pos)
routeDescriptionTextView.text = selRoute.longName
-
+ val oldRoute = viewModel.getRouteIDQueried()
+ val resetSpinner = (oldRoute != null) && (oldRoute.trim() != selRoute.gtfsId.trim())
+ Log.d(DEBUG_TAG, "Selected route: ${selRoute.gtfsId}, reset spinner: $resetSpinner")
+ //launch query for this gtfsID
viewModel.setRouteIDQuery(selRoute.gtfsId)
+ //reset spinner position
+ if(resetSpinner) patternsSpinner.setSelection(0)
}
@@ -135,7 +133,7 @@
patternsSpinner.onItemSelectedListener = object : OnItemSelectedListener{
override fun onItemSelected(p0: AdapterView<*>?, p1: View?, position: Int, p3: Long) {
val patternWithStops = currentPatterns.get(position)
-
+ //
setPatternAndReqStops(patternWithStops)
}
@@ -173,7 +171,8 @@
viewModel.patternsWithStopsByRouteLiveData.observe(this){
patterns ->
run {
- currentPatterns = patterns.sortedBy { p->"${p.pattern.directionId} - ${p.pattern.headsign}" }
+ currentPatterns = patterns.sortedBy { p-> p.pattern.code }
+ //patterns. //sortedBy {-1*it.stopsIndices.size}// "${p.pattern.directionId} - ${p.pattern.headsign}" }
patternsAdapter?.let {
it.clear()
it.addAll(currentPatterns.map { p->"${p.pattern.directionId} - ${p.pattern.headsign}" })
@@ -181,7 +180,8 @@
}
val pos = patternsSpinner.selectedItemPosition
- if(pos!= INVALID_POSITION){
+ //might be possible that the selectedItem is different (larger than list size)
+ if(pos!= INVALID_POSITION && pos >= 0 && (pos < currentPatterns.size)){
setPatternAndReqStops(currentPatterns[pos])
}
@@ -264,7 +264,6 @@
override fun onContextItemSelected(item: MenuItem): Boolean {
- val info = item.getMenuInfo();
if (stopsRecyclerView.getAdapter() !is StopRecyclerAdapter) return false
val adapter =stopsRecyclerView.adapter as StopRecyclerAdapter
diff --git a/src/it/reyboz/bustorino/fragments/LinesViewModel.kt b/src/it/reyboz/bustorino/fragments/LinesViewModel.kt
--- a/src/it/reyboz/bustorino/fragments/LinesViewModel.kt
+++ b/src/it/reyboz/bustorino/fragments/LinesViewModel.kt
@@ -46,6 +46,10 @@
routeIDToSearch.value = routeID
}
+ fun getRouteIDQueried(): String?{
+ return routeIDToSearch.value
+ }
+
fun requestStopsForGTFSIDs(gtfsIDs: List<String>){
oldRepo.requestStopsWithGtfsIDs(gtfsIDs) {
if (it.isSuccess) {
diff --git a/src/it/reyboz/bustorino/util/LinesNameSorter.java b/src/it/reyboz/bustorino/util/LinesNameSorter.java
--- a/src/it/reyboz/bustorino/util/LinesNameSorter.java
+++ b/src/it/reyboz/bustorino/util/LinesNameSorter.java
@@ -18,9 +18,16 @@
package it.reyboz.bustorino.util;
+import android.util.Log;
+import androidx.annotation.NonNull;
+
import java.util.Comparator;
public class LinesNameSorter implements Comparator<String> {
+ final static private int cc = 100;
+ final static private int ERROR_PARSING = -10;
+ final static private int FIRST_1_LETTER = 120;
+ final static private int FIRST_2_LETTERS=220;
@Override
public int compare(String name1, String name2) {
name1 = name1.trim();
@@ -49,7 +56,7 @@
}
return name1.compareTo(name2);
}
- }**/
+ }*
//One of them is not
int num1 = -1;
if(isInteger(name1)) num1 = Integer.parseInt(name1);
@@ -58,14 +65,21 @@
if(num1 >= 0 && num2 >=0){
//we're very happy
- return (num1-num2)*10;
+ return (num1-num2)*cc;
} else if (num1>=0) {
//name2 is not fully integer
+ if(name2.contains(" ")){
+ final String[] allStr = name2.split(" ");
+ if(isInteger(allStr[0])) {
+ return (num1-Integer.parseInt(allStr[0]))*cc - incrementFromLastChar(allStr[1].trim().charAt(0));
+ }
+ //sennò si fa come sotto
+ }
final String name2sub = name2.substring(0, name2.length()-1).trim();
char lastchar = name2.charAt(name2.length()-1);
if(isInteger(name2sub)){
num2 = Integer.parseInt(name2sub);
- int diff = (num1-num2)*10;
+ int diff = (num1-num2)*cc;
return diff - incrementFromLastChar(lastchar);
} else{
//failed
@@ -77,7 +91,7 @@
char lastchar = name1.charAt(name1.length()-1);
if (isInteger(name1sub)){
num1 = Integer.parseInt(name1sub);
- int diff = (num1-num2)*10;
+ int diff = (num1-num2)*cc;
return diff + incrementFromLastChar(lastchar);
} else {
return name1.compareTo(name2);
@@ -85,9 +99,72 @@
}
//last case
return name1.compareTo(name2);
+ **/
+ //DO ALL CASES
+ final CompareHolder c1 = getValueOfComplexName(name1);
+ final CompareHolder c2 = getValueOfComplexName(name2);
+ if (c1.value != ERROR_PARSING && c2.value != ERROR_PARSING){
+
+ return (c1.value-c2.value)*100+c1.extra.compareTo(c2.extra);
+ } else {
+ if(c2.value== ERROR_PARSING && c1.value==ERROR_PARSING){
+ return c1.extra.compareTo(c2.extra);
+ }
+ else if(c1.value == ERROR_PARSING){
+ return 1;
+ }
+ else {
+ return -1;
+ }
+ //Log.e("BusTo-Parsing","Error with the string");
+ //throw new IllegalArgumentException("Error with the string name parsing");
+ }
}
+ private static CompareHolder getValueOfComplexName(String name){
+ String namec = name.trim();
+
+ if (isInteger(namec)) return new CompareHolder(Integer.parseInt(namec),"");
+
+ //check for the first part
+ if(namec.contains(" ")){
+ final String[] allStr = namec.split(" ");
+ if(isInteger(allStr[0])) {
+ int g = Integer.parseInt(allStr[0]);
+ return new CompareHolder(g, allStr[1]);
+ }
+ else return new CompareHolder(-7, namec);
+ }else {
+ final String name1sub = namec.substring(0, namec.length()-1).trim();
+ String lastPart = namec.substring(namec.length()-1);
+ int g;
+ if (isInteger(name1sub)) {
+ return new CompareHolder(Integer.parseInt(name1sub), lastPart);
+ } else if(name1sub.equals("M1")){
+ return new CompareHolder(-1, lastPart);
+ } else {
+ //check NightBuster (X+name)
+ if(isInteger(namec.substring(1))){
+ g = Integer.parseInt((namec.substring(1)));
+ return new CompareHolder(FIRST_1_LETTER, namec);
+ } else if (isInteger(namec.substring(2))) {
+ return new CompareHolder(FIRST_2_LETTERS, namec);
+ }
+ return new CompareHolder(ERROR_PARSING, namec);
+ }
+ }
+ }
+
+ private static class CompareHolder {
+ int value;
+ String extra;
+
+ public CompareHolder(int value,@NonNull String extra) {
+ this.value = value;
+ this.extra = extra;
+ }
+ }
public static boolean isInteger(String strNum) {
if (strNum == null) {
return false;
@@ -109,7 +186,7 @@
case 'N':
return 3;
default:
- return 6;
+ return 1;
}
}
}
diff --git a/src/it/reyboz/bustorino/util/PatternWithStopsSorter.kt b/src/it/reyboz/bustorino/util/PatternWithStopsSorter.kt
new file mode 100644
--- /dev/null
+++ b/src/it/reyboz/bustorino/util/PatternWithStopsSorter.kt
@@ -0,0 +1,21 @@
+package it.reyboz.bustorino.util
+
+import it.reyboz.bustorino.data.gtfs.MatoPatternWithStops
+
+/**
+ * Sorter for the patterns, which takes into account direction and length of pattern
+ */
+class PatternWithStopsSorter: Comparator<MatoPatternWithStops> {
+ override fun compare(p0: MatoPatternWithStops?, p1: MatoPatternWithStops?): Int {
+ if (p0 != null && p1!=null) {
+ if(p0.pattern.directionId != p1.pattern.directionId){
+ return p0.pattern.directionId - p1.pattern.directionId
+ }
+ val g = -1*(p0.stopsIndices.size - p1.stopsIndices.size)
+ if(g!=0)
+ return g;
+ else return p0.pattern.code.compareTo(p1.pattern.code)
+ }
+ else return 0;
+ }
+}
\ No newline at end of file
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Mar 11, 10:15 (17 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1737655
Default Alt Text
D84.1773220557.diff (16 KB)
Attached To
Mode
D84: Get lines better showing, fix bug in changing route
Attached
Detach File
Event Timeline
Log In to Comment