/// <summary> /// Initializises Commands, NavigationHandler and ConnectivityHandler, SettingsHandler of Model /// </summary> /// <param name="handler">For navigation</param> public MainPageVM(NavigationHandler handler) { _handler = handler; _connectivityHandler = ConnectivityHandler.SingletonConnectivityHandler; _settingsHandler = SettingsHandler.SingletonSettingsHandler; AudioPlayerPageCommand = new Command(GotoAudioPlayerPage); AudioLibPageCommand = new Command(GotoAudioLibPage); ConnectionPageCommand = new Command(GotoConnectionPage); ModesPageCommand = new Command(GotoModesPage); SettingsPageCommand = new Command(GotoSettingsPage); _iconOn = "bluetooth_on.png"; _iconOff = "bluetooth_off.png"; Icon = _iconOn; }
private async void OnSubmitBtnClicked(object sender, EventArgs args) { DisableUI(); // Disable UI var usernameText = UsernameEntry.Text; var passwordText = PasswordEntry.Text; var confirmText = ConfirmEntry.Text; var language = items[LanguagePicker.SelectedIndex]; if (!string.IsNullOrEmpty(usernameText) && !string.IsNullOrEmpty(passwordText) && passwordText == confirmText && !string.IsNullOrEmpty(language)) { ConnectivityHandler conHandler = new ConnectivityHandler(); bool isConnected = await conHandler.IsConnected(); if (isConnected) { var users = await AppContext.Repository.GetAsync <User>(x => x.Username == usernameText); bool userExists = false; if (users != null) { var oldUser = users.FirstOrDefault(); if (oldUser != null) { userExists = true; } } if (userExists) { RegisterCallbackLabel.Text = "User named " + usernameText + " exists"; EnableUI(); // Enable UI } else { var newUser = new User(); newUser.Username = usernameText; newUser.Password = passwordText; newUser.CodingLanguage = language; try { await AppContext.Repository.InsertAsync(newUser); RegisterCallbackLabel.TextColor = Color.Green; RegisterCallbackLabel.Text = "User has been registered successfully"; EnableUI(); // Enable UI } catch (Exception ex) { RegisterCallbackLabel.Text = "User Insert Error: " + ex; EnableUI(); // Enable UI } } } else { RegisterCallbackLabel.Text = "No Internet Connection"; EnableUI(); // Enable UI } } else { RegisterCallbackLabel.Text = "Empty or Invalid Inputs"; EnableUI(); // Enable UI } }
private async void OnLoginBtnClicked(object sender, EventArgs args) { DisableUI(); // Disable UI var usernameText = UsernameEntry.Text; var passwordText = PasswordEntry.Text; if (!string.IsNullOrEmpty(usernameText) && !string.IsNullOrEmpty(passwordText)) { ConnectivityHandler conHandler = new ConnectivityHandler(); bool isConnected = await conHandler.IsConnected(); if (isConnected) { var users = await AppContext.Repository.GetAsync <User>(x => x.Username == usernameText); if (users == null) { LoginCallbackLabel.Text = "Username doesn't exist"; EnableUI(); // Enable UI } else { var user = users.FirstOrDefault(); if (user == null) { LoginCallbackLabel.Text = "Username doesn't exist"; EnableUI(); // Enable UI } else { if (PasswordEntry.Text == user.Password) { LoginCallbackLabel.TextColor = Color.Green; LoginCallbackLabel.Text = "Map page loading.."; //Set stored data Application.Current.Properties["loggedUser"] = JsonConvert.SerializeObject(user); await Application.Current.SavePropertiesAsync(); //GOTO: MapPage Navigation.InsertPageBefore(new MapPage(AppContext), this); Navigation.RemovePage(this); //After login await AppContext.InitializeLoginAsync(user); } else { LoginCallbackLabel.Text = "Wrong password"; EnableUI(); // Enable UI } } } } else { LoginCallbackLabel.Text = "No Internet Connection"; EnableUI(); // Enable UI } } else { LoginCallbackLabel.Text = "Username and password must be filled"; EnableUI(); // Enable UI } }