public override void ViewDidLoad() 
		{
			base.ViewDidLoad();
			
			backBtn.TouchDown += HandleBackBtnBackBarButtonItemClicked;
			okBtn.TouchDown+= HandleOkBtnTouchDown;
			
			// Facebook
			facebookApp = new FaceBook.FaceBookApplication(this);
			/*
			facebookApp.OnLoginComplete+= ()=>
			{
				GraphUser guser = AppDelegateIPhone.AIphone.FacebookServ.GetMyProfile();
				if (guser != null)
				{
					NSUserDefaults.StandardUserDefaults.SetDouble((double)guser.id,"FacebookId");
					var id = AppDelegateIPhone.AIphone.MainUser.Id;
					AppDelegateIPhone.AIphone.UsersServ.UpdateSocialdId(guser.id, id, 1);
				}
			};
			*/
			facebookApp.OnExtraLoginComplete+= (GraphUser u)=>
			{
				GraphUser guser = u;//AppDelegateIPhone.AIphone.FacebookServ.GetMyProfile();
				if (guser != null)
				{
					NSUserDefaults.StandardUserDefaults.SetDouble((double)guser.id,"FacebookId");
					var id = AppDelegateIPhone.AIphone.MainUser.Id;
					AppDelegateIPhone.AIphone.UsersServ.UpdateSocialdId(guser.id, id, 1);
				}
			};			
			
			SwitchFacebook.ValueChanged += delegate {
				if (SwitchFacebook.On)
				{
					facebookApp.Login();					
				}
				else
				{
					facebookApp.Logout();
				}
			};
			
			// Twitter			
			twitterApp = new Twitter.TwitterApplication(this);			
			SwitchTwitter.ValueChanged += delegate {
				if (SwitchTwitter.On)
				{
					twitterApp.Login();
				}
				else
				{
					twitterApp.Logout();
				}
			};
			
			var view = new UIView(new RectangleF(0, 40 , 320, 1));
			view.Layer.BackgroundColor = UIColor.LightGray.CGColor;
			this.View.AddSubview(view);
		}
Example #2
0
		public Settings () : base (UITableViewStyle.Grouped, null)
		{
			msp = AppDelegateIPhone.tabBarController.SelectedViewController as MSPNavigationController;
			msp.OnViewAppeared += HandleMspOnViewAppeared;
			
			twitterApp = new Twitter.TwitterApplication(msp);
			facebookApp = new FaceBook.FaceBookApplication(msp);
			
			bool twitterLoggedIn = twitterApp.LoggedIn();
			bool facebookLoggedIn = facebookApp.LoggedIn();			
			
			Util.Defaults.SetInt (twitterLoggedIn ? 1 : 0, "twitterOption");
			Util.Defaults.SetInt (facebookLoggedIn ? 1 : 0, "facebookOption");
			
			Root = new RootElement (Locale.GetText ("Settings"))
			{
				new Section (Locale.GetText ("share your post on:")){
					(facebook = new CustomCheckboxElement (Locale.GetText ("Facebook"), facebookLoggedIn)),
					(twitter = new CustomCheckboxElement(Locale.GetText ("Twitter"),  twitterLoggedIn)),
				}							
			};
			
			facebook.ValueChanged += (sender, e) => 
			{
				if (!facebookApp.LoggedIn())
				{
					//facebookApp.Login();
					var _MSP = AppDelegateIPhone.tabBarController.SelectedViewController as UINavigationController;
					var vc = new SocialNetworksParentViewController(_MSP);
					_MSP.PushViewController(vc, true);
					return;
				}
				
				facebook.SetValue(facebook.Value);
				
				Util.Defaults.SetInt (facebook.Value ? 1 : 2, "facebookOption");
				Util.Defaults.Synchronize ();
			};
			twitter.ValueChanged += (sender, e) => 
			{
				if (!twitterApp.LoggedIn())
				{					
					//twitterApp.Login();
					var _MSP = AppDelegateIPhone.tabBarController.SelectedViewController as UINavigationController;
					var vc = new SocialNetworksParentViewController(_MSP);
					_MSP.PushViewController(vc, true);
					return;
				}
				
				twitter.SetValue(twitter.Value);
				
				Util.Defaults.SetInt (twitter.Value ? 1 : 2, "twitterOption");
				Util.Defaults.Synchronize ();
			};
		}
