public async Task<User> GetProfileInfoFromGoogle(string access_token)
		{
			User user = new User();
			//Google API REST request
			string userInfo = await fnDownloadString(string.Format(googUesrInfoAccessleUrl, access_token));
			if (userInfo != "Exception")
			{
				//step 4: Deserialize the JSON response to get data in class object
				googleInfo = JsonConvert.DeserializeObject<GoogleInfo>(userInfo);
                LoggedInUserName = googleInfo.email;

				user.UserName = !string.IsNullOrWhiteSpace(googleInfo.name)?googleInfo.name:(!string.IsNullOrWhiteSpace(googleInfo.email)?googleInfo.email:"");
				user.DisplayName = googleInfo.name;
				user.AllowCommunitySharing = true;
				user.AuthenticationToken = access_token;
				user.Email = googleInfo.email;
				user.Gender = googleInfo.gender;
				user.ProfileImageUrl = googleInfo.picture;
				user.UserId = googleInfo.id;
			}
			else
			{
				//Toast.MakeText (Context, "connrection failed", ToastLength.Short);
				//	Toast.MakeText(this, "Connection failed! Please try again", ToastLength.Short).Show();
			}
            return user;
		}
		async void SerialiseFacebookUserData(string json)
		{
			FacebookInfo fbUser = JsonConvert.DeserializeObject<FacebookInfo>(json);
			User user = new User ();
			user.UserName = fbUser.name;
			user.DisplayName = fbUser.name;
			user.Email = fbUser.email;
			user.UserId = fbUser.id;

			await PurposeColor.App.SaveUserData( user, false);
		}
		public ProfileSettingsPage(int userId = 0)
		{
			NavigationPage.SetHasNavigationBar(this, false);
			masterLayout = new CustomLayout();
			masterLayout.BackgroundColor = Constants.PAGE_BG_COLOR_LIGHT_GRAY;
			subTitleBar = new PurposeColorSubTitleBar(Constants.SUB_TITLE_BG_COLOR, "       Profile Info", false, true);
			subTitleBar.BackButtonTapRecognizer.Tapped += (s, e) =>
			{
				try
				{
					Navigation.PopAsync();
				}
				catch (Exception ex)
				{
				}
			};

			mainTitleBar = new PurposeColorTitleBar(Color.FromRgb(8, 135, 224), "Purpose Color", Color.Black, "back", false);
			progressBar = DependencyService.Get<PurposeColor.interfaces.IProgressBar>();
			progressBar.ShowProgressbar ("Retriving user details..");

			try {
				currentUser = App.Settings.GetUser ();
			} catch (Exception ex) {
				
			}

			if (userId != 0) {
				userIdForProfileInfo = userId;
				// get user info from service.
			} 
			else 
			{
				if (currentUser == null) {
					return;
				}
				else
				{
					userInfo = currentUser;
				}
			}

			this.Appearing += ProfileSettingsPage_Appearing;
			progressBar.HideProgressbar ();
		}
        async void OnSignInButtonClicked(object sender, EventArgs e)
        {
            try
            {
				App.IsLoggedIn = false;
                if (String.IsNullOrEmpty(userNameEntry.Text))
                {
                    await DisplayAlert(Constants.ALERT_TITLE, "Please provide username.", Constants.ALERT_OK);
                    return;
                }

                #region FOR TESTING

                if (userNameEntry.Text == "apptester")
                {
                    App.IsTesting = true;
					UpdateBurgerMenuList();
					App.IsLoggedIn = true;
					bool userSaved = await App.Settings.SaveUser(new User { UserId = "2", UserName = "******", AllowCommunitySharing = true, Email= "*****@*****.**", StatusNote="Testing..", AllowFollowers = true }); // for testing only
                    if (!userSaved)
                    {
                        await DisplayAlert(Constants.ALERT_TITLE, "Could not save user to local database.", Constants.ALERT_OK);
                    }
                    App.masterPage.IsPresented = false;
					UpdateBurgerMenuList();
                    App.masterPage.Detail = new NavigationPage(new FeelingNowPage());
                    return;
                }
                else
                {
                    App.IsTesting = false;
                }

                #endregion

                System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(Constants.emailRegexString, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Match match = regex.Match(userNameEntry.Text);
                if (!match.Success)
                {
                    await DisplayAlert(Constants.ALERT_TITLE, "Username will be same as your valid email address.", Constants.ALERT_OK);
                    return;
                }

                if (String.IsNullOrEmpty(passwordEntry.Text))
                {
                    await DisplayAlert(Constants.ALERT_TITLE, "Please provide password.", Constants.ALERT_OK);
                    return;
                }

                #region SERVIDE
                if (!String.IsNullOrEmpty(userNameEntry.Text) && !String.IsNullOrEmpty(passwordEntry.Text))
                {

                    IProgressBar progress = DependencyService.Get<IProgressBar>();
                    progress.ShowProgressbar("Signing in..");

                    try
                    {
                        bool isSaveSuccess = false;
                        var serviceResult = await PurposeColor.Service.ServiceHelper.Login(userNameEntry.Text, passwordEntry.Text);
                        if (serviceResult.code != null && serviceResult.code == "200")
                        {
							UpdateBurgerMenuList();
                            var loggedInUser = serviceResult.resultarray;
                            if (loggedInUser != null)
                            {
                                User newUser = null;
                                if (!string.IsNullOrEmpty(loggedInUser.email))
                                {
                                    newUser = await App.Settings.GetUserWithUserName(loggedInUser.email);
                                }

                                if (newUser == null)
                                {
                                    newUser = new User();
                                }

                                newUser.StatusNote = string.IsNullOrEmpty(loggedInUser.note) ? string.Empty : loggedInUser.note;
                                newUser.DisplayName = string.IsNullOrEmpty(loggedInUser.firstname) ? string.Empty : loggedInUser.firstname;
                                newUser.Email = string.IsNullOrEmpty(loggedInUser.email) ? string.Empty : loggedInUser.email;
                                newUser.ProfileImageUrl = string.IsNullOrEmpty(loggedInUser.profileurl) ? string.Empty : loggedInUser.profileurl;
                                newUser.UserId = loggedInUser.user_id;
								newUser.VerifiedStatus = loggedInUser.verified_status;
								newUser.AllowCommunitySharing = string.IsNullOrEmpty(loggedInUser.community_status) ? false: (loggedInUser.community_status == "1" ? true : false);
								newUser.AllowFollowers = string.IsNullOrEmpty(loggedInUser.follow_status) ? false: (loggedInUser.follow_status == "1" ? true : false); 
                                if (loggedInUser.usertype_id != null)
                                {
                                    newUser.UserType = int.Parse(loggedInUser.usertype_id);
                                }
                                if (loggedInUser.regdate != null)
                                {
                                    //newUser.RegistrationDate = DateTime.ParseExact(serviceResult.regdate, "yyyy/MM/dd", System.Globalization.CultureInfo.InvariantCulture);
                                    newUser.RegistrationDate = loggedInUser.regdate;
                                }

								App.Current.Properties["IsLoggedIn"] = true; // Persist Data - Save data in Xamarin.Forms

                                isSaveSuccess = await App.Settings.SaveUser(newUser);

                                PurposeColor.Model.GlobalSettings globalSettings = App.Settings.GetAppGlobalSettings();
								if(globalSettings != null)
								{
									globalSettings.ShowRegistrationScreen = false;
									globalSettings.IsLoggedIn = true;
									globalSettings.IsFirstLogin = true;
									await App.Settings.SaveAppGlobalSettings(globalSettings);
								}

                                progress.HideProgressbar();
                                App.masterPage.IsPresented = false;
                                App.masterPage.Detail = new NavigationPage(new FeelingNowPage());

                                //if (Device.OS != TargetPlatform.WinPhone)
                                //{
                                //    Navigation.RemovePage(this);
                                //}
                            }
                            else
                            {
                                progress.HideProgressbar();
                                await DisplayAlert(Constants.ALERT_TITLE, "Network error. Could not retrive user details.", Constants.ALERT_OK);
                                App.masterPage.IsPresented = false;
                                App.masterPage.Detail = new NavigationPage(new FeelingNowPage());
                                //if (Device.OS != TargetPlatform.WinPhone)
                                //{
                                //    Navigation.RemovePage(this);
                                //}
                            }
                        }
                        else
                        {
                            progress.HideProgressbar();
                            await DisplayAlert(Constants.ALERT_TITLE, "Could not login. Username password does not match, Please try again.", Constants.ALERT_OK);
                            return;
                        }
                    }
                    catch (Exception ex)
                    {
                        progress.HideProgressbar();
                        DisplayAlert(Constants.ALERT_TITLE, "Network error, Please try again.", Constants.ALERT_OK);
                        Debug.WriteLine("OnSignInButtonClicked: " + ex.Message);
                    }
                    progress.HideProgressbar();
                }

                #endregion

            }
            catch (Exception)
            {
            }

        }
		public void Dispose()
		{
			this.statusEntry = null;
			userInfo = null;
			masterLayout = null;
			galleryInputStackTapRecognizer = null;
			galleryInputStack = null;
			galleryInput = null;
			profilePic = null;
			progressBar = null;
			userProfile = null;
			mainTitleBar = null;
			subTitleBar = null;
			CommunitySharingLabel= null;
			communityShareIcon = null;
			communityStatusBtn = null;
			User currentUser = null;

			GC.Collect();
		}
		async System.Threading.Tasks.Task<bool> GetProfileInfo()
		{

			try {
				userProfile = await ServiceHelper.GetProfileInfoByUserId (userIdForProfileInfo);
				if (userProfile != null) {
					userInfo = new User ();
					userInfo.UserName = userProfile.firstname;
					userInfo.StatusNote = userProfile.note;
					userInfo.VerifiedStatus = userProfile.verified_status;
					userInfo.Email = userProfile.email;
					userInfo.ProfileImageUrl = userProfile.profileurl;
				}
				return true;
			} catch (Exception ex) {

			}
			return false;
		}
        }// end - OnElementChanged()

		async void SerialiseFacebookUserData(string json)
		{
			FacebookInfo fbUser = JsonConvert.DeserializeObject<FacebookInfo>(json);
			User user = new User ();
			user.UserName = fbUser.name;
			user.DisplayName = fbUser.name;
			user.Email = fbUser.email;
			user.UserId = fbUser.id;

			await PurposeColor.App.SaveUserData( user, false);

			//App.SuccessfulLoginAction.Invoke(); // was working//

		}
		public async Task<bool> SaveUser(User user)
		{
			bool isUserAdded = false;

			try
			{
				if (Connection.Table<User>().FirstOrDefault(t => t.UserName == user.UserName) == null)
				{
					Connection.Insert(user);
				}
				else
				{
					Connection.Update(user);
				}

				isUserAdded = true;
			}
			catch (Exception ex)
			{
				Debug.WriteLine("SaveUser :: " + ex.Message);
				isUserAdded = false;
				return isUserAdded;
			}

			return isUserAdded;
		}
		//public GemsDetailsPage(List<EventMedia> mediaArray, List<ActionMedia> actionMediaArray, string pageTitleVal, string titleVal, string desc, string Media, string NoMedia, string gemId, GemType gemType)
		public CommunityGems(DetailsPageModel model)
		{
			NavigationPage.SetHasNavigationBar(this, false);
			masterLayout = new CustomLayout();
			masterLayout.BackgroundColor = Color.FromRgb(244, 244, 244);
			masterScroll = new ScrollView();
			masterScroll.IsClippedToBounds = true;
			masterScroll.BackgroundColor = Color.FromRgb(244, 244, 244);
			progressBar = DependencyService.Get<IProgressBar>();
			currentUser = App.Settings.GetUser ();

			modelObject = model;
			CurrentGemId = model.gemId;
			CurrentGemType = model.gemType;

			cancelToken = new CancellationTokenSource ();
			mainTitleBar = new PurposeColorTitleBar(Color.FromRgb(8, 135, 224), "Purpose Color", Color.Black, "back", false);
			mainTitleBar.imageAreaTapGestureRecognizer.Tapped += OnImageAreaTapGestureRecognizerTapped;
			subTitleBar = new CommunityGemSubTitleBar(Constants.SUB_TITLE_BG_COLOR, Constants.COMMUNITY_GEMS, true);
			subTitleBar.myGemsTapRecognizer.Tapped += async (object sender, EventArgs e) => 
			{
				IProgressBar progress = DependencyService.Get<IProgressBar>();
				progress.ShowProgressbar( "Loading Mygems.." );

				CommunityGemsObject myGems = await ServiceHelper.GetMyGemsDetails();
				if( myGems != null )
				{
					//communityGems = null;
					Navigation.PushAsync( new MyGemsPage( myGems ) );
					myGemsCount = myGems.resultarray.Count;
				}

				progress.HideProgressbar();

				/*	masterStack.Children.Clear();
				masterStackLayout.Children.Clear();
				masterScroll.Content = null;

				RenderGems( communityGems );*/


			};
			subTitleBar.BackButtonTapRecognizer.Tapped += async (object sender, EventArgs e) =>
			{
				try
				{
					App.masterPage.IsPresented = !App.masterPage.IsPresented;
				}
				catch (Exception)
				{
				}
			};


			this.Appearing += OnAppearing;




			Label pageTitle = new Label();
			pageTitle.Text = model.pageTitleVal;
			pageTitle.TextColor = Color.Black;
			pageTitle.FontFamily = Constants.HELVERTICA_NEUE_LT_STD;
			pageTitle.FontAttributes = FontAttributes.Bold;
			pageTitle.WidthRequest = App.screenWidth * 80 / 100;
			pageTitle.HeightRequest = 50;
			pageTitle.XAlign = TextAlignment.Start;
			pageTitle.YAlign = TextAlignment.Start;
			pageTitle.FontSize = Device.OnPlatform(15, 20, 15);

			BoxView emptyLayout = new BoxView();
			emptyLayout.BackgroundColor = Color.Transparent;
			emptyLayout.WidthRequest = App.screenWidth * 90 / 100;
			emptyLayout.HeightRequest = 30;

			masterStackLayout = new StackLayout();
			masterStackLayout.Orientation = StackOrientation.Vertical;

			TapGestureRecognizer chatTap = new TapGestureRecognizer ();
			Image chat = new Image ();
			chat.Source = "chat.png";
			chat.Aspect = Aspect.Fill;
			chat.WidthRequest = App.screenWidth * 16 / 100;
			chat.HeightRequest = App.screenWidth * 12 / 100;
			chat.GestureRecognizers.Add ( chatTap );
			chatTap.Tapped += async (object sender, EventArgs e) => 
			{
				await Navigation.PushAsync( new ChatPage() );
			};

			masterLayout.AddChildToLayout(mainTitleBar, 0, 0);
			masterLayout.AddChildToLayout(chat, 80, 1);
			masterLayout.AddChildToLayout(subTitleBar, 0, Device.OnPlatform(9, 10, 10));
			masterLayout.AddChildToLayout(masterScroll, -1, 18);

			masterScroll.Scrolled += OnMasterScrollScrolled;

			Content = masterLayout;
		}
		public ChatDetailsPage ( ObservableCollection<ChatDetails> chats,string tosusrID, string userImageUrl, string toUserName )
		{


			App.CurrentChatUserID = tosusrID;
			NavigationPage.SetHasNavigationBar(this, false);

			chatList = chats;
			touserID = tosusrID;
			currentuser = App.Settings.GetUser ();

		    timer = DependencyService.Get<IAdvancedTimer>();
			timer.initTimer (30000, SyncChatHistoryFromServer, true);
			timer.startTimer ();
			//Xamarin.Forms.Device.StartTimer ( TimeSpan.FromSeconds( 1 ), SyncChatHistoryFromServer );


			string chatTouser = toUserName;

			if (chatTouser.Length > 30)
			{
				chatTouser = chatTouser.Substring(0, 30);
				chatTouser += "...";
			}


			progressBar = DependencyService.Get< IProgressBar > ();
			mainTitleBar = new PurposeColorTitleBar(Color.FromRgb(8, 135, 224), chatTouser, Color.Black, userImageUrl, true);
			mainTitleBar.imageAreaTapGestureRecognizer.Tapped += (object sender, EventArgs e) => 
			{
				App.masterPage.IsPresented = true;
			};
			subTitleBar = new CommunityGemChatTitleBar(Constants.SUB_TITLE_BG_COLOR, chatTouser, userImageUrl, false);
			subTitleBar.BackButtonTapRecognizer.Tapped += async (object sender, EventArgs e) => 
			{
				timer.stopTimer ();
				App.CurrentChatUserID = null;
				await Navigation.PopAsync();
			};

			masterLayout = new CustomLayout ();
			masterLayout.WidthRequest = App.screenWidth;
			masterLayout.HeightRequest = App.screenHeight - 50;
			masterLayout.BackgroundColor = Color.FromRgb(45, 62, 80);

			chatHistoryListView = new ListView();
			chatHistoryListView.ItemTemplate = new DataTemplate(typeof(ChatHistoryListCell));
			chatHistoryListView.SeparatorVisibility = SeparatorVisibility.None;
			chatHistoryListView.HeightRequest = App.screenHeight * 70 / 100;
			chatHistoryListView.HasUnevenRows = true;
			chatHistoryListView.BackgroundColor =  Color.FromRgb(54, 79, 120);
			chatHistoryListView.ItemsSource = chatList;
			if( chatList != null && chatList.Count > 1 )
				chatHistoryListView.ScrollTo( chatList[ chatList.Count -1 ], ScrollToPosition.End, true );
			
			chatHistoryListView.ItemTapped += (object sender, ItemTappedEventArgs e) => 
			{
				chatHistoryListView.SelectedItem = null;
			};
			chatHistoryListView.ItemSelected += (object sender, SelectedItemChangedEventArgs e) => 
			{
				chatHistoryListView.SelectedItem = null;
			};


		

			ExtendedEntry chatEntry = new ExtendedEntry
			{
				Placeholder = "Enter your chat...",
				BackgroundColor = Color.White,//Color.White,
				WidthRequest = App.screenWidth * .80,
				HorizontalOptions = LayoutOptions.Start,
				TextColor = Color.Black
			};
			chatEntry.TextChanged += ChatEntry_TextChanged;

			Image postChatButton = new Image();
			postChatButton.Source = Device.OnPlatform("icon_send.png", "icon_send.png", "//Assets//icon_send.png");

			postChatButton.VerticalOptions = LayoutOptions.Center;
			postChatButton.HorizontalOptions = LayoutOptions.Center;
			TapGestureRecognizer postChatButtonTap = new TapGestureRecognizer();

			postChatButton.GestureRecognizers.Add(postChatButtonTap);

			StackLayout inputCountainer = new StackLayout
			{
				Spacing = Device.OnPlatform(5, 5, 1),
				Padding = Device.OnPlatform(5, 5, 5),
				Orientation = StackOrientation.Horizontal,
				BackgroundColor = Color.FromRgb( 45, 62, 80 ),
				Children = { chatEntry, postChatButton },
				WidthRequest = App.screenWidth
			};


			masterLayout.AddChildToLayout(mainTitleBar, 0, 0);
			masterLayout.AddChildToLayout(subTitleBar, 0, Device.OnPlatform(9, 10, 10));
			masterLayout.AddChildToLayout ( chatHistoryListView, 0, 17 );
			masterLayout.AddChildToLayout ( inputCountainer, 0, 85 );

			ScrollView masterScroll = new ScrollView ();
			masterScroll.Orientation = ScrollOrientation.Vertical;
			masterScroll.Content = masterLayout;
			masterScroll.IsClippedToBounds = true;

			postChatButtonTap.Tapped += async (object sender, EventArgs e) => 
			{
				ChatDetails detail = new ChatDetails();
				detail.AuthorName = "prvn";
				detail.Message = chatEntry.Text;
				detail.FromUserID = currentuser.UserId.ToString();
				detail.CurrentUserid = currentuser.UserId.ToString();
				chatList.Add( detail );
				chatEntry.Text = "";
				chatHistoryListView.ScrollTo( chatList[ chatList.Count -1 ], ScrollToPosition.End, true );

				if(!string.IsNullOrEmpty( detail.Message ))
					await ServiceHelper.SendChatMessage( currentuser.UserId.ToString(), touserID, detail.Message );
			};



			/*	this.Appearing += async (object sender, EventArgs e) => 
			{

				progressBar.ShowProgressbar( "Preparing chat window..." );
				masterScroll.IsVisible = true;

				chatUsersList = await ServiceHelper.GetAllChatUsers ();



				progressBar.HideProgressbar();

			};*/


			MessagingCenter.Subscribe<CrossPushNotificationListener, string>(this, "boom", (page, message) =>
				{
					string pushResult = message;
					string[] delimiters = { "&&" };
					string[] clasIDArray = pushResult.Split(delimiters, StringSplitOptions.None);
					string chatMessage = clasIDArray [0];
					string fromUser = clasIDArray [1];


					if( touserID == fromUser )
					{
						ChatDetails detail = new ChatDetails();
						detail.AuthorName = fromUser;
						detail.Message = chatMessage;
						detail.FromUserID = fromUser;
						detail.CurrentUserid = currentuser.UserId.ToString();
						chatList.Add( detail );

						if( chatList != null && chatList.Count > 1 )
						chatHistoryListView.ScrollTo( chatList[ chatList.Count -1 ], ScrollToPosition.End, true );
					}


				});


			Content = masterScroll;

		}
