Пример #1
0
		public static void PassPostToAllNotificationsFeedsIfExists (Notification notification, FeedTypeEnum.FeedType key)
		{
			if (notification == null)
			{
				return;
			}

			if (notification.post != null && notification.post.IsExpired () && key == FeedTypeEnum.FeedType.StatusFeed){
				return;
			}

			foreach (KeyValuePair<string, List<Notification>> currentDict in Globe.SharedInstance.NotificationFeeds) { 
				bool foundIt = false;	
				for (int i = 0; i < currentDict.Value.Count; i++) {
					if (currentDict.Value [i].idNotification == notification.idNotification) {
						currentDict.Value [i] = notification;
						foundIt = true;
					}

					if (key == FeedTypeEnum.FeedType.StatusFeed && currentDict.Value [i].post != null && notification.post != null && currentDict.Value [i].post.idPost == notification.post.idPost) {
						currentDict.Value [i] = notification;
						foundIt = true;
					}
				}

				if (!foundIt && currentDict.Key == key.ToString ()) {
					currentDict.Value.Add (notification);
				}

				currentDict.Value.Sort ((x, y) => y.datestamp.Value.CompareTo (x.datestamp.Value));

			}
		}
		public void BindDataToCell (Notification notification, FeedTypeEnum.FeedType target, List<Notification> underlyingDataSource, NSIndexPath indexPath, UITableView tableView, NotificationFeedTableViewSource source)
		{
			CellCaptionLabel.AttributedText = NativeStringUtils.ParseStringForKeywords (notification, notification.message);
			CellCaptionLabel.TextContainer.LineFragmentPadding = 0;
			CellCaptionLabel.TextContainerInset = UIEdgeInsets.Zero;
			CellCaptionLabel.ContentInset = new UIEdgeInsets (5, 0, 5, 0);
			CellCaptionLabel.SizeToFit ();

			CellTimeElapsedLabel.Text = StringUtils.GetPrettyDateAbs (notification.datestamp);

			CellTimeRemaining.ClipsToBounds = true;
			CellTimeRemaining.Layer.CornerRadius = 4;

			SetCommentImage (notification);
			SetTimeRemaining (notification);
			SetPostUserImageAndUsername (notification);
			SetUserAction (notification, target);
			SetButtonListeners (notification, underlyingDataSource, indexPath, tableView, source, target);
			SetPostImage (notification);
		}
Пример #3
0
		public static void PassPostToAllFeedsIfExistsWithInclude (Post post, FeedTypeEnum.FeedType key)
		{
			if (post == null){
				return;
			}

			if (post.IsExpired () && (key != FeedTypeEnum.FeedType.MyProfileFeed || post.userReposter != null)) {
				return;
			}

			foreach (KeyValuePair<string, List<Post>> currentDict in Globe.SharedInstance.PostFeeds) { 
				bool foundIt = false;
				for (int i = 0; i < currentDict.Value.Count; i++) {
					if (currentDict.Value [i].idPost == post.idPost) {
						currentDict.Value [i] = post;
						foundIt = true;
					}
				}

				if (!foundIt && currentDict.Key == key.ToString ()) {
					post.feedType = (int)key;
					currentDict.Value.Add (post);
				}

				currentDict.Value.Sort ((x, y) => y.datestamp.Value.CompareTo (x.datestamp.Value));
			}


			foreach (KeyValuePair<string, List<Notification>> currentDict in Globe.SharedInstance.NotificationFeeds) {
				for (int i = 0; i < currentDict.Value.Count; i++) {
					if (currentDict.Value [i].post != null && currentDict.Value [i].post.idPost == post.idPost) {
						currentDict.Value [i].post = post;
					}
				}
			}
		}
