Page MenuHomeGitPull.it

D84.1729631156.diff
No OneTemporary

Size
31 KB
Referenced Files
None
Subscribers
None

D84.1729631156.diff

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/drawable/line.xml b/res/drawable/line.xml
new file mode 100644
--- /dev/null
+++ b/res/drawable/line.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle">
+
+ <solid android:color="@color/grey_100" />
+
+ <padding
+ android:top="10dp"
+ android:left="10dp"
+ android:right="10dp"
+ android:bottom="10dp"/>
+</shape>
\ No newline at end of file
diff --git a/res/drawable/line_drawable.xml b/res/drawable/line_drawable.xml
new file mode 100644
--- /dev/null
+++ b/res/drawable/line_drawable.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item
+ android:state_pressed="true"
+ android:drawable="@drawable/line"/>
+
+ <item
+ android:drawable="@drawable/line"/>
+</selector>
\ No newline at end of file
diff --git a/res/drawable/thumb.xml b/res/drawable/thumb.xml
new file mode 100644
--- /dev/null
+++ b/res/drawable/thumb.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle">
+
+ <corners
+ android:topLeftRadius="40dp"
+ android:topRightRadius="40dp"
+ android:bottomLeftRadius="40dp"
+ android:bottomRightRadius="40dp"
+ />
+
+ <padding
+ android:paddingLeft="22dp"
+ android:paddingRight="22dp" />
+
+ <solid android:color="@color/grey_600" />
+
+</shape>
\ No newline at end of file
diff --git a/res/drawable/thumb_drawable.xml b/res/drawable/thumb_drawable.xml
new file mode 100644
--- /dev/null
+++ b/res/drawable/thumb_drawable.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item
+ android:state_pressed="true"
+ android:drawable="@drawable/thumb"/>
+
+ <item
+ android:drawable="@drawable/thumb"/>
+</selector>
\ No newline at end of file
diff --git a/res/layout/arrivals_nearby_card.xml b/res/layout/arrivals_nearby_card.xml
--- a/res/layout/arrivals_nearby_card.xml
+++ b/res/layout/arrivals_nearby_card.xml
@@ -8,8 +8,8 @@
android:focusable="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- card_view:cardCornerRadius="1dp"
- android:layout_margin="8dp" android:padding="4dp">
+ card_view:cardCornerRadius="5dp"
+ android:layout_margin="5dp" android:padding="6dp">
<RelativeLayout
@@ -21,29 +21,30 @@
android:id="@+id/lineNameTextView"
android:text="10" android:textSize="22sp"
android:textColor="@color/orange_700"
- android:layout_marginLeft="20dp"
- android:layout_marginStart="20dp"
+ android:layout_marginLeft="10dp"
+ android:layout_marginStart="10dp"
android:layout_alignParentLeft="true"
- android:layout_margin="10dp"
- android:textStyle="normal" android:layout_marginRight="20dp" android:layout_marginEnd="20dp"
- android:layout_marginBottom="20dp"/>
+ android:gravity="center_vertical"
+ android:textStyle="normal" android:layout_marginRight="10dp" android:layout_marginEnd="10dp"
+ android:layout_marginBottom="10dp" android:layout_marginTop="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/lineDirectionTextView"
- android:text="piazza statuto"
+ android:text="MADONNA DEL PILONE, LARGO TABACCHI"
android:textSize="20sp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_toLeftOf="@id/arrivalsDistanceTextView"
android:layout_toRightOf="@id/lineNameTextView"
+ android:layout_toEndOf="@id/lineNameTextView"
android:textStyle="normal"
android:layout_marginRight="6dp"
android:layout_marginEnd="6dp"
android:layout_alignBaseline="@id/lineNameTextView"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
- android:layout_marginStart="10dp" />
+ android:layout_marginStart="10dp"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignBaseline="@id/arrivalsTimeTextView"
android:textAppearance="?android:attr/textAppearanceMedium"
@@ -82,9 +83,10 @@
android:textAppearance="?android:attr/textAppearanceLarge"
/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
- android:layout_margin="@dimen/default_textView_margin"
+ android:layout_marginTop="12dp"
android:layout_marginBottom="10dp"
- android:layout_marginEnd="15dp"
+ android:layout_marginEnd="12dp"
+ android:layout_marginRight="12dp"
android:id="@+id/arrivalsDistanceTextView" android:text="200 m" android:textSize="15sp"
android:layout_marginLeft="15dp"
android:layout_marginStart="15dp"
diff --git a/res/layout/entry_bus_stop.xml b/res/layout/entry_bus_stop.xml
--- a/res/layout/entry_bus_stop.xml
+++ b/res/layout/entry_bus_stop.xml
@@ -3,7 +3,9 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="8dip"
- android:paddingBottom="8dip" >
+ android:paddingBottom="8dip"
+ android:background="?android:attr/selectableItemBackground"
+>
<TextView
android:id="@+id/busStopName"
diff --git a/res/layout/fragment_lines.xml b/res/layout/fragment_lines.xml
--- a/res/layout/fragment_lines.xml
+++ b/res/layout/fragment_lines.xml
@@ -85,7 +85,14 @@
android:layout_marginBottom="8dp"
android:layout_marginTop="0dp"
android:layout_margin="4dp"
- app:layout_constraintHorizontal_bias="0.0" />
+ app:layout_constraintHorizontal_bias="0.0"
+ app:fastScrollEnabled="true"
+ app:fastScrollHorizontalThumbDrawable="@drawable/thumb_drawable"
+ app:fastScrollHorizontalTrackDrawable="@drawable/line_drawable"
+ app:fastScrollVerticalThumbDrawable="@drawable/thumb_drawable"
+ app:fastScrollVerticalTrackDrawable="@drawable/line_drawable"
+
+ />
<!--
<TextView
android:text="TextView"
diff --git a/res/layout/stop_card.xml b/res/layout/stop_card.xml
--- a/res/layout/stop_card.xml
+++ b/res/layout/stop_card.xml
@@ -8,8 +8,8 @@
android:focusable="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- card_view:cardCornerRadius="1dp"
- android:layout_margin="8dp" android:padding="4dp">
+ card_view:cardCornerRadius="5dp"
+ android:layout_margin="5dp" android:padding="4dp">
<LinearLayout
android:orientation="horizontal"
diff --git a/res/layout/bus_stop_line_elmt.xml b/res/layout/stop_line_element.xml
rename from res/layout/bus_stop_line_elmt.xml
rename to res/layout/stop_line_element.xml
--- a/res/layout/bus_stop_line_elmt.xml
+++ b/res/layout/stop_line_element.xml
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:background="?android:attr/selectableItemBackground"
+ android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
@@ -10,7 +12,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"
@@ -21,23 +23,23 @@
app:layout_constraintTop_toBottomOf="@+id/topStub"/>
<View
android:layout_width="8dp"
- android:layout_height="16dp" android:id="@+id/topStub"
- android:background="@color/blue_500"
+ android:layout_height="6dp" android:id="@+id/topStub"
+ 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 +49,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"
@@ -86,11 +88,12 @@
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
-
app:layout_constraintTop_toBottomOf="@id/busStopLocality"
android:layout_marginTop="5dp"
-
android:textAppearance="?android:attr/textAppearanceSmall"
- android:textColor="@color/grey_600" app:layout_constraintEnd_toEndOf="parent"/>
+ android:textColor="@color/grey_600"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintBottom_toBottomOf="parent"
+ android:layout_marginBottom="9dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
diff --git a/res/values-it/strings.xml b/res/values-it/strings.xml
--- a/res/values-it/strings.xml
+++ b/res/values-it/strings.xml
@@ -182,7 +182,11 @@
<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>
+
+
<!-- lines -->
- <string name="long_press_for_options">Tocca a lungo per le opzioni</string>
+ <string name="long_press_stop_4_options">Tocca a lungo la fermata per le opzioni</string>
</resources>
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/res/values/strings.xml b/res/values/strings.xml
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -201,7 +201,10 @@
<item>CAPITALIZE_FIRST</item>
</array>
+ <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_for_options">Long press for options</string>
+ <string name="long_press_stop_4_options">Long press the stop for options</string>
+
</resources>
diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml
--- a/res/xml/preferences.xml
+++ b/res/xml/preferences.xml
@@ -1,12 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
- <androidx.preference.PreferenceCategory
- android:title="@string/general_settings">
- <androidx.preference.SwitchPreferenceCompat
- android:defaultValue="false"
- android:title="@string/settings_experimental" android:key="@string/pref_key_experimental"/>
- </androidx.preference.PreferenceCategory>
+
<androidx.preference.PreferenceCategory
android:title="@string/pref_recents_group_title">
<!--
@@ -59,6 +54,14 @@
/>
</androidx.preference.PreferenceCategory>
+ <!--TODO: If we want lines preferences (eg showing arrivals on click)
+ <androidx.preference.PreferenceCategory android:title="@string/lines">
+ <androidx.preference.CheckBoxPreference
+ android:title=""
+ />
+ </androidx.preference.PreferenceCategory>
+ -->
+
<androidx.preference.PreferenceCategory android:title="Database">
<androidx.preference.Preference
android:title="@string/database_update_req"
@@ -66,4 +69,11 @@
android:key="pref_db_update_now"
/>
</androidx.preference.PreferenceCategory>
+
+ <androidx.preference.PreferenceCategory
+ android:title="@string/settings_experimental">
+ <androidx.preference.SwitchPreferenceCompat
+ android:defaultValue="false"
+ android:title="@string/pref_experimental_msg" android:key="@string/pref_key_experimental"/>
+ </androidx.preference.PreferenceCategory>
</androidx.preference.PreferenceScreen>
diff --git a/src/it/reyboz/bustorino/adapters/StopRecyclerAdapter.java b/src/it/reyboz/bustorino/adapters/StopRecyclerAdapter.java
--- a/src/it/reyboz/bustorino/adapters/StopRecyclerAdapter.java
+++ b/src/it/reyboz/bustorino/adapters/StopRecyclerAdapter.java
@@ -17,7 +17,6 @@
*/
package it.reyboz.bustorino.adapters;
-import android.util.Log;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.MenuInflater;
@@ -36,7 +35,7 @@
public class StopRecyclerAdapter extends RecyclerView.Adapter<StopRecyclerAdapter.ViewHolder> {
private List<Stop> stops;
private static final int ITEM_LAYOUT_FAVORITES = R.layout.entry_bus_stop;
- private static final int ITEM_LAYOUT_LINES = R.layout.bus_stop_line_elmt;
+ private static final int ITEM_LAYOUT_LINES = R.layout.stop_line_element;
private static final int busIcon = R.drawable.bus;
private static final int trainIcon = R.drawable.subway;
private static final int tramIcon = R.drawable.tram;
@@ -213,7 +212,7 @@
vh.bottomStub.setVisibility(View.VISIBLE);
vh.topStub.setVisibility(View.VISIBLE);
if(position == 0) {
- vh.topStub.setVisibility(View.GONE);
+ vh.topStub.setVisibility(View.INVISIBLE);
}
else if (position == stops.size()-1) {
vh.bottomStub.setVisibility(View.GONE);
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()
}
@@ -68,16 +71,29 @@
private val linesComparator = Comparator<GtfsRoute> { a,b ->
return@Comparator linesNameSorter.compare(a.shortName, b.shortName)
}
+ private var firstClick = true;
private val adapterListener = object : StopAdapterListener {
override fun onTappedStop(stop: Stop?) {
//var r = ""
//stop?.let { r= it.stopDisplayName.toString() }
- Toast.makeText(context,R.string.long_press_for_options,Toast.LENGTH_SHORT).show()
+ if(viewModel.shouldShowMessage) {
+ Toast.makeText(context, R.string.long_press_stop_4_options, Toast.LENGTH_SHORT).show()
+ viewModel.shouldShowMessage=false
+ }
+ stop?.let {
+ mListener?.requestArrivalsForStopID(it.ID)
+ }
+ if(stop == null){
+ Log.e(DEBUG_TAG,"Passed wrong stop")
+ }
+ if(mListener == null){
+ Log.e(DEBUG_TAG, "Listener is null")
+ }
}
override fun onLongPressOnStop(stop: Stop?): Boolean {
- Log.d("BusTO-LinesFrag", "LongPressOnStop")
+ Log.d(DEBUG_TAG, "LongPressOnStop")
return true
}
}
@@ -93,16 +109,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 +128,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 +146,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 +184,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 +193,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 +277,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,11 @@
routeIDToSearch.value = routeID
}
+ fun getRouteIDQueried(): String?{
+ return routeIDToSearch.value
+ }
+ var shouldShowMessage = true;
+
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

Mime Type
text/plain
Expires
Tue, Oct 22, 23:05 (16 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
641001
Default Alt Text
D84.1729631156.diff (31 KB)

Event Timeline