public static async Task<List<CustomListViewItem>> GetEmotions(int sliderValue)
        {

            if (!CrossConnectivity.Current.IsConnected)
            {
                return null;
            }


            var client = new System.Net.Http.HttpClient();

            client.BaseAddress = new Uri(Constants.SERVICE_BASE_URL);

            string uriString = "api.php?action=emotions&user_id=2&emotion_value=" + sliderValue.ToString();

            var response = await client.GetAsync(uriString);

            if (response != null && response.StatusCode == HttpStatusCode.OK)
            {
                var earthquakesJson = response.Content.ReadAsStringAsync().Result;

                var rootobject = JsonConvert.DeserializeObject<Emotions>(earthquakesJson);

                List<CustomListViewItem> emotionsList = new List<CustomListViewItem>();

                if (rootobject != null && rootobject.emotion_title != null)
                {
                    foreach (var item in rootobject.emotion_title)
                    {
                        CustomListViewItem listItem = new CustomListViewItem();
                        listItem.Name = item;
                        listItem.SliderValue = sliderValue;
                        emotionsList.Add(listItem);
                    }
                    client.Dispose();
                }
                return emotionsList;
            }

            List<CustomListViewItem> noEmotionsList = new List<CustomListViewItem>();
            noEmotionsList.Add(new CustomListViewItem { Name = "No emotions Found" });
            return null;

        }
		public static async Task<List<CustomListViewItem>> GetAllEmotions(string userID)
        {
            try
            {
				
                if (!CrossConnectivity.Current.IsConnected)
                {
                    return null;
                }


                var client = new System.Net.Http.HttpClient();

                client.BaseAddress = new Uri(Constants.SERVICE_BASE_URL);

				string uriString = "api.php?action=getallemotions&user_id=" + userID;

                var response = await client.GetAsync(uriString);

                if (response != null && response.StatusCode == HttpStatusCode.OK)
                {
                    var allEmotionsJson = response.Content.ReadAsStringAsync().Result;

                    var rootobject = JsonConvert.DeserializeObject<EmotionsCollections>(allEmotionsJson);

                    List<CustomListViewItem> emotionsList = new List<CustomListViewItem>();

                    if (rootobject != null && rootobject.resultarray != null)
                    {
                        foreach (var item in rootobject.resultarray)
                        {
                            CustomListViewItem listItem = new CustomListViewItem();
                            listItem.Name = item.emotion_title;
                            listItem.EmotionID = item.emotion_id;
                            listItem.SliderValue = Convert.ToInt32(item.emotion_value);
                            emotionsList.Add(listItem);
                        }
                        client.Dispose();
                    }
                    return emotionsList;
                }

                List<CustomListViewItem> noEmotionsList = new List<CustomListViewItem>();
                noEmotionsList.Add(new CustomListViewItem { Name = "No emotions Found" });
                return null;
            }
            catch (Exception ex)
            {
                return null;
            }


        }
        public static async Task<List<CustomListViewItem>> GetAllSpportingActions()
        {
            List<CustomListViewItem> actionsList = null;
            try
            {
				User user =  App.Settings.GetUser();

                if (user == null)
                {
                    // show alert
                    return null;
                }

                if (!CrossConnectivity.Current.IsConnected)
                {
                    return null;
                }
                var client = new System.Net.Http.HttpClient();

                client.BaseAddress = new Uri(Constants.SERVICE_BASE_URL);

                string uriString = "api.php?action=getallactions&user_id=" + user.UserId.ToString();

                var response = await client.GetAsync(uriString);

                var actionsJson = response.Content.ReadAsStringAsync().Result;

                actionsList = new List<CustomListViewItem>();

                var rootobject = JsonConvert.DeserializeObject<AllSupportingActions>(actionsJson);
                if (rootobject != null && rootobject.resultarray != null)
                {
                    foreach (var item in rootobject.resultarray)
                    {
                        CustomListViewItem listItem = new CustomListViewItem();
                        listItem.Name = item.action_title;
                        listItem.EventID = item.goalaction_id;
                        actionsList.Add(listItem);
                    }
                    client.Dispose();
                }
                return actionsList;
            }
            catch (Exception ex)
            {
                var test = ex.Message;
                return actionsList;
            }
        }
        public static async Task<List<CustomListViewItem>> GetAllEvents()
        {
            try
            {

                if (!CrossConnectivity.Current.IsConnected)
                {
                    return null;
                }

                var client = new System.Net.Http.HttpClient();
                User user = App.Settings.GetUser();

                if (user == null)
                {
                    // show alert
                    return null;
                }
                else
                {
                    client.BaseAddress = new Uri(Constants.SERVICE_BASE_URL);
                    string uriString = "api.php?action=getallevents&user_id=" + user.UserId;
                    var response = await client.GetAsync(uriString);
                    if (response != null && response.StatusCode == HttpStatusCode.OK)
                    {
                        var eventsJson = response.Content.ReadAsStringAsync().Result;

                        var rootobject = JsonConvert.DeserializeObject<AllEvents>(eventsJson);

                        List<CustomListViewItem> eventsList = new List<CustomListViewItem>();

                        if (rootobject != null && rootobject.resultarray != null)
                        {
                            foreach (var item in rootobject.resultarray)
                            {
                                CustomListViewItem listItem = new CustomListViewItem();
                                listItem.Name = item.event_title;
                                listItem.EventID = item.event_id;
                                eventsList.Add(listItem);
                            }
                            client.Dispose();
                        }
                        return eventsList;
                    }
                }// else ie, user != null

            }
            catch (Exception ex)
            {
                var test = ex.Message;
            }
            return null;
        }
        public static async Task<bool> GetNearByLocations( double lattitude, double longitude )
        {
            try
            {
              if (!CrossConnectivity.Current.IsConnected)
                {
                    return false;
                }

                var client = new System.Net.Http.HttpClient();
                User user = App.Settings.GetUser();

                if (user == null)
                {
                    // show alert
                    return false;
                }
                else
                {
                    client.BaseAddress = new Uri("https://maps.googleapis.com/maps/api/place/nearbysearch/");
                    string lat = lattitude.ToString();
                    string lon = longitude.ToString();
                    string uriString = "json?location=" + lat + "," + lon + "&radius=500&key=AIzaSyAuqCJwc2K4wQeUvTcywvoR9WcsRI5AIn4";
                    var response = await client.GetAsync(uriString);
                    if (response != null && response.StatusCode == HttpStatusCode.OK)
                    {
                        var eventsJson = response.Content.ReadAsStringAsync().Result;

                        var rootobject = JsonConvert.DeserializeObject<LocationMasterObject>(eventsJson);

                        if( rootobject != null  && rootobject.results != null )
                        {
                            foreach (var item in rootobject.results)
                            {
                                CustomListViewItem listItem = new CustomListViewItem();
                                listItem.Name = item.name;
                                App.nearByLocationsSource.Add( listItem );
                            }
                            client.Dispose();
                        }

                       return true;
                    }
                    return true;
                }

            }
            catch (Exception ex)
            {
                var test = ex.Message;
            }
            return true;
        }
        public static async Task<bool> GetCurrentAddressToList( double lattitude, double longitude )
        {
            try
            {
              if (!CrossConnectivity.Current.IsConnected)
                {
                    return false;
                }

                var client = new System.Net.Http.HttpClient();
                User user = App.Settings.GetUser();

                if (user == null)
                {
                    // show alert
                    return false;
                }
                else
                {
                    client.BaseAddress = new Uri("http://maps.googleapis.com/maps/api/geocode/");
                    string lat = lattitude.ToString();
                    string lon = longitude.ToString();
                    string uriString = "json?latlng=" + lat + "," + lon + "&sensor=true";
                    var response = await client.GetAsync(uriString);
                    if (response != null && response.StatusCode == HttpStatusCode.OK)
                    {
                        var eventsJson = response.Content.ReadAsStringAsync().Result;

                        var rootobject = JsonConvert.DeserializeObject<AddressBase>(eventsJson);

                        if( rootobject != null  && rootobject.results != null )
                        {
                            foreach (var item in rootobject.results )
                            {
                                CustomListViewItem listItem = new CustomListViewItem();
                                listItem.Name = item.formatted_address;
                                App.nearByLocationsSource.Add(listItem);
                            }
                            client.Dispose();
                        }

                       return true;
                    }
                    return true;
                }

            }
            catch (Exception ex)
            {
                var test = ex.Message;
            }
            return true;
        }
        public async void OnGoalsPickerItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            try
            {

                CustomListViewItem item = e.SelectedItem as CustomListViewItem;
                goalsAndDreamsPickerButton.Text = item.Name;
                goalsAndDreamsPickerButton.TextColor = Color.Black;
                View pickView = masterLayout.Children.FirstOrDefault(pick => pick.ClassId == "ePicker");
				if( pickView != null )
                masterLayout.Children.Remove(pickView);
                pickView = null;
                actionPickerButton.IsVisible = true;
                selectedGoal = item;
                if (selectedActions != null)
                {
                    selectedActions.Clear();
                }
                if (actionPreviewListSource != null)
                {
                    actionPreviewListSource.Clear();
                }
				actionlist = App.actionsListSource;

				foreach (var action in actionlist) {
					action.Source = Device.OnPlatform("tick_box.png", "tick_box.png", "//Assets//tick_box.png");
				}

				if(aePicker != null)
				{
					aePicker.listView.ItemsSource = null;
					aePicker.listView.ItemsSource = actionlist;
				}
				//await Task.Delay(100);

                OnActionPickerButtonClicked(actionPickerButton, EventArgs.Empty);

            }
            catch (System.Exception ex)
            {
                var test = ex.Message;
            }
        }
        public void Dispose()
        {
            this.mainTitleBar.imageAreaTapGestureRecognizer.Tapped -= imageAreaTapGestureRecognizer_Tapped;
            this.mainTitleBar = null;
            this.subTitleBar.BackButtonTapRecognizer.Tapped -= OnBackButtonTapRecognizerTapped;
            this.subTitleBar.NextButtonTapRecognizer.Tapped -= NextButtonTapRecognizer_Tapped;
            this.Appearing -= FeelingNowPage_Appearing;
            this.goalsAndDreamsPickerButton.Clicked -= OnGoalsPickerButtonClicked;
            this.goalsAndDreamsPickerButton = null;
            this.actionPickerButton.Clicked -= OnActionPickerButtonClicked;
            this.actionPickerButton = null;
            this.subTitleBar = null;
            this.masterLayout = null;
            // this.deviceSpec = null;
            actionPreviewListSource.Clear();
            actionPreviewListSource = null;
            this.actionPreviewListView = null;
            this.listContainer = null;
            this.slider = null;
            this.selectedGoal = null;
            this.selectedActions = null;

            GC.Collect();
        }
        async void NextButtonTapRecognizer_Tapped(object sender, System.EventArgs e)
        {
			User user = null;
			try {
				user = App.Settings.GetUser();
			} catch (Exception ex) {

			}
            IProgressBar progress = DependencyService.Get<IProgressBar>();
            try
            {
                if (string.IsNullOrWhiteSpace(eventDescription.Text) || string.IsNullOrWhiteSpace(eventTitle.Text))
                {
                    await DisplayAlert(Constants.ALERT_TITLE, "Value cannot be empty", Constants.ALERT_OK);
                }
                else
                {
                    string input = pageTitle;
                    CustomListViewItem item = new CustomListViewItem { Name = eventDescription.Text };
                    bool serviceResultOK = false;
                    if (input == Constants.ADD_ACTIONS || input == Constants.EDIT_ACTIONS)
                    {
                        #region ADD || EDIT ACTIONS

                        try
                        {
							GoalDetails newGoal = new GoalDetails();



                            ActionModel details = new ActionModel();
                            if (!isUpdatePage)
                            {
                                progress.ShowProgressbar("Creating new action..");
                            }
                            else
                            {
                                progress.ShowProgressbar("Updating the action..");
                                details.action_id = currentGemId;
                            }
                            details.action_title = eventTitle.Text;
                            details.action_details = eventDescription.Text;
							details.user_id = user.UserId;
                            details.location_latitude = lattitude;
                            details.location_longitude = longitude;
							if(!string.IsNullOrEmpty(currentAddress))
							{
								details.location_address = currentAddress;
							}
                            //details.start_date = DateTime.Now.ToString("yyyy/MM/dd"); // for testing only
                            //details.end_date = DateTime.Now.AddDays(1).ToString("yyyy/MM/dd"); // for testing only
                            //details.start_time = DateTime.Now.AddHours(1).ToString("HH:mm"); //for testing only
                            //details.end_time = DateTime.Now.AddHours(2).ToString("HH:mm"); //for testing only

                            if (!string.IsNullOrEmpty(App.SelectedActionStartDate))
                            {
								DateTime myDate = DateTime.Now;//DateTime.ParseExact("2009-05-08 14:40:52,531", "yyyy-MM-dd HH:mm:ss,fff", System.Globalization.CultureInfo.InvariantCulture);
                                myDate = DateTime.Parse(App.SelectedActionStartDate);
                                details.start_date = App.SelectedActionStartDate;
                                details.end_date = App.SelectedActionEndDate;
                                details.start_time = myDate.ToString("HH:mm");
                                myDate = DateTime.Parse(App.SelectedActionEndDate);
                                details.end_time = myDate.ToString("HH:mm");
                                details.action_repeat = "0";
                                details.action_alert = App.SelectedActionReminderValue.ToString();
                            }
                            

                            if (!string.IsNullOrEmpty(currentAddress))
                            {
                                details.location_address = currentAddress;
                            }

                            if (!await ServiceHelper.AddAction(details))
                            {
                                await DisplayAlert(Constants.ALERT_TITLE, Constants.NETWORK_ERROR_MSG, Constants.ALERT_OK);
                            }
                            else
                            {
                                try
                                {
                                    var suportingActions = await ServiceHelper.GetAllSpportingActions(); //for testing only
                                    if (suportingActions != null)
                                    {
                                        App.actionsListSource = null;
                                        App.actionsListSource = new List<CustomListViewItem>();
                                        foreach (var action in suportingActions)
                                        {
                                            App.actionsListSource.Add(action);
                                        }
                                    }


									CustomListViewItem newEmotionItem = new CustomListViewItem();
									newEmotionItem.EventID = App.actionsListSource.First().EventID;
									newEmotionItem.Name = App.actionsListSource.First().Name;
									newEmotionItem.SliderValue = App.actionsListSource.First().SliderValue;
									newEmotionItem.Source = Device.OnPlatform("tick_box.png", "tick_box.png", "//Assets//tick_box.png");
									SelectedItemChangedEventArgs newEmotionEvent = new SelectedItemChangedEventArgs( newEmotionItem );
									feelingSecondPage.OnActionPickerItemSelected( this, newEmotionEvent );

                                    serviceResultOK = true;
                                }
                                catch (System.Exception)
                                {
                                    DisplayAlert(Constants.ALERT_TITLE, "Error in retrieving goals list, Please try again", Constants.ALERT_OK);
                                }
                            }

//                            ILocalNotification notfiy = DependencyService.Get<ILocalNotification>();
//                            if (!isUpdatePage)
//                            {
//								notfiy.ShowNotification("Purpose Color - Action Created", "", eventTitle.Text, false);
//                            }
//                            else
//                            {
//								notfiy.ShowNotification("Purpose Color - Action Updated","", eventTitle.Text, false);
//                            }
                        }
                        catch (Exception ex)
                        {
                            var test = ex.Message;
                        }

                        progress.HideProgressbar();

                        
                        #endregion
                    }
                    else if (input == Constants.ADD_EVENTS || input == Constants.EDIT_EVENTS)
                    {
                        #region ADD || EDIT EVENTS

                        try
                        {
                            EventDetails details = new EventDetails();
                            details.event_title = eventTitle.Text;
                            details.event_details = eventDescription.Text;
							details.user_id = user.UserId;
                            details.location_latitude = lattitude;
                            details.location_longitude = longitude;
							if (!string.IsNullOrEmpty(currentAddress))
							{
								details.location_address = currentAddress;
							}
                            
                            if (!isUpdatePage)
                            {
                                progress.ShowProgressbar("Creating new event..");
                            }
                            else
                            {
                                progress.ShowProgressbar("Updating the event..");
                                details.event_id = currentGemId;
                            }

                            if (!await ServiceHelper.AddEvent(details))
                            {
                                await DisplayAlert(Constants.ALERT_TITLE, Constants.NETWORK_ERROR_MSG, Constants.ALERT_OK);
                            }
                            else
                            {
                                await FeelingNowPage.DownloadAllEvents();
                                serviceResultOK = true;


								CustomListViewItem newEmotionItem = new CustomListViewItem();
								newEmotionItem.EventID = App.eventsListSource.First().EventID;
								newEmotionItem.Name = App.eventsListSource.First().Name;
								newEmotionItem.SliderValue = App.eventsListSource.First().SliderValue;

								SelectedItemChangedEventArgs newEmotionEvent = new SelectedItemChangedEventArgs( newEmotionItem );
								feelingsPage.OnEventPickerItemSelected( this, newEmotionEvent );

//								if(!isUpdatePage)
//								{
//									await Navigation.PopModalAsync();
//								}
//								else {
//									await Navigation.PopModalAsync();
//								}
                            }
                        }
                        catch (Exception ex)
                        {
                            var test = ex.Message;
                        }
                        progress.HideProgressbar();
                        
                        #endregion
                    }
                    else if (input == Constants.ADD_GOALS || input == Constants.EDIT_GOALS)
                    {
                        #region ADD || EDIT GOALS
		
                        try
                        {
                            GoalDetails newGoal = new GoalDetails();

                            //EventDetails newGoal = new EventDetails();
                            newGoal.goal_title = eventTitle.Text;
                            newGoal.goal_details = eventDescription.Text;
							newGoal.user_id = user.UserId;
                            newGoal.location_latitude = lattitude;
                            newGoal.location_longitude = longitude;
                            newGoal.category_id = "1";

                            if (!string.IsNullOrEmpty(App.SelectedActionStartDate))
                            {
                                newGoal.start_date = App.SelectedActionStartDate; //DateTime.Now.ToString("yyyy/MM/dd"); // for testing only
                                newGoal.end_date = App.SelectedActionEndDate; //DateTime.Now.AddDays(1).ToString("yyyy/MM/dd"); // for testing onl
                            }
                            
                            if (!string.IsNullOrEmpty(currentAddress))
                            {
                                newGoal.location_address = currentAddress;
                            }

                            if (!isUpdatePage)
                            {
                                progress.ShowProgressbar("Creating new goal..");
                            }
                            else
                            {
                                progress.ShowProgressbar("Updating the goal..");
                                newGoal.goal_id = currentGemId;
                            }

                            if (!await ServiceHelper.AddGoal(newGoal))
                            {
                                await DisplayAlert(Constants.ALERT_TITLE, Constants.NETWORK_ERROR_MSG, Constants.ALERT_OK);
                            }
                            else
                            {
                                try
                                {
									var goals = await ServiceHelper.GetAllGoals( user.UserId );
                                    if (goals != null)
                                    {
                                        App.goalsListSource = null;
                                        App.goalsListSource = new List<CustomListViewItem>();
                                        foreach (var goal in goals)
                                        {
                                            App.goalsListSource.Add(goal);
                                        }
                                    }


									CustomListViewItem newEmotionItem = new CustomListViewItem();
									newEmotionItem.EventID = App.goalsListSource.First().EventID;
									newEmotionItem.Name = App.goalsListSource.First().Name;
									newEmotionItem.SliderValue = App.goalsListSource.First().SliderValue;

									SelectedItemChangedEventArgs newGoalsEvent = new SelectedItemChangedEventArgs( newEmotionItem );
									feelingSecondPage.OnGoalsPickerItemSelected( this, newGoalsEvent );

                                    serviceResultOK = true;
                                }
                                catch (System.Exception)
                                {
                                    DisplayAlert(Constants.ALERT_TITLE, "Error in retrieving goals list, Please try again", Constants.ALERT_OK);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            DisplayAlert(Constants.ALERT_TITLE, ex.Message, Constants.ALERT_OK);
                        }
                        progress.HideProgressbar();
 
	                    #endregion
                    }

                    if (serviceResultOK)
                    {
                        if (!isUpdatePage)
                        {
							await Navigation.PopAsync();
                        }
                        else
                        {
							if(Device.OS != TargetPlatform.iOS)
							{
								await Navigation.PopToRootAsync();
							}
							else
							{
								await Navigation.PopToRootAsync();
							}
							#region MyRegionNavigate back to GEM details page
							//progress.ShowProgressbar("Loading");
//
//							if (App.isEmotionsListing) {
//								try {
//									SelectedEventDetails eventDetails = await ServiceHelper.GetSelectedEventDetails(currentGemId);
//									if (eventDetails != null)
//									{
//										List<string> listToDownload = new List<string>();
//
//										foreach (var eventi in eventDetails.event_media) 
//										{
//											if(string.IsNullOrEmpty(eventi.event_media))
//											{
//												continue;
//											}
//
//											if (eventi.media_type == "png" || eventi.media_type == "jpg" || eventi.media_type == "jpeg") 
//											{
//
//												listToDownload.Add(Constants.SERVICE_BASE_URL+eventi.event_media);
//												string fileName = System.IO.Path.GetFileName(eventi.event_media);
//												eventi.event_media = App.DownloadsPath + fileName;
//											}
//											else
//											{
//												eventi.event_media = Constants.SERVICE_BASE_URL + eventi.event_media ;
//											}
//										}
//
//										if (listToDownload != null && listToDownload.Count > 0) {
//											IDownload downloader = DependencyService.Get<IDownload>();
//											//progressBar.ShowProgressbar("loading details..");
//											await downloader.DownloadFiles(listToDownload);
//
//										}
//
//										DetailsPageModel model = new DetailsPageModel();
//										model.actionMediaArray = null;
//										model.eventMediaArray = eventDetails.event_media;
//										model.goal_media = null;
//										model.Media = null;
//										model.NoMedia = null;
//										model.pageTitleVal = "Event Details";
//										model.titleVal = eventDetails.event_title;
//										model.description = eventDetails.event_details;
//										model.gemType = GemType.Event;
//										model.gemId = currentGemId;
//										progress.HideProgressbar();
//
//										await Navigation.PushAsync(new GemsDetailsPage(model));
//										eventDetails = null;
//									}
//								} catch (Exception ) {
//									progress.HideProgressbar();
//									Navigation.PopAsync();
//								}
//							}
//							else
//							{
//								//-- call service for Action details
//								try {
//
//									SelectedActionDetails actionDetails = await ServiceHelper.GetSelectedActionDetails(currentGemId);
//
//									List<string> listToDownload = new List<string>();
//
//									foreach (var action in actionDetails.action_media) 
//									{
//										if( string.IsNullOrEmpty(action.action_media))
//										{
//											continue;
//										}
//
//										if (action.media_type == "png" || action.media_type == "jpg" || action.media_type == "jpeg")
//										{
//
//											listToDownload.Add(Constants.SERVICE_BASE_URL+action.action_media);
//											string fileName = System.IO.Path.GetFileName(action.action_media);
//											action.action_media = App.DownloadsPath + fileName;
//										}
//										else
//										{
//											action.action_media = Constants.SERVICE_BASE_URL + action.action_media;
//										}
//									}
//
//									if (listToDownload != null && listToDownload.Count > 0) {
//										IDownload downloader = DependencyService.Get<IDownload>();
//										//progressBar.ShowProgressbar("loading details..");
//										await downloader.DownloadFiles(listToDownload);
//										//progressBar.HideProgressbar();
//									}
//
//									if (actionDetails != null) {
//										DetailsPageModel model = new DetailsPageModel();
//										model.actionMediaArray = actionDetails.action_media;
//										model.eventMediaArray = null;
//										model.goal_media = null;
//										model.Media = null;
//										model.NoMedia = null;
//										model.pageTitleVal = "Action Details";
//										model.titleVal = actionDetails.action_title;
//										model.description = actionDetails.action_details;
//										model.gemType = GemType.Action;
//										model.gemId = currentGemId;
//
//										progress.HideProgressbar();
//										await Navigation.PushAsync(new GemsDetailsPage(model));
//
//
//
//
//										actionDetails = null;
//									}
//								} catch (Exception ) {
//									progress.HideProgressbar();
//									Navigation.PopAsync();
//								}
//        
//							
							#endregion

                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var test = ex.Message;
            }
        }
		public void Dispose()
		{
			this.eventPickerButton = null;
			this.eventPickerButton.Clicked -= OnEventPickerButtonClicked;
			this.emotionalPickerButton = null;
			this.emotionalPickerButton.Clicked -= OnEmotionalPickerButtonClicked;
			this.slider = null;
			this.masterLayout = null;
			this.progressBar = null;
			this.selectedEmotionItem = null;
			this.selectedEventItem = null;
			this.about = null;
			this.subTitleBar.NextButtonTapRecognizer.Tapped -= OnNextButtonTapRecognizerTapped;
			this.subTitleBar.BackButtonTapRecognizer.Tapped -= OnBackButtonTapRecognizerTapped;
			this.subTitleBar = null;
			this.Appearing -= OnFeelingNowPageAppearing;
			this.mainTitleBar = null;
			sliderValLabel = null;
			emotionTextLabel = null;
			eventTextLabel = null;
			imagesContainer = null;
			feedbackLabelStack = null;
			sliderFeedbackStack = null;
			feelingFeedbackStack = null;
			eventFeedbackStack = null;
			hLine = null;
			emotionTextTap = null;

			GC.Collect();
		}
		public void OnEventPickerItemSelected(object sender, SelectedItemChangedEventArgs e)
		{
			try
			{
				CustomListViewItem item = e.SelectedItem as CustomListViewItem;
				if (item == null) {
					return;
				}
				if (string.IsNullOrEmpty(item.Name)) {
					return;
				}

				eventPickerButton.Text = item.Name;
				eventPickerButton.TextColor = Color.Black;
				selectedEventItem = item;
				View pickView = masterLayout.Children.FirstOrDefault(pick => pick.ClassId == "ePicker");
				if( pickView != null )
				masterLayout.Children.Remove(pickView);
				pickView = null;
				GC.Collect();
				SetFeedBackLablText();
				string trimmedText = item.Name;
				if (trimmedText.Length > 15)
				{
					trimmedText = trimmedText.Substring(0, 15);
					trimmedText += "..";
				}
				eventFeedbackStack.IsVisible = true;
				eventFeedbackStack.HeightRequest = 0;
				eventTextLabel.Text = item.Name;

				AnimateToplabels(3);
			}
			catch (System.Exception ex)
			{
				DisplayAlert(Constants.ALERT_TITLE, "Please try again", Constants.ALERT_OK);
			}
		}
		public async void OnEmotionalPickerItemSelected(object sender, SelectedItemChangedEventArgs e)
		{
			try
			{
				CustomListViewItem item = e.SelectedItem as CustomListViewItem;
				if (item == null) {
					return;
				}
				if (string.IsNullOrEmpty(item.Name)) {
					return;
				}
				emotionalPickerButton.Text = item.Name;
				selectedEmotionItem = item;
				emotionalPickerButton.TextColor = Color.Black;
				App.SelectedEmotion = item.Name;
				View pickView = masterLayout.Children.FirstOrDefault(pick => pick.ClassId == "ePicker");
				if( pickView != null )
				masterLayout.Children.Remove(pickView);
				pickView = null;
				GC.Collect();
				eventPickerButton.IsVisible = true;
				about.IsVisible = true;
				if (! eventsDisplaying)
				{
					await Task.Delay(100);
					OnEventPickerButtonClicked(eventPickerButton, EventArgs.Empty);
					//SetFeedBackLablText();
				}

				string trimmedText = item.Name;
				if (trimmedText.Length > 15)
				{
					trimmedText = trimmedText.Substring(0, 15);
					trimmedText += "..";
				}

				emotionTextLabel.Text = item.Name;
				feelingFeedbackStack.IsVisible = true;
				feelingFeedbackStack.HeightRequest = 0;
				AnimateToplabels(2);

			}
			catch (System.Exception ex)
			{
				DisplayAlert(Constants.ALERT_TITLE, "Please try again", Constants.ALERT_OK);
			}
		}
        void OnAddButtonClicked(object sender, EventArgs e)
        {
            try
            {

                if (pageTitle == Constants.SELECT_EMOTIONS)
                {
                    CustomEntry emotionsEntry = new CustomEntry();
                    emotionsEntry.BackgroundColor = Color.White;
                    emotionsEntry.Placeholder = "Enter emotion";
                    emotionsEntry.WidthRequest = screenWidth * 75 / 100;
                    emotionsEntry.TextColor = Color.Black;
                    listTitle.IsVisible = false;
                    addButton.IsVisible = false;
					emotionsEntry.TextChanged += EmotionsEntry_TextChanged;

                    addEmotionButton = new Image();
                    addEmotionButton.Source = (FileImageSource)ImageSource.FromFile(Device.OnPlatform("tick_with_bg.png", "tick_with_bg.png", "//Assets//tick_with_bg.png"));

                    addEmotionButton.WidthRequest = Device.OnPlatform(25, 25, 30);
                    addEmotionButton.HeightRequest = Device.OnPlatform(25, 25, 30);

                    StackLayout addEmotionButtonLayout = new StackLayout();
                    addEmotionButtonLayout.HeightRequest = 50;
                    addEmotionButtonLayout.WidthRequest = 50;
                    addEmotionButtonLayout.BackgroundColor = Color.Transparent;

                    TapGestureRecognizer addEmotionButtonLayoutTapGestureRecognizer = new TapGestureRecognizer();
                    addEmotionButtonLayoutTapGestureRecognizer.Tapped += async (
                        object addsender, EventArgs adde) =>
                    {

                        IProgressBar progressBar = DependencyService.Get<IProgressBar>();

                        progressBar.ShowProgressbar("sending new emotion");


						//User user = App.Settings.GetUser();

                        listTitle.IsVisible = true;
                        addButton.IsVisible = true;
                        addEmotionButton.IsVisible = false;
                        emotionsEntry.IsVisible = false;
                        addEmotionButtonLayout.IsVisible = false;

                        if (emotionsEntry.Text == null)
                        {
                            progressBar.ShowToast("emotion is empty");
                            progressBar.HideProgressbar();
                            return;
                        }

                        if (emotionsEntry.Text != null && emotionsEntry.Text.Trim().Length == 0)
                        {
                            progressBar.ShowToast("emotion is empty");
                            progressBar.HideProgressbar();
                            return;
                        }
						User user = App.Settings.GetUser();
						if (user == null) {
							return;
						}
						var addService = await ServiceHelper.AddEmotion(FeelingNowPage.sliderValue.ToString(), emotionsEntry.Text,  user.UserId);

                        await FeelingsPage.DownloadAllEmotions();




                        View pickView = pageContainedLayout.Children.FirstOrDefault(pick => pick.ClassId == "ePicker");
                        pageContainedLayout.Children.Remove(pickView);
                        pickView = null;
                        progressBar.HideProgressbar();
						if(listView.SelectedItem != null)
						{
							listView.SelectedItem = null;
						}

						//await Task.Delay( TimeSpan.FromSeconds( 1 ) );

						CustomListViewItem newEmotionItem = new CustomListViewItem();
						newEmotionItem.EmotionID = App.emotionsListSource.First().EmotionID;
						newEmotionItem.Name = App.emotionsListSource.First().Name;
						newEmotionItem.SliderValue = App.emotionsListSource.First().SliderValue;

						SelectedItemChangedEventArgs newEmotionEvent = new SelectedItemChangedEventArgs( newEmotionItem );
						FeelingsPage.OnEmotionalPickerItemSelected( this, newEmotionEvent );

                    };
                    addEmotionButtonLayout.GestureRecognizers.Add(addEmotionButtonLayoutTapGestureRecognizer);

                    masterLayout.AddChildToLayout(addEmotionButton, 85, (100 - topYPos - 2) - 6);
                    masterLayout.AddChildToLayout(emotionsEntry, 7, (100 - topYPos - 2) - Device.OnPlatform(7, 7, 9));
                    masterLayout.AddChildToLayout(addEmotionButtonLayout, Device.OnPlatform(80, 80, 83), Device.OnPlatform((100 - topYPos - 1) - 9, (100 - topYPos - 1) - 9, (100 - topYPos - 1) - 8));
                }
                else
                {
                    //Navigation.PushAsync(new AddEventsSituationsOrThoughts(pageTitle));
					AddEventsSituationsOrThoughts addUtitlty = new AddEventsSituationsOrThoughts(pageTitle);
					/*addUtitlty.feelingsPage = FeelingsPage;
					addUtitlty.feelingSecondPage = feelingSecondPage;*/
					Navigation.PushAsync( addUtitlty );
                    View pickView = pageContainedLayout.Children.FirstOrDefault(pick => pick.ClassId == "ePicker");
                    pageContainedLayout.Children.Remove(pickView);
                    pickView = null;
                }

            }
            catch (Exception ex)
            {
                var test = ex.Message;
            }
        }