static public async Task <Protocol.LoginInfo> GetLoginInfo(string authToken, string userLogin) { JsonValue results = await HttpGetToJsonAsync(Settings.BaseUrl + "api/user/login/" + userLogin, authToken); var info = new Protocol.LoginInfo(results); if (info.succeeded()) { Log.Info(LogTag, "Successfully queried for info about user {0}", userLogin); } else { Log.Error(LogTag, "Could not query for info about user {0}: {1}", userLogin, info.error); } return(info); }
protected override async void OnCreate(Bundle bundle) { base.OnCreate(bundle); Log.SetLogger(new LogAndroid()); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Set support action bar based on toolbar from layout XML var mainToolbar = FindViewById <Toolbar>(Resource.Id.mainToolbar); SetSupportActionBar(mainToolbar); // Set flag to allow status bar colour to be managed by this activity. Window.SetFlags(WindowManagerFlags.DrawsSystemBarBackgrounds, WindowManagerFlags.DrawsSystemBarBackgrounds); Settings settings = new Settings(ApplicationContext); var statusLabel = FindViewById <TextView>(Resource.Id.loginStatus); var enabled = FindViewById <CheckBox>(Resource.Id.checkEnable); var buttonNotifications = FindViewById <Button>(Resource.Id.buttonNotifications); var login = FindViewById <TextView>(Resource.Id.editLogin); var password = FindViewById <TextView>(Resource.Id.editPassword); // First run initialisation. if (!settings.afterFirstRun) { // Set default values from NotificationPreferences.xml PreferenceManager.SetDefaultValues(ApplicationContext, Resource.Xml.NotificationPreferences, true); // If notification sound is null, set it to the system-default sound if (settings.downloadSound == null) { settings.downloadSound = RingtoneManager.GetDefaultUri(RingtoneType.Notification).ToString(); } if (settings.uploadSound == null) { settings.uploadSound = RingtoneManager.GetDefaultUri(RingtoneType.Notification).ToString(); } // Indicate that first run init is complete. settings.afterFirstRun = true; settings.commit(); } // Load up defaults from Settings. enabled.Checked = settings.enabled; login.Text = settings.userName; password.Text = settings.password; if (settings.authToken.IsNullOrEmpty()) { statusLabel.Text = "Not logged in"; } else { statusLabel.Text = "Logged in as " + settings.userName; } // Wire up UI events. enabled.CheckedChange += delegate { bool oldSetting = settings.enabled; settings.enabled = enabled.Checked; settings.commit(); if (!oldSetting) { LifeSharpService.Start(this); } }; buttonNotifications.Click += delegate { Intent intent = new Intent(this, typeof(ConfigureNotificationsActivity)); StartActivity(intent); }; var defaultStreamSpinner = FindViewById <Spinner>(Resource.Id.defaultStream); await fillStreams(settings); defaultStreamSpinner.ItemSelected += delegate { if (_streamIds == null) { return; } settings.defaultStream = _streamIds[defaultStreamSpinner.SelectedItemPosition]; settings.commit(); Log.Info("LifeSharp", "Setting new default stream to {0}", settings.defaultStream); }; Button button = FindViewById <Button>(Resource.Id.buttonLogin); button.Click += async delegate { settings.userName = login.Text; settings.password = password.Text; settings.commit(); Log.Info("LifeSharp", "Logging in with user {0} and password {1}", login.Text, password.Text); try { string result = await Network.Login(settings); if (result == null) { statusLabel.Text = "Log in failed"; settings.authToken = null; enabled.Checked = false; } else { statusLabel.Text = "Logged in successfully"; settings.authToken = result; enabled.Checked = true; } // Get our user ID. Protocol.LoginInfo loginInfo = await Network.GetLoginInfo(result, settings.userName); if (loginInfo.succeeded()) { settings.userId = loginInfo.id; // Commit so that user ID is available to upcoming fillStreams() call. settings.commit(); } // Obtain list of streams owned by user. await fillStreams(settings); settings.commit(); // This won't have already happened if we didn't have login info. LifeSharpService.Start(this); } catch (Exception ex) { Log.Info("LifeSharp", "Can't contact server: {0}", ex); statusLabel.Text = "Exception during login"; } }; button = FindViewById <Button>(Resource.Id.buttonGallery); button.Click += delegate(object sender, EventArgs e) { StartActivity(typeof(GalleryActivity)); }; ReceiveBoot.CompleteStartup(this, settings); }