Пример #4
0
		public static void ParseForMentionOrHash(UITapGestureRecognizer obj, NSIndexPath indexPath, UITableView tableView, FeedTypeEnum.FeedType target = 0)
		{
			UITextView textView = (UITextView)obj.View;
			UITextRange textRange;
			string text = textView.Text;

			//contains emoji fix
			if (StringUtils.ContainsEmoji(text))
			{
				//try to remove the emoji's first
				text = System.Text.RegularExpressions.Regex.Replace(text, @"\p{Cs}", "");
				if (String.IsNullOrEmpty(text))
				{
					return;
				}

				//if it has emoji's just go to the post page.
				//if (tableView != null)
				//{
				//	tableView.Delegate.RowSelected(tableView, indexPath);
				//}
				//return;
			}

			try
			{
				textRange = textView.Tokenizer.GetRangeEnclosingPosition(textView.GetClosestPositionToPoint(obj.LocationInView(textView)), UITextGranularity.Word, UITextDirection.Forward);
			}
			catch (Exception)
			{
				if (tableView != null && tableView.Delegate != null)
				{
					tableView.Delegate.RowSelected(tableView, indexPath);
				}
				return;
			}

			if (textRange == null)
			{
				if (tableView != null && tableView.Delegate != null)
				{
					tableView.Delegate.RowSelected(tableView, indexPath);
				}
				return;
			}

			nint clickedLocation = textView.GetOffsetFromPosition(textView.BeginningOfDocument, textRange.Start); //-1
			nint newLoc = text.LastIndexOf(" ", (int)clickedLocation) + 1;

			nint newLen = text.IndexOf(" ", (int)clickedLocation);//textView.GetOffsetFromPosition (textRange.Start, textRange.End);
			if (newLen == -1)
			{//no space exist after
				newLen = text.Length;
			}

			if (textRange == null || newLoc == -1)
			{
				if (tableView != null && tableView.Delegate != null)
				{
					tableView.Delegate.RowSelected(tableView, indexPath);
				}
				return;
			}

			string prefix = text.Substring((int)newLoc, 1);
			Console.WriteLine(prefix);

			if (prefix == "@")
			{
				if (target == FeedTypeEnum.FeedType.StatusFeed)
				{
					((HomeViewController)((UINavigationController)((AppDelegate)UIApplication.SharedApplication.Delegate).TabBarController.ViewControllers[0]).ViewControllers[0]).DismissModalViewController(false);
				}
				var test = text.Substring((int)newLoc, (int)(newLen - newLoc));
				TenServiceHelper.GoToGuestProfile(test); //remove -1
			}
			else if (prefix == "#")
			{
				if (target == FeedTypeEnum.FeedType.StatusFeed)
				{
					((HomeViewController)((UINavigationController)((AppDelegate)UIApplication.SharedApplication.Delegate).TabBarController.ViewControllers[0]).ViewControllers[0]).DismissModalViewController(false);
				}
				TenServiceHelper.GoToSearchTags(text.Substring((int)newLoc, (int)(newLen - newLoc))); //remove -1
			}
			else {
				if (tableView != null && tableView.Delegate != null)
				{
					tableView.Delegate.RowSelected(tableView, indexPath);
				}
				return;

			}
		}
Пример #5
0
		public static void GoToListOf(FeedTypeEnum.FeedType type, int objectid)
		{
			ListOfTableViewController vc = (ListOfTableViewController)((AppDelegate)UIApplication.SharedApplication.Delegate).TabBarController.Storyboard.InstantiateViewController("ListOfTableViewController");
			vc.Target = type;
			vc.EmptyTableString = Strings.no_users_found;
			vc.Objectid = objectid;

			UITabBarController TabBarController = ((AppDelegate)UIApplication.SharedApplication.Delegate).TabBarController;
			UINavigationController NavigationController = ((UINavigationController)TabBarController.ViewControllers[TabBarController.SelectedIndex]);
			((NavigationController.ViewControllers[NavigationController.ViewControllers.Length - 1])).NavigationController.PushViewController(vc, true);
		}