Example #3
0
		void FacebookAuth ()
		{ 					
			facebookApp = new FaceBook.FaceBookApplication (this);
			facebookApp.OnExtraLoginComplete += (GraphUser u) =>
			{	
				GraphUser guser = u;//AppDelegateIPhone.AIphone.FacebookServ.GetMyProfile ();
				if (guser != null) {
					NSUserDefaults.StandardUserDefaults.SetDouble ((double)guser.id, "FacebookId");
					
					PostAuth(guser.name, guser.id);
				}				
			};
			
			facebookApp.Login ();
		}
		public override void ViewDidLoad() 
		{
			base.ViewDidLoad();
			
			backBtn.TouchDown += HandleBackBtnBackBarButtonItemClicked;
/*
			UIGraphics.BeginImageContext(facebookBtn.Frame.Size);
			CGContext context = UIGraphics.GetCurrentContext();
			context.SetFillColor(0.0f,1.0f,0.0f,1.0f);
			context.FillRect(facebookBtn.Frame);
			UIImage image = UIGraphics.GetImageFromCurrentImageContext();
			UIGraphics.EndImageContext();
			FacebookBtn.SetBackgroundImage(image,UIControlState.Normal);
*/
			// Facebook
			facebookApp = new FaceBook.FaceBookApplication(this);			

			facebookBtn.TouchDown += delegate {
				if (facebookApp.LoggedIn())
				{										
					facebookApp.Publish("21Off", imageUrl, image.Name ?? "No comment", imageUrl);
					AppDelegateIPhone.ShowMessage(View, "Posted on facebook", null, 2);
				}
				else
				{
					var _MSP = AppDelegateIPhone.tabBarController.SelectedViewController as UINavigationController;
					var vc = new SocialNetworksParentViewController(_MSP);
					_MSP.PushViewController(vc, true);
				}
			};
						
			// Twitter			
			twitterApp = new Twitter.TwitterApplication(this);
			
			TwitterBtn.TouchDown += delegate {
				if (twitterApp.LoggedIn())
				{					
					twitterApp.Publish("21Off", imageUrl, image.Name ?? "No comment" , imageUrl);
					AppDelegateIPhone.ShowMessage(View, "Posted on twitter", null, 2);
				}
				else
				{
					var _MSP = AppDelegateIPhone.tabBarController.SelectedViewController as UINavigationController;
					var vc = new SocialNetworksParentViewController(_MSP);
					_MSP.PushViewController(vc, true);
				}
			};
			
			// 21Off
			if (this.image.UserId == AppDelegateIPhone.AIphone.MainUser.Id)
			{
				SelfshareLbl.Hidden = SelfshareBtn.Hidden = selfShareSubLbl.Hidden = true;
			}
			else
			{
				SelfshareBtn.TouchDown += delegate
				{
					Action act  = ()=>
					{
						AppDelegateIPhone.AIphone.ShareServ.PhotoShare(image);
					};
					
					AppDelegateIPhone.ShowRealLoading(null, "Sharing post", null, act);
				};
			}
		}
Example #5
0
		public void LoadFacebookFriends()
		{
			var facebookApp = new FaceBook.FaceBookApplication(this);
			if (!facebookApp.LoggedIn())
			{
				InvokeOnMainThread(()=>
				{
					var soc = new SocialNetworksParentViewController(_MSP);
					_MSP.PushViewController(soc, true);
				});								
				return;
			}
	
			List<Decimal> friends = AppDelegateIPhone.AIphone.FacebookServ.GetFriends();
			if (friends == null)
			{
				Util.LogException("friends", new Exception());
				return;
			}
			
			var socialIds = new List<long>();
			foreach (decimal d in friends)
			{
				socialIds.Add((long)d);
			}
			var fBresp = AppDelegateIPhone.AIphone.UsersServ.GetSocialIds(socialIds, 1);

			List<User> facebookFriends = fBresp.Subscribers;
			if (facebookFriends == null)
			{
				Util.LogException("facebookFriends", new Exception());
				return;
			}
			if (facebookFriends.Count == 0)
			{
				InvokeOnMainThread(()=>
				{
					var alert = new UIAlertView("Search", "No facebook friend found", null, "Ok");
					alert.Show();
				});
				return;
			}
					
			facebookApp = new FaceBook.FaceBookApplication (this);
			InvokeOnMainThread(()=>
			{								
				var root = new RootElement("") { new Section() };
				var dv = new DialogViewController(root, true);
				
				foreach (User fuser in facebookFriends)
				{
					var user = new UserElementII(fuser, RelationType.Friends);
					root[0].Add(user);
				}
				foreach (long socialId in fBresp.Others)
				{					
					var guser = new GraphUser() { id = socialId };										
					var fbUser = new FbUserElement(guser, u => 
                    {													
						WebViewController.OpenUrl (dv, "https://www.facebook.com/dialog/apprequests?app_id=168889879843414&message=Welcome to 21Off!&redirect_uri=http://www.21off.net");					 
					});
					root[0].Add(fbUser);
				}				
				
				var ev = new EmptyViewController(() => _MSP.PopViewControllerAnimated(true), "Facebook friends");
				dv.TableView.BackgroundView = new UIImageView(UIImage.FromBundle("Images/Ver4/fond"));
				dv.View.Frame = new RectangleF(0, 40, 320, 480 - 40);
				ev.Add(dv.View);
				_MSP.PushViewController(ev, false);
			});		
		}
		private void NetworkPost(Image image)
		{
			try
			{			
				string img = string.Format("{0}/{1}/{2}.jpg", UrlStore.streamingUrl, image.UserId, image.Id);
				if (_Settings.twitter.Value)
				{
					var twitterApp = new Twitter.TwitterApplication(this);
					if (twitterApp.LoggedIn())
					{
						twitterApp.Publish("21Off", img, image.Name ?? "No comment" , img);
					}
					else
					{
						using(var alert = new UIAlertView("Warning","Not logged in",null,"OK",null))
						{ alert.Show();}
					}
				}
				if (_Settings.facebook.Value)
				{
					var faceBookApp = new FaceBook.FaceBookApplication(this);
					if (faceBookApp.LoggedIn())
					{
						faceBookApp.Publish(image.Name ?? "No comment", img, "Posted with 21Off", img);
					}
					else
					{
						using(var alert = new UIAlertView("Warning","Not logged in",null,"OK",null))
						{ alert.Show();}
					}
				}
			}
			catch (Exception ex)
			{
				Util.LogException("NetworkPost", ex);
			}
		}