/// <summary>
 /// Invokes an action on the main UI thread
 /// </summary>
 /// <param name="action">The action to execute.</param>
 /// <param name="controller">View controller containiner the main UI thread</param>
 public static void ExecuteOnMainThread(this Action action, UIViewController controller)
 {
     controller.BeginInvokeOnMainThread(() =>
     {
         action();
     });
 }
Пример #2
0
        void ISimpleEmailPlugin.SendEmail(string toEmail, string subject, string message)
        {
            if (_vc == null)
            {
                throw new MissingMethodException("You have to call Init() method before");
            }

            if (MFMailComposeViewController.CanSendMail)
            {
                var to = new string[] { toEmail };

                if (MFMailComposeViewController.CanSendMail)
                {
                    _mailController = new MFMailComposeViewController();
                    _mailController.SetToRecipients(to);
                    _mailController.SetSubject(subject);
                    _mailController.SetMessageBody(message, false);
                    _mailController.Finished += (object s, MFComposeResultEventArgs args) => {
                        _vc.BeginInvokeOnMainThread(() => {
                            args.Controller.DismissViewController(true, null);
                        });
                    };
                }

                _vc.PresentViewController(_mailController, true, null);
            }
            else
            {
                new UIAlertView("Can't send email", string.Empty, null, "OK").Show();
            }
        }
Пример #3
0
 public void GetUnReadMessageCount(UILabel CounterText, UIViewController GelenBase)
 {
     new System.Threading.Thread(new System.Threading.ThreadStart(delegate
     {
         #region Message Count
         WebService webService = new WebService();
         var Donus             = webService.OkuGetir("chats/user");
         if (Donus != null)
         {
             mFriends = Newtonsoft.Json.JsonConvert.DeserializeObject <List <SonMesajlarListViewDataModel> >(Donus.ToString());
             SonMesajKiminKontrolunuYap();
             var toplam = OkunmaamisSayi(0, mFriends) + OkunmaamisSayi(1, mFriends) + OkunmaamisSayi(2, mFriends);
             if (toplam > 0)
             {
                 GelenBase.InvokeOnMainThread(delegate()
                 {
                     try
                     {
                         if (toplam > 9)
                         {
                             CounterText.Text = "9+";
                         }
                         else
                         {
                             CounterText.Text = toplam.ToString();
                         }
                         CounterText.Hidden = false;
                     }
                     catch
                     {
                         CounterText.Hidden = true;
                     }
                 });
             }
             else
             {
                 GelenBase.BeginInvokeOnMainThread(delegate()
                 {
                     try
                     {
                         CounterText.Hidden = true;
                     }
                     catch
                     {
                         CounterText.Hidden = true;
                     }
                 });
             }
         }
         #endregion
     })).Start();
 }
Пример #4
0
        /// <summary>
        /// Composes a new email to be sent.
        /// </summary>
        /// <param name="recipient">The receipient to send to.</param>
        /// <param name="subject">The subject for the email.</param>
        public void ComposesEmail(string recipient, string subject)
        {
            UIViewController            presentingController = this.getPresentingController();
            MFMailComposeViewController mailController       = new MFMailComposeViewController();

            mailController.SetToRecipients(new[] { recipient });
            mailController.SetSubject(subject);

            mailController.Finished +=
                (sender, e) => presentingController.BeginInvokeOnMainThread(
                    () => e.Controller.DismissViewController(true, null));

            presentingController.PresentViewController(mailController, true, null);
        }
		/// <summary>
		/// Initialize the binding manager for a view controller.
		/// </summary>
		/// <param name="bindings">The binding manager for this view.</param>
		/// <param name="controller">The view controller for this view.</param>
		public static void Initialize (this BindingManager bindings, UIViewController controller)
		{
			UpdateScheduler.Initialize (a =>
				controller.BeginInvokeOnMainThread (new Action(a)));
		}
 /// <summary>
 /// Initialize the binding manager for a view controller.
 /// </summary>
 /// <param name="bindings">The binding manager for this view.</param>
 /// <param name="controller">The view controller for this view.</param>
 public static void Initialize(this BindingManager bindings, UIViewController controller)
 {
     UpdateScheduler.Initialize(a =>
                                controller.BeginInvokeOnMainThread(new Action(a)));
 }
Пример #7
0
		/// <summary>
		/// Starts the login process.
		/// </summary>
		public void Login(UIViewController parent, bool animate)
		{
			switch (Config.Network)
			{
				case SocialNetwork.Facebook:
					{
						var config = (FacebookConfig)Config;
						var authorizor = new FacebookAuthorizationViewController(config.AppID,
#if true // fel
							config.Permissions, FbDisplayType.Popup);
#else
							config.Permissions, FbDisplayType.Touch);
#endif
				
						authorizor.AccessToken += delegate(string accessToken, DateTime expires) {
							try
							{
								var wc = new System.Net.WebClient();
								var result = wc.DownloadData("https://graph.facebook.com/me?access_token="+accessToken);
								var stream = new MemoryStream(result);						
								var jsonArray = (System.Json.JsonObject)System.Json.JsonObject.Load(stream);
								string username = jsonArray["name"].ToString().Replace("\"", "");
								this.UserId = jsonArray["id"].ToString().Replace("\"", "");
								this.AccessToken = accessToken;
								this.Username = username;
#if true // fel
								this.ExpirationDate = expires;
#endif
								parent.BeginInvokeOnMainThread(delegate{
									parent.DismissModalViewControllerAnimated(animate);
									OnSuccess();
								});
							}
							catch (Exception ex)
							{
								OnFailure();
							}
						};
				
						authorizor.Canceled += delegate {
							OnFailure();
						};
				
						authorizor.AuthorizationFailed += delegate {
							OnFailure();
						};
				
						parent.BeginInvokeOnMainThread(delegate{
							parent.PresentModalViewController(authorizor,animate);
						});
					}
					break;
				case SocialNetwork.Twitter:
					{
						var config = (TwitterConfig)Config;
						var authorizor = new TweetStation.OAuthAuthorizer(new TweetStation.OAuthConfig(){
							ConsumerKey = config.ConsumerKey,
							ConsumerSecret = config.ConsumerSecret,
							Callback = config.Callback,
							RequestTokenUrl = "https://api.twitter.com/oauth/request_token",
							AccessTokenUrl = "https://api.twitter.com/oauth/access_token",
							AuthorizeUrl = "https://api.twitter.com/oauth/authorize"
						});
						parent.BeginInvokeOnMainThread(delegate {
							authorizor.AcquireRequestToken();
							authorizor.AuthorizeUser(parent,delegate(){
								if (authorizor.AccessScreenname != "")
								{
									this.Username = authorizor.AccessScreenname;
									this.AccessToken = authorizor.AccessToken;
									this.AccessTokenSecret = authorizor.AccessTokenSecret;
									OnSuccess();
								}
								else
								{
									OnFailure();
								}
							});
						});
					}
					break;
			}
		}