Пример #6
0
		//Users
		public static List<User> ParseForUsers (JToken token, FeedTypeEnum.FeedType key, int offset)
		{

			//List<User> ListToReturn = new List<User> ();
			//foreach (JToken jt in (JArray)token ["users"]) {
			//	ListToReturn.Add (JsonConvert.DeserializeObject<User> (jt.ToString ()));
			//}
	
				
			//return ListToReturn;

			JArray resultArray = (JArray)token["users"];

			if (resultArray.Count == 0)
			{
				throw new RESTError(Strings.no_active_posts);
			}

			if (!Globe.SharedInstance.UserFeeds.ContainsKey(key.ToString()))
			{
				Globe.SharedInstance.UserFeeds.Add(key.ToString(), new List<User>());
			}

			//if (offset == 0){}
			foreach (JToken userToken in resultArray)
			{
				FeedUtils.PassUserToAllFeedsIfExists(JsonConvert.DeserializeObject<User>(userToken.ToString()), key);
			}
			return Globe.SharedInstance.UserFeeds[key.ToString()];
		}
Пример #7
0
		//Posts
		public static List<Post> ParseForPosts (JToken token, FeedTypeEnum.FeedType key, int offset)
		{

			JArray resultArray = (JArray)token ["posts"];

			if (offset == 0)
			{
				if (Globe.SharedInstance.PostFeeds.ContainsKey(key.ToString()))
				{
					Globe.SharedInstance.PostFeeds[key.ToString()].Clear();
				}
			}

			if (resultArray.Count == 0) {
				throw new RESTError (Strings.no_active_posts);
			}

			if (!Globe.SharedInstance.PostFeeds.ContainsKey (key.ToString ())) {
				Globe.SharedInstance.PostFeeds.Add (key.ToString (), new List<Post> ());
			}

			if (offset == 0) {
				Globe.SharedInstance.PostFeeds[key.ToString()].Clear();
			}
			foreach (JToken postToken in resultArray) {
				FeedUtils.PassPostToAllFeedsIfExistsWithInclude (JsonConvert.DeserializeObject<Post> (postToken.ToString ()), key);
			}
			return Globe.SharedInstance.PostFeeds [key.ToString ()];
		}
Пример #8
0
		//notifications
		public static List<Notification> ParseForNotifications (JToken token, FeedTypeEnum.FeedType key)
		{
			JArray resultArray = (JArray)token ["notifications"];

			if (resultArray.Count == 0) {
				throw new RESTError (Strings.no_notifications);
			}

			if (!Globe.SharedInstance.NotificationFeeds.ContainsKey (key.ToString ())) {
				Globe.SharedInstance.NotificationFeeds.Add (key.ToString (), new List<Notification> ());
			}

			foreach (JToken notificationToken in resultArray) {
				Notification notification = JsonConvert.DeserializeObject<Notification> (notificationToken.ToString ());

				if (notification.type == Strings.notification_type_repost)
				{
					notification.message = notification.user.username + " reposted your post";
				}

				if (key == FeedTypeEnum.FeedType.StatusFeed && notification.type == Strings.notification_type_comment) {
					notification.message = "\"" + notification.message + "\"";
				}
				FeedUtils.PassPostToAllNotificationsFeedsIfExists (notification, key);
			}
			return Globe.SharedInstance.NotificationFeeds [key.ToString ()];

		}