예제 #11
0
		public static void NavigateToChatDetailsPage(User userInfo, string tosusrID, string userImageUrl, string toUserName )
		{
			Device.BeginInvokeOnMainThread(  async () => 
				{
					ObservableCollection<ChatDetails> chats = new ObservableCollection<ChatDetails>();

					ChatDetails test = new ChatDetails();
					test.AuthorName = "prvn";
					test.CurrentUserid = App.Settings.GetUser().UserId;
					test.Message = "test chat";

					chats.Add( test );

					await Navigator.PushModalAsync( new ChatDetailsPage( chats,tosusrID, userImageUrl, toUserName) );


				});
		}
예제 #12
0
		public static async Task<bool> SaveUserData(User userInfo, bool isGoogleuser)
		{
			UserDetailsOnLogin userdetails = null;
			User currentUser = null;
			try 
			{
				
				if (isGoogleuser) {
					// call api  to save google user
					userdetails = await ServiceHelper.GoogleUserLogin(userInfo.Email, userInfo.UserName, userInfo.UserId,userInfo.ProfileImageUrl,userInfo.Gender);

					//get useer//

				} else {
					// call api for saving facebook user
					userdetails = await ServiceHelper.FacebookLogin(userInfo.Email, userInfo.UserName, userInfo.UserId);
				}

				if(userdetails!= null && userdetails.resultarray!= null && userdetails.code == "200")
				{
					currentUser = new User();
					var loggedInUser = userdetails.resultarray;
					currentUser.StatusNote = string.IsNullOrEmpty(loggedInUser.note) ? string.Empty : loggedInUser.note;
					currentUser.DisplayName = string.IsNullOrEmpty(loggedInUser.firstname) ? string.Empty : loggedInUser.firstname;
					currentUser.Email = string.IsNullOrEmpty(loggedInUser.email) ? string.Empty : loggedInUser.email;
					currentUser.ProfileImageUrl = string.IsNullOrEmpty(loggedInUser.profileurl) ? string.Empty : loggedInUser.profileurl;
					currentUser.UserId = loggedInUser.user_id;
					currentUser.VerifiedStatus = loggedInUser.verified_status;
					currentUser.UserName = string.IsNullOrEmpty(loggedInUser.firstname) ? string.Empty : loggedInUser.firstname;

					if (loggedInUser.usertype_id != null)
					{
						currentUser.UserType = int.Parse(loggedInUser.usertype_id);
					}
					if (loggedInUser.regdate != null)
					{
						currentUser.RegistrationDate = loggedInUser.regdate;
					}
				}

				if (currentUser != null) 
				{
					App.Settings.SaveUser (currentUser);
				}

				return true;
			} catch (Exception ex) 
			{
				var test = ex.Message;
			}
			return false;
		}
        public CommentsView(CustomLayout parentLayout, List<Comment> allComments, string gemId, GemType gemType, bool isCommunityGem, Label commentsLabel = null)
        {
            pageContainedLayout = parentLayout;
            commentLabel = commentsLabel != null ? commentsLabel : new Label();
            currentGemId = gemId;
            curentGemType = gemType;

            isCommunityShared = isCommunityGem;

            if (allComments != null)
            {
				if (allComments == null || allComments.Count < 1)
				{ // for popup height adjustment
					topSpacing = 95;
					bottomSpacing = 30;

				}
				else if (allComments.Count < 3)
                { // for popup height adjustment
                    topSpacing = 95;
                    bottomSpacing = 45;
                }
                else
                {
                    topSpacing = Device.OnPlatform(95, 100, 100);
                    bottomSpacing = Device.OnPlatform(90, 90, 90);
                }

                Comments = allComments;
            }
            else
            {
                bottomSpacing = Device.OnPlatform(20, 30, 30);        // for popup height adjustment
                topSpacing = 50;
            }

            try
            {

                currentUser = App.Settings.GetUser();
				currentUserId = currentUser.UserId;
            }
            catch (Exception ex)
            {
            }

            popupHeightValue = topSpacing - bottomSpacing;

            masterLayout = new CustomLayout();
            progressBar = DependencyService.Get<PurposeColor.interfaces.IProgressBar>();

            #region EMPTY AREA TAP GESTURERECOGNIZER

            StackLayout layout = new StackLayout();
            layout.BackgroundColor = Color.Black;
            layout.Opacity = .8;
            layout.WidthRequest = App.screenWidth;
			layout.HeightRequest = App.screenHeight + 20;

            masterLayout.AddChildToLayout(layout, 0, Device.OnPlatform(-10, 0, 0));

            TapGestureRecognizer emptyAreaTapGestureRecognizer = new TapGestureRecognizer();
            emptyAreaTapGestureRecognizer.Tapped += (s, e) =>
            {
                //HideCommentsPopup();
            };
            layout.GestureRecognizers.Add(emptyAreaTapGestureRecognizer);

            #endregion

            #region LIST TITLE

            StackLayout listHeader = new StackLayout();
            listHeader.WidthRequest = App.screenWidth * .96;
            listHeader.HeightRequest = App.screenHeight * Device.OnPlatform(.06, .06, .07);
            listHeader.BackgroundColor = Color.FromRgb(30, 126, 210);
            masterLayout.AddChildToLayout(listHeader, 2, (popupHeightValue - Device.OnPlatform(7, 7, 7)));

            listTitle = new Label();
            listTitle.Text = "Comments";
            listTitle.TextColor = Color.White;
            listTitle.FontFamily = Constants.HELVERTICA_NEUE_LT_STD;
            listTitle.FontSize = Device.OnPlatform(15, 15, 20);
            masterLayout.AddChildToLayout(listTitle, Device.OnPlatform(3, 3, 3), (popupHeightValue - Device.OnPlatform(6, 6, 5)));

            int fontSize = 15;
            if (App.screenDensity > 1.5)
            {
                fontSize = Device.OnPlatform(15, 17, 17);
            }
            else
            {
                fontSize = 15;
            }

            listTitle.FontSize = Device.OnPlatform(fontSize, fontSize, 20);


            closeButton = new Button
            {
                Text = Device.OnPlatform("    X", "  X", "  X"),
                BackgroundColor = Color.Transparent,
                FontFamily = Constants.HELVERTICA_NEUE_LT_STD,
                TextColor = Color.White,
                WidthRequest = App.screenWidth * Device.OnPlatform(.15, .15, .16),
                HeightRequest = App.screenHeight * Device.OnPlatform(.06, .07, .07),
                FontSize = Device.OnPlatform(17, 16, 21),
                BorderColor = Color.Transparent,
                BorderWidth = 0

            };

            closeButton.Clicked += (s, e) =>
            {
                HideCommentsPopup();
            };

            masterLayout.AddChildToLayout(closeButton, 83, (popupHeightValue - Device.OnPlatform(7, 8, 8))); //x and y percentage.. // hv to correct pixel by TranslationY.
            closeButton.TranslationY = Device.OnPlatform(2, 2, 2);
            #endregion

            listContainer = new StackLayout();
            listContainer.BackgroundColor = Color.White;
            listContainer.WidthRequest = App.screenWidth * .96;
            listContainer.Orientation = StackOrientation.Vertical;

            #region COMMENTS VIEW GENERATING


            if (Comments == null || Comments.Count < 1)
            {
                listContainer.Children.Add(new StackLayout
                {
						BackgroundColor  = Color.FromRgb(220, 220, 220),
                    Padding = 10,
                    HeightRequest = 30,
                    //BackgroundColor = Color.White,
                    //WidthRequest = 100,
                    ClassId = "NoCommentContainer",
                    Children = { new Label { Text = "No comments yet..",//Add your first comment..", 
								TextColor = Color.Black,
								BackgroundColor = Color.Transparent,
							FontSize = Device.OnPlatform(16, 16, 20),
							FontFamily = Constants.HELVERTICA_NEUE_LT_STD
						}
					}
							
                });
				listContainer.BackgroundColor  = Color.FromRgb(220, 220, 220);//Constants.PAGE_BG_COLOR_LIGHT_GRAY;

            }
            else
            {
                foreach (var comment in Comments)
                {
                    GenerateCommentView(comment);

                }// for each
            }
            #endregion

            #region INPUT
            //newCommentEntry = new PurposeColor.CustomControls.CustomEditor
			newCommentEntry = new ExtendedEntry
            {
                Placeholder = "Add new comment",
                HeightRequest = Device.OnPlatform(50, 50, 72),
				BackgroundColor = Color.White,
                WidthRequest = App.screenWidth * .80,
                HorizontalOptions = LayoutOptions.Start,
                Text = Device.OnPlatform(string.Empty, string.Empty, "Add new Comment.."),
				TextColor  = Color.Black
            };

			newCommentEntry.Focused += NewCommentEntry_Focused;
			newCommentEntry.Unfocused += NewCommentEntry_Unfocused;
			newCommentEntry.TextChanged += NewCommentEntry_TextChanged;
            addCommentButton = new Image();
            addCommentButton.Source = Device.OnPlatform("icon_send.png", "icon_send.png", "//Assets//icon_send.png");

            addCommentButton.VerticalOptions = LayoutOptions.Center;
            addCommentButton.HorizontalOptions = LayoutOptions.Center;
            addCommentButtonTap = new TapGestureRecognizer();
            addCommentButtonTap.Tapped += addCommentButtonTapped;
            addCommentButton.GestureRecognizers.Add(addCommentButtonTap);

            inputCountainer = new StackLayout
            {
                Spacing = Device.OnPlatform(5, 5, 1),
                Padding = Device.OnPlatform(5, 5, 5),
                Orientation = StackOrientation.Horizontal,
                BackgroundColor = Color.White,
                Children = { newCommentEntry, addCommentButton }
            };
            //listContainer.Children.Add(new BoxView{HeightRequest = 1, BackgroundColor = Color.Gray});


            #endregion

            #region OUTER CONTAINERS

            ScrollView scrollView = new ScrollView
            {
                Content = listContainer,
                //BackgroundColor = Color.White,
                HeightRequest = (App.screenHeight * bottomSpacing / 100) - Device.OnPlatform(90, 90, 250), // adjusts the bottom spacing. // set bottomspacing
                IsClippedToBounds = true
            };

            commentsAndInputs = new StackLayout
            {
                Spacing = 1,
                Children = { scrollView, new BoxView { HeightRequest = 1, BackgroundColor = Constants.INPUT_GRAY_LINE_COLOR }, inputCountainer },
                BackgroundColor = Color.White,
                WidthRequest = App.screenWidth * .96, // should be same width as popup title bar.
                Orientation = StackOrientation.Vertical
					
            };

			masterLayout.AddChildToLayout(commentsAndInputs, 2, popupHeightValue - Device.OnPlatform(1, 1, 1));

            #endregion

            if (Device.OS == TargetPlatform.WinPhone)
            {
                addCommentButton.WidthRequest = 60;
                addCommentButton.HeightRequest = 60;
            }

			Content = masterLayout;
        }
		public FeelingNowPage()
		{
			NavigationPage.SetHasNavigationBar(this, false);
			masterLayout = new CustomLayout();
			masterLayout.BackgroundColor = Color.FromRgb(244, 244, 244);
			screenHeight = App.screenHeight;
			screenWidth = App.screenWidth;
			progressBar = DependencyService.Get<IProgressBar>();
			currentUser = App.Settings.GetUser ();
			AddEventsSituationsOrThoughts.feelingsPage = this;

			mainTitleBar = new PurposeColorTitleBar(Color.FromRgb(8, 135, 224), "Purpose Color", Color.Black, "back", true);
			mainTitleBar.imageAreaTapGestureRecognizer.Tapped += imageAreaTapGestureRecognizer_Tapped;
			subTitleBar = new PurposeColorSubTitleBar(Constants.SUB_TITLE_BG_COLOR, "Emotional Awareness");
			subTitleBar.NextButtonTapRecognizer.Tapped += OnNextButtonTapRecognizerTapped;
			subTitleBar.BackButtonTapRecognizer.Tapped += OnBackButtonTapRecognizerTapped;

			slider = new CustomSlider
			{
				Minimum = -2,
				Maximum = 2,
				WidthRequest = screenWidth * 90 / 100
			};
			slider.StopGesture = GetstopGetsture;

			Label howYouAreFeeling = new Label();
			howYouAreFeeling.Text = Constants.HOW_YOU_ARE_FEELING;
			howYouAreFeeling.FontFamily = Constants.HELVERTICA_NEUE_LT_STD;
			howYouAreFeeling.TextColor = Color.FromRgb(40, 47, 50);
			howYouAreFeeling.HorizontalOptions = LayoutOptions.Center;

			Label howYouAreFeeling2 = new Label();
			howYouAreFeeling2.Text = "feeling now ?";
			howYouAreFeeling2.FontFamily = Constants.HELVERTICA_NEUE_LT_STD;
			howYouAreFeeling2.TextColor = Color.FromRgb(40, 47, 50);
			howYouAreFeeling2.HorizontalOptions = LayoutOptions.Center;

			#region  Emotion pic button
			emotionalPickerButton = new PurposeColor.interfaces.CustomImageButton ();
			emotionalPickerButton.ImageName = Device.OnPlatform ("select_box_whitebg.png", "select_box_whitebg.png", @"/Assets/select_box_whitebg.png");
			emotionalPickerButton.Text = "Select Emotion";

			emotionalPickerButton.FontFamily = Constants.HELVERTICA_NEUE_LT_STD;
			emotionalPickerButton.TextOrientation = interfaces.TextOrientation.Left;
			emotionalPickerButton.TextColor = Color.Gray;
			emotionalPickerButton.WidthRequest = screenWidth * 90 / 100;
			emotionalPickerButton.Clicked += OnEmotionalPickerButtonClicked;

			eventPickerButton = new PurposeColor.interfaces.CustomImageButton ();
			eventPickerButton.IsVisible = false;
			eventPickerButton.ImageName = Device.OnPlatform ("select_box_whitebg.png", "select_box_whitebg.png", "/Assets/select_box_whitebg.png");
			eventPickerButton.Text = "Events, Situation & Thoughts";
			eventPickerButton.FontFamily = Constants.HELVERTICA_NEUE_LT_STD;
			eventPickerButton.TextOrientation = interfaces.TextOrientation.Left;
			eventPickerButton.TextColor = Color.Gray;
			eventPickerButton.WidthRequest = screenWidth * 90 / 100;


			if (!eventsDisplaying)
			{
				eventPickerButton.Clicked += OnEventPickerButtonClicked;
			}
			#endregion

			#region About text
			about = new Label ();
			about.IsVisible = false;
			about.Text = "About";
			about.FontFamily = Constants.HELVERTICA_NEUE_LT_STD;
			about.WidthRequest = screenWidth;
			about.HorizontalOptions = LayoutOptions.Center;
			about.XAlign = TextAlignment.Center;

			about.FontFamily = Constants.HELVERTICA_NEUE_LT_STD;
			about.TextColor = Color.FromRgb (40, 47, 50);

			int fontSize = 15;
			if (App.screenDensity > 1.5) {
				howYouAreFeeling.FontSize = Device.OnPlatform (20, 22, 30);
				howYouAreFeeling2.FontSize = Device.OnPlatform (20, 22, 30);
				about.FontSize = Device.OnPlatform (15, 18, 30);

				emotionalPickerButton.HeightRequest = screenHeight * 6 / 100;
				fontSize = 17;
				eventPickerButton.HeightRequest = screenHeight * 6 / 100;
			} else {
				howYouAreFeeling.FontSize = Device.OnPlatform (16, 18, 26);
				howYouAreFeeling2.FontSize = Device.OnPlatform (16, 18, 26);
				about.FontSize = Device.OnPlatform (16, 18, 26);

				emotionalPickerButton.HeightRequest = screenHeight * 9 / 100;
				fontSize = 15;
				eventPickerButton.HeightRequest = screenHeight * 9 / 100;
			}

			emotionalPickerButton.FontSize = Device.OnPlatform (fontSize, fontSize, 22);
			eventPickerButton.FontSize = Device.OnPlatform (fontSize, fontSize, 22);
			#endregion

			this.Appearing += OnFeelingNowPageAppearing;

			sliderValue = slider.CurrentValue;
			masterLayout.AddChildToLayout(mainTitleBar, 0, 0);
			masterLayout.AddChildToLayout(subTitleBar, 0, Device.OnPlatform(9, 10, 10));

			sliderValLabel = new Label
			{
				TextColor = Constants.BLUE_BG_COLOR,
				BackgroundColor = Color.Transparent,
				XAlign = TextAlignment.Start
			};

			sliderValueImage = new Image {
				Source = "Sliderfeedback0.png",
				HeightRequest = 30,
				Aspect = Aspect.Fill, 
				InputTransparent = true,
				BackgroundColor = Color.Transparent,

			};

			#region SLIDER LABEL TAP

			TapGestureRecognizer sliderLabelTapRecognizer = new TapGestureRecognizer();
			sliderLabelTapRecognizer.Tapped += (s, e) =>
			{
				/// show a slider as a popup and get its value,
				RemoveSliderPopup();
				popupSlider = new CustomSlider
				{
					Minimum = -2,
					Maximum = 2,
					WidthRequest = screenWidth * 90 / 100,
					HorizontalOptions = LayoutOptions.Center,
					VerticalOptions = LayoutOptions.Center,
					CurrentValue = sliderValue
				};

				StackLayout sliderBg = new StackLayout
				{
					BackgroundColor = Color.Black,
					Opacity = .95,
					HeightRequest = App.screenHeight,
					WidthRequest = App.screenWidth,
					HorizontalOptions = LayoutOptions.Center,
					VerticalOptions = LayoutOptions.Center,
					Children = {
						new StackLayout{HeightRequest = 250},
						new StackLayout{
							Children = { popupSlider },
							Padding = 10,
							BackgroundColor = Color.FromRgb(244, 244, 244),
							HorizontalOptions = LayoutOptions.Center,
							VerticalOptions = LayoutOptions.Center,
							Opacity = 1
						}
					},
					ClassId = "sliderBg"
				};

				TapGestureRecognizer sliderBgTapRecognizer = new TapGestureRecognizer();
				sliderBg.GestureRecognizers.Add(sliderBgTapRecognizer);
				sliderBgTapRecognizer.Tapped += (snd, eve) =>
				{
					RemoveSliderPopup();
				};

				popupSlider.CurrentValue = slider.CurrentValue;
				popupSlider.StopGesture = GetstopGetsture;

				masterLayout.AddChildToLayout(sliderBg, 0, 0);
			};

			#endregion

			emotionTextLabel = new Label
			{
				TextColor = Constants.BLUE_BG_COLOR,
				BackgroundColor = Color.Transparent,
				XAlign = TextAlignment.Start,
				FontFamily = Constants.HELVERTICA_NEUE_LT_STD,
				FontSize = Device.OnPlatform(12, 14, 26)
			};
			emotionTextTap = new TapGestureRecognizer();
			emotionTextTap.Tapped += EmotionTextTap_Tapped;

			eventTextLabel = new Label
			{
				TextColor = Constants.BLUE_BG_COLOR,
				BackgroundColor = Color.Transparent,
				XAlign = TextAlignment.Start,
				FontFamily = Constants.HELVERTICA_NEUE_LT_STD,
				FontSize = Device.OnPlatform(12, 14, 26)
			};

			eventTextTap = new TapGestureRecognizer();
			eventTextTap.Tapped += async (s, e) =>
			{
				if (!eventsDisplaying)
				{
					await Task.Delay(100);
					OnEventPickerButtonClicked(eventPickerButton, EventArgs.Empty);
				}
			};
			//eventTextLabel.GestureRecognizers.Add(eventTextTap);

			sliderFeedbackStack = new StackLayout {
				IsVisible = false,
				BackgroundColor = Color.Transparent,
				VerticalOptions = LayoutOptions.Center,
				Orientation = StackOrientation.Horizontal, 
				Spacing = 0, Padding = new Thickness (App.screenWidth * .10, 0, 10, 0), 
				Children = {
					new Label {
						FontFamily = Constants.HELVERTICA_NEUE_LT_STD,
						FontSize = Device.OnPlatform(12, 14, 26),
						Text = "Happiness : ",
						TextColor = Color.Black,
						VerticalOptions = LayoutOptions.End,
					},
					sliderValueImage
				}
			};
			sliderFeedbackStack.GestureRecognizers.Add(sliderLabelTapRecognizer);


			feelingFeedbackStack = new StackLayout {
				IsVisible = false,
				Orientation = StackOrientation.Horizontal,
				Spacing = 0,
				Padding = new Thickness (App.screenWidth * .10, 0, 10, 0),
				Children = {
					new Label {
						Text = "Feeling : " ,
						TextColor = Color.Black,
						FontFamily = Constants.HELVERTICA_NEUE_LT_STD,
						FontSize = Device.OnPlatform(12, 14, 26),
					},
					emotionTextLabel
				}
			};
			feelingFeedbackStack.GestureRecognizers.Add(emotionTextTap);

			eventFeedbackStack = new StackLayout {
				IsVisible = false,
				//BackgroundColor = Color.Red,
				Orientation = StackOrientation.Horizontal,
				Spacing = 0,
				Padding = new Thickness (App.screenWidth * .10, 0, 10, 0),
				Children = {
					new Label {
						Text = "Event : " ,
						TextColor = Color.Black,
						FontFamily = Constants.HELVERTICA_NEUE_LT_STD,
						FontSize = Device.OnPlatform(12, 14, 26),
					},
					eventTextLabel
				}
			};
			eventFeedbackStack.GestureRecognizers.Add(eventTextTap);

			// add this to a customLayout n a stack with bg transparent.
			topLabelsContainer = new CustomLayout {
				WidthRequest = screenWidth,
			};

			topLabelBg = new StackLayout {
				WidthRequest = screenWidth,
				BackgroundColor = Color.Gray,
				Opacity = .2
			};

			topBgandCloseBtn = new StackLayout {
				//BackgroundColor  = Color.Yellow, // for testing only
				Orientation = StackOrientation.Vertical,
				Spacing = 0,
				Children = {topLabelBg}
			};

			topCloseBtn = new Image {
				Source = "downarrow.png",
				IsVisible = false,
				HeightRequest = 25,
				WidthRequest = 35,
				HorizontalOptions = LayoutOptions.End
			};
			topBgandCloseBtn.Children.Add (topCloseBtn);

			TapGestureRecognizer topCloseBtnTapRecognizer = new TapGestureRecognizer();
			topCloseBtnTapRecognizer.Tapped += (s, e) =>
			{
				AnimateToplabels(0);
			};

			topCloseBtn.GestureRecognizers.Add (topCloseBtnTapRecognizer);

			feedbackLabelStack = new StackLayout
			{
				Orientation = StackOrientation.Vertical,
				//BackgroundColor = Constants.PAGE_BG_COLOR_LIGHT_GRAY,
				HorizontalOptions = LayoutOptions.Center,
				VerticalOptions = LayoutOptions.Center,
				Spacing = 2,
				WidthRequest = App.screenWidth,
				Children = {sliderFeedbackStack, feelingFeedbackStack, eventFeedbackStack}
			};
			topLabelsContainer.AddChildToLayout (topBgandCloseBtn, 0, 0);
			topLabelsContainer.AddChildToLayout (feedbackLabelStack, 0, 0);


			//masterLayout.AddChildToLayout(feedbackLabelStack, 0, Device.OnPlatform(16, 18, 10));
			masterLayout.AddChildToLayout(topLabelsContainer, 0, Device.OnPlatform(16, 18, 10));

			masterLayout.AddChildToLayout(howYouAreFeeling, 16, Device.OnPlatform(33, 33, 30));
			masterLayout.AddChildToLayout(howYouAreFeeling2, 29, Device.OnPlatform(38, 38, 27));
			masterLayout.AddChildToLayout(slider, 5, 43);

			masterLayout.AddChildToLayout(emotionalPickerButton, 5, Device.OnPlatform(50, 57, 47));
			masterLayout.AddChildToLayout(about, 0, Device.OnPlatform(62, 66, 59));
			masterLayout.AddChildToLayout(eventPickerButton, 5, Device.OnPlatform(70, 73, 67));




			//SetFeedBackLablText();
			Content = masterLayout;

		}