public static MyAccountViewModel Load(BaseViewModel parent) { MainWindowViewModel windowViewModel = parent.FindAncestor <MainWindowViewModel>(); if (windowViewModel == null) { throw new NullReferenceException("Could not find MainWindowViewModel ancestor"); } if (windowViewModel.CurrentAccount == null) { throw new InvalidOperationException("There's no current account."); } return(new MyAccountViewModel(parent) { CurrentAccount = windowViewModel.CurrentAccount, _rememberUsername = windowViewModel.CurrentAccount.RememberUsername, _rememberPassword = windowViewModel.CurrentAccount.RememberPassword, _autoLogin = windowViewModel.CurrentAccount.AutoLogin }); }
public static async void EmailDeveloper(BaseViewModel current) { try { string accountInfo = ""; var mainScreen = current is MainScreenViewModel ? current as MainScreenViewModel : current.FindAncestor <MainScreenViewModel>(); if (mainScreen != null && mainScreen.CurrentAccount != null) { accountInfo = " - " + mainScreen.CurrentAccount.GetTelemetryUserId() + " - " + mainScreen.CurrentAccount.DeviceId; } await Launcher.LaunchUriAsync(new Uri("mailto:[email protected]&subject=Power Planner for Win 10 - Contact Developer - " + Variables.VERSION + accountInfo)); } catch (Exception ex) { TelemetryExtension.Current?.TrackException(ex); } }
public static void EmailDeveloper(Context context, BaseViewModel current) { string accountInfo = ""; var mainScreen = current is MainScreenViewModel ? current as MainScreenViewModel : current.FindAncestor <MainScreenViewModel>(); if (mainScreen != null && mainScreen.CurrentAccount != null) { accountInfo = " - " + mainScreen.CurrentAccount.GetTelemetryUserId() + " - " + mainScreen.CurrentAccount.DeviceId; } var _version = PowerPlannerAppDataLibrary.Variables.VERSION.ToString(); Intent emailIntent = new Intent(Intent.ActionSendto); emailIntent.SetData(Android.Net.Uri.Parse("mailto:")); // Sendto and mailto ensures only email apps are shown emailIntent.PutExtra(Intent.ExtraEmail, new string[] { "*****@*****.**" }); emailIntent.PutExtra(Intent.ExtraSubject, "Power Planner Droid - Contact Developer - " + _version + accountInfo); // Note that we're not including body text, since when sending from Outlook, it trims the leading newlines leaving no space for user to write. //emailIntent.PutExtra(Intent.ExtraText, "\n\nPower Planner Droid - Version " + _version + accountInfo); try { context.StartActivity(Intent.CreateChooser(emailIntent, "Send email")); } catch { Toast.MakeText(context, "You need to set up your email.", ToastLength.Short); } }
public static AddTaskOrEventViewModel CreateForEdit(BaseViewModel parent, EditParameter editParams) { var account = parent.FindAncestor <MainWindowViewModel>()?.CurrentAccount; if (account == null) { throw new NullReferenceException("CurrentAccount was null"); } ViewItemClass c = editParams.Item.Class; TaskOrEventType type = editParams.Item.Type; if (c == null) { throw new NullReferenceException("Class of the item was null. Item id " + editParams.Item.Identifier); } if (c.Semester == null) { throw new NullReferenceException("Semester of the class was null. Item id " + editParams.Item.Identifier); } if (c.Semester.Classes == null) { throw new NullReferenceException("Classes of the semester was null. Item id " + editParams.Item.Identifier); } var model = new AddTaskOrEventViewModel(parent) { Account = account, State = OperationState.Editing, EditParams = editParams, Name = editParams.Item.Name, Classes = GetClassesWithNoClassClass(c.Semester.Classes), Date = editParams.Item.DateInSchoolTime.Date, Details = editParams.Item.Details, Type = type, ImageNames = editParams.Item.ImageNames.ToArray(), IsInDifferentTimeZone = parent.FindAncestorOrSelf <MainScreenViewModel>().CurrentAccount.IsInDifferentTimeZone, Class = c // Assign class last, since it also assigns weight categories }; // Assign existing image attachments model.ImageAttachments = new ObservableCollection <BaseEditingImageAttachmentViewModel>(editParams.Item.ImageNames.Select(i => new EditingExistingImageAttachmentViewModel(model, i))); switch (editParams.Item.GetActualTimeOption()) { case DataItemMegaItem.TimeOptions.AllDay: model.SelectedTimeOption = model.TimeOption_AllDay; break; case DataItemMegaItem.TimeOptions.BeforeClass: model.SelectedTimeOption = model.TimeOption_BeforeClass; break; case DataItemMegaItem.TimeOptions.Custom: model._startTime = new TimeSpan(editParams.Item.DateInSchoolTime.Hour, editParams.Item.DateInSchoolTime.Minute, 0); model._endTime = editParams.Item.EndTimeInSchoolTime.TimeOfDay; model.SelectedTimeOption = model.TimeOption_Custom; break; case DataItemMegaItem.TimeOptions.DuringClass: model.SelectedTimeOption = model.TimeOption_DuringClass; break; case DataItemMegaItem.TimeOptions.EndOfClass: model.SelectedTimeOption = model.TimeOption_EndOfClass; break; case DataItemMegaItem.TimeOptions.StartOfClass: model.SelectedTimeOption = model.TimeOption_StartOfClass; break; } // We don't want to consider setting the initial time option as the user configuring the time option model._userChangedSelectedTimeOption = false; return(model); }
public static AddTaskOrEventViewModel CreateForAdd(BaseViewModel parent, AddParameter addParams) { AccountDataItem account = parent.FindAncestor <MainWindowViewModel>()?.CurrentAccount; if (account == null) { throw new NullReferenceException("CurrentAccount was null"); } if (addParams.Classes.Count == 0) { throw new InvalidOperationException("No classes"); } bool intelligentlyPickDate = true; DateTime now = DateTime.Now; IList <ViewItemClass> classes = GetClassesWithNoClassClass(addParams.Classes); ViewItemClass c = addParams.SelectedClass; if (c == null) { if (addParams.Type == TaskOrEventType.Task || addParams.Type == TaskOrEventType.Event) { var prevClassIdentifier = NavigationManager.GetPreviousAddItemClass(); if (prevClassIdentifier != null) { // Remember user's selection c = classes.FirstOrDefault(i => i.Identifier == prevClassIdentifier); } if (c == null) { // If date is specified if (addParams.DueDate != null) { // If today if (addParams.DueDate.Value.Date == now.Date) { // Pick currently going on class c = PowerPlannerApp.GetClosestClassBasedOnSchedule(now, account, addParams.Classes); } // If there wasn't a class going on (or wasn't today), pick first class on that day if (c == null) { c = PowerPlannerApp.GetFirstClassOnDay(addParams.DueDate.Value, account, addParams.Classes); } } // Otherwise else { // Intelligently pick based on schedule c = PowerPlannerApp.GetClosestClassBasedOnSchedule(now, account, addParams.Classes); } } if (c == null) { // If there wasn't a class and we're just doing the dummy pick first, // don't intelligently pick class date intelligentlyPickDate = false; c = classes.First(); } } else { // Tasks don't have classes intelligentlyPickDate = false; } } DateTime date; if (addParams.DueDate != null) { date = addParams.DueDate.Value; } else { var prevDate = NavigationManager.GetPreviousAddItemDate(); if (prevDate != null) { date = prevDate.Value; } else { DateTime?nextClassDate = null; if (intelligentlyPickDate) { nextClassDate = PowerPlannerApp.GetNextClassDate(account, c); } if (nextClassDate != null) { date = nextClassDate.Value; } else { date = DateTime.Today; } } } return(new AddTaskOrEventViewModel(parent) { Account = account, State = OperationState.Adding, AddParams = addParams, Classes = classes, Date = date.Date, Type = addParams.Type, IsClassPickerVisible = !addParams.HideClassPicker, IsWeightCategoryPickerVisible = true, ImageAttachments = new ObservableCollection <BaseEditingImageAttachmentViewModel>(), IsInDifferentTimeZone = parent.FindAncestorOrSelf <MainScreenViewModel>().CurrentAccount.IsInDifferentTimeZone, Class = c // Assign class last, since it also assigns weight categories, and updates time options from remembered times }); }