bitwarden-android/src/App/Pages/BaseViewModel.cs
Federico Maccaroni e97a37222a
[PM-2658] Settings Reorganization feature (#2702)
* [PM-2658] Settings Reorganization Init (#2697)

* PM-2658 Started settings reorganization (settings main + vault + about)

* PM-2658 Added settings controls based on templates and implemented OtherSettingsPage

* PM-2658 Fix format

* [PM-3512] Settings Appearance (#2703)

* PM-3512 Implemented new Appearance Settings

* PM-3512 Fix format

* [PM-3510] Implement Account Security Settings view (#2714)

* PM-3510 Implemented Security settings view

* PM-3510 Fix format

* PM-3510 Added empty placeholder to pending login requests and also improved a11y on security settings view.

* PM-3511 Implemented autofill settings view (#2735)

* [PM-3695] Add Connect to Watch to Other settings (#2736)

* PM-3511 Implemented autofill settings view

* PM-3695 Add Connect to watch setting to other settings view

* [PM-3693] Clear old Settings approach (#2737)

* PM-3511 Implemented autofill settings view

* PM-3693 Remove old Settings approach

* PM-3845 Fix default dark theme description verbiage (#2759)

* PM-3839 Fix allow screen capture and submit crash logs to init their state when the page appears (#2760)

* PM-3834 Fix dialogs strings on settings (#2758)

* [PM-3834] Fix import items link (#2782)

* PM-3834 Fix import items link

* PM-3834 Fix import items link, removed old link.

* [PM-4092] Fix vault timeout policies on new Settings (#2796)

* PM-4092 Fix vault timeout policy on settings for disabling controls and reset timeout when surpassing maximum

* PM-4092 Removed testing hardcoding of policy data
2023-09-27 16:26:12 -03:00

73 lines
2.5 KiB
C#

using System;
using System.Threading.Tasks;
using System.Windows.Input;
using Bit.App.Abstractions;
using Bit.App.Controls;
using Bit.App.Resources;
using Bit.Core.Abstractions;
using Bit.Core.Exceptions;
using Bit.Core.Utilities;
using Xamarin.CommunityToolkit.ObjectModel;
using Xamarin.Essentials;
using Xamarin.Forms;
namespace Bit.App.Pages
{
public abstract class BaseViewModel : ExtendedViewModel
{
private string _pageTitle = string.Empty;
private AvatarImageSource _avatar;
private LazyResolve<IDeviceActionService> _deviceActionService = new LazyResolve<IDeviceActionService>();
private LazyResolve<IPlatformUtilsService> _platformUtilsService = new LazyResolve<IPlatformUtilsService>();
private LazyResolve<ILogger> _logger = new LazyResolve<ILogger>();
public string PageTitle
{
get => _pageTitle;
set => SetProperty(ref _pageTitle, value);
}
public AvatarImageSource AvatarImageSource
{
get => _avatar ?? new AvatarImageSource();
set => SetProperty(ref _avatar, value);
}
public ContentPage Page { get; set; }
protected void HandleException(Exception ex, string message = null)
{
if (ex is ApiException apiException && apiException.Error != null)
{
message = apiException.Error.GetSingleMessage();
}
Xamarin.Essentials.MainThread.InvokeOnMainThreadAsync(async () =>
{
await _deviceActionService.Value.HideLoadingAsync();
await _platformUtilsService.Value.ShowDialogAsync(message ?? AppResources.GenericErrorMessage);
}).FireAndForget();
_logger.Value.Exception(ex);
}
protected AsyncCommand CreateDefaultAsyncCommnad(Func<Task> execute, Func<object, bool> canExecute = null)
{
return new AsyncCommand(execute,
canExecute,
ex => HandleException(ex),
allowsMultipleExecutions: false);
}
protected async Task<bool> HasConnectivityAsync()
{
if (Connectivity.NetworkAccess == NetworkAccess.None)
{
await _platformUtilsService.Value.ShowDialogAsync(
AppResources.InternetConnectionRequiredMessage,
AppResources.InternetConnectionRequiredTitle);
return false;
}
return true;
}
}
}