-
Notifications
You must be signed in to change notification settings - Fork 389
feat: add hide all alerts banner above active alerts #1534 #1553
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -659,6 +659,7 @@ synchronized void refresh() { | |
| refreshStopFavorite(); | ||
| refreshFilter(); | ||
| refreshError(); | ||
| refreshHideAllAlerts(); | ||
| refreshHiddenAlerts(); | ||
| refreshArrivalInfoVisibilityAndListeners(); | ||
| refreshHeaderSize(); | ||
|
|
@@ -1388,6 +1389,91 @@ public boolean equals(Object obj) { | |
| } | ||
| } | ||
|
|
||
| private HideAllAlert mHideAllAlert = null; | ||
|
|
||
| private static class HideAllAlert implements AlertList.Alert { | ||
| private final CharSequence mString; | ||
| private final Controller mController; | ||
|
|
||
| HideAllAlert(CharSequence seq, Controller controller) { | ||
| mString = seq; | ||
| mController = controller; | ||
| } | ||
|
|
||
| @Override | ||
| public String getId() { | ||
| return "STATIC: HIDE ALL ALERT"; | ||
| } | ||
|
|
||
| @Override | ||
| public int getType() { | ||
|
|
||
| return TYPE_SHOW_HIDDEN_ALERTS; | ||
| } | ||
|
|
||
| @Override | ||
| public int getFlags() { | ||
| return FLAG_HASMORE; | ||
| } | ||
|
|
||
| @Override | ||
| public CharSequence getString() { | ||
| return mString; | ||
| } | ||
|
|
||
| @Override | ||
| public void onClick() { | ||
| ObaContract.ServiceAlerts.hideAllAlerts(); | ||
| mController.refresh(); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return getId().hashCode(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (this == obj) return true; | ||
| if (obj == null || getClass() != obj.getClass()) return false; | ||
| HideAllAlert other = (HideAllAlert) obj; | ||
| return getId().equals(other.getId()); | ||
| } | ||
| } | ||
|
|
||
| private void refreshHideAllAlerts() { | ||
| if (mController == null) { | ||
| return; | ||
| } | ||
| AlertList alerts = mController.getAlertList(); | ||
|
|
||
| if (mHideAllAlert != null) { | ||
| alerts.remove(mHideAllAlert); | ||
| } | ||
|
|
||
| // Count visible alerts (excluding response errors and special alerts) | ||
| int visibleAlertCount = 0; | ||
| for (int i = 0; i < alerts.getCount(); i++) { | ||
| AlertList.Alert alert = alerts.getItem(i); | ||
| int type = alert.getType(); | ||
| if (type == AlertList.Alert.TYPE_ERROR || type == AlertList.Alert.TYPE_WARNING || | ||
| type == AlertList.Alert.TYPE_INFO) { | ||
| visibleAlertCount++; | ||
| } | ||
| } | ||
|
Comment on lines
+1454
to
+1463
|
||
|
|
||
| // Show hide all button if there are visible alerts | ||
| if (visibleAlertCount > 0) { | ||
| CharSequence activeAlertsText = mContext.getResources().getQuantityString( | ||
| R.plurals.alert_filter_text, visibleAlertCount, visibleAlertCount); | ||
| CharSequence hideAllText = mContext.getResources().getString(R.string.alert_hide_all); | ||
| CharSequence combinedText = activeAlertsText + " " + hideAllText; | ||
|
|
||
| mHideAllAlert = new HideAllAlert(combinedText, mController); | ||
| alerts.insert(mHideAllAlert, 0); | ||
| } | ||
|
Comment on lines
+1466
to
+1474
|
||
| } | ||
|
|
||
| private void refreshHiddenAlerts() { | ||
| if (mController == null) { | ||
| return; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -422,14 +422,15 @@ | |
| <string name="all_alert_hidden_snackbar_text">All alerts are now hidden</string> | ||
| <string name="alert_hidden_snackbar_action">UNDO</string> | ||
| <plurals name="alert_filter_text"> | ||
| <item quantity="one">%1$d active alert is hidden</item> | ||
| <item quantity="one">%1$d active alert shown</item> | ||
| <!-- Entire element below should be on a single line if XML is reformatted - see #99 --> | ||
| <item quantity="other"> | ||
| <xliff:g id="count">%1$d</xliff:g> | ||
| active alerts are hidden | ||
| active alerts shown | ||
| </item> | ||
| </plurals> | ||
|
Comment on lines
424
to
431
|
||
| <string name="alert_filter_showall">(show all)</string> | ||
| <string name="alert_hide_all">(hide all)</string> | ||
|
|
||
| <!-- Find --> | ||
| <string name="find_hint_nofavoritestops">Find a stop by entering its stop number in the search | ||
|
|
||
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.
If
visibleAlertCountis 0,mHideAllAlertis removed from the list but the field is left non-null, so subsequent refreshes will keep callingalerts.remove(mHideAllAlert)on an object that's no longer in the adapter. It would be cleaner to setmHideAllAlert = nullwhen the banner isn't shown.