Skip to content

Commit

Permalink
Make alerts EVEN less crashy
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil McAlister committed Jan 27, 2018
1 parent a12a457 commit 51ddfd9
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions Trippit/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ private async Task UpdateAlerts()
{
List<TransitTrafficAlert> newAlerts = response
.Result
.Distinct(_transitTrafficAlertComparer) // Sometimes we get a bunch of duplicate alerts that have different IDs, but no other difference
.Where(x => !String.IsNullOrWhiteSpace(x.DescriptionText?.Text)) // or empty alerts
.Distinct(_transitTrafficAlertComparer)
.OrderBy(x => x.StartDate)
.ToList();
AreAlertsFresh = newAlerts.Any(newAlert => TrafficAlerts.All(oldAlert => oldAlert.Id != newAlert.Id));
Expand Down Expand Up @@ -148,22 +147,12 @@ internal class TransitTrafficAlertComparer : IEqualityComparer<TransitTrafficAle
{
public bool Equals(TransitTrafficAlert x, TransitTrafficAlert y)
{
return x.DescriptionText.Language == y.DescriptionText.Language
&& x.DescriptionText.Text == y.DescriptionText.Text
&& x.StartDate == y.StartDate
&& x.EndDate == y.EndDate;
return x.Id == y.Id;
}

public int GetHashCode(TransitTrafficAlert obj)
{
unchecked
{
var hashCode = obj.DescriptionText != null ? obj.DescriptionText.Language.GetHashCode() : 0;
hashCode = (hashCode * 397) ^ obj.DescriptionText?.Text?.GetHashCode() ?? 0;
hashCode = (hashCode * 397) ^ obj.StartDate.GetHashCode();
hashCode = (hashCode * 397) ^ obj.EndDate.GetHashCode();
return hashCode;
}
return obj?.Id?.GetHashCode() ?? 0;
}
}
}
Expand Down

0 comments on commit 51ddfd9

Please # to comment.