From 814e0a03f3ff238c55e8ae7fce6c116846131e9d Mon Sep 17 00:00:00 2001 From: Jakub Holovsky Date: Sun, 14 May 2017 12:07:47 +0200 Subject: [PATCH] Optimized first load of the app. --- ParkAndRidePrague.Core/packages.config | 2 +- ParkAndRidePrague.UWP/Package.appxmanifest | 2 +- ParkAndRidePrague.UWP/_language-cs.appx | Bin 4484 -> 4535 bytes ParkAndRidePrague.UWP/_pkginfo.txt | 2 +- .../Properties/AndroidManifest.xml | 2 +- .../AppResources.Designer.cs | 9 ++ .../ParkAndRidePrague/AppResources.cs.resx | 3 + .../ParkAndRidePrague/AppResources.resx | 3 + .../ParkAndRidePrague/MainPage.xaml.cs | 136 +++++++++++------- 9 files changed, 101 insertions(+), 58 deletions(-) diff --git a/ParkAndRidePrague.Core/packages.config b/ParkAndRidePrague.Core/packages.config index 431f4a1..e87513e 100644 --- a/ParkAndRidePrague.Core/packages.config +++ b/ParkAndRidePrague.Core/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/ParkAndRidePrague.UWP/Package.appxmanifest b/ParkAndRidePrague.UWP/Package.appxmanifest index 4116b00..e7fed70 100644 --- a/ParkAndRidePrague.UWP/Package.appxmanifest +++ b/ParkAndRidePrague.UWP/Package.appxmanifest @@ -1,6 +1,6 @@  - + Prague P+R diff --git a/ParkAndRidePrague.UWP/_language-cs.appx b/ParkAndRidePrague.UWP/_language-cs.appx index 6804f3f132b2b1009a4042165fc0e9017f494ac4..6f329f483cd65813ee32a86a67727bc365e1335f 100644 GIT binary patch delta 3792 zcmZu!XHXML+m+rDB#0;-r8lV(BmqPuNRwWrh7#!#iUfpEm5vAqgx;$Z5s?lGM4CwN z9T5W3dxU&=?|Z*@?##P8TW0s!=f|GebIyix)o}r})k#Q2u25c9HuH*jAU|3@V}RFT zm{+q<o-$3?zfuRpYuTu`HHG_63 zv~$#M>1t8lVU=0=8bq=b9O|3>+rH`Ikup~YRb|&U*lljS>Db$Tw#|Hx#P7}5><9)B zSMIBuA_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3;UO^^Td!;z8lqFX8u4h#Dvev{#w~f4kL%A*> zvzd@(Z1<{2|H@dei|EX-xXAm%Eh-PG*oOQ_9`;~-zR zbvyNhnfUr{6UlXwOWe+64{f0FE!C&op2L7MMj;l=tZ6KNkHWa z)~>xNQ%#Yv$XSB~wkAB@srdvIpp}ZM{OvEwo8|4u{={bEi-&L}9Dvu*{s>{f^c0l| zsa8xWGj9>;!vft)H&CfPpHtNq;WIvnWz`J@3k#s0Zoq8HcuBe|C+U1@>z%z|PQQ9O zbz`X2?URe=?O`Ui)nZO{5+&b>17y80y!xph>Z#5sc7r-ye)p?G#uKO*MfNzitTx1U!)dM7cf)^z(4LA}tnWh5p=d=k^fnE{bK7XIotC3lzv<33!#bFk;nkQ|1gncGk~J>j|_1}L}BRg2ouE3Hp% zM=bwWzcKkY9{+cC70#b*37EZ!jS|%1-|T - + diff --git a/ParkAndRidePrague/ParkAndRidePrague/AppResources.Designer.cs b/ParkAndRidePrague/ParkAndRidePrague/AppResources.Designer.cs index dca4d4d..e955164 100644 --- a/ParkAndRidePrague/ParkAndRidePrague/AppResources.Designer.cs +++ b/ParkAndRidePrague/ParkAndRidePrague/AppResources.Designer.cs @@ -115,6 +115,15 @@ public static string sinceLastUpdate { } } + /// + /// Looks up a localized string similar to sorting by location. + /// + public static string sortingByLocation { + get { + return ResourceManager.GetString("sortingByLocation", resourceCulture); + } + } + /// /// Looks up a localized string similar to Taken Places. /// diff --git a/ParkAndRidePrague/ParkAndRidePrague/AppResources.cs.resx b/ParkAndRidePrague/ParkAndRidePrague/AppResources.cs.resx index f4b8d3b..c1ef3be 100644 --- a/ParkAndRidePrague/ParkAndRidePrague/AppResources.cs.resx +++ b/ParkAndRidePrague/ParkAndRidePrague/AppResources.cs.resx @@ -135,6 +135,9 @@ Od poslední aktualizace + + řadím dle polohy + Obsazená místa diff --git a/ParkAndRidePrague/ParkAndRidePrague/AppResources.resx b/ParkAndRidePrague/ParkAndRidePrague/AppResources.resx index b749a54..128265a 100644 --- a/ParkAndRidePrague/ParkAndRidePrague/AppResources.resx +++ b/ParkAndRidePrague/ParkAndRidePrague/AppResources.resx @@ -135,6 +135,9 @@ Since Last Update + + sorting by location + Taken Places diff --git a/ParkAndRidePrague/ParkAndRidePrague/MainPage.xaml.cs b/ParkAndRidePrague/ParkAndRidePrague/MainPage.xaml.cs index a0b9434..0b06aa7 100644 --- a/ParkAndRidePrague/ParkAndRidePrague/MainPage.xaml.cs +++ b/ParkAndRidePrague/ParkAndRidePrague/MainPage.xaml.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Threading.Tasks; @@ -73,76 +74,103 @@ private async void ListViewParkingsOnRefreshing(object sender, EventArgs eventAr private async Task RefreshParkings(bool displayLoading) { - UpdateStatus(AppResources.updating); - if (displayLoading) - UpdateLoading(true); + UpdateStatus(AppResources.updating); + if (displayLoading) + UpdateLoading(true); - var hasInternetAccess = await NetworkHelper.HasInternetAccess(); - if (!hasInternetAccess) - { - UpdateStatus(AppResources.noNetwork); + var hasInternetAccess = await NetworkHelper.HasInternetAccess(); + if (!hasInternetAccess) + { + UpdateStatus(AppResources.noNetwork); - if (displayLoading) - UpdateLoading(false); + if (displayLoading) + UpdateLoading(false); - return; - } + return; + } - var apiResult = await parkingApi.GetParkings(); + var apiResult = await parkingApi.GetParkings(); - if (apiResult.Error) - { - UpdateStatus(AppResources.cannotUpdateParkings); + if (apiResult.Error) + { + UpdateStatus(AppResources.cannotUpdateParkings); - if (displayLoading) - UpdateLoading(false); + if (displayLoading) + UpdateLoading(false); - return; - } + return; + } - foreach (var observableParking in parkings) - { - var parking = apiResult.Result.SingleOrDefault(p => p.Id == observableParking.Id); - if (parking != null) - { - if (parking.LastUpdateDate == observableParking.LastUpdateDate) - parking.PreviousFreePlacesCount = observableParking.PreviousFreePlacesCount; - else - parking.PreviousFreePlacesCount = observableParking.FreePlacesCount; - } - } - ((App)Application.Current).InvokeParkingsRefreshed(apiResult); - var refreshedParkings = apiResult.Result; - - try - { - var locator = CrossGeolocator.Current; - locator.DesiredAccuracy = 50; - if (locator.IsGeolocationAvailable && locator.IsGeolocationEnabled) - { - var position = await CrossGeolocator.Current.GetPositionAsync(); - refreshedParkings = - refreshedParkings.OrderBy(p => p.GetDistance(position.Latitude, position.Longitude)) - .ToList(); - } - } - catch (Exception exception) - { - logger.Log(exception); - } - + foreach (var observableParking in parkings) + { + var parking = apiResult.Result.SingleOrDefault(p => p.Id == observableParking.Id); + if (parking != null) + { + if (parking.LastUpdateDate == observableParking.LastUpdateDate) + parking.PreviousFreePlacesCount = observableParking.PreviousFreePlacesCount; + else + parking.PreviousFreePlacesCount = observableParking.FreePlacesCount; + } + } + ((App)Application.Current).InvokeParkingsRefreshed(apiResult); + var refreshedParkings = apiResult.Result; + + if (parkings.Count == 0) + { + // If we came to the app for the first time, show parkings then do sorting. + RefreshParkings(refreshedParkings); + refreshedParkings = await SortParkings(refreshedParkings, true); + RefreshParkings(refreshedParkings); + } + else + { + refreshedParkings = await SortParkings(refreshedParkings, false); + RefreshParkings(refreshedParkings); + } + + if (displayLoading) + UpdateLoading(false); + UpdateStatus($"{AppResources.updatedAt.ToLower()} {apiResult.UpdatedAt:HH:mm:ss}"); + } + + private void RefreshParkings(List refreshedParkings) + { parkings.Clear(); foreach (var parking in refreshedParkings) { parkings.Add(parking); } + } + + private async Task> SortParkings(List refreshedParkings, bool displayMessage) + { + try + { + var locator = CrossGeolocator.Current; + locator.DesiredAccuracy = 50; + if (locator.IsGeolocationAvailable && locator.IsGeolocationEnabled) + { + if (displayMessage) + UpdateStatus(AppResources.sortingByLocation); + var position = await CrossGeolocator.Current.GetPositionAsync(); + refreshedParkings = + refreshedParkings.OrderBy(p => p.GetDistance(position.Latitude, position.Longitude)) + .ToList(); + } + else + { + refreshedParkings = refreshedParkings.OrderBy(p => p.Name).ToList(); + } + } + catch (Exception exception) + { + logger.Log(exception); + } - if (displayLoading) - UpdateLoading(false); - UpdateStatus($"{AppResources.updatedAt.ToLower()} {apiResult.UpdatedAt.ToString("HH:mm:ss")}"); + return refreshedParkings; } - private void UpdateLoading(bool showLoading) + private void UpdateLoading(bool showLoading) { Device.BeginInvokeOnMainThread(() => {