async void OnAppearing(object sender, EventArgs e) { if (commonGoalsObject != null && commonGoalsObject.GoalsDetails != null && commonGoalsObject.GoalsDetails.Count > 0) return; commonGoalsObject = null; commonGoalsObject = new CommonGoalsObject (); commonGoalsObject.GoalsDetails = new List<CommonGoalsDetails>(); IProgressBar progress = DependencyService.Get<IProgressBar>(); progress.ShowProgressbar("Loading pending items.."); try { pendingGoalsObject = await ServiceHelper.GetAllPendingGoalsAndActions (); if( pendingGoalsObject == null || pendingGoalsObject.resultarray == null ) { var success = await DisplayAlert (Constants.ALERT_TITLE, "Error in fetching Pending goals", Constants.ALERT_OK, Constants.ALERT_RETRY); if (!success) { OnAppearing (sender, EventArgs.Empty); return; } else { if (Device.OS != TargetPlatform.WinPhone) pendingGoalsObject = App.Settings.GetPendingGoalsObject(); progress.HideProgressbar (); } } else { foreach (var goalItem in pendingGoalsObject.resultarray) { CommonGoalsDetails commonGoalsDetails = new CommonGoalsDetails(); commonGoalsDetails.GoalMedia = goalItem.goal_media; commonGoalsDetails.GoalTitle = goalItem.goal_title; commonGoalsDetails.GoalID = goalItem.goal_id; commonGoalsDetails.GoalDesc = goalItem.goal_details; commonGoalsDetails.IsPending = true; commonGoalsDetails.ActionTitle = new List<CommonActionTitle>(); foreach (var actionItem in goalItem.pending_action_title) { CommonActionTitle commonTitle = new CommonActionTitle(); commonTitle.actionstatus_id = actionItem.actionstatus_id; commonTitle.action_title = actionItem.action_title; commonTitle.goalaction_id = actionItem.goalaction_id; commonTitle.goal_id = actionItem.goal_id; commonTitle.savedgoal_id = actionItem.savedgoal_id; commonGoalsDetails.ActionTitle.Add( commonTitle ); } if ( null == commonGoalsObject.GoalsDetails.Find( tst => tst.GoalID == commonGoalsDetails.GoalID )) commonGoalsObject.GoalsDetails.Add( commonGoalsDetails ); } App.Settings.DeleteAllPendingGoals(); App.Settings.SavePendingGoalsDetails( pendingGoalsObject ); } commonGoalsObject.GoalsDetails.Add( new CommonGoalsDetails{ GoalID="header"} ); gemsGoalsObject = await ServiceHelper.GetAllMyGoals(); if( gemsGoalsObject == null || gemsGoalsObject.resultarray == null ) { var success = await DisplayAlert (Constants.ALERT_TITLE, "Error in fetching all goals", Constants.ALERT_OK, Constants.ALERT_RETRY); if (!success) { OnAppearing (sender, EventArgs.Empty); return; } else { if (Device.OS != TargetPlatform.WinPhone) gemsGoalsObject = App.Settings.GetCompletedGoalsObject(); progress.HideProgressbar(); } } else { foreach (var allGoalItem in gemsGoalsObject.resultarray) { CommonGoalsDetails commonGoalsDetails = new CommonGoalsDetails(); commonGoalsDetails.GoalMedia = allGoalItem.goal_media; commonGoalsDetails.GoalTitle = allGoalItem.goal_title; commonGoalsDetails.GoalID = allGoalItem.goal_id; commonGoalsDetails.GoalDesc = allGoalItem.goal_details; commonGoalsDetails.ActionTitle = new List<CommonActionTitle>(); commonGoalsDetails.IsPending = false; if( allGoalItem.action_title != null && allGoalItem.action_title.Count > 0 ) { foreach (var allActionItem in allGoalItem.action_title) { CommonActionTitle commonTitle = new CommonActionTitle(); commonTitle.action_title = allActionItem.action_title; commonTitle.goalaction_id = allActionItem.goalaction_id; commonTitle.goal_id = allActionItem.goal_id; commonGoalsDetails.ActionTitle.Add( commonTitle ); } } if ( null == commonGoalsObject.GoalsDetails.Find( tst => tst.GoalID == commonGoalsDetails.GoalID )) commonGoalsObject.GoalsDetails.Add( commonGoalsDetails ); } App.Settings.DeleteAllCompletedGoals(); App.Settings.SaveCompletedGoalsDetails(gemsGoalsObject); } allCommonGoalsObject = new CommonGoalsObject(); allCommonGoalsObject.GoalsDetails = commonGoalsObject.GoalsDetails.Skip(0).Take( commonGoalsObject.GoalsDetails.Count ).ToList(); /*if( pendingGoalsObject.resultarray.Count + gemsGoalsObject.resultarray.Count < 30 ) { #region PENDING GOALS CreatePendingGoalsView( true ); #endregion #region ALL GOALS HEADING CreateAllGoalsHeading(); #endregion #region ALL GOALS CreateAllGoalsView(); #endregion } else if( pendingGoalsObject.resultarray.Count > 30 ) { pendingGoalsObject.resultarray = pendingGoalsObject.resultarray.Skip(0).Take(30).ToList(); #region PENDING GOALS CreatePendingGoalsView( true ); #endregion }*/ commonGoalsObject.GoalsDetails = commonGoalsObject.GoalsDetails.Skip(0).Take( MAX_ROWS_AT_A_TIME ).ToList(); await DownloadMedias(); RenderGoalsPage( false ); masterScroll.Padding = new Thickness(10, 10, 10, 0); masterScroll.Scrolled += OnScroll; masterScroll.Content = masterStack; masterLayout.AddChildToLayout(mainTitleBar, 0, 0); // masterLayout.AddChildToLayout(subTitleBar, 0, Device.OnPlatform(9, 10, 10)); masterLayout.AddChildToLayout(masterScroll, 0, 10); Content = masterLayout; } catch (Exception) { } progress.HideProgressbar(); }
bool OnLoadPreviousGemsClicked (object sender, EventArgs e) { try { pendingGoalsObject = null; gemsGoalsObject = null; CommonGoalsDetails firstItem = commonGoalsObject.GoalsDetails.First (); CommonGoalsObject gemsObj = new CommonGoalsObject(); gemsObj.GoalsDetails = allCommonGoalsObject.GoalsDetails.Skip(0).Take( allCommonGoalsObject.GoalsDetails.Count ).ToList(); int firstRendererItemIndex = gemsObj.GoalsDetails.FindIndex (itm => itm.GoalID == firstItem.GoalID);;//gemsObj.resultarray.IndexOf ( lastItem ); if (firstRendererItemIndex > 0 && ( firstRendererItemIndex + 1 ) < gemsObj.GoalsDetails.Count ) { reachedEnd = false; reachedFront = false; int itemCountToCopy = MAX_ROWS_AT_A_TIME; commonGoalsObject = null; commonGoalsObject = new CommonGoalsObject (); commonGoalsObject.GoalsDetails = new List<CommonGoalsDetails>(); gemsObj.GoalsDetails.RemoveRange( firstRendererItemIndex, gemsObj.GoalsDetails.Count - firstRendererItemIndex ); if( firstRendererItemIndex > MAX_ROWS_AT_A_TIME ) gemsObj.GoalsDetails.RemoveRange( 0, firstRendererItemIndex - MAX_ROWS_AT_A_TIME ); commonGoalsObject.GoalsDetails = gemsObj.GoalsDetails; gemsObj = null; masterStack.Children.Clear(); masterScroll.Content = null; GC.Collect(); RenderGoalsPage( false ); masterScroll.Content = masterStack; return true; } else { reachedFront = true; return false; } } catch (Exception ex) { DisplayAlert ( Constants.ALERT_TITLE, "Low memory error.", Constants.ALERT_OK ); return false; } }
bool OnLoadMoreGemsClicked (object sender, EventArgs e) { try { pendingGoalsObject = null; gemsGoalsObject = null; CommonGoalsDetails lastItem = commonGoalsObject.GoalsDetails.Last (); CommonGoalsObject gemsObj = new CommonGoalsObject(); gemsObj.GoalsDetails = allCommonGoalsObject.GoalsDetails.Skip(0).Take( allCommonGoalsObject.GoalsDetails.Count ).ToList(); int lastRendererItemIndex = gemsObj.GoalsDetails.FindIndex (itm => itm.GoalID == lastItem.GoalID); if (lastRendererItemIndex > 0 && ( lastRendererItemIndex + 1 ) < gemsObj.GoalsDetails.Count ) { reachedEnd = false; reachedFront = false; int itemCountToCopy = gemsObj.GoalsDetails.Count - lastRendererItemIndex; itemCountToCopy = (itemCountToCopy > MAX_ROWS_AT_A_TIME) ? MAX_ROWS_AT_A_TIME : itemCountToCopy; commonGoalsObject = null; commonGoalsObject = new CommonGoalsObject (); commonGoalsObject.GoalsDetails = new List<CommonGoalsDetails>(); commonGoalsObject.GoalsDetails = gemsObj.GoalsDetails.Skip (lastRendererItemIndex).Take (itemCountToCopy).ToList(); gemsObj = null; masterStack.Children.Clear(); masterScroll.Content = null; GC.Collect(); if( itemCountToCopy < MAX_ROWS_AT_A_TIME ) RenderGoalsPage( true ); else RenderGoalsPage( false ); masterScroll.Content = masterStack; return true; } else { reachedEnd = true; return false; } } catch (Exception ex) { //DisplayAlert ( Constants.ALERT_TITLE, "Low memory error.", Constants.ALERT_OK ); return false; } }
async void OnPendingGoalsTapped(object sender, EventArgs e) { StackLayout layout = sender as StackLayout; if( layout != null && layout.Children != null && layout.Children.Count > 0 ) { Image img = (Image)layout.Children[0]; if (img != null && img.ClassId != null ) { string[] delimiters = { "&&" }; string[] clasIDArray = img.ClassId.Split(delimiters, StringSplitOptions.None); string selectedSavedGoalID = clasIDArray [1]; string selectedGoalID = clasIDArray [0]; if (!string.IsNullOrEmpty (selectedSavedGoalID)) { IProgressBar progress = DependencyService.Get<IProgressBar> (); progress.ShowProgressbar ( "Completing action...." ); var change = await ServiceHelper.ChangePendingActionStatus ( selectedSavedGoalID ); if (!change) { progress.HideProgressbar(); DisplayAlert (Constants.ALERT_OK, "Failed to complete action", Constants.ALERT_OK); return; } else { await DisplayAlert (Constants.ALERT_OK, "Action is completed", Constants.ALERT_OK); /*App.masterPage.IsPresented = false; App.masterPage.Detail = new NavigationPage(new GoalsPage()); await DeletePendingActionRowFromStack(selectedGoalID, selectedSavedGoalID);*/ masterScroll.Scrolled -= OnScroll; commonGoalsObject = null; pendingGoalsObject = null; gemsGoalsObject = null; masterStack.Children.Clear(); masterScroll.Content = null; OnAppearing ( this, EventArgs.Empty ); masterScroll.Scrolled += OnScroll; } progress.HideProgressbar (); } } } }