Skip to content

Commit 51ddfd9

Browse files
author
Neil McAlister
committed
Make alerts EVEN less crashy
1 parent a12a457 commit 51ddfd9

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

Diff for: Trippit/ViewModels/MainViewModel.cs

+3-14
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ private async Task UpdateAlerts()
105105
{
106106
List<TransitTrafficAlert> newAlerts = response
107107
.Result
108-
.Distinct(_transitTrafficAlertComparer) // Sometimes we get a bunch of duplicate alerts that have different IDs, but no other difference
109-
.Where(x => !String.IsNullOrWhiteSpace(x.DescriptionText?.Text)) // or empty alerts
108+
.Distinct(_transitTrafficAlertComparer)
110109
.OrderBy(x => x.StartDate)
111110
.ToList();
112111
AreAlertsFresh = newAlerts.Any(newAlert => TrafficAlerts.All(oldAlert => oldAlert.Id != newAlert.Id));
@@ -148,22 +147,12 @@ internal class TransitTrafficAlertComparer : IEqualityComparer<TransitTrafficAle
148147
{
149148
public bool Equals(TransitTrafficAlert x, TransitTrafficAlert y)
150149
{
151-
return x.DescriptionText.Language == y.DescriptionText.Language
152-
&& x.DescriptionText.Text == y.DescriptionText.Text
153-
&& x.StartDate == y.StartDate
154-
&& x.EndDate == y.EndDate;
150+
return x.Id == y.Id;
155151
}
156152

157153
public int GetHashCode(TransitTrafficAlert obj)
158154
{
159-
unchecked
160-
{
161-
var hashCode = obj.DescriptionText != null ? obj.DescriptionText.Language.GetHashCode() : 0;
162-
hashCode = (hashCode * 397) ^ obj.DescriptionText?.Text?.GetHashCode() ?? 0;
163-
hashCode = (hashCode * 397) ^ obj.StartDate.GetHashCode();
164-
hashCode = (hashCode * 397) ^ obj.EndDate.GetHashCode();
165-
return hashCode;
166-
}
155+
return obj?.Id?.GetHashCode() ?? 0;
167156
}
168157
}
169158
}

0 commit comments

Comments
 (0)