public void RegisterUser() { if (ValidateInput()) { DismissKeyboard(); AppController.Utility.ExecuteDelayedAction(300, default(System.Threading.CancellationToken), () => { if (_isRegisteringUser) { return; } _isRegisteringUser = true; _password = this.PasswordText.Text; // Prevent user form tapping views while logging ((MainActivity)this.Activity).BlockUI(); // Create a new cancellation token for this request _cts = new CancellationTokenSource(); AppController.RegisterUser(_cts, _email, _password, // Service call success (data) => { var f = new RegistrationDoneFragment(); this.FragmentManager.PopBackStack("BeforeRegistration0Fragment", (int)PopBackStackFlags.Inclusive); this.FragmentManager.BeginTransaction() .AddToBackStack("BeforeRegistrationDoneFragment") .Replace(Resource.Id.ContentLayout, f, "RegistrationDoneFragment") .Commit(); }, // Service call error (error) => { this.PasswordText.RequestFocus(); Toast.MakeText(this.Activity.Application, error, ToastLength.Long).Show(); }, // Service call finished () => { _isRegisteringUser = false; // Allow user to tap views ((MainActivity)this.Activity).UnblockUI(); }); }); } }
private void LoginUser() { if (ValidateInput()) { if (_isLogginUser) { return; } _isLogginUser = true; _email = this.EmailText.Text; _password = this.PasswordText.Text; // Prevent user form tapping views while logging ((MainViewController)this.MainViewController).BlockUI(); // Create a new cancellation token for this request _cts1 = new CancellationTokenSource(); AppController.LoginUser(_cts1, _email, _password, // Service call success (data) => { AppController.Settings.LastLoginUsernameUsed = _email; AppController.Settings.AuthAccessToken = data.AuthAccessToken; AppController.Settings.AuthExpirationDate = data.AuthExpirationDate.GetValueOrDefault().ToLocalTime(); ((AppDelegate)UIApplication.SharedApplication.Delegate).RegisterToNotificationsHub(); var c = new ChatViewController(); c.Arguments = new UIBundle(); c.Arguments.PutString("Email", _email); this.NavigationController.PushViewController(c, true); }, // Service call error (error) => { if (error.Contains("confirm")) { this.VerifyButton.Hidden = false; } UIToast.MakeText(error, UIToastLength.Long).Show(); }, // Service call finished () => { _isLogginUser = false; // Allow user to tap views ((MainViewController)this.MainViewController).UnblockUI(); }); } }
public void OnCompleted(JSONObject json, GraphResponse response) { try { string fbId = json.GetString("id"); string fbToken = AccessToken.CurrentAccessToken.Token; string fbEmail = json.GetString("email"); _email = fbEmail; // Create a new cancellation token for this request _cts0 = new CancellationTokenSource(); AppController.LoginUser(_cts0, fbId, fbEmail, fbToken, // Service call success (data) => { AppController.Settings.LastLoginUsernameUsed = _email; AppController.Settings.AuthAccessToken = data.AuthAccessToken; AppController.Settings.AuthExpirationDate = data.AuthExpirationDate.GetValueOrDefault().ToLocalTime(); ((ChattyApplication)this.Activity.Application).RegisterToNotificationsHub(); var f = new ChatFragment(); f.Arguments = new Bundle(); f.Arguments.PutString("Email", _email); this.FragmentManager.BeginTransaction() .AddToBackStack("BeforeChatFragment") .Replace(Resource.Id.ContentLayout, f, "ChatFragment") .Commit(); }, // Service call error (error) => { Toast.MakeText(this.Activity.Application, error, ToastLength.Long).Show(); }, // Service call finished () => { // Allow user to tap views ((MainActivity)this.Activity).UnblockUI(); }); } catch (Exception ex) { ((MainActivity)this.Activity).UnblockUI(); Toast.MakeText(this.Activity.ApplicationContext, "Error", ToastLength.Long).Show(); } finally { LoginManager.Instance.LogOut(); } }
public void RegisterUser() { if (ValidateInput()) { DismissKeyboard(); AppController.Utility.ExecuteDelayedAction(300, default(System.Threading.CancellationToken), () => { if (_isRegisteringUser) { return; } _isRegisteringUser = true; _password = this.PasswordText.Text; // Prevent user form tapping views while logging ((MainViewController)this.MainViewController).BlockUI(); // Create a new cancellation token for this request _cts = new CancellationTokenSource(); AppController.RegisterUser(_cts, _email, _password, // Service call success (data) => { var c = new RegistrationDoneViewController(); this.NavigationController.PopToViewController(this.NavigationController.ViewControllers.Single(x => x is LoginViewController), false); this.NavigationController.PushViewController(c, true); }, // Service call error (error) => { this.PasswordText.RequestUserInput(); UIToast.MakeText(error, UIToastLength.Long).Show(); }, // Service call finished () => { _isRegisteringUser = false; // Allow user to tap views ((MainViewController)this.MainViewController).UnblockUI(); }); }); } }
private void SendMessage() { string content = this.MessageText.Text; if (!String.IsNullOrWhiteSpace(content)) { if (_isSendingMessage) { return; } _isSendingMessage = true; // Add message to the message list Message message = new Message { Sender = null, Content = content, SendDate = DateTime.MinValue }; _source.AddItem(message); this.MessageList.ReloadData(); this.MessageList.ScrollToRow( NSIndexPath.FromItemSection((nint)(_source.Count - 1), 0), UITableViewScrollPosition.Bottom, false); _cts1 = new CancellationTokenSource(); AppController.SendMessage(_cts1, _email, content, (data) => { message.MessageId = data.MessageId; message.SendDate = data.SendDate.GetValueOrDefault(); this.MessageList.ReloadData(); }, (error) => { message.SendDate = DateTime.MaxValue; this.MessageList.ReloadData(); UIToast.MakeText(error, UIToastLength.Long).Show(); }, () => { _isSendingMessage = false; }); // Ready to send new message this.MessageText.Text = String.Empty; AdjustMessageTextHeight(); } }
public override void OnCreate() { base.OnCreate(); // Setup Application AppController.EnableSettings(new AdMaiora.AppKit.Data.UserSettingsPlatformAndroid()); AppController.EnableUtilities(new AdMaiora.AppKit.Utils.ExecutorPlatformAndroid()); AppController.EnableServices(new AdMaiora.AppKit.Services.ServiceClientPlatformAndroid()); // Setup push notifications RegisterForRemoteNotifications(AppController.Globals.GoogleGcmSenderID); // Setup Facebook Xamarin.Facebook.FacebookSdk.SdkInitialize(this.ApplicationContext); }
private void SendMessage() { string content = this.MessageText.Text; if (!String.IsNullOrWhiteSpace(content)) { if (_isSendingMessage) { return; } _isSendingMessage = true; // Add message to the message list Message message = new Message { Sender = null, Content = content, SendDate = DateTime.MinValue }; _adapter.AddItem(message); this.MessageList.ReloadData(); this.MessageList.SmoothScrollToPosition(_adapter.ItemCount); _cts1 = new CancellationTokenSource(); AppController.SendMessage(_cts1, _email, content, (data) => { message.MessageId = data.MessageId; message.SendDate = data.SendDate.GetValueOrDefault(); this.MessageList.ReloadData(); }, (error) => { message.SendDate = DateTime.MaxValue; this.MessageList.ReloadData(); Toast.MakeText(this.Activity.Application, error, ToastLength.Long).Show(); }, () => { _isSendingMessage = false; }); // Ready to send new message this.MessageText.Text = String.Empty; } }
public void DataRequestHandler(GraphRequestConnection connection, NSObject result, NSError err) { try { string fbId = result.ValueForKey(new NSString("id")).ToString(); string fbToken = AccessToken.CurrentAccessToken.TokenString; string fbEmail = result.ValueForKey(new NSString("email")).ToString(); _email = fbEmail; // Create a new cancellation token for this request _cts0 = new CancellationTokenSource(); AppController.LoginUser(_cts0, fbId, fbEmail, fbToken, // Service call success (data) => { AppController.Settings.LastLoginUsernameUsed = _email; AppController.Settings.AuthAccessToken = data.AuthAccessToken; AppController.Settings.AuthExpirationDate = data.AuthExpirationDate.GetValueOrDefault().ToLocalTime(); ((AppDelegate)UIApplication.SharedApplication.Delegate).RegisterToNotificationsHub(); var c = new ChatViewController(); c.Arguments = new UIBundle(); c.Arguments.PutString("Email", _email); this.NavigationController.PushViewController(c, true); }, // Service call error (error) => { UIToast.MakeText(error, UIToastLength.Long).Show(); }, // Service call finished () => { // Allow user to tap views ((MainViewController)this.MainViewController).UnblockUI(); }); } catch (Exception ex) { ((MainViewController)this.MainViewController).UnblockUI(); UIToast.MakeText("Error", UIToastLength.Long).Show(); } }
private void VerifyUser() { if (ValidateInput()) { if (_isConfirmingUser) { return; } _isConfirmingUser = true; _email = this.EmailText.Text; _password = this.PasswordText.Text; // Prevent user form tapping views while logging ((MainActivity)this.Activity).BlockUI(); this.VerifyButton.Visibility = ViewStates.Gone; // Create a new cancellation token for this request _cts1 = new CancellationTokenSource(); AppController.VerifyUser(_cts1, _email, _password, // Service call success () => { Toast.MakeText(this.Activity.Application, "You should receive a new mail!", ToastLength.Long).Show(); }, // Service call error (error) => { Toast.MakeText(this.Activity.Application, error, ToastLength.Long).Show(); }, // Service call finished () => { _isConfirmingUser = false; // Allow user to tap views ((MainActivity)this.Activity).UnblockUI(); }); } }
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) { // Setup Application AppController.EnableSettings(new AdMaiora.AppKit.Data.UserSettingsPlatformiOS()); AppController.EnableUtilities(new AdMaiora.AppKit.Utils.ExecutorPlatformiOS()); AppController.EnableServices(new AdMaiora.AppKit.Services.ServiceClientPlatformiOS()); // Setup push notifications RegisterForRemoteNotifications(launchOptions); // Setup Facebook Facebook.CoreKit.Settings.AppID = "1111406372229015"; Facebook.CoreKit.Settings.DisplayName = "Chatty"; Facebook.CoreKit.Profile.EnableUpdatesOnAccessTokenChange(true); Facebook.CoreKit.ApplicationDelegate.SharedInstance.FinishedLaunching(application, launchOptions); // Override point for customization after application launch. // If not required for your application you can safely delete this method return(RegisterMainLauncher(new SplashViewController(), launchOptions)); }
private bool RestoreUser() { if (!AppController.IsUserRestorable) { return(false); } if (_isLogginUser) { return(true); } _isLogginUser = true; // Create a new cancellation token for this request _cts = new CancellationTokenSource(); AppController.RestoreUser(_cts, AppController.Settings.AuthAccessToken, // Service call success (data) => { UIBundle b = new UIBundle(); b.PutBoolean("UserRestored", true); b.PutString("Email", data.Email); MakeRoot(typeof(MainViewController), b); }, // Service call error (error) => { MakeRoot(typeof(MainViewController)); UIToast.MakeText(error, UIToastLength.Long).Show(); }, // Service call finished () => { _isLogginUser = false; }); return(true); }
private void RefreshMessages() { lock (ReceiverLock) { if (_lastMessageId == 0) { if (AppController.Settings.LastMessageId == 0) { return; } _lastMessageId = AppController.Settings.LastMessageId; AppController.Settings.LastMessageId = 0; } if (_cts2 != null && !_cts2.IsCancellationRequested) { _cts2.Cancel(); } _cts2 = new CancellationTokenSource(); var cts = _cts2; Poco.Message[] newMessages = null; AppController.RefreshMessages( _cts2, _lastMessageId, _email, (data) => { if ((cts?.IsCancellationRequested).GetValueOrDefault(true)) { return; } lock (ReceiverLock) { newMessages = data?.Messages?.ToArray(); if (newMessages?.Length > 0) { var lm = newMessages.Last(); _lastMessageId = lm.MessageId; } } }, (error) => { // Do Nothing }, () => { if ((cts?.IsCancellationRequested).GetValueOrDefault(true)) { return; } lock (ReceiverLock) { bool playSound = false; if (newMessages != null) { foreach (var m in newMessages) { if (!_source.HasMessage(m.MessageId)) { playSound = true; // Add message to the message list Message message = new Message { MessageId = m.MessageId, Sender = m.Sender, Content = m.Content, SendDate = m.SendDate.GetValueOrDefault() }; _source.AddItem(message); } } } this.MessageList.ReloadData(); this.MessageList.ScrollToRow( NSIndexPath.FromItemSection((nint)(_source.Count - 1), 0), UITableViewScrollPosition.Bottom, false); if (playSound) { PlaySound(); } } }); } }
private void RefreshMessages() { lock (ReceiverLock) { if (_lastMessageId == 0) { if (AppController.Settings.LastMessageId == 0) { return; } _lastMessageId = AppController.Settings.LastMessageId; AppController.Settings.LastMessageId = 0; } if (_cts2 != null && !_cts2.IsCancellationRequested) { _cts2.Cancel(); } _cts2 = new CancellationTokenSource(); var cts = _cts2; Poco.Message[] newMessages = null; AppController.RefreshMessages( _cts2, _lastMessageId, _email, (data) => { if (cts.IsCancellationRequested) { return; } lock (ReceiverLock) { newMessages = data.Messages?.ToArray(); _lastMessageId = (newMessages?.Last().MessageId).GetValueOrDefault(0); } }, (error) => { // Do Nothing }, () => { if (cts.IsCancellationRequested) { return; } lock (ReceiverLock) { bool playSound = false; if (newMessages != null) { foreach (var m in newMessages) { if (!_adapter.HasMessage(m.MessageId)) { playSound = true; // Add message to the message list Message message = new Message { MessageId = m.MessageId, Sender = m.Sender, Content = m.Content, SendDate = m.SendDate.GetValueOrDefault() }; _adapter.AddItem(message); } } } this.MessageList.ReloadData(); this.MessageList.SmoothScrollToPosition(_adapter.ItemCount); if (playSound) { PlaySound(); } } }); } }