-
Notifications
You must be signed in to change notification settings - Fork 307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed #851 - added filter by arrivals/departures option to ArrivalsListFragment #1290
base: main
Are you sure you want to change the base?
Changes from all commits
95ff499
b4f3d3e
cea7aa1
3a840f3
5f5f3f3
94ad2d6
362c7d2
15cab18
a0e081c
2d935b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
import android.content.Context; | ||
import android.content.res.Resources; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import org.onebusaway.android.R; | ||
import org.onebusaway.android.app.Application; | ||
import org.onebusaway.android.io.elements.ObaArrivalInfo; | ||
|
@@ -52,7 +54,8 @@ public int compare(ArrivalInfo lhs, ArrivalInfo rhs) { | |
public static ArrayList<ArrivalInfo> convertObaArrivalInfo(Context context, | ||
ObaArrivalInfo[] arrivalInfo, | ||
ArrayList<String> filter, long ms, | ||
boolean includeArrivalDepartureInStatusLabel) { | ||
boolean includeArrivalDepartureInStatusLabel, | ||
ArrivalFilter arrivalFilter) { | ||
final int len = arrivalInfo.length; | ||
ArrayList<ArrivalInfo> result = new ArrayList<ArrivalInfo>(len); | ||
if (filter != null && filter.size() > 0) { | ||
|
@@ -61,7 +64,7 @@ public static ArrayList<ArrivalInfo> convertObaArrivalInfo(Context context, | |
if (filter.contains(arrival.getRouteId())) { | ||
ArrivalInfo info = new ArrivalInfo(context, arrival, ms, | ||
includeArrivalDepartureInStatusLabel); | ||
if (shouldAddEta(info)) { | ||
if (shouldAddEta(info) && shouldAddArrivalFilter(info, arrivalFilter)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please explain your logic here ? |
||
result.add(info); | ||
} | ||
} | ||
|
@@ -71,7 +74,7 @@ public static ArrayList<ArrivalInfo> convertObaArrivalInfo(Context context, | |
for (ObaArrivalInfo obaArrivalInfo : arrivalInfo) { | ||
ArrivalInfo info = new ArrivalInfo(context, obaArrivalInfo, ms, | ||
includeArrivalDepartureInStatusLabel); | ||
if (shouldAddEta(info)) { | ||
if (shouldAddEta(info) && shouldAddArrivalFilter(info, arrivalFilter)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and here can you explain the logic |
||
result.add(info); | ||
} | ||
} | ||
|
@@ -82,6 +85,43 @@ public static ArrayList<ArrivalInfo> convertObaArrivalInfo(Context context, | |
return result; | ||
} | ||
|
||
public static ArrayList<ArrivalInfo> convertObaArrivalInfo(Context context, | ||
ObaArrivalInfo[] arrivalInfo, | ||
ArrayList<String> filter, long ms, | ||
boolean includeArrivalDepartureInStatusLabel) { | ||
return convertObaArrivalInfo(context, arrivalInfo, filter, ms, includeArrivalDepartureInStatusLabel, ArrivalFilter.BOTH); | ||
} | ||
|
||
// This enum class represents the string array resource R.array.stop_info_arrival_filter_options | ||
public enum ArrivalFilter { | ||
BOTH(0), | ||
ARRIVALS_ONLY(1), | ||
DEPARTURES_ONLY(2); | ||
|
||
public final int arrayResourceIndex; | ||
|
||
ArrivalFilter(int arrayResourceIndex) { | ||
this.arrayResourceIndex = arrayResourceIndex; | ||
} | ||
|
||
public String getOptionString(Resources appResources) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not used ? |
||
return appResources.getStringArray(R.array.stop_info_arrival_filter_options)[arrayResourceIndex]; | ||
} | ||
|
||
public static String[] getOptionsArray(Resources appResources) { | ||
return appResources.getStringArray(R.array.stop_info_arrival_filter_options); | ||
} | ||
|
||
public static ArrivalFilter fromArrayResourceIndex(int arrayResourceIndex) { | ||
switch (arrayResourceIndex) { | ||
case 0: return BOTH; | ||
case 1: return ARRIVALS_ONLY; | ||
case 2: return DEPARTURES_ONLY; | ||
default: throw new IllegalArgumentException(); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Returns true if this ETA should be added based on the user preference for adding negative | ||
* arrival times, and false if it should not | ||
|
@@ -106,6 +146,15 @@ private static boolean shouldAddEta(ArrivalInfo info) { | |
return false; | ||
} | ||
|
||
private static boolean shouldAddArrivalFilter(ArrivalInfo info, @NonNull ArrivalFilter arrivalFilter) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please write comments explaining this function? |
||
switch (arrivalFilter) { | ||
case BOTH: return true; | ||
case ARRIVALS_ONLY: return info.isArrival(); | ||
case DEPARTURES_ONLY: return !info.isArrival(); | ||
default: throw new IllegalArgumentException(); | ||
} | ||
} | ||
|
||
/** | ||
* Returns the index in the provided infoList for the first non-negative arrival ETA in the | ||
* list, or -1 if no non-negative ETAs exist in the list | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -227,4 +227,10 @@ | |
<item>@string/trip_plan_arriving</item> | ||
</string-array> | ||
|
||
<string-array name="stop_info_arrival_filter_options"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are using localization to support multiple languages so make sure to translate those strings to all supported languages |
||
<item>Both</item> | ||
<item>Arrivals only</item> | ||
<item>Departures only</item> | ||
</string-array> | ||
|
||
</resources> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1280,4 +1280,5 @@ | |
<string name="display_test_wide_alerts_for_regions">Display test-wide alerts for regions</string> | ||
<string name="do_you_want_to_plan_the_trip_now">Do you want to plan the trip now?</string> | ||
<string name="plan_trip">Plan Trip?</string> | ||
<string name="stop_info_option_filter_arrivals_departures">Filter arrivals/departures</string> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Translate that to multiple languages |
||
</resources> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spaces