Skip to content
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

[FIX] issue #9 - Add activity indicator while loading motels data from Azure #13

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7ddf70e
Merge pull request #1 from AngelGarcia13/master
RicardoBritoBrens Aug 15, 2020
5333ef9
[IMP] improve code style
RicardoBritoBrens Aug 16, 2020
164dcb0
[IMP] short using
RicardoBritoBrens Aug 16, 2020
07b2922
[ADD] add needed folders to split functionalities
RicardoBritoBrens Aug 16, 2020
e754c2b
[FIX] fix issue #10 Handle exceptions while perform
RicardoBritoBrens Aug 16, 2020
c33b47d
* MainActivity.cs:
RicardoBritoBrens Aug 16, 2020
ab05e53
[FIX] re add missing class
RicardoBritoBrens Aug 16, 2020
1f4a870
[ADD] add new property to handle busy status
RicardoBritoBrens Aug 16, 2020
5fe3ae3
[FIX] fix issue #9 - Add activity indicator
RicardoBritoBrens Aug 16, 2020
e20c10b
[FIX] fix wrong property type
RicardoBritoBrens Aug 16, 2020
01724fe
[IMP] start tracking missing classes
RicardoBritoBrens Aug 16, 2020
af79fd7
[IMP] move class to it's right folder
RicardoBritoBrens Aug 21, 2020
9e580d7
[REM] remove unnecessary file
RicardoBritoBrens Aug 21, 2020
73e2cd7
[FIX] fix nuget packages conflicts
RicardoBritoBrens Aug 23, 2020
685cffc
Merge branch 'AngelGarcia13-master'
RicardoBritoBrens Aug 23, 2020
0ee7710
Merge branch 'master' into solve-issue-9-add-activity-indicator-while…
RicardoBritoBrens Aug 23, 2020
2e55390
[FIX] re add missing files
RicardoBritoBrens Aug 29, 2020
3464f25
[FIX] fix wrong library version reference
RicardoBritoBrens Aug 29, 2020
4c97ff0
Merge branch 'master' into solve-issue-9-add-activity-indicator-while…
RicardoBritoBrens Aug 29, 2020
12cb8ee
[REM] remove secrets from tracking and fix namespace
RicardoBritoBrens Aug 29, 2020
f395307
Merge pull request #3 from AngelGarcia13/master
RicardoBritoBrens Sep 1, 2020
6d02220
Merge pull request #4 from RicardoBritoBrens/master
RicardoBritoBrens Sep 1, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,4 @@ MigrationBackup/
.DS_Store
src/App/CabanasRD/Helpers/Secrets.cs
src/App/CabanasRD/secrets.json

2 changes: 1 addition & 1 deletion src/App/CabanasRD.Android/CabanasRD.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,4 @@
<AndroidAsset Include="Assets\marker.png" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
</Project>
</Project>
2 changes: 2 additions & 0 deletions src/App/CabanasRD.Android/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Prism.Ioc;
using FFImageLoading.Forms.Platform;
using Xamarin.Forms;
using Acr.UserDialogs;

