Exemplo n.º 1
0
        public SettingsViewModel(IAppService appService)
        {
            AppService = appService;
            LoadSettings(appService.AppSettings);


            ClearStatistic = new Command(
                execute: async() =>
            {
                var displayAlert = new DialogProvider(Page);
                var changeTask   = await displayAlert.DisplayAlert("Clear Task Statistics", "All statistics about finished task will be deleted. Did you want to continue.", "ok", "cancel");
                if (!changeTask)
                {
                    return;
                }
                AppService.ClearStatistics();
            }
                );

            Save = new Command(
                execute: async() =>
            {
                var settings = this.CreatePomodoroSettings();
                if (settings != null)
                {
                    IsBusy      = true;
                    var isSaved = await AppService.SaveSettingsAsync(settings);
                    if (isSaved)
                    {
                        var notificator = DependencyService.Get <INotification>();
                        notificator.Show("Saved.");
                    }
                    IsBusy = false;
                }
            }
                );

            LoadDefault = new Command(
                execute: async() =>
            {
                var settings = AppConstants.DEFAULT_APP_SETTINGS;
                if (settings != null)
                {
                    this.IsBusy = true;
                    await AppService.SaveSettingsAsync(settings);
                    this.LoadSettings(settings);
                    this.IsBusy = false;
                }
            }
                );
        }