diff options
author | marcinzelent <marcin@zelent.net> | 2017-02-10 02:14:58 +0100 |
---|---|---|
committer | marcinzelent <marcin@zelent.net> | 2017-02-10 02:14:58 +0100 |
commit | 1a23ae92dfe4e6589fbc50e56993b8b965e21bcb (patch) | |
tree | d3c817455daa1fe3b639188d4d1d19224f2c2d6f | |
parent | 82686fa108e064c0584236d6aa121c1d007eecfc (diff) |
Added DeleteButton on each ListViewItem, added editing events functionality, improved UI, cleaned up project, fixed some bugs.
-rw-r--r-- | EventMaker/EventMaker/App.xaml | 55 | ||||
-rw-r--r-- | EventMaker/EventMaker/App.xaml.cs | 12 | ||||
-rw-r--r-- | EventMaker/EventMaker/Common/RelayArgCommand.cs | 69 | ||||
-rw-r--r-- | EventMaker/EventMaker/Converter/DateTimeConverter.cs | 12 | ||||
-rw-r--r-- | EventMaker/EventMaker/EventMaker.csproj | 17 | ||||
-rw-r--r-- | EventMaker/EventMaker/Handler/EventHandler.cs | 32 | ||||
-rw-r--r-- | EventMaker/EventMaker/Model/EventCatalogSingleton.cs | 9 | ||||
-rw-r--r-- | EventMaker/EventMaker/Persistency/PersistencyService.cs | 2 | ||||
-rw-r--r-- | EventMaker/EventMaker/View/CreateEventPage.xaml | 6 | ||||
-rw-r--r-- | EventMaker/EventMaker/View/CreateEventPage.xaml.cs | 11 | ||||
-rw-r--r-- | EventMaker/EventMaker/View/EditEventPage.xaml | 170 | ||||
-rw-r--r-- | EventMaker/EventMaker/View/EditEventPage.xaml.cs | 26 | ||||
-rw-r--r-- | EventMaker/EventMaker/View/EventItem.xaml | 15 | ||||
-rw-r--r-- | EventMaker/EventMaker/View/EventItem.xaml.cs | 27 | ||||
-rw-r--r-- | EventMaker/EventMaker/View/EventPage.xaml | 152 | ||||
-rw-r--r-- | EventMaker/EventMaker/View/EventPage.xaml.cs | 13 | ||||
-rw-r--r-- | EventMaker/EventMaker/ViewModel/EventViewModel.cs | 85 |
17 files changed, 519 insertions, 194 deletions
diff --git a/EventMaker/EventMaker/App.xaml b/EventMaker/EventMaker/App.xaml index 5b48429..6881b63 100644 --- a/EventMaker/EventMaker/App.xaml +++ b/EventMaker/EventMaker/App.xaml @@ -3,5 +3,60 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" RequestedTheme="Light"> + <Application.Resources> + <Style x:Key="EventsListViewItem" TargetType="ListViewItem"> + <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" /> + <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" /> + <Setter Property="Background" Value="White" /> + <Setter Property="Foreground" Value="{ThemeResource ListViewItemForeground}" /> + <Setter Property="TabNavigation" Value="Local" /> + <Setter Property="IsHoldingEnabled" Value="True" /> + <Setter Property="Padding" Value="0" /> + <Setter Property="Margin" Value="12,12,12,0"/> + <Setter Property="BorderThickness" Value="1"/> + <Setter Property="BorderBrush" Value="#DFE0E4"/> + <Setter Property="HorizontalContentAlignment" Value="Stretch" /> + <Setter Property="VerticalContentAlignment" Value="Center" /> + <Setter Property="MinWidth" Value="{ThemeResource ListViewItemMinWidth}" /> + <Setter Property="MinHeight" Value="{ThemeResource ListViewItemMinHeight}" /> + <Setter Property="AllowDrop" Value="False" /> + <Setter Property="UseSystemFocusVisuals" Value="True" /> + <Setter Property="FocusVisualMargin" Value="0" /> + <Setter Property="FocusVisualPrimaryBrush" Value="{ThemeResource ListViewItemFocusVisualPrimaryBrush}" /> + <Setter Property="FocusVisualPrimaryThickness" Value="2" /> + <Setter Property="FocusVisualSecondaryBrush" Value="{ThemeResource ListViewItemFocusVisualSecondaryBrush}" /> + <Setter Property="FocusVisualSecondaryThickness" Value="1" /> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="ListViewItem"> + <ListViewItemPresenter ContentTransitions="{TemplateBinding ContentTransitions}" + Control.IsTemplateFocusTarget="True" + SelectionCheckMarkVisualEnabled="{ThemeResource ListViewItemSelectionCheckMarkVisualEnabled}" + CheckBrush="{ThemeResource ListViewItemCheckBrush}" + CheckBoxBrush="{ThemeResource ListViewItemCheckBoxBrush}" + DragBackground="{ThemeResource ListViewItemDragBackground}" + DragForeground="{ThemeResource ListViewItemDragForeground}" + FocusBorderBrush="{ThemeResource ListViewItemFocusBorderBrush}" + FocusSecondaryBorderBrush="{ThemeResource ListViewItemFocusSecondaryBorderBrush}" + PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackground}" + PointerOverBackground="{ThemeResource ListViewItemBackgroundPointerOver}" + PointerOverForeground="{ThemeResource ListViewItemForegroundPointerOver}" + SelectedBackground="White" + SelectedForeground="{ThemeResource ListViewItemForegroundSelected}" + SelectedPointerOverBackground="White" + PressedBackground="{ThemeResource ListViewItemBackgroundPressed}" + SelectedPressedBackground="{ThemeResource ListViewItemBackgroundSelectedPressed}" + DisabledOpacity="{ThemeResource ListViewItemDisabledThemeOpacity}" + DragOpacity="{ThemeResource ListViewItemDragThemeOpacity}" + ReorderHintOffset="{ThemeResource ListViewItemReorderHintThemeOffset}" + HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" + VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" + ContentMargin="{TemplateBinding Padding}" + CheckMode="{ThemeResource ListViewItemCheckMode}" /> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + </Application.Resources> </Application> diff --git a/EventMaker/EventMaker/App.xaml.cs b/EventMaker/EventMaker/App.xaml.cs index 9e69362..154099a 100644 --- a/EventMaker/EventMaker/App.xaml.cs +++ b/EventMaker/EventMaker/App.xaml.cs @@ -32,11 +32,12 @@ namespace EventMaker /// <param name="e">Details about the launch request and process.</param> protected override void OnLaunched(LaunchActivatedEventArgs e) { -#if DEBUG - if (System.Diagnostics.Debugger.IsAttached) - { - DebugSettings.EnableFrameRateCounter = true; - } + //#if DEBUG + // if (System.Diagnostics.Debugger.IsAttached) + // { + // DebugSettings.EnableFrameRateCounter = true; + // } + //#endif ApplicationViewTitleBar titleBar = ApplicationView.GetForCurrentView().TitleBar; if (titleBar != null) @@ -44,7 +45,6 @@ namespace EventMaker titleBar.BackgroundColor = Color.FromArgb(255, 16, 110, 190); titleBar.ButtonBackgroundColor = Color.FromArgb(255, 16, 110, 190); } -#endif Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, diff --git a/EventMaker/EventMaker/Common/RelayArgCommand.cs b/EventMaker/EventMaker/Common/RelayArgCommand.cs deleted file mode 100644 index aab6319..0000000 --- a/EventMaker/EventMaker/Common/RelayArgCommand.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using System.Windows.Input; - -namespace EventMaker.Common -{ - public class RelayArgCommand : ICommand - { - private readonly Action _execute; - private readonly Func<bool> _canExecute; - /// <summary> - /// Raised when RaiseCanExecuteChanged is called. - /// </summary> - public event EventHandler CanExecuteChanged; - /// <summary> - /// Creates a new command that can always execute. - /// </summary> - /// <param name="execute">The execution logic.</param> - public RelayArgCommand(Action execute) : this(execute, null) - { - } - /// <summary> - /// Creates a new command. - /// </summary> - /// <param name="execute">The execution logic.</param> - /// <param name="canExecute">The execution status logic.</param> - public RelayArgCommand(Action execute, Func<bool> canExecute) - { - if (execute == null) throw new ArgumentNullException("execute"); - _execute = execute; - _canExecute = canExecute; - } - /// <summary> - /// Determines whether this <see cref="RelayCommand"/> can execute in its current state. - /// </summary> - /// <param name="parameter"> - /// Data used by the command. If the command does not require data to be passed, this object can be set to null. - /// </param> - /// <returns>true if this command can be executed; otherwise, false.</returns> - public bool CanExecute(object parameter) - { - return _canExecute == null ? true : _canExecute(); - } - /// <summary> - /// Executes the <see cref="RelayCommand"/> on the current command target. - /// </summary> - /// <param name="parameter"> - /// Data used by the command. If the command does not require data to be passed, this object can be set to null. - /// </param> - public void Execute(object parameter) - { - _execute(); - } - /// <summary> - /// Method used to raise the <see cref="CanExecuteChanged"/> event - /// to indicate that the return value of the <see cref="CanExecute"/> - /// method has changed. - /// </summary> - public void RaiseCanExecuteChanged() - { - var handler = CanExecuteChanged; - if (handler != null) - { - handler(this, EventArgs.Empty); - } - } - } - - -} diff --git a/EventMaker/EventMaker/Converter/DateTimeConverter.cs b/EventMaker/EventMaker/Converter/DateTimeConverter.cs deleted file mode 100644 index 9ee35ef..0000000 --- a/EventMaker/EventMaker/Converter/DateTimeConverter.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace EventMaker.Converter -{ - public class Converter - { - public static DateTime DateTimeOffsetAndTimeSetToDateTime(DateTimeOffset date, TimeSpan time) - { - return new DateTime(date.Year, date.Month, date.Day, time.Hours, time.Minutes, 0); - } - } -} diff --git a/EventMaker/EventMaker/EventMaker.csproj b/EventMaker/EventMaker/EventMaker.csproj index 422fe79..7972536 100644 --- a/EventMaker/EventMaker/EventMaker.csproj +++ b/EventMaker/EventMaker/EventMaker.csproj @@ -95,10 +95,7 @@ <Compile Include="App.xaml.cs"> <DependentUpon>App.xaml</DependentUpon> </Compile> - <Compile Include="Common\RelayArgCommand.cs" /> <Compile Include="Common\RelayCommand.cs" /> - <Compile Include="Converter\DateTimeConverter.cs" /> - <Compile Include="Handler\EventHandler.cs" /> <Compile Include="Model\Event.cs" /> <Compile Include="Model\EventCatalogSingleton.cs" /> <Compile Include="Persistency\PersistencyService.cs" /> @@ -107,6 +104,12 @@ <Compile Include="View\CreateEventPage.xaml.cs"> <DependentUpon>CreateEventPage.xaml</DependentUpon> </Compile> + <Compile Include="View\EditEventPage.xaml.cs"> + <DependentUpon>EditEventPage.xaml</DependentUpon> + </Compile> + <Compile Include="View\EventItem.xaml.cs"> + <DependentUpon>EventItem.xaml</DependentUpon> + </Compile> <Compile Include="View\EventPage.xaml.cs"> <DependentUpon>EventPage.xaml</DependentUpon> </Compile> @@ -137,6 +140,14 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> + <Page Include="View\EditEventPage.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> + <Page Include="View\EventItem.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> <Page Include="View\EventPage.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> diff --git a/EventMaker/EventMaker/Handler/EventHandler.cs b/EventMaker/EventMaker/Handler/EventHandler.cs deleted file mode 100644 index 448e007..0000000 --- a/EventMaker/EventMaker/Handler/EventHandler.cs +++ /dev/null @@ -1,32 +0,0 @@ -using EventMaker.Model; -using EventMaker.ViewModel; - -namespace EventMaker.Handler -{ - public class EventHandler - { - public EventViewModel EventViewModel { get; set; } - public EventHandler(EventViewModel eventViewModel) - { - EventViewModel=eventViewModel; - } - - public void CreateEvent() - { - EventViewModel.EventCatalogSingleton.Add(new Event() - { - Id = EventViewModel.Id, - Name = EventViewModel.Name, - Description = EventViewModel.Description, - DateTime = Converter.Converter.DateTimeOffsetAndTimeSetToDateTime(EventViewModel.Date,EventViewModel.Time), - Place = EventViewModel.Place - }); - } - - public void DeleteEvent() - { - EventViewModel.EventCatalogSingleton.Remove(EventViewModel.EventCatalogSingleton.Events[EventViewModel.SelectedEventIndex]); - EventViewModel.SelectedEventIndex = 0; - } - } -} diff --git a/EventMaker/EventMaker/Model/EventCatalogSingleton.cs b/EventMaker/EventMaker/Model/EventCatalogSingleton.cs index b309870..df5d30c 100644 --- a/EventMaker/EventMaker/Model/EventCatalogSingleton.cs +++ b/EventMaker/EventMaker/Model/EventCatalogSingleton.cs @@ -30,9 +30,14 @@ namespace EventMaker.Model { Events = await Persistency.PersistencyService.LoadEventsFromJsonAsync() ?? new ObservableCollection<Event>(); } - public void Remove(Event eventToBeRemoved) + public void Remove(int index) { - Events.Remove(eventToBeRemoved); + Events.RemoveAt(index); + Persistency.PersistencyService.SaveEventsAsJsonAsync(Events); + } + public void Update(int index, Event eventToUpdate) + { + Events[index] = eventToUpdate; Persistency.PersistencyService.SaveEventsAsJsonAsync(Events); } public ObservableCollection<Event> Events { get; set; } diff --git a/EventMaker/EventMaker/Persistency/PersistencyService.cs b/EventMaker/EventMaker/Persistency/PersistencyService.cs index a3b7808..4688b66 100644 --- a/EventMaker/EventMaker/Persistency/PersistencyService.cs +++ b/EventMaker/EventMaker/Persistency/PersistencyService.cs @@ -12,11 +12,13 @@ namespace EventMaker.Persistency { private static readonly StorageFolder LocalFolder = ApplicationData.Current.LocalFolder; private static StorageFile _eventsFile; + public static async void SaveEventsAsJsonAsync(ObservableCollection<Event> events) { _eventsFile = await LocalFolder.CreateFileAsync("events.json",CreationCollisionOption.OpenIfExists); File.WriteAllText(_eventsFile.Path, JsonConvert.SerializeObject(events)); } + public static async Task<ObservableCollection<Event>> LoadEventsFromJsonAsync() { try diff --git a/EventMaker/EventMaker/View/CreateEventPage.xaml b/EventMaker/EventMaker/View/CreateEventPage.xaml index a6bf30b..30554bf 100644 --- a/EventMaker/EventMaker/View/CreateEventPage.xaml +++ b/EventMaker/EventMaker/View/CreateEventPage.xaml @@ -158,13 +158,13 @@ <Style BasedOn="{ StaticResource TextBoxStyle}" TargetType="TextBox"/> </StackPanel.Resources> <TextBlock FontSize="50" Text="Add Event" VerticalAlignment="Center" Margin="10,0,0,0"/> - <TextBox PlaceholderText="Name" Text="{Binding Name,Mode=TwoWay}" /> - <TextBox PlaceholderText="Description" Text="{Binding Description,Mode=TwoWay}" MinHeight="64" MaxHeight="320" TextWrapping="Wrap"/> + <TextBox PlaceholderText="Name" Text="{Binding EventTemplate.Name,Mode=TwoWay}" /> + <TextBox PlaceholderText="Description" Text="{Binding EventTemplate.Description,Mode=TwoWay}" MinHeight="64" MaxHeight="320" TextWrapping="Wrap"/> <StackPanel Orientation="Horizontal"> <CalendarDatePicker Date="{Binding Date,Mode=TwoWay}" Margin="10,0,10,10" BorderThickness="1"/> <TimePicker Time="{Binding Time,Mode=TwoWay}" Margin="10,0,10,10" Style="{StaticResource TimePickerStyle1}"/> </StackPanel> - <TextBox PlaceholderText="Place" Text="{Binding Place,Mode=TwoWay}"/> + <TextBox PlaceholderText="Place" Text="{Binding EventTemplate.Place,Mode=TwoWay}"/> <Button Height="32" Width="84" Content="Add" Command="{Binding CreateEventCommand}" HorizontalAlignment="Right" Margin="0,0,10,0" Background="#FF106EBE" Foreground="White" Click="GoToEventPage"/> </StackPanel> </Grid> diff --git a/EventMaker/EventMaker/View/CreateEventPage.xaml.cs b/EventMaker/EventMaker/View/CreateEventPage.xaml.cs index 8bdcf5c..9035ff9 100644 --- a/EventMaker/EventMaker/View/CreateEventPage.xaml.cs +++ b/EventMaker/EventMaker/View/CreateEventPage.xaml.cs @@ -1,4 +1,5 @@ using Windows.UI.Core; +using Windows.UI.Xaml; namespace EventMaker.View { @@ -13,15 +14,11 @@ namespace EventMaker.View } private void OnBackRequested(object sender, BackRequestedEventArgs e) { - if (Frame.CanGoBack) - { - Frame.GoBack(); - e.Handled = true; - currentView.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed; - } + Frame.Navigate(typeof(EventPage)); + currentView.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed; } - private void GoToEventPage(object sender, Windows.UI.Xaml.RoutedEventArgs e) + private void GoToEventPage(object sender, RoutedEventArgs e) { Frame.Navigate(typeof(EventPage)); currentView.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed; diff --git a/EventMaker/EventMaker/View/EditEventPage.xaml b/EventMaker/EventMaker/View/EditEventPage.xaml new file mode 100644 index 0000000..ea8747c --- /dev/null +++ b/EventMaker/EventMaker/View/EditEventPage.xaml @@ -0,0 +1,170 @@ +<Page + x:Class="EventMaker.View.EditEventPage" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:local="using:EventMaker.View" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:viewModel="using:EventMaker.ViewModel" + mc:Ignorable="d"> + + <Page.DataContext> + <viewModel:EventViewModel/> + </Page.DataContext> + + <Page.Resources> + <Style x:Key="TextBoxStyle" TargetType="TextBox"> + <Setter Property="Margin" Value="10,0,10,10"/> + <Setter Property="BorderThickness" Value="1"/> + </Style> + <Style x:Key="TimePickerStyle1" TargetType="TimePicker"> + <Setter Property="IsTabStop" Value="False"/> + <Setter Property="MinWidth" Value="200"/> + <Setter Property="MaxWidth" Value="456"/> + <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/> + <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}"/> + <Setter Property="Foreground" Value="{ThemeResource TimePickerButtonForeground}"/> + <Setter Property="HorizontalAlignment" Value="Left"/> + <Setter Property="VerticalAlignment" Value="Center"/> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="TimePicker"> + <StackPanel x:Name="LayoutRoot" Margin="{TemplateBinding Padding}"> + <StackPanel.Resources> + <Style x:Key="TimePickerFlyoutButtonStyle" TargetType="Button"> + <Setter Property="UseSystemFocusVisuals" Value="False"/> + <Setter Property="ElementSoundMode" Value="FocusOnly"/> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="Button"> + <Grid Background="{TemplateBinding Background}"> + <VisualStateManager.VisualStateGroups> + <VisualStateGroup x:Name="CommonStates"> + <VisualState x:Name="Normal"/> + <VisualState x:Name="PointerOver"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ContentPresenter"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TimePickerButtonBorderBrushPointerOver}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ContentPresenter"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TimePickerButtonBackgroundPointerOver}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TimePickerButtonForegroundPointerOver}"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + <VisualState x:Name="Pressed"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ContentPresenter"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TimePickerButtonBackgroundPressed}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ContentPresenter"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TimePickerButtonBorderBrushPressed}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TimePickerButtonForegroundPressed}"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + <VisualState x:Name="Disabled"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ContentPresenter"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TimePickerButtonBackgroundDisabled}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ContentPresenter"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TimePickerButtonBorderBrushDisabled}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TimePickerButtonForegroundDisabled}"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + </VisualStateGroup> + <VisualStateGroup x:Name="FocusStates"> + <VisualState x:Name="Focused"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ContentPresenter"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TimePickerButtonBackgroundFocused}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TimePickerButtonForegroundFocused}"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + <VisualState x:Name="Unfocused"/> + <VisualState x:Name="PointerFocused"/> + </VisualStateGroup> + </VisualStateManager.VisualStateGroups> + <ContentPresenter x:Name="ContentPresenter" AutomationProperties.AccessibilityView="Raw" BorderBrush="{ThemeResource TimePickerButtonBorderBrush}" BorderThickness="1" Background="{ThemeResource TimePickerButtonBackground}" Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"/> + </Grid> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + </StackPanel.Resources> + <VisualStateManager.VisualStateGroups> + <VisualStateGroup x:Name="CommonStates"> + <VisualState x:Name="Normal"/> + <VisualState x:Name="Disabled"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="HeaderContentPresenter"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TimePickerHeaderForegroundDisabled}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="FirstColumnDivider"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TimePickerSpacerFillDisabled}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="SecondColumnDivider"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TimePickerSpacerFillDisabled}"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + </VisualStateGroup> + </VisualStateManager.VisualStateGroups> + <ContentPresenter x:Name="HeaderContentPresenter" AutomationProperties.AccessibilityView="Raw" ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" Foreground="{ThemeResource TimePickerHeaderForeground}" Margin="0,0,0,8" Visibility="Collapsed" x:DeferLoadStrategy="Lazy"/> + <Button x:Name="FlyoutButton" Background="{TemplateBinding Background}" Foreground="{TemplateBinding Foreground}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" IsEnabled="{TemplateBinding IsEnabled}" Style="{StaticResource TimePickerFlyoutButtonStyle}"> + <Grid x:Name="FlyoutButtonContentGrid"> + <Grid.ColumnDefinitions> + <ColumnDefinition x:Name="FirstTextBlockColumn" Width="*"/> + <ColumnDefinition Width="Auto"/> + <ColumnDefinition x:Name="SecondTextBlockColumn" Width="*"/> + <ColumnDefinition Width="Auto"/> + <ColumnDefinition x:Name="ThirdTextBlockColumn" Width="*"/> + </Grid.ColumnDefinitions> + <Border x:Name="FirstPickerHost" Grid.Column="0"> + <TextBlock x:Name="HourTextBlock" AutomationProperties.AccessibilityView="Raw" FontWeight="{TemplateBinding FontWeight}" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" Padding="0,3,0,5" TextAlignment="Center"/> + </Border> + <Rectangle x:Name="FirstColumnDivider" Grid.Column="1" Fill="{ThemeResource TimePickerSpacerFill}" HorizontalAlignment="Center" Width="2"/> + <Border x:Name="SecondPickerHost" Grid.Column="2"> + <TextBlock x:Name="MinuteTextBlock" AutomationProperties.AccessibilityView="Raw" FontWeight="{TemplateBinding FontWeight}" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" Padding="0,3,0,5" TextAlignment="Center"/> + </Border> + <Rectangle x:Name="SecondColumnDivider" Grid.Column="3" Fill="{ThemeResource TimePickerSpacerFill}" HorizontalAlignment="Center" Width="2"/> + <Border x:Name="ThirdPickerHost" Grid.Column="4"> + <TextBlock x:Name="PeriodTextBlock" AutomationProperties.AccessibilityView="Raw" FontWeight="{TemplateBinding FontWeight}" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" Padding="0,3,0,5" TextAlignment="Center"/> + </Border> + </Grid> + </Button> + </StackPanel> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + </Page.Resources> + + <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> + <StackPanel MaxWidth="600"> + <StackPanel.Resources> + <Style BasedOn="{StaticResource TextBoxStyle}" TargetType="TextBox"/> + </StackPanel.Resources> + <TextBlock FontSize="50" Text="Edit Event" VerticalAlignment="Center" Margin="10,0,0,0"/> + <TextBox PlaceholderText="Name" Text="{Binding EventTemplate.Name,Mode=TwoWay}" /> + <TextBox PlaceholderText="Description" Text="{Binding EventTemplate.Description,Mode=TwoWay}" MinHeight="64" MaxHeight="320" TextWrapping="Wrap"/> + <StackPanel Orientation="Horizontal"> + <CalendarDatePicker Date="{Binding Date,Mode=TwoWay}" Margin="10,0,10,10" BorderThickness="1"/> + <TimePicker Time="{Binding Time,Mode=TwoWay}" Margin="10,0,10,10" Style="{StaticResource TimePickerStyle1}"/> + </StackPanel> + <TextBox PlaceholderText="Place" Text="{Binding EventTemplate.Place,Mode=TwoWay}"/> + <Button Height="32" Width="84" Content="Save" Command="{Binding UpdateEventCommand}" HorizontalAlignment="Right" Margin="0,0,10,0" Background="#FF106EBE" Foreground="White" Click="GoToEventPage"/> + </StackPanel> + </Grid> +</Page> diff --git a/EventMaker/EventMaker/View/EditEventPage.xaml.cs b/EventMaker/EventMaker/View/EditEventPage.xaml.cs new file mode 100644 index 0000000..61a3a0c --- /dev/null +++ b/EventMaker/EventMaker/View/EditEventPage.xaml.cs @@ -0,0 +1,26 @@ +using Windows.UI.Core; + +namespace EventMaker.View +{ + public sealed partial class EditEventPage + { + SystemNavigationManager currentView = SystemNavigationManager.GetForCurrentView(); + public EditEventPage() + { + InitializeComponent(); + currentView.BackRequested += OnBackRequested; + currentView.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible; + } + private void OnBackRequested(object sender, BackRequestedEventArgs e) + { + Frame.Navigate(typeof(EventPage)); + currentView.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed; + } + + private void GoToEventPage(object sender, Windows.UI.Xaml.RoutedEventArgs e) + { + Frame.Navigate(typeof(EventPage)); + currentView.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed; + } + } +} diff --git a/EventMaker/EventMaker/View/EventItem.xaml b/EventMaker/EventMaker/View/EventItem.xaml new file mode 100644 index 0000000..dded6c5 --- /dev/null +++ b/EventMaker/EventMaker/View/EventItem.xaml @@ -0,0 +1,15 @@ +<UserControl + x:Class="EventMaker.View.EventItem" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:local="using:EventMaker.View" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + mc:Ignorable="d" + d:DesignHeight="300" + d:DesignWidth="400"> + + <Grid> + + </Grid> +</UserControl> diff --git a/EventMaker/EventMaker/View/EventItem.xaml.cs b/EventMaker/EventMaker/View/EventItem.xaml.cs new file mode 100644 index 0000000..42b8c1a --- /dev/null +++ b/EventMaker/EventMaker/View/EventItem.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using Windows.Foundation; +using Windows.Foundation.Collections; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Controls.Primitives; +using Windows.UI.Xaml.Data; +using Windows.UI.Xaml.Input; +using Windows.UI.Xaml.Media; +using Windows.UI.Xaml.Navigation; + +// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236 + +namespace EventMaker.View +{ + public sealed partial class EventItem : UserControl + { + public EventItem() + { + this.InitializeComponent(); + } + } +} diff --git a/EventMaker/EventMaker/View/EventPage.xaml b/EventMaker/EventMaker/View/EventPage.xaml index fa8762a..7b4166a 100644 --- a/EventMaker/EventMaker/View/EventPage.xaml +++ b/EventMaker/EventMaker/View/EventPage.xaml @@ -8,6 +8,87 @@ xmlns:core="using:Microsoft.Xaml.Interactions.Core" x:Class="EventMaker.View.EventPage" mc:Ignorable="d"> + + <Page.Resources> + <Style x:Key="TextBlockStyle" TargetType="TextBlock"> + <Setter Property="Margin" Value="0,0,0,10"/> + <Setter Property="Foreground" Value="White"/> + </Style> + <ControlTemplate x:Key="DeleteButtonStyle" TargetType="Button"> + <Grid x:Name="RootGrid" Background="Transparent"> + <VisualStateManager.VisualStateGroups> + <VisualStateGroup x:Name="CommonStates"> + <VisualState x:Name="Normal"> + <Storyboard> + <PointerUpThemeAnimation Storyboard.TargetName="RootGrid" /> + </Storyboard> + </VisualState> + <VisualState x:Name="PointerOver"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootGrid" + Storyboard.TargetProperty="Background"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonBackgroundPointerOver}" /> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" + Storyboard.TargetProperty="Foreground"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonForegroundPointerOver}" /> + </ObjectAnimationUsingKeyFrames> + <PointerUpThemeAnimation Storyboard.TargetName="RootGrid" /> + </Storyboard> + </VisualState> + <VisualState x:Name="Pressed"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootGrid" + Storyboard.TargetProperty="Background"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonBackgroundPressed}" /> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" + Storyboard.TargetProperty="BorderBrush"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonBorderBrushPressed}" /> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" + Storyboard.TargetProperty="Foreground"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonForegroundPressed}" /> + </ObjectAnimationUsingKeyFrames> + <PointerDownThemeAnimation Storyboard.TargetName="RootGrid" /> + </Storyboard> + </VisualState> + <VisualState x:Name="Disabled"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootGrid" + Storyboard.TargetProperty="Background"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonBackgroundDisabled}" /> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" + Storyboard.TargetProperty="BorderBrush"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonBorderBrushDisabled}" /> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" + Storyboard.TargetProperty="Foreground"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonForegroundDisabled}" /> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + </VisualStateGroup> + </VisualStateManager.VisualStateGroups> + <ContentPresenter x:Name="ContentPresenter" + BorderBrush="{TemplateBinding BorderBrush}" + BorderThickness="{TemplateBinding BorderThickness}" + Content="{TemplateBinding Content}" + ContentTransitions="{TemplateBinding ContentTransitions}" + ContentTemplate="{TemplateBinding ContentTemplate}" + Padding="10" + HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" + VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" + AutomationProperties.AccessibilityView="Raw" /> + </Grid> + </ControlTemplate> + </Page.Resources> + + <Page.DataContext> + <viewModel:EventViewModel/> + </Page.DataContext> + <Page.BottomAppBar> <CommandBar> <CommandBar.Content> @@ -20,24 +101,71 @@ </core:EventTriggerBehavior> </interactivity:Interaction.Behaviors> </AppBarButton> - <AppBarButton Icon="Delete" Label="Delete Event" Command="{Binding DeleteEventCommand}"/> </CommandBar> </Page.BottomAppBar> - <Page.DataContext> - <viewModel:EventViewModel/> - </Page.DataContext> + <Grid Background="#E9EBEE"> + <ListView x:Name="EventsList" ItemsSource="{Binding EventCatalogSingleton.Events}" + SelectedIndex="{Binding SelectedEventIndex, Mode=TwoWay}"> - <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> - <ListView x:Name="EventsList" ItemsSource="{Binding EventCatalogSingleton.Events}" SelectedIndex="{Binding SelectedEventIndex, Mode=TwoWay}"> + <ListView.ItemContainerStyle> + <Style BasedOn="{StaticResource EventsListViewItem}" TargetType="ListViewItem"/> + </ListView.ItemContainerStyle> <ListView.ItemTemplate> + <DataTemplate> - <StackPanel> - <TextBlock Text="{Binding Name}" FontWeight="Bold" FontSize="18"/> - <TextBlock Text="{Binding Description}" FontStyle="Italic"/> - <TextBlock Text="{Binding DateTime}"/> - <TextBlock Text="{Binding Place}"/> - </StackPanel> + <Grid> + + <Grid.RowDefinitions> + <RowDefinition/> + <RowDefinition/> + </Grid.RowDefinitions> + <Grid Background="#FF106EBE" > + <Grid.ColumnDefinitions> + <ColumnDefinition Width="*"/> + <ColumnDefinition Width="50px"/> + </Grid.ColumnDefinitions> + <StackPanel Padding="10"> + <StackPanel.Resources> + <Style BasedOn="{StaticResource TextBlockStyle}" TargetType="TextBlock"/> + </StackPanel.Resources> + <TextBlock Text="{Binding Name}" FontWeight="Bold" FontSize="24" TextWrapping="Wrap"/> + <TextBlock Text="{Binding DateTime}" TextWrapping="Wrap"/> + <TextBlock Text="{Binding Place}" TextWrapping="Wrap"/> + </StackPanel> + <Button DataContext="{Binding ElementName=EventsList, Path=DataContext}" + Command="{Binding DeleteEventCommand}" + Template="{StaticResource DeleteButtonStyle}" + Grid.Column="1" + VerticalAlignment="Top" + HorizontalAlignment="Right" + Click="SelectEvent"> + <SymbolIcon Symbol="Clear" Foreground="White" ToolTipService.ToolTip="Delete"/> + </Button> + <Button DataContext="{Binding ElementName=EventsList, Path=DataContext}" + Command="{Binding LoadEventCommand}" + Template="{StaticResource DeleteButtonStyle}" + Grid.Column="1" + Margin="0,44,0,0" + VerticalAlignment="Top" + HorizontalAlignment="Right" + Click="SelectEvent"> + <SymbolIcon Symbol="Edit" Foreground="White" ToolTipService.ToolTip="Edit"/> + + <interactivity:Interaction.Behaviors> + <core:EventTriggerBehavior EventName="Click"> + <core:NavigateToPageAction TargetPage="EventMaker.View.EditEventPage"/> + </core:EventTriggerBehavior> + </interactivity:Interaction.Behaviors> + + </Button> + </Grid> + <TextBlock Grid.Row="1" + Text="{Binding Description}" + TextWrapping="Wrap" + Foreground="Black" + Padding="10"/> + </Grid> </DataTemplate> </ListView.ItemTemplate> </ListView> diff --git a/EventMaker/EventMaker/View/EventPage.xaml.cs b/EventMaker/EventMaker/View/EventPage.xaml.cs index f36b083..a94c488 100644 --- a/EventMaker/EventMaker/View/EventPage.xaml.cs +++ b/EventMaker/EventMaker/View/EventPage.xaml.cs @@ -1,4 +1,7 @@ -namespace EventMaker.View +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; + +namespace EventMaker.View { public sealed partial class EventPage { @@ -6,5 +9,13 @@ { InitializeComponent(); } + + private void SelectEvent(object sender, RoutedEventArgs e) + { + var item = ((Grid)((Button)sender).Parent).DataContext; + var container = (ListViewItem)EventsList.ContainerFromItem(item); + + container.IsSelected = true; + } } } diff --git a/EventMaker/EventMaker/ViewModel/EventViewModel.cs b/EventMaker/EventMaker/ViewModel/EventViewModel.cs index 468191b..d10ea79 100644 --- a/EventMaker/EventMaker/ViewModel/EventViewModel.cs +++ b/EventMaker/EventMaker/ViewModel/EventViewModel.cs @@ -1,7 +1,7 @@ using System; -using EventMaker.Model; using System.ComponentModel; using System.Runtime.CompilerServices; +using EventMaker.Model; using System.Windows.Input; using EventMaker.Annotations; using EventMaker.Common; @@ -10,72 +10,63 @@ namespace EventMaker.ViewModel { public class EventViewModel : INotifyPropertyChanged { - public Handler.EventHandler EventHandler { get; set; } - public static int SelectedEventIndex { get; set; } - private int _id; - private string _name, _place, _description; - private DateTimeOffset _date; - private TimeSpan _time; + private static Event _eventTemplate = new Event(); public EventCatalogSingleton EventCatalogSingleton { get; set; } + public static int SelectedEventIndex { get; set; } + public static DateTimeOffset Date { get; set; } = DateTimeOffset.Now; + public static TimeSpan Time { get; set; } public ICommand CreateEventCommand { get; set; } public ICommand DeleteEventCommand { get; set; } + public ICommand LoadEventCommand { get; set; } + public ICommand UpdateEventCommand { get; set; } - public int Id + public Event EventTemplate { - get { return _id; } + get { return _eventTemplate; } set { - _id = value; - OnPropertyChanged(nameof(Id)); + _eventTemplate = value; + OnPropertyChanged(nameof(EventTemplate)); } } - public string Name - { - get { return _name; } - set { _name = value; - OnPropertyChanged(nameof(Name)); - } - } - public string Place + + public EventViewModel() { - get { return _place; } - set { _place = value; - OnPropertyChanged(nameof(Place)); - } + EventCatalogSingleton = EventCatalogSingleton.Instance; + CreateEventCommand = new RelayCommand(CreateEvent); + DeleteEventCommand = new RelayCommand(DeleteEvent); + LoadEventCommand = new RelayCommand(LoadEvent); + UpdateEventCommand = new RelayCommand(UpdateEvent); } - public string Description + + private void CreateEvent() { - get { return _description; } - set { _description = value; - OnPropertyChanged(nameof(Description)); - } + EventTemplate.DateTime = new DateTime(Date.Year, Date.Month, Date.Day, Time.Hours, Time.Minutes, Time.Seconds); + EventCatalogSingleton.Add(EventTemplate); + EventTemplate=new Event(); + Date=DateTimeOffset.Now; } - public DateTimeOffset Date + + private void DeleteEvent() { - get { return _date; } - set { _date = value; - OnPropertyChanged(nameof(Date)); - } + EventCatalogSingleton.Remove(SelectedEventIndex); } - public TimeSpan Time + + private void LoadEvent() { - get { return _time; } - set { _time = value; - OnPropertyChanged(nameof(Time)); - } + EventTemplate = EventCatalogSingleton.Events[SelectedEventIndex]; + Date = new DateTimeOffset(EventTemplate.DateTime); + Time = new TimeSpan(EventTemplate.DateTime.Ticks); } - public EventViewModel() + + private void UpdateEvent() { - EventCatalogSingleton = EventCatalogSingleton.Instance; - EventHandler = new Handler.EventHandler(this); - CreateEventCommand = new RelayCommand(EventHandler.CreateEvent); - DeleteEventCommand = new RelayCommand(EventHandler.DeleteEvent); - DateTime dt = DateTime.Now; - _date = new DateTimeOffset(dt.Year, dt.Month, dt.Day, 0, 0, 0, 0, new TimeSpan()); - _time = new TimeSpan(dt.Hour, dt.Minute, dt.Second); + EventTemplate.DateTime = new DateTime(Date.Year, Date.Month, Date.Day, Time.Hours, Time.Minutes, Time.Seconds); + EventCatalogSingleton.Update(SelectedEventIndex,EventTemplate); + EventTemplate=new Event(); + Date = DateTimeOffset.Now; } - public event PropertyChangedEventHandler PropertyChanged; [NotifyPropertyChangedInvocator] |