using Fitness.ViewModels;
using Fitness.Views;
using Tizen.NUI;
+using Tizen.NUI.Components;
namespace Fitness.Services
{
public async Task NavigateToExercisingView(WorkoutViewModel workoutViewModel)
{
var result = await PrivilegeService.Instance.CheckCameraPrivilege();
- if (result == Tizen.Security.RequestResult.AllowForever)
+ if (result == Tizen.Security.RequestResult.AllowForever
+ && TryCreateCameraDependentView(
+ () => new ExercisingView()
+ {
+ BindingContext = new ExercisingViewModel(workoutViewModel),
+ },
+ out Controls.Page view))
{
- var view = new ExercisingView()
- {
- BindingContext = new ExercisingViewModel(workoutViewModel),
- };
navigation.Push(view);
}
}
public async Task NavigateToScanningView()
{
var result = await PrivilegeService.Instance.CheckCameraPrivilege();
- if (result == Tizen.Security.RequestResult.AllowForever)
+
+ if (result == Tizen.Security.RequestResult.AllowForever
+ && TryCreateCameraDependentView(() => new ScanningView(), out Controls.Page view))
{
- navigation.Push(new ScanningView());
+ navigation.Push(view);
}
}
{
navigation.PopToRoot();
}
+
+ private bool TryCreateCameraDependentView(Func<Controls.Page> constructor, out Controls.Page view)
+ {
+ const string Message = "Cannot find the camera.";
+
+ try
+ {
+ view = constructor();
+
+ return true;
+ }
+ catch (System.Reflection.TargetInvocationException e) when (e.InnerException is Tizen.Multimedia.CameraDeviceNotFoundException)
+ {
+ Notification
+ .MakeToast(Message, Notification.ToastBottom)
+ .Post(Notification.ToastLong);
+
+ view = null;
+
+ return false;
+ }
+ }
}
}