Exemple #1
0
        public MyScheduleItemView(Context context, ViewItemSchedule s) : base(context)
        {
            Schedule = s;

            base.Orientation = Orientation.Vertical;
            base.SetPaddingRelative(ThemeHelper.AsPx(context, 5), ThemeHelper.AsPx(context, 5), 0, 0);

            m_classColorBindingInstance = Binding.SetBinding(s.Class, nameof(s.Class.Color), (c) =>
            {
                base.Background = new ColorDrawable(ColorTools.GetColor(c.Color));
            });

            // Can't figure out how to let both class name and room wrap while giving more importance
            // to room like I did on UWP, so just limiting name to 2 lines for now till someone complains.
            var textViewName = CreateTextView("");

            m_classNameBindingInstance = Binding.SetBinding(s.Class, nameof(s.Class.Name), (c) =>
            {
                textViewName.Text = c.Name;
            });

            textViewName.SetMaxLines(2);
            base.AddView(textViewName);

            base.AddView(CreateTextView(GetStringTimeToTime(s)));

            if (!string.IsNullOrWhiteSpace(s.Room))
            {
                base.AddView(CreateTextView(s.Room));
            }
        }
            private View CreateCircle(ViewGroup root, BaseViewItemHomeworkExamGrade item)
            {
                View view = new View(root.Context)
                {
                    Background       = ContextCompat.GetDrawable(root.Context, Resource.Drawable.circle),
                    LayoutParameters = new LinearLayout.LayoutParams(
                        ThemeHelper.AsPx(Context, 5),
                        ThemeHelper.AsPx(Context, 5))
                    {
                        RightMargin = ThemeHelper.AsPx(Context, 3)
                    }
                };

                if (item is BaseViewItemHomeworkExam)
                {
                    ViewCompat.SetBackgroundTintList(view, new ColorStateList(new int[][]
                    {
                        new int[] { }
                    },
                                                                              new int[]
                    {
                        ColorTools.GetColor((item as BaseViewItemHomeworkExam).GetClassOrNull().Color).ToArgb()
                    }));
                }

                return(view);
            }
        private async void InitializeTile(PreviewTile tile)
        {
            try
            {
                tile.DisplayName = ViewModel.Class.Name;

                if (ViewModel.Settings.CustomColor != null)
                {
                    tile.VisualElements.BackgroundColor = ColorTools.GetColor(ViewModel.Settings.CustomColor);
                }
                else
                {
                    tile.VisualElements.BackgroundColor = ColorTools.GetColor(ViewModel.Class.Color);
                }

                tile.VisualElements.ShowNameOnSquare150x150Logo = true;
                tile.VisualElements.Square44x44Logo             = new Uri("ms-appx:///Assets/Square44x44Logo.png");
                tile.VisualElements.Square71x71Logo             = new Uri("ms-appx:///Assets/Square71x71Logo.png");
                tile.VisualElements.Square150x150Logo           = new Uri("ms-appx:///Assets/Square150x150Logo.png");
                tile.VisualElements.Square310x310Logo           = new Uri("ms-appx:///Assets/Square310x310Logo.png");
                tile.VisualElements.Wide310x150Logo             = new Uri("ms-appx:///Assets/Wide310x150Logo.png");

                await tile.UpdateAsync();
            }

            catch (Exception ex)
            {
                TelemetryExtension.Current?.TrackException(ex);
            }
        }
        private void UpdateVisuals()
        {
            if (Item == null)
            {
                return;
            }

            try
            {
                base.Background     = new ColorDrawable(ColorTools.GetColor(Item.Class.Color));
                _textViewTitle.Text = Item.Name;

                if (Item.IsComplete)
                {
                    _viewIsComplete.Visibility = ViewStates.Visible;
                    _textViewTitle.Alpha       = 0.7f;
                }
                else
                {
                    _viewIsComplete.Visibility = ViewStates.Gone;
                    _textViewTitle.Alpha       = 1f;
                }
            }
            catch (Exception ex)
            {
                TelemetryExtension.Current?.TrackException(ex);
            }
        }
        private static async Task UpdateTileAsync(SecondaryTile tile, AccountDataItem account, AccountDataStore data, Guid classId)
        {
            try
            {
                DateTime todayInLocal = DateTime.Today;

                // Get the class tile settings
                ClassTileSettings settings = await account.GetClassTileSettings(classId);

                ClassData classData = await LoadDataAsync(data, classId, DateTime.SpecifyKind(todayInLocal, DateTimeKind.Utc), settings);

                // If classData was null, that means the class wasn't found, so we should delete the tile
                if (classData == null)
                {
                    await tile.RequestDeleteAsync();
                    return;
                }

                bool changed = false;

                string desiredName = GetTrimmedClassName(classData.Class.Name);

                Color desiredColor;

                if (settings.CustomColor != null)
                    desiredColor = ColorTools.GetColor(settings.CustomColor);
                else
                    desiredColor = ColorTools.GetColor(classData.Class.Color);

                if (!tile.DisplayName.Equals(desiredName))
                {
                    changed = true;
                    tile.DisplayName = desiredName;
                }

                if (!tile.VisualElements.BackgroundColor.Equals(desiredColor))
                {
                    changed = true;
                    tile.VisualElements.BackgroundColor = desiredColor;
                }

                if (changed)
                    await tile.UpdateAsync();


                var updater = TileUpdateManager.CreateTileUpdaterForSecondaryTile(tile.TileId);

                UpdateUpcomingTile(updater, classData.AllUpcoming, todayInLocal, UpcomingTileType.ClassTile, settings);
            }

            catch (Exception ex)
            {
                if (!UWPExceptionHelper.TrackIfNotificationsIssue(ex, "Tiles"))
                {
                    throw ex;
                }
            }
        }
