private void moreMessages() { OnBind(); visibleMessages += 10; var x = db.Table <Message> (); if (x.Where(q => q.conversation == conversation).Count() < visibleMessages) { new Thread(async() => { while (!await network.UpdateHistory(db, user, chat, visibleMessages)) { await network.Authenticate(db, user); } RunOnUiThread(() => { if (isUnbound()) { return; } UpdateMessages(user); }); }).Start(); } else { UpdateMessages(user); } InvalidateOptionsMenu(); }
private void initializeNotAuthenticated() { SetContentView(Resource.Layout.Authentication); Button login = FindViewById <Button> (Resource.Id.login); login.Click += async delegate { InputMethodManager manager = (InputMethodManager)GetSystemService(InputMethodService); manager.HideSoftInputFromWindow(FindViewById <EditText> (Resource.Id.username).WindowToken, 0); manager.HideSoftInputFromWindow(FindViewById <EditText> (Resource.Id.password).WindowToken, 0); manager.HideSoftInputFromWindow(FindViewById <EditText> (Resource.Id.server).WindowToken, 0); login.Text = "Connecting..."; login.Enabled = false; var user = new User() { user = FindViewById <EditText> (Resource.Id.username).Text.ToLower(), password = FindViewById <EditText> (Resource.Id.password).Text, server = !string.IsNullOrEmpty(FindViewById <EditText> (Resource.Id.server).Text) ? FindViewById <EditText> (Resource.Id.server).Text : FindViewById <EditText> (Resource.Id.server).Hint }; if (user.user == "" || user.password == "") { login.Text = "Login"; login.Enabled = true; return; } if (await network.Authenticate(db, user)) { login.Text = "Loading data..."; new Thread(async() => { int i = 0; db.Insert(user); while (!await network.UpdateChats(db, user)) { await network.Authenticate(db, user); } var x = db.Table <Chat> (); int count = x.Count(); var tasks = new List <Task <bool> >(); RunOnUiThread(() => { if (isUnbound()) { return; } initializeAuthenticated(user); }); foreach (var chat in x) { while (!await network.UpdateHistory(db, user, chat, 30)) { await network.Authenticate(db, user); } OnUpdateRequested(); } }).Start(); } else { login.Text = "Retry Login"; login.Enabled = true; } }; }