public async void done(object sender, EventArgs e) { displayActivityIndicator(); await Task.Run(() => { FileHandler fileHandler = new FileHandler(); fileHandler.updateStoredEventsFile(); fileHandler.updateMyEventsFile(); Device.BeginInvokeOnMainThread(() => { mainPage.populateGrid(); Navigation.PopModalAsync(); }); }); }
public async void DeleteButton_Clicked(object sender, EventArgs e) { bool x = await DisplayAlert("Are you sure?", "\"" + GlobalVariables.eventToBeDeleted + "\" will be deleted.", "Delete", "Cancel"); if (x) { Device.BeginInvokeOnMainThread(() => { displaySelectingIndicator(); }); await Task.Run(() => { Thread.Sleep(400); for (int i = 0; i < GlobalVariables.myEvents.Count; i++) { if (GlobalVariables.myEvents[i].getName().Equals(GlobalVariables.eventToBeDeleted)) { GlobalVariables.myEvents.RemoveAt(i); if (GlobalVariables.myEvents.Count == 0) { Device.BeginInvokeOnMainThread(() => { displayEmptyEvents(); populateMyEventsGrid(); }); } else { Device.BeginInvokeOnMainThread(() => { populateMyEventsGrid(); scrollView.Content = myEventsGrid; }); } //remove event from saved file FileHandler fileHandler = new FileHandler(); fileHandler.updateMyEventsFile(); return; } } }); } }
public async void newDayRefresh() { bool setToGrid = false; if (lastDay == -1) { await Task.Run(() => { Device.BeginInvokeOnMainThread(() => { populateGrid(); }); }); setToGrid = true; } currentDay = DateTime.Now.Day; if (lastDay != currentDay) { lastDay = currentDay; FileHandler fileHandler = new FileHandler(); //set current date text Device.BeginInvokeOnMainThread(() => { currentDate.Text = DateTime.Now.ToString("D"); }); //new day, change any events that were today to next year //*************************?? int myEventsIndex = 0; int storedEventsIndex = 0; int index = 0; bool myEventType; while (myEventsIndex < GlobalVariables.myEvents.Count || storedEventsIndex < GlobalVariables.storedEvents.Count) { myEventType = true; if (myEventsIndex < GlobalVariables.myEvents.Count) { if (storedEventsIndex < GlobalVariables.storedEvents.Count) { if (GlobalVariables.myEvents[myEventsIndex].getDate() < GlobalVariables.storedEvents[storedEventsIndex].getDate()) { index = myEventsIndex++; } else { index = storedEventsIndex++; myEventType = false; } } else { index = myEventsIndex++; } } else { index = storedEventsIndex++; myEventType = false; } if (myEventType) { if (GlobalVariables.myEvents[index].getDaysUntil() < 0) { if (GlobalVariables.myEvents[index].isOneTimeEvent()) { if (!setToGrid && GlobalVariables.myEvents[index].isVisible()) { GlobalVariables.myEvents[index].removeFromGrid(); //move remaining real child locations to new indices for (int j = 1; j < GlobalVariables.grid2_realChildLocations.Count; j++) { if (GlobalVariables.grid2_realChildLocations[j] > GlobalVariables.grid2_realChildLocations[0]) { GlobalVariables.grid2_realChildLocations[j] -= 5; } } GlobalVariables.grid2_realChildLocations.RemoveAt(0); } GlobalVariables.myEvents.RemoveAt(index--); myEventsIndex--; Thread.Sleep(200); continue; } GlobalVariables.resetEvent(GlobalVariables.myEvents[index]); if (!setToGrid && GlobalVariables.myEvents[index].isVisible()) { Thread.Sleep(100); GlobalVariables.myEvents[index].refreshRow(); } } if (!setToGrid && GlobalVariables.myEvents[index].isVisible()) { GlobalVariables.myEvents[index].refreshBackground(); } } else //stored event type { if (GlobalVariables.storedEvents[index].getDaysUntil() < 0) { GlobalVariables.resetEvent(GlobalVariables.storedEvents[index]); if (!setToGrid && GlobalVariables.storedEvents[index].isVisible()) { Thread.Sleep(100); GlobalVariables.storedEvents[index].refreshRow(); } } if (!setToGrid && GlobalVariables.storedEvents[index].isVisible()) { GlobalVariables.storedEvents[index].refreshBackground(); } } } //check if a one time event has lapsed since last app open for (int i = 0; i < GlobalVariables.myEvents.Count; i++) { if (GlobalVariables.myEvents[i].isOneTimeEvent() && eventHasLapsed(GlobalVariables.myEvents[i])) { GlobalVariables.myEvents.RemoveAt(i--); continue; } } await Task.Run(() => { try { fileHandler.updateMyEventsFile(); } catch (Exception ex) { Debug.WriteLine("Exception trying to update my events file:\n" + ex.Message); } }); //set page's content back to original stack if (setToGrid) { while (animating) { ; } Thread.Sleep(150); while (populatingGrid) { ; } Device.BeginInvokeOnMainThread(() => { Content = animationStack; animationStack.Children.Insert(0, mainStack); Device.BeginInvokeOnMainThread(async() => { animationStack.Children.RemoveAt(1); uint fadeTime = 800; Device.BeginInvokeOnMainThread(async() => { await utilitiesPadding.FadeTo(1.0, fadeTime); }); Device.BeginInvokeOnMainThread(async() => { await Buttons.FadeTo(1.0, fadeTime); }); await gridStack.FadeTo(1.0, fadeTime); }); }); } } }