Exemple #6
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is byte[])
            {
                return(ColorTools.GetColor(value as byte[]));
            }

            return(value);
        }
        /// <summary>
        /// Gets the brush for the task/event item, based on its class color
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        private SolidColorBrush getBrush(BaseViewItemMegaItem item)
        {
            if (item is ViewItemTaskOrEvent taskOrEvent)
            {
                return(new SolidColorBrush(ColorTools.GetColor(taskOrEvent.Class.Color)));
            }

            return(Brushes.Black);
        }
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            if (value is byte[])
            {
                byte[] arr = value as byte[];
                return(ColorTools.GetColor(arr));
            }

            return(Colors.Black);
        }
Exemple #9
0
 public static Android.Content.Res.ColorStateList GetBackgroundColorStateList(ViewItemTaskOrEvent item)
 {
     return(new Android.Content.Res.ColorStateList(new int[][]
     {
         new int[] { }
     },
                                                   new int[]
     {
         item.IsComplete ? new Color(180, 180, 180).ToArgb() : ColorTools.GetColor(item.Class.Color).ToArgb()
     }));
 }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is byte[] b)
            {
                Color color = ColorTools.GetColor(b);

                return(ColorTools.GetColorStateList(color));
            }

            return(value);
        }
 public static Android.Content.Res.ColorStateList GetBackgroundColorStateList(BaseViewItemHomeworkExam item)
 {
     return(new Android.Content.Res.ColorStateList(new int[][]
     {
         new int[] { }
     },
                                                   new int[]
     {
         item.IsComplete() ? new Color(180, 180, 180).ToArgb() : ColorTools.GetColor(item.GetClassOrNull().Color).ToArgb()
     }));
 }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is byte[])
            {
                Color color = ColorTools.GetColor(value as byte[]);

                return(new ColorDrawable(color));
            }

            return(value);
        }
Exemple #13
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            if (value is Color)
            {
                return(new SolidColorBrush((Color)value));
            }
            else if (value is byte[])
            {
                return(new SolidColorBrush(ColorTools.GetColor(value as byte[])));
            }

            return(value);
        }