namespace CabanasRD.Droid
{
Expand All @@ -30,6 +31,7 @@ protected override void OnCreate(Bundle savedInstanceState)

Xamarin.FormsGoogleMaps.Init(this, savedInstanceState);
CachedImageRenderer.Init(true);
UserDialogs.Init(this);

LoadApplication(new App(new AndroidInitializer()));

Expand Down
5,202 changes: 3,959 additions & 1,243 deletions src/App/CabanasRD.Android/Resources/Resource.designer.cs

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/App/CabanasRD/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ private MapperConfiguration GetMapperConfiguration()
.ForMember(dest => dest.Latitude, source => source.MapFrom(src => double.Parse(src.Latitude)))
.ForMember(dest => dest.Longitude, source => source.MapFrom(src => double.Parse(src.Longitude)))
.ForMember(dest => dest.Services, source => source.MapFrom(src => src.MotelServices))
.ForMember(dest => dest.Images, source => source.MapFrom(src => src.Images.Select(i => new Domain.Motels.MotelImage{
.ForMember(dest => dest.Images, source => source.MapFrom(src => src.Images.Select(i => new Domain.Motels.MotelImage
{
Url = $"{i}.{imagesExtension}"
})))
.ForMember(dest => dest.Phones, source => source.MapFrom(src => src.Phones.Select(p => new Domain.Motels.MotelPhone
Expand Down
3 changes: 3 additions & 0 deletions src/App/CabanasRD/CabanasRD.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Acr.UserDialogs" Version="7.1.0.446" />
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="3.4.0" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="3.4.0" />
</ItemGroup>
Expand All @@ -43,6 +44,8 @@
<Folder Include="Framework\APIs\" />
<Folder Include="Framework\APIs\Models\" />
<Folder Include="Helpers\" />
<Folder Include="Extensions\" />
<Folder Include="Resources\Messages\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Core\CabanasRD.Data\CabanasRD.Data.csproj" />
Expand Down
21 changes: 21 additions & 0 deletions src/App/CabanasRD/Extensions/TaskExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Threading.Tasks;

namespace CabanasRD.Extensions
{
public static class TaskExtensions
{
public static async void Await(this Task task, Action completedCallback, Action<Exception> errorCallBack)
RicardoBritoBrens marked this conversation as resolved.
Show resolved Hide resolved
{
try
{
await task;
completedCallback?.Invoke();
}
catch (Exception exception)
{
errorCallBack?.Invoke(exception);
}
}
}
}
2 changes: 1 addition & 1 deletion src/App/CabanasRD/Framework/DataSources/MotelsSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task<IReadOnlyList<Motel>> GetAll()
{
var cabanasResponse = await _cabanasAPI.GetMotels(Helpers.Secrets.ApiKey);

return _mapper.Map<List<APIs.Models.MotelResponse>, List<Domain.Motels.Motel>>(cabanasResponse);
return _mapper.Map<List<APIs.Models.MotelResponse>, List<Motel>>(cabanasResponse);
}
catch (ApiException ex)
{
Expand Down
14 changes: 14 additions & 0 deletions src/App/CabanasRD/Messages/DisplayAlertCommonMessages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
namespace CabanasRD.Messages
{
public static class CommonDisplayAlertMessages
RicardoBritoBrens marked this conversation as resolved.
Show resolved Hide resolved
{
public static string OK => nameof(OK);
public static string Inforamtion => "Información";
public static string Warning => "Advertencia";
public static string Error => "Error";

public static string TryAgain => "Intentar Nuevamente";
public static string No => "No";
}
}
8 changes: 8 additions & 0 deletions src/App/CabanasRD/Messages/Errors.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;
namespace CabanasRD.Messages
{
public static class Errors
{
public static string IternarlServerError => "Se produjo un error interno en el servidor";
}
}
8 changes: 8 additions & 0 deletions src/App/CabanasRD/Messages/Informations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;
namespace CabanasRD.Messages
{
public static class Informations
{
public static string Loading => "Cargando información de Cabañas...";
}
}
8 changes: 8 additions & 0 deletions src/App/CabanasRD/Messages/Warnings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;
namespace CabanasRD.Messages
{
public static class Warning
{
public static string ThereIsAnErrorGettingTheInformationFromTheServer => "Se produjo un error al momento de obtener la información desde el servidor";
}
}
88 changes: 72 additions & 16 deletions src/App/CabanasRD/UI/Map/ViewModels/MotelsMapPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,27 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using Acr.UserDialogs;
using CabanasRD.Domain.Motels;
using CabanasRD.Extensions;
using CabanasRD.Messages;
using CabanasRD.UI.Map.Models;
using CabanasRD.UI.ViewModels;
using CabanasRD.UseCases.Motels;
using Prism.Commands;
using Prism.Navigation;
using Prism.Services;
using Xamarin.Forms.GoogleMaps;

namespace CabanasRD.UI.Map.ViewModels
{
public class MotelsMapPageViewModel : ViewModelBase
{
public ObservableCollection<MotelLocation> Locations { get; set; }
public IReadOnlyList<Motel> Motels { get; set; }
private IList<MotelLocation> searchResultLocations;
private IPageDialogService _dialogService;
public IList<MotelLocation> SearchResultLocations
{
get { return searchResultLocations; }
Expand Down Expand Up @@ -50,12 +58,13 @@ public string SearchText
SetProperty(ref searchText, value);
}
}

private MotelLocation selectedLocation;
public MotelLocation SelectedLocation
{
get { return selectedLocation; }
set {
set
{
SetProperty(ref selectedLocation, value);
if (selectedLocation != null)
{
Expand All @@ -64,18 +73,20 @@ public MotelLocation SelectedLocation
}
}
}


public MotelsMapPageViewModel(INavigationService navigationService, GetAllMotels getAllMotels)

public MotelsMapPageViewModel(INavigationService navigationService, IPageDialogService dialogService, GetAllMotels getAllMotels)
: base(navigationService)
{
_getAllMotels = getAllMotels;
_dialogService = dialogService;
Title = "Cabañas";
Locations = new ObservableCollection<MotelLocation>();
Motels = new List<Motel>();
Pins = new ObservableCollection<Pin>();
SearchResultLocations = new List<MotelLocation>();
TextSearchChangedCommand = new DelegateCommand(TextSearchChanged);
LoadMotelsLocations();
LoadMotelsLocations().Await(Completed, ErrorHandler);
}

private void TextSearchChanged()
Expand All @@ -94,10 +105,54 @@ private void TextSearchChanged()
}

//TODO: [Enhancement] Avoid async void calls!
private async void LoadMotelsLocations()
private async Task LoadMotelsLocations()
{
IsBusy = true;
try
{
using (UserDialogs.Instance.Loading(Informations.Loading, null, null, true))
{
// TODO: Add an activity indicator while loading the information
Motels = await _getAllMotels.Invoke();
}

}
catch (Exception exception)
{
// TODO: Register Crash and Exceptions into AppCenter
Console.WriteLine(exception.Message);

var dialogServiceResult = await _dialogService
.DisplayAlertAsync
(
CommonDisplayAlertMessages.Warning,
Messages.Warning.ThereIsAnErrorGettingTheInformationFromTheServer,
CommonDisplayAlertMessages.TryAgain,
CommonDisplayAlertMessages.No
);

if (dialogServiceResult)
{
await LoadMotelsLocations();
}
return;
}
}

public void InfoWindowSelected(Pin pin)
{
var motelDetails = Locations.FirstOrDefault(l => l.Pin.Equals(pin));
var navParams = new NavigationParameters
{
{ "MotelDetails", motelDetails.Motel }
};
NavigationService.NavigateAsync("MotelDetailsPage", navParams);
}

foreach (var item in await _getAllMotels.Invoke())
private void Completed()
{
IsBusy = false;
foreach (var item in Motels)
{
var pinItem = new Pin
{
Expand All @@ -112,19 +167,20 @@ private async void LoadMotelsLocations()
Pin = pinItem,
Motel = item
});

Pins.Add(pinItem);
}

}

public void InfoWindowSelected(Pin pin)
private void ErrorHandler(Exception exception)
{
var motelDetails = Locations.FirstOrDefault(l => l.Pin.Equals(pin));
var navParams = new NavigationParameters();
navParams.Add("MotelDetails", motelDetails.Motel);
NavigationService.NavigateAsync("MotelDetailsPage", navParams);
}
IsBusy = false;
_dialogService.DisplayAlertAsync
(
CommonDisplayAlertMessages.Error,
Messages.Errors.IternarlServerError,
CommonDisplayAlertMessages.OK
);

}
}
}
7 changes: 7 additions & 0 deletions src/App/CabanasRD/UI/ViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public string Title
set { SetProperty(ref _title, value); }
}

private bool _isBusy;
public bool IsBusy
{
get { return _isBusy; }
set { SetProperty(ref _isBusy, value); }
}

public ViewModelBase(INavigationService navigationService)
{
NavigationService = navigationService;
Expand Down
30 changes: 15 additions & 15 deletions src/CabanasRD.sln
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CabanasRD.Android", "App\CabanasRD.Android\CabanasRD.Android.csproj", "{A0394B14-3E67-409F-850C-C63541341B01}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CabanasRD.iOS", "App\CabanasRD.iOS\CabanasRD.iOS.csproj", "{3A224F40-1524-4A96-AF79-C197E382EF19}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CabanasRD.UITests", "Tests\CabanasRD.UITests\CabanasRD.UITests.csproj", "{B47FE63C-12B9-4243-B48B-69783C877B24}"
Expand All @@ -23,6 +21,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CabanasRD.Data", "Core\Caba
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CabanasRD.UseCases", "Core\CabanasRD.UseCases\CabanasRD.UseCases.csproj", "{23DB08E4-5DC7-48C8-B877-1C03900146C8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CabanasRD.Android", "App\CabanasRD.Android\CabanasRD.Android.csproj", "{A0394B14-3E67-409F-850C-C63541341B01}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -33,18 +33,6 @@ Global
Release|iPhone = Release|iPhone
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A0394B14-3E67-409F-850C-C63541341B01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A0394B14-3E67-409F-850C-C63541341B01}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A0394B14-3E67-409F-850C-C63541341B01}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A0394B14-3E67-409F-850C-C63541341B01}.Release|Any CPU.Build.0 = Release|Any CPU
{A0394B14-3E67-409F-850C-C63541341B01}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{A0394B14-3E67-409F-850C-C63541341B01}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{A0394B14-3E67-409F-850C-C63541341B01}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{A0394B14-3E67-409F-850C-C63541341B01}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{A0394B14-3E67-409F-850C-C63541341B01}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{A0394B14-3E67-409F-850C-C63541341B01}.Debug|iPhone.Build.0 = Debug|Any CPU
{A0394B14-3E67-409F-850C-C63541341B01}.Release|iPhone.ActiveCfg = Release|Any CPU
{A0394B14-3E67-409F-850C-C63541341B01}.Release|iPhone.Build.0 = Release|Any CPU
{3A224F40-1524-4A96-AF79-C197E382EF19}.Debug|Any CPU.ActiveCfg = Debug|iPhoneSimulator
{3A224F40-1524-4A96-AF79-C197E382EF19}.Debug|Any CPU.Build.0 = Debug|iPhoneSimulator
{3A224F40-1524-4A96-AF79-C197E382EF19}.Release|Any CPU.ActiveCfg = Release|iPhoneSimulator
Expand Down Expand Up @@ -129,15 +117,27 @@ Global
{23DB08E4-5DC7-48C8-B877-1C03900146C8}.Debug|iPhone.Build.0 = Debug|Any CPU
{23DB08E4-5DC7-48C8-B877-1C03900146C8}.Release|iPhone.ActiveCfg = Release|Any CPU
{23DB08E4-5DC7-48C8-B877-1C03900146C8}.Release|iPhone.Build.0 = Release|Any CPU
{A0394B14-3E67-409F-850C-C63541341B01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A0394B14-3E67-409F-850C-C63541341B01}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A0394B14-3E67-409F-850C-C63541341B01}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A0394B14-3E67-409F-850C-C63541341B01}.Release|Any CPU.Build.0 = Release|Any CPU
{A0394B14-3E67-409F-850C-C63541341B01}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{A0394B14-3E67-409F-850C-C63541341B01}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{A0394B14-3E67-409F-850C-C63541341B01}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{A0394B14-3E67-409F-850C-C63541341B01}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{A0394B14-3E67-409F-850C-C63541341B01}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{A0394B14-3E67-409F-850C-C63541341B01}.Debug|iPhone.Build.0 = Debug|Any CPU
{A0394B14-3E67-409F-850C-C63541341B01}.Release|iPhone.ActiveCfg = Release|Any CPU
{A0394B14-3E67-409F-850C-C63541341B01}.Release|iPhone.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{9D2E14BC-1FA3-400B-8345-41D8B90334E2} = {27826693-7F7E-41EC-8676-42F84C8931D0}
{A0394B14-3E67-409F-850C-C63541341B01} = {27826693-7F7E-41EC-8676-42F84C8931D0}
{3A224F40-1524-4A96-AF79-C197E382EF19} = {27826693-7F7E-41EC-8676-42F84C8931D0}
{B47FE63C-12B9-4243-B48B-69783C877B24} = {BC1A5396-3A78-44C6-942E-C15D701E031E}
{E6285AFF-138B-4513-A5FD-93742F7AED62} = {BC1A5396-3A78-44C6-942E-C15D701E031E}
{4119B139-9C7A-4049-B86B-E75EFF8B754C} = {56A51795-B524-4BA9-AF41-41E4106618C1}
{FFEA01C3-36FF-4E83-A964-316A80C0C2D1} = {56A51795-B524-4BA9-AF41-41E4106618C1}
{23DB08E4-5DC7-48C8-B877-1C03900146C8} = {56A51795-B524-4BA9-AF41-41E4106618C1}
{A0394B14-3E67-409F-850C-C63541341B01} = {27826693-7F7E-41EC-8676-42F84C8931D0}
EndGlobalSection
EndGlobal