Пример #9
0
		public static void PassUserToAllFeedsIfExists(User user, FeedTypeEnum.FeedType key)
		{
			if (user == null)
			{
				return;
			}

			foreach (KeyValuePair<string, List<User>> currentDict in Globe.SharedInstance.UserFeeds)
			{
				bool foundIt = false;
				for (int i = 0; i < currentDict.Value.Count; i++)
				{
					if (currentDict.Value[i].idUser == user.idUser)
					{
						currentDict.Value[i] = user;
						foundIt = true;
					}
				}

				if (!foundIt && currentDict.Key == key.ToString())
				{
					currentDict.Value.Add(user);
				}

				currentDict.Value.Sort((x, y) => y.username.CompareTo(x.username));

			}
		}
		private void SetButtonListeners (Notification notification, List<Notification> underlyingDataSource, NSIndexPath indexPath, UITableView tableView, NotificationFeedTableViewSource source, FeedTypeEnum.FeedType target)
		{
			UITapGestureRecognizer tapGesture = new UITapGestureRecognizer (delegate(UITapGestureRecognizer obj) {
				TenServiceHelper.ParseForMentionOrHash(obj, indexPath, tableView);
			});
			CellCaptionLabel.AddGestureRecognizer (tapGesture);
			CellCaptionLabel.Selectable = true;
			CellCaptionLabel.DataDetectorTypes = UIDataDetectorType.Link;

			CellUserImageButton.RemoveTarget (null, null, UIControlEvent.TouchUpInside);
			CellUserImageButton.TouchUpInside += (sender, e) => {
				if (target == FeedTypeEnum.FeedType.StatusFeed) {
					((HomeViewController)((UINavigationController)((AppDelegate)UIApplication.SharedApplication.Delegate).TabBarController.ViewControllers [0]).ViewControllers [0]).DismissModalViewController (false);
				}

				if (notification.post == null) {
					TenServiceHelper.GoToGuestProfile (notification.user);
				} else {
					TenServiceHelper.GoToGuestProfile (notification.post.userPoster);
				}
			};

			CellUsernameLabel.RemoveTarget (null, null, UIControlEvent.TouchUpInside);
			CellUsernameLabel.TouchUpInside += (sender, e) => {
				if (target == FeedTypeEnum.FeedType.StatusFeed) {
					((HomeViewController)((UINavigationController)((AppDelegate)UIApplication.SharedApplication.Delegate).TabBarController.ViewControllers [0]).ViewControllers [0]).DismissModalViewController (false);
				}

				if (notification.post == null) {
					TenServiceHelper.GoToGuestProfile (notification.user);
				} else {
					if(notification.user != null && (notification.user.idUser != Globe.SharedInstance.User.idUser) || target ==	FeedTypeEnum.FeedType.StatusFeed){
						TenServiceHelper.GoToGuestProfile (notification.user);
					}  else {
						TenServiceHelper.GoToGuestProfile (notification.post.userPoster);
					}
				}
			};


			CellClockImage.RemoveTarget (null, null, UIControlEvent.TouchUpInside);
			CellClockImage.TouchUpInside += (sender, e) => {
				if (target == FeedTypeEnum.FeedType.StatusFeed) {
					((HomeViewController)((UINavigationController)((AppDelegate)UIApplication.SharedApplication.Delegate).TabBarController.ViewControllers [0]).ViewControllers [0]).DismissModalViewController (false);
				}

				TenServiceHelper.GoToListOf (FeedTypeEnum.FeedType.LikersListOfFeed, notification.post.idPost);
			};

			CellTimeRemaining.RemoveTarget (null, null, UIControlEvent.TouchUpInside);
			CellTimeRemaining.TouchUpInside += (sender, e) => {
				if (target == FeedTypeEnum.FeedType.StatusFeed) {
					((HomeViewController)((UINavigationController)((AppDelegate)UIApplication.SharedApplication.Delegate).TabBarController.ViewControllers [0]).ViewControllers [0]).DismissModalViewController (false);
				}

				TenServiceHelper.GoToListOf (FeedTypeEnum.FeedType.LikersListOfFeed, notification.post.idPost);
			};
		}
		private void SetUserAction (Notification notification, FeedTypeEnum.FeedType target)
		{
			if (target == FeedTypeEnum.FeedType.StatusFeed) {
				CellUserActionButton.Hidden = false;
				if (notification.user.IsMe()) {
					CellUserActionButton.SetTitle ("by you", UIControlState.Normal);
					CellUserActionButton.SetTitle ("by you", UIControlState.Highlighted);
					CellUserActionButton.SetTitle ("by you", UIControlState.Selected);
				} else {
					CellUserActionButton.SetTitle ("by " + notification.user.username, UIControlState.Normal);
					CellUserActionButton.SetTitle ("by " + notification.user.username, UIControlState.Highlighted);
					CellUserActionButton.SetTitle ("by " + notification.user.username, UIControlState.Selected);
				}
			} else {
				CellUserActionButton.Hidden = true;
			}
		}
Пример #12
0
		public static void GoToListOf (Android.Support.V4.App.FragmentManager fragmentManager, int containerId, int objectid, FeedTypeEnum.FeedType target)
		{
			ListOfFragment fragment = new ListOfFragment();
			fragment.objectid = objectid;
			fragment.Target = target;
			fragmentManager.BeginTransaction().Add(containerId, fragment).AddToBackStack(null).Commit();
		}