Skip to content

Commit

Permalink
Fixed refreshing routes grid
Browse files Browse the repository at this point in the history
  • Loading branch information
damiansikora85 committed Jan 16, 2024
1 parent 1c65cd1 commit d2b6d0f
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions BusSchedule/Pages/RoutesPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public RoutesPage()
private async void OnScheduleUpdated(ScheduleDataUpdatedMessage message)
{
await RefreshData();
RefreshGrid();
}

protected override async void OnAppearing()
Expand All @@ -53,19 +54,7 @@ protected override async void OnAppearing()
UserDialogs.Instance.HideLoading();
#endif


int row = 0, col = 0;
int maxCol = grid.ColumnDefinitions.Count;
grid.Children.Clear();
foreach (var busService in _viewModel.Routes)
{
var item = new RouteView(busService);
item.OnServiceClicked += OnBusServiceSelected;
grid.Add(item, col, row);
col++;
row = col == maxCol ? row + 1 : row;
col %= maxCol;
}
RefreshGrid();

if (DateTime.TryParse(preferences.Get("rate_popup_last_shown", DateTime.MinValue.ToString()), out var ratePopupLastShown))
{
Expand All @@ -89,6 +78,22 @@ protected override async void OnAppearing()
base.OnAppearing();
}

private void RefreshGrid()
{
int row = 0, col = 0;
int maxCol = grid.ColumnDefinitions.Count;
grid.Children.Clear();
foreach (var busService in _viewModel.Routes)
{
var item = new RouteView(busService);
item.OnServiceClicked += OnBusServiceSelected;
grid.Add(item, col, row);
col++;
row = col == maxCol ? row + 1 : row;
col %= maxCol;
}
}

private Task RefreshData()
{
return Policy.Handle<Exception>().RetryAsync(async (exc, retryNum) =>
Expand Down

0 comments on commit d2b6d0f

Please sign in to comment.