2022-12-14 00:53:04 +03:00
|
|
|
|
using System;
|
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
|
using Bit.App.Controls;
|
|
|
|
|
using Bit.App.Resources;
|
|
|
|
|
using Bit.Core.Abstractions;
|
2023-01-20 16:38:31 +03:00
|
|
|
|
using Bit.Core.Exceptions;
|
2022-12-14 00:53:04 +03:00
|
|
|
|
using Bit.Core.Services;
|
2022-02-23 20:40:17 +03:00
|
|
|
|
using Bit.Core.Utilities;
|
2019-04-05 05:28:03 +03:00
|
|
|
|
using Xamarin.Forms;
|
2019-03-29 00:10:10 +03:00
|
|
|
|
|
2019-03-29 06:52:33 +03:00
|
|
|
|
namespace Bit.App.Pages
|
2019-03-29 00:10:10 +03:00
|
|
|
|
{
|
2019-03-29 19:52:57 +03:00
|
|
|
|
public abstract class BaseViewModel : ExtendedViewModel
|
2019-03-29 00:10:10 +03:00
|
|
|
|
{
|
|
|
|
|
private string _pageTitle = string.Empty;
|
2022-02-23 20:40:17 +03:00
|
|
|
|
private AvatarImageSource _avatar;
|
2022-12-14 00:53:04 +03:00
|
|
|
|
private LazyResolve<IDeviceActionService> _deviceActionService = new LazyResolve<IDeviceActionService>();
|
|
|
|
|
private LazyResolve<IPlatformUtilsService> _platformUtilsService = new LazyResolve<IPlatformUtilsService>();
|
|
|
|
|
private LazyResolve<ILogger> _logger = new LazyResolve<ILogger>();
|
2019-03-29 00:10:10 +03:00
|
|
|
|
|
|
|
|
|
public string PageTitle
|
|
|
|
|
{
|
|
|
|
|
get => _pageTitle;
|
|
|
|
|
set => SetProperty(ref _pageTitle, value);
|
|
|
|
|
}
|
2019-04-05 05:28:03 +03:00
|
|
|
|
|
2022-02-23 20:40:17 +03:00
|
|
|
|
public AvatarImageSource AvatarImageSource
|
|
|
|
|
{
|
|
|
|
|
get => _avatar ?? new AvatarImageSource();
|
|
|
|
|
set => SetProperty(ref _avatar, value);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-05 05:28:03 +03:00
|
|
|
|
public ContentPage Page { get; set; }
|
2022-12-14 00:53:04 +03:00
|
|
|
|
|
|
|
|
|
protected void HandleException(Exception ex, string message = null)
|
|
|
|
|
{
|
2023-01-20 16:38:31 +03:00
|
|
|
|
if (ex is ApiException apiException && apiException.Error != null)
|
|
|
|
|
{
|
|
|
|
|
message = apiException.Error.GetSingleMessage();
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-14 00:53:04 +03:00
|
|
|
|
Xamarin.Essentials.MainThread.InvokeOnMainThreadAsync(async () =>
|
|
|
|
|
{
|
|
|
|
|
await _deviceActionService.Value.HideLoadingAsync();
|
|
|
|
|
await _platformUtilsService.Value.ShowDialogAsync(message ?? AppResources.GenericErrorMessage);
|
|
|
|
|
}).FireAndForget();
|
|
|
|
|
_logger.Value.Exception(ex);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-29 00:10:10 +03:00
|
|
|
|
}
|
|
|
|
|
}
|