Exemple #14
0
        /// <summary>
        /// Gets the brush for the homework item, based on its class color
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        private SolidColorBrush getBrush(BaseViewItemHomeworkExamGrade item)
        {
            if (item is ViewItemHomework)
            {
                return(new SolidColorBrush(ColorTools.GetColor((item as ViewItemHomework).Class.Color)));
            }

            else if (item is ViewItemExam)
            {
                return(new SolidColorBrush(ColorTools.GetColor((item as ViewItemExam).Class.Color)));
            }

            return(Brushes.Black);
        }
                public void UpdateDay(DateTime date, DayType dayType, bool isToday)
                {
                    _date = date;

                    if (isToday)
                    {
                        _backgroundView.SetBackgroundResource(Resource.Color.calendarBackgroundToday);
                    }
                    else
                    {
                        switch (dayType)
                        {
                        case DayType.ThisMonth:
                            _backgroundView.SetBackgroundResource(Resource.Color.calendarBackgroundThisMonth);
                            break;

                        default:
                            _backgroundView.SetBackgroundResource(Resource.Color.calendarBackgroundOther);
                            break;
                        }
                    }

                    _tv.Text = date.Day.ToString();

                    if (isToday)
                    {
                        _tv.SetTextColor(ColorTools.GetColor(this.Context, Resource.Color.calendarTextToday));
                    }
                    else
                    {
                        _tv.SetTextColor(_defaultTextColors);
                    }

                    UpdateSelectedStatus();

                    _myHomeworkCircles.SetItemsSource(_viewModel.SemesterItemsViewGroup.Items.Sublist(i => i is BaseViewItemHomeworkExam && i.Date.Date == date.Date && !(i as BaseViewItemHomeworkExam).IsComplete()));

                    if (_holidaysOnDay != null && _holidaysChangedHandler != null)
                    {
                        _holidaysOnDay.CollectionChanged -= _holidaysChangedHandler;
                    }
                    _holidaysOnDay                    = HolidaysOnDay.Create(_viewModel.SemesterItemsViewGroup.Items, date.Date);
                    _holidaysChangedHandler           = new WeakEventHandler <NotifyCollectionChangedEventArgs>(_holidaysOnDay_CollectionChanged).Handler;
                    _holidaysOnDay.CollectionChanged += _holidaysChangedHandler;
                    UpdateIsHoliday();
                }
        public override void OnViewModelLoadedOverride()
        {
            switch (ViewModel.State)
            {
            case AddClassViewModel.OperationState.Editing:
                Title = PowerPlannerResources.GetString("AddClassPage_EditTitle");
                break;

            case AddClassViewModel.OperationState.Adding:
                Title = PowerPlannerResources.GetString("AddClassPage_AddTitle");
                break;
            }

            _colorPicker.SelectedColor = ColorTools.GetColor(ViewModel.Color);
            SetMenu(Resource.Menu.add_class_menu);

            FindViewById <Button>(Resource.Id.ButtonStartDate).Click += StartDate_Click;
            FindViewById <Button>(Resource.Id.ButtonEndDate).Click   += EndDate_Click;

            if (ViewModel.Name.Length == 0)
            {
                KeyboardHelper.FocusAndShow(FindViewById <EditText>(Resource.Id.EditTextName));
            }
        }
                public MyCalendarDayView(Context context, MyCalendarView calendarView, CalendarViewModel viewModel) : base(context)
                {
                    _calendarView = calendarView;
                    _viewModel    = viewModel;

                    int margin = ThemeHelper.AsPx(Context, 1);

                    Clickable        = true;
                    LayoutParameters = new LinearLayout.LayoutParams(
                        LinearLayout.LayoutParams.MatchParent,
                        LinearLayout.LayoutParams.MatchParent);

                    _backgroundView = new View(Context)
                    {
                        LayoutParameters = new FrameLayout.LayoutParams(
                            FrameLayout.LayoutParams.MatchParent,
                            FrameLayout.LayoutParams.MatchParent)
                        {
                            TopMargin    = margin,
                            LeftMargin   = margin,
                            RightMargin  = margin,
                            BottomMargin = margin
                        }
                    };
                    base.AddView(_backgroundView);

                    _backgroundOverlayView = new View(Context)
                    {
                        LayoutParameters = new FrameLayout.LayoutParams(
                            FrameLayout.LayoutParams.MatchParent,
                            FrameLayout.LayoutParams.MatchParent)
                        {
                            TopMargin    = margin,
                            LeftMargin   = margin,
                            RightMargin  = margin,
                            BottomMargin = margin
                        },
                        Visibility = ViewStates.Gone
                    };
                    base.AddView(_backgroundOverlayView);

                    var padding = ThemeHelper.AsPx(Context, 4);

                    _myHomeworkCircles = new MyHomeworkCircles(Context)
                    {
                        LayoutParameters = new FrameLayout.LayoutParams(
                            FrameLayout.LayoutParams.MatchParent,
                            FrameLayout.LayoutParams.WrapContent)
                        {
                            Gravity      = GravityFlags.Bottom,
                            LeftMargin   = padding,
                            BottomMargin = padding,
                            RightMargin  = padding
                        }
                    };
                    this.AddView(_myHomeworkCircles);

                    _tv = new TextView(Context)
                    {
                        Gravity          = GravityFlags.Top | GravityFlags.Right,
                        LayoutParameters = new FrameLayout.LayoutParams(
                            FrameLayout.LayoutParams.MatchParent,
                            FrameLayout.LayoutParams.WrapContent)
                        {
                            TopMargin   = ThemeHelper.AsPx(Context, 2),
                            RightMargin = padding
                        }
                    };
                    _defaultTextColors = _tv.TextColors;

                    this.AddView(_tv);

                    _selectedRectangleView = new View(Context)
                    {
                        LayoutParameters = new FrameLayout.LayoutParams(
                            FrameLayout.LayoutParams.MatchParent,
                            FrameLayout.LayoutParams.MatchParent),
                        Visibility = ViewStates.Gone
                    };
                    _selectedRectangleView.Background = ContextCompat.GetDrawable(Context, Resource.Drawable.CalendarSelectedDayBorder);
                    ViewCompat.SetBackgroundTintList(_selectedRectangleView, new ColorStateList(new int[][] { new int[0] }, new int[] { ColorTools.GetColor(this.Context, Resource.Color.accent) }));
                    this.AddView(_selectedRectangleView);

                    this.Click += MyCalendarDayView_Click;

                    UpdateSelectedStatus();

                    _calendarView.SelectedDateChanged += new WeakEventHandler <EventArgs>(_calendarView_SelectedDateChanged).Handler;
                }
        private async void appBarPinClass_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (!(await PowerPlannerApp.Current.IsFullVersionAsync()))
                {
                    PowerPlannerApp.Current.PromptPurchase(LocalizedResources.GetString("String_PinningClassPremiumFeatureMessage"));
                    return;
                }

                if (ViewModel == null || ViewModel.ViewItemsGroupClass.Class == null)
                {
                    return;
                }

                if ((AppBarPinClass.Icon as SymbolIcon).Symbol == Symbol.Pin)
                {
                    var acct = await AccountsManager.GetOrLoad(ViewModel.MainScreenViewModel.CurrentLocalAccountId);

                    var data = await AccountDataStore.Get(ViewModel.MainScreenViewModel.CurrentLocalAccountId);

                    await ClassTileHelper.PinTileAsync(acct, data, ViewModel.ViewItemsGroupClass.Class.Identifier, ViewModel.ViewItemsGroupClass.Class.Name, ColorTools.GetColor(ViewModel.ViewItemsGroupClass.Class.Color));
                }

                else
                {
                    await ClassTileHelper.UnpinTile(ViewModel.MainScreenViewModel.CurrentLocalAccountId, ViewModel.ViewItemsGroupClass.Class.Identifier);
                }

                UpdatePinButton();
            }

            catch (Exception ex)
            {
                TelemetryExtension.Current?.TrackException(ex);
            }
        }
Exemple #19
0
            public MyScheduleItem(Context context, ViewItemSchedule s) : base(context)
            {
                Schedule = s;

                ViewItemClass c = s.Class as ViewItemClass;

                base.Orientation = Orientation.Vertical;
                base.Background  = new ColorDrawable(ColorTools.GetColor(c.Color));

                double hours = (s.EndTime.TimeOfDay - s.StartTime.TimeOfDay).TotalHours;

                base.LayoutParameters = new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.MatchParent,
                    (int)Math.Max(HeightOfHour * hours, 0));

                var marginSides   = ThemeHelper.AsPx(context, 6);
                var marginBetween = ThemeHelper.AsPx(context, -2);

                var tvClass = new TextView(context)
                {
                    Text     = c.Name,
                    Typeface = Typeface.DefaultBold
                };

                tvClass.SetTextColor(Color.White);
                tvClass.SetSingleLine(true);
                tvClass.SetPadding(marginSides, 0, marginSides, 0);

                var tvTime = new TextView(context)
                {
                    Text     = PowerPlannerResources.GetStringTimeToTime(DateHelper.ToShortTimeString(s.StartTime), DateHelper.ToShortTimeString(s.EndTime)),
                    Typeface = Typeface.DefaultBold
                };

                tvTime.SetTextColor(Color.White);
                tvTime.SetSingleLine(true);
                tvTime.SetPadding(marginSides, marginBetween, marginSides, 0);

                var tvRoom = new TextView(context)
                {
                    Text     = s.Room,
                    Typeface = Typeface.DefaultBold
                };

                tvRoom.SetTextColor(Color.White);
                tvRoom.SetPadding(marginSides, marginBetween, marginSides, 0);

                if (hours >= 1.1)
                {
                    base.AddView(tvClass);
                    base.AddView(tvTime);
                    base.AddView(tvRoom);
                }

                else
                {
                    LinearLayout firstGroup = new LinearLayout(context);

                    tvClass.LayoutParameters = new LinearLayout.LayoutParams(
                        0,
                        LinearLayout.LayoutParams.WrapContent)
                    {
                        Weight = 1
                    };
                    firstGroup.AddView(tvClass);

                    tvTime.SetPadding(marginSides, 0, marginSides, 0);
                    tvTime.LayoutParameters = new LinearLayout.LayoutParams(
                        LinearLayout.LayoutParams.WrapContent,
                        LinearLayout.LayoutParams.WrapContent);
                    firstGroup.AddView(tvTime);

                    base.AddView(firstGroup);

                    base.AddView(tvRoom);
                }
            }
Exemple #20
0
        public SettingsListItem(Context context, IAttributeSet attrs) : base(context, attrs)
        {
            Android.Content.Res.TypedArray a = context.Theme.ObtainStyledAttributes(attrs, Resource.Styleable.SettingsListItem, 0, 0);

            try
            {
                base.SetPaddingRelative(ThemeHelper.AsPx(context, 16), ThemeHelper.AsPx(context, 8), ThemeHelper.AsPx(context, 16), ThemeHelper.AsPx(context, 8));

                ImageView icon = new ImageView(context)
                {
                    LayoutParameters = new LinearLayout.LayoutParams(
                        ThemeHelper.AsPx(context, 48),
                        ThemeHelper.AsPx(context, 48))
                    {
                        Gravity = GravityFlags.CenterVertical
                    }
                };

                Drawable iconDrawable = a.GetDrawable(Resource.Styleable.SettingsListItem_settingIcon);
                if (iconDrawable != null)
                {
                    icon.SetImageDrawable(iconDrawable);
                    if (Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
                    {
                        icon.ImageTintList = new Android.Content.Res.ColorStateList(new int[][] { new int[0] }, new int[] {
                            ColorTools.IsInNightMode(this.Context) ? new Color(84, 107, 199) : new Color(46, 54, 109)
                        });
                    }
                }

                base.AddView(icon);

                LinearLayout texts = new LinearLayout(context)
                {
                    Orientation      = Orientation.Vertical,
                    LayoutParameters = new LinearLayout.LayoutParams(
                        LinearLayout.LayoutParams.WrapContent,
                        LinearLayout.LayoutParams.WrapContent)
                    {
                        Gravity = GravityFlags.CenterVertical
                    }
                };
                texts.SetPaddingRelative(ThemeHelper.AsPx(context, 8), 0, 0, 0);

                string title = a.GetString(Resource.Styleable.SettingsListItem_settingTitle);
                _textViewTitle = new TextView(context)
                {
                    Text      = title ?? "title",
                    Ellipsize = Android.Text.TextUtils.TruncateAt.End
                };
                _textViewTitle.SetTypeface(_textViewTitle.Typeface, Android.Graphics.TypefaceStyle.Bold);
                _textViewTitle.SetSingleLine(true);
                _textViewTitle.SetTextColor(ColorTools.GetColor(this.Context, Resource.Color.foregroundFull));
                texts.AddView(_textViewTitle);

                string subtitle = a.GetString(Resource.Styleable.SettingsListItem_settingSubtitle);
                _textViewSubtitle = new TextView(context)
                {
                    Text      = subtitle ?? "",
                    Ellipsize = Android.Text.TextUtils.TruncateAt.End
                };
                _textViewSubtitle.SetSingleLine(true);
                texts.AddView(_textViewSubtitle);

                base.AddView(texts);
            }

#if DEBUG
            catch (Exception ex)
            {
                System.Diagnostics.Debugger.Break();
            }
#endif

            finally { a.Recycle(); }
        }
            public RemoteViews GetViewAt(int position)
            {
                try
                {
                    object item = _items[position];

                    if (item is DateTime)
                    {
                        var dateHeaderView = new RemoteViews(_context.PackageName, Resource.Layout.WidgetScheduleDateListItem);
                        dateHeaderView.SetTextViewText(Resource.Id.WidgetScheduleDateHeaderTextView, WidgetAgendaService.WidgetAgendaFactory.ToFriendlyDate((DateTime)item, _now));

                        return(dateHeaderView);
                    }

                    if (item is string)
                    {
                        // String represents "Nothing due!", etc
                        var emptyView = new RemoteViews(_context.PackageName, Resource.Layout.WidgetScheduleEmptyListItem);
                        emptyView.SetTextViewText(Resource.Id.WidgetScheduleEmptyListItemTextView, item as string);

                        return(emptyView);
                    }

                    if (item is ViewItemHoliday)
                    {
                        var holiday = item as ViewItemHoliday;

                        RemoteViews holidayView = new RemoteViews(_context.PackageName, Resource.Layout.WidgetScheduleHolidayListItem);
                        holidayView.SetTextViewText(Resource.Id.WidgetScheduleHolidayNameTextView, holiday.Name.Trim());
                        holidayView.SetInt(Resource.Id.WidgetScheduleHolidayListItem, "setBackgroundColor", Views.DayScheduleSnapshotView.HolidayColor);

                        Intent holidayIntent = new Intent()
                                               .SetAction(Intent.ActionView)
                                               .SetData(Android.Net.Uri.Parse("powerplanner:?" + new ViewHolidayArguments()
                        {
                            ItemId         = holiday.Identifier,
                            LaunchSurface  = LaunchSurface.SecondaryTile,
                            LocalAccountId = _localAccountId
                        }.SerializeToString()));
                        holidayView.SetOnClickFillInIntent(Resource.Id.WidgetScheduleHolidayListItem, holidayIntent);

                        return(holidayView);
                    }

                    var schedule = item as ViewItemSchedule;
                    var c        = schedule.Class;
                    if (c == null)
                    {
                        var emptyView = new RemoteViews(_context.PackageName, Resource.Layout.WidgetScheduleEmptyListItem);
                        return(emptyView);
                    }

                    bool hasRoom = !string.IsNullOrWhiteSpace(schedule.Room);

                    RemoteViews classView = new RemoteViews(_context.PackageName, hasRoom ? Resource.Layout.WidgetScheduleClassWithRoomListItem : Resource.Layout.WidgetScheduleClassListItem);
                    classView.SetTextViewText(Resource.Id.WidgetScheduleClassNameTextView, c.Name.Trim());
                    classView.SetTextViewText(Resource.Id.WidgetScheduleClassTimeTextView, Views.ListItems.MyScheduleItemView.GetStringTimeToTime(schedule));
                    if (hasRoom)
                    {
                        classView.SetTextViewText(Resource.Id.WidgetScheduleClassRoomTextView, schedule.Room.Trim());
                    }
                    classView.SetInt(Resource.Id.WidgetScheduleClassListItem, "setBackgroundColor", ColorTools.GetColor(c.Color));

                    Intent classIntent = new Intent()
                                         .SetAction(Intent.ActionView)
                                         .SetData(Android.Net.Uri.Parse("powerplanner:?" + new ViewClassArguments()
                    {
                        ItemId         = c.Identifier,
                        LaunchSurface  = LaunchSurface.SecondaryTile,
                        LocalAccountId = _localAccountId
                    }.SerializeToString()));
                    classView.SetOnClickFillInIntent(Resource.Id.WidgetScheduleClassListItem, classIntent);

                    return(classView);
                }
                catch (Exception ex)
                {
                    // Out of range exception can be expected since the items list can change while we're working
                    if (!(ex is ArgumentOutOfRangeException))
                    {
                        TelemetryExtension.Current?.TrackException(ex);
                    }

                    var emptyView = new RemoteViews(_context.PackageName, Resource.Layout.WidgetScheduleEmptyListItem);
                    return(emptyView);
                }
            }
            public MyScheduleItem(ViewItemSchedule s)
            {
                ViewItemClass c = s.Class as ViewItemClass;

                base.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Top;
                base.Background        = new SolidColorBrush(ColorTools.GetColor(c.Color));

                var timeSpan     = s.EndTime.TimeOfDay - s.StartTime.TimeOfDay;
                var hours        = timeSpan.TotalHours;
                var showTimeText = timeSpan.TotalMinutes >= 38;

                base.Height = Math.Max(HEIGHT_OF_HOUR * hours, 0);

                base.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });
                base.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });
                base.RowDefinitions.Add(new RowDefinition()
                {
                    Height = new GridLength(1, GridUnitType.Star)
                });

                base.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = GridLength.Auto
                });
                base.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = new GridLength(1, GridUnitType.Star)
                });

                TextBlock tbClass = new TextBlock()
                {
                    Text         = c.Name,
                    Style        = Application.Current.Resources["BaseTextBlockStyle"] as Style,
                    Foreground   = Brushes.White,
                    FontWeight   = FontWeights.SemiBold,
                    Margin       = new Windows.UI.Xaml.Thickness(6, 0, 6, 0),
                    TextWrapping = Windows.UI.Xaml.TextWrapping.NoWrap,
                    FontSize     = 14
                };

                Grid.SetColumnSpan(tbClass, 2);
                base.Children.Add(tbClass);

                // Add the time text (xx:xx to xx:xx) - do NOT show the date text for anything below 38 minutes as that will overlap with the title and get pushed beneath it.
                TextBlock tbTime = null;

                if (showTimeText)
                {
                    var timeFormatter = new DateTimeFormatter("shorttime");
                    tbTime = new TextBlock()
                    {
                        Text         = LocalizedResources.Common.GetStringTimeToTime(timeFormatter.Format(s.StartTime), timeFormatter.Format(s.EndTime)),
                        Style        = Application.Current.Resources["BaseTextBlockStyle"] as Style,
                        Foreground   = Brushes.White,
                        FontWeight   = FontWeights.SemiBold,
                        Margin       = new Windows.UI.Xaml.Thickness(6, -2, 6, 0),
                        TextWrapping = Windows.UI.Xaml.TextWrapping.NoWrap,
                        FontSize     = 14
                    };
                }

                TextBlock tbRoom = new TextBlock()
                {
                    Text         = s.Room,
                    Style        = Application.Current.Resources["BaseTextBlockStyle"] as Style,
                    Foreground   = Brushes.White,
                    FontWeight   = FontWeights.SemiBold,
                    Margin       = new Windows.UI.Xaml.Thickness(6, -2, 6, 0),
                    TextWrapping = Windows.UI.Xaml.TextWrapping.WrapWholeWords,
                    FontSize     = 14
                };

                if (hours >= 1.1)
                {
                    if (showTimeText)
                    {
                        Grid.SetRow(tbTime, 1);
                        Grid.SetColumnSpan(tbTime, 2);
                        base.Children.Add(tbTime);
                    }

                    if (!string.IsNullOrWhiteSpace(s.Room))
                    {
                        Grid.SetRow(tbRoom, showTimeText ? 2 : 1);
                        Grid.SetColumnSpan(tbRoom, 2);
                        base.Children.Add(tbRoom);
                    }
                }

                else
                {
                    if (showTimeText)
                    {
                        tbTime.Margin            = new Thickness(tbTime.Margin.Left, tbTime.Margin.Top, tbTime.Margin.Right, 8);
                        tbTime.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Bottom;
                        Grid.SetRow(tbTime, 2);
                        base.Children.Add(tbTime);
                    }

                    tbRoom.Margin            = new Thickness(tbRoom.Margin.Left, tbRoom.Margin.Top, tbRoom.Margin.Right, 8);
                    tbRoom.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Bottom;
                    tbRoom.TextAlignment     = TextAlignment.Right;
                    tbRoom.TextWrapping      = TextWrapping.NoWrap;
                    tbRoom.TextTrimming      = TextTrimming.CharacterEllipsis;
                    Grid.SetRow(tbRoom, showTimeText ? 2 : 1);
                    Grid.SetColumn(tbRoom, 1);
                    base.Children.Add(tbRoom);
                }
            }
        private async void appBarPin_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (!await PowerPlannerApp.Current.IsFullVersionAsync())
                {
                    PowerPlannerApp.Current.PromptPurchase(LocalizedResources.GetString("Settings_Tiles_ClassTile_PromptPremiumFeature"));
                    return;
                }

                if (ViewModel.Account == null || ViewModel.Class == null)
                {
                    return;
                }

                if ((appBarPin.Icon as SymbolIcon).Symbol == Symbol.Pin)
                {
                    var data = await AccountDataStore.Get(ViewModel.Account.LocalAccountId);

                    await ClassTileHelper.PinTileAsync(ViewModel.Account, data, ViewModel.Class.Identifier, ViewModel.Class.Name, ColorTools.GetColor(ViewModel.Class.Color));
                }

                else
                {
                    await ClassTileHelper.UnpinTile(ViewModel.Account.LocalAccountId, ViewModel.Class.Identifier);
                }

                UpdatePinButton();
            }

            catch (Exception ex)
            {
                TelemetryExtension.Current?.TrackException(ex);
            }
        }
            public RemoteViews GetViewAt(int position)
            {
                try
                {
                    object item = _items[position];

                    if (item is DateTime)
                    {
                        var dateHeaderView = new RemoteViews(_context.PackageName, Resource.Layout.WidgetAgendaDateListItem);
                        dateHeaderView.SetTextViewText(Resource.Id.WidgetAgendaDateHeaderTextView, ToFriendlyDate((DateTime)item, _now));

                        return(dateHeaderView);
                    }

                    if (item is string)
                    {
                        // String represents "Nothing due!", etc
                        var emptyView = new RemoteViews(_context.PackageName, Resource.Layout.WidgetAgendaEmptyListItem);
                        emptyView.SetTextViewText(Resource.Id.WidgetAgendaEmptyListItemTextView, item as string);

                        return(emptyView);
                    }

                    var task = item as BaseViewItemHomeworkExam;
                    var c    = task.GetClassOrNull();
                    if (c == null)
                    {
                        var emptyView = new RemoteViews(_context.PackageName, Resource.Layout.WidgetAgendaEmptyListItem);
                        return(emptyView);
                    }

                    RemoteViews taskView = new RemoteViews(_context.PackageName, Resource.Layout.WidgetAgendaTaskListItem);
                    taskView.SetTextViewText(Resource.Id.WidgetAgendaTaskTextView, task.Name);
                    taskView.SetInt(Resource.Id.WidgetAgendaTaskColorBar, "setBackgroundColor", ColorTools.GetColor(c.Color));

                    Intent taskIntent = new Intent()
                                        .SetAction(Intent.ActionView)
                                        .SetData(Android.Net.Uri.Parse("powerplanner:?" + ArgumentsHelper.CreateArgumentsForView(task, _localAccountId).SerializeToString()));
                    taskView.SetOnClickFillInIntent(Resource.Id.WidgetAgendaTaskListItem, taskIntent);

                    return(taskView);
                }
                catch (Exception ex)
                {
                    // Out of range exception can be expected since the items list can change while we're working
                    if (!(ex is ArgumentOutOfRangeException))
                    {
                        TelemetryExtension.Current?.TrackException(ex);
                    }

                    var emptyView = new RemoteViews(_context.PackageName, Resource.Layout.WidgetAgendaEmptyListItem);
                    return(emptyView);
                }
            }