public ChooseTimeDialog() { InitializeComponent(); scheduledTime = new ItemScheduledTime(); _timePicker.Time = DateTime.Now.TimeOfDay; Title = "New Alarm"; BindingContext = this; var settingsDatabaseController = new SettingsDatabaseController(); var curr_settings = settingsDatabaseController.GetSettings(); if (curr_settings == null) { curr_settings = new ItemSettings() { IsDatabaseSetUp = true, LastDifficultyChosen = "Advanced" }; settingsDatabaseController.SaveSettings(curr_settings); } switch (curr_settings.LastDifficultyChosen) { case "A1": pickerIndex = 0; break; case "A2": pickerIndex = 1; break; case "B1": pickerIndex = 2; break; case "B2": pickerIndex = 3; break; default: pickerIndex = 4; break; } _difficultyPicker.SelectedIndex = pickerIndex; }
public SettingsViewModel(INavigationService navigationService, SettingsDatabaseController settingsDatabase) : base(settingsDatabase) { GetSettings(); SaveSettingsCommand = new DelegateCommand(async() => { if (BasicSettings.WinningScore <= 0) { BasicSettings.WinningScore = 200; } await SettingsDatabase.SaveBasicSettingsAsync(BasicSettings); await navigationService.GoBackAsync(); }); ReturnToGameCommand = new DelegateCommand(async() => { await navigationService.GoBackAsync(); }); }
async void OnCloseButtonClicked(object sender, EventArgs e) { scheduledTime.Hour = _timePicker.Time.Hours; scheduledTime.Minute = _timePicker.Time.Minutes; var settingsDatabaseController = new SettingsDatabaseController(); var curr_settings = settingsDatabaseController.GetSettings(); pickerIndex = _difficultyPicker.SelectedIndex; switch (pickerIndex) { case 0: curr_settings.LastDifficultyChosen = "A1"; break; case 1: curr_settings.LastDifficultyChosen = "A2"; break; case 2: curr_settings.LastDifficultyChosen = "B1"; break; case 3: curr_settings.LastDifficultyChosen = "B2"; break; case 4: curr_settings.LastDifficultyChosen = "Advanced"; break; } settingsDatabaseController.SaveSettings(curr_settings); scheduledTime.Difficulty = curr_settings.LastDifficultyChosen; // TODO DELETE var alarmService = DependencyService.Get <ISetAlarm>(); if (scheduledTime.ID.HasValue) { alarmService.CancelAlarm(scheduledTime.ID.Value); } int id = alarmService.SetAlarm(scheduledTime.Hour, scheduledTime.Minute, scheduledTime.Difficulty); scheduledTime.ID = id; var scheduledTimeDatabaseController = new ScheduledTimeDatabaseController(); scheduledTimeDatabaseController.SaveScheduledTime(scheduledTime); await Navigation.PopToRootAsync(); }
public MatchViewModel(INavigationService navigationService, IPageDialogService pageDialog, MatchDatabaseController matchDatabase, SettingsDatabaseController settingsDatabase) : base(settingsDatabase) { _matchDatabase = matchDatabase; GetSettings(); GetMatchRounds(); AddMatchRoundCommand = new DelegateCommand(async() => { GetSettings(); bool isNewGame = false; if (MatchRound.WeScore == 0 && MatchRound.ThemScore == 0) { await pageDialog.DisplayAlertAsync("Error", "El resultado de la ronda no puede estar en blanco", "Cancelar"); return; } await matchDatabase.SaveMatchRound(MatchRound); if (WeTotalScore + MatchRound.WeScore >= BasicSettings.WinningScore || ThemTotalScore + MatchRound.ThemScore >= BasicSettings.WinningScore) { string winnerTeam = WeTotalScore + MatchRound.WeScore > ThemTotalScore + MatchRound.ThemScore ? "Nosotros" : "Ellos"; isNewGame = await pageDialog.DisplayAlertAsync("GANADOR", $"El equipo de {winnerTeam} ha ganado!", "Nueva partida", "Cerrar"); } if (isNewGame) { await matchDatabase.DeleteAllMatchRounds(); } GetMatchRounds(); MatchRound = new MatchRound(); }); DeleteMatchRoundCommand = new DelegateCommand <MatchRound>(async(round) => { await matchDatabase.DeleteMatchRound(round.Id); GetMatchRounds(); }); NewMatchCommand = new DelegateCommand(async() => { await matchDatabase.DeleteAllMatchRounds(); GetMatchRounds(); }); RefreshCommand = new DelegateCommand(() => GetMatchRounds()); GoToSettingsCommand = new DelegateCommand(async() => await navigationService.NavigateAsync(NavConstants.SettingsPage)); }
public BaseViewModel(SettingsDatabaseController settingsDatabase) { SettingsDatabase = settingsDatabase; }