From 1a23ae92dfe4e6589fbc50e56993b8b965e21bcb Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Fri, 10 Feb 2017 02:14:58 +0100 Subject: Added DeleteButton on each ListViewItem, added editing events functionality, improved UI, cleaned up project, fixed some bugs. --- EventMaker/EventMaker/App.xaml | 55 +++++++ EventMaker/EventMaker/App.xaml.cs | 12 +- EventMaker/EventMaker/Common/RelayArgCommand.cs | 69 --------- .../EventMaker/Converter/DateTimeConverter.cs | 12 -- EventMaker/EventMaker/EventMaker.csproj | 17 ++- EventMaker/EventMaker/Handler/EventHandler.cs | 32 ---- .../EventMaker/Model/EventCatalogSingleton.cs | 9 +- .../EventMaker/Persistency/PersistencyService.cs | 2 + EventMaker/EventMaker/View/CreateEventPage.xaml | 6 +- EventMaker/EventMaker/View/CreateEventPage.xaml.cs | 11 +- EventMaker/EventMaker/View/EditEventPage.xaml | 170 +++++++++++++++++++++ EventMaker/EventMaker/View/EditEventPage.xaml.cs | 26 ++++ EventMaker/EventMaker/View/EventItem.xaml | 15 ++ EventMaker/EventMaker/View/EventItem.xaml.cs | 27 ++++ EventMaker/EventMaker/View/EventPage.xaml | 152 ++++++++++++++++-- EventMaker/EventMaker/View/EventPage.xaml.cs | 13 +- EventMaker/EventMaker/ViewModel/EventViewModel.cs | 85 +++++------ 17 files changed, 519 insertions(+), 194 deletions(-) delete mode 100644 EventMaker/EventMaker/Common/RelayArgCommand.cs delete mode 100644 EventMaker/EventMaker/Converter/DateTimeConverter.cs delete mode 100644 EventMaker/EventMaker/Handler/EventHandler.cs create mode 100644 EventMaker/EventMaker/View/EditEventPage.xaml create mode 100644 EventMaker/EventMaker/View/EditEventPage.xaml.cs create mode 100644 EventMaker/EventMaker/View/EventItem.xaml create mode 100644 EventMaker/EventMaker/View/EventItem.xaml.cs 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"> + + + 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 /// Details about the launch request and process. 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 _canExecute; - /// - /// Raised when RaiseCanExecuteChanged is called. - /// - public event EventHandler CanExecuteChanged; - /// - /// Creates a new command that can always execute. - /// - /// The execution logic. - public RelayArgCommand(Action execute) : this(execute, null) - { - } - /// - /// Creates a new command. - /// - /// The execution logic. - /// The execution status logic. - public RelayArgCommand(Action execute, Func canExecute) - { - if (execute == null) throw new ArgumentNullException("execute"); - _execute = execute; - _canExecute = canExecute; - } - /// - /// Determines whether this can execute in its current state. - /// - /// - /// Data used by the command. If the command does not require data to be passed, this object can be set to null. - /// - /// true if this command can be executed; otherwise, false. - public bool CanExecute(object parameter) - { - return _canExecute == null ? true : _canExecute(); - } - /// - /// Executes the on the current command target. - /// - /// - /// Data used by the command. If the command does not require data to be passed, this object can be set to null. - /// - public void Execute(object parameter) - { - _execute(); - } - /// - /// Method used to raise the event - /// to indicate that the return value of the - /// method has changed. - /// - 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 @@ App.xaml - - - @@ -107,6 +104,12 @@ CreateEventPage.xaml + + EditEventPage.xaml + + + EventItem.xaml + EventPage.xaml @@ -137,6 +140,14 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + Designer MSBuild:Compile 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(); } - 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 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 events) { _eventsFile = await LocalFolder.CreateFileAsync("events.json",CreationCollisionOption.OpenIfExists); File.WriteAllText(_eventsFile.Path, JsonConvert.SerializeObject(events)); } + public static async Task> 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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -20,24 +101,71 @@ - - - - + + - - + +