From 512f2d0dfd19a6f5e13a6c65537b0f0ca34de150 Mon Sep 17 00:00:00 2001 From: Donatas Adamonis Date: Mon, 29 May 2017 21:35:27 +0200 Subject: some changes --- .../ApartmentManager/ApartmentManager.csproj | 6 +- .../ApartmentManager/Assets/Person1.jpg | Bin 448838 -> 0 bytes .../ApartmentManager/Assets/Person2.jpg | Bin 48173 -> 0 bytes .../ApartmentManager/Assets/Person3.jpg | Bin 4614 -> 0 bytes ApartmentManager/ApartmentManager/Assets/plan.jpg | Bin 69301 -> 0 bytes .../Common/Controls/NavMenuListView.cs | 120 +++++++++++++++++++++ .../ApartmentManager/Controls/NavMenuListView.cs | 120 --------------------- .../ApartmentManager/Handler/ApartmentHandler.cs | 8 -- .../Singletons/CatalogSingleton.cs | 23 ++-- .../ViewModel/ApartmentViewModel.cs | 24 ++--- 10 files changed, 143 insertions(+), 158 deletions(-) delete mode 100644 ApartmentManager/ApartmentManager/Assets/Person1.jpg delete mode 100644 ApartmentManager/ApartmentManager/Assets/Person2.jpg delete mode 100644 ApartmentManager/ApartmentManager/Assets/Person3.jpg delete mode 100644 ApartmentManager/ApartmentManager/Assets/plan.jpg create mode 100644 ApartmentManager/ApartmentManager/Common/Controls/NavMenuListView.cs delete mode 100644 ApartmentManager/ApartmentManager/Controls/NavMenuListView.cs diff --git a/ApartmentManager/ApartmentManager/ApartmentManager.csproj b/ApartmentManager/ApartmentManager/ApartmentManager.csproj index 81f44b5..5f8866e 100644 --- a/ApartmentManager/ApartmentManager/ApartmentManager.csproj +++ b/ApartmentManager/ApartmentManager/ApartmentManager.csproj @@ -99,7 +99,7 @@ AppShell.xaml - + @@ -168,10 +168,6 @@ - - - - diff --git a/ApartmentManager/ApartmentManager/Assets/Person1.jpg b/ApartmentManager/ApartmentManager/Assets/Person1.jpg deleted file mode 100644 index edf9716..0000000 Binary files a/ApartmentManager/ApartmentManager/Assets/Person1.jpg and /dev/null differ diff --git a/ApartmentManager/ApartmentManager/Assets/Person2.jpg b/ApartmentManager/ApartmentManager/Assets/Person2.jpg deleted file mode 100644 index 4e67876..0000000 Binary files a/ApartmentManager/ApartmentManager/Assets/Person2.jpg and /dev/null differ diff --git a/ApartmentManager/ApartmentManager/Assets/Person3.jpg b/ApartmentManager/ApartmentManager/Assets/Person3.jpg deleted file mode 100644 index b9ed3a7..0000000 Binary files a/ApartmentManager/ApartmentManager/Assets/Person3.jpg and /dev/null differ diff --git a/ApartmentManager/ApartmentManager/Assets/plan.jpg b/ApartmentManager/ApartmentManager/Assets/plan.jpg deleted file mode 100644 index 54df873..0000000 Binary files a/ApartmentManager/ApartmentManager/Assets/plan.jpg and /dev/null differ diff --git a/ApartmentManager/ApartmentManager/Common/Controls/NavMenuListView.cs b/ApartmentManager/ApartmentManager/Common/Controls/NavMenuListView.cs new file mode 100644 index 0000000..9591ad1 --- /dev/null +++ b/ApartmentManager/ApartmentManager/Common/Controls/NavMenuListView.cs @@ -0,0 +1,120 @@ +using System; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Media; +using Windows.UI.Xaml.Media.Animation; + +namespace ApartmentManager.Controls +{ + /// + /// A specialized ListView to represent the items in the navigation menu. + /// + /// + /// This class handles the following: + /// 1. Sizes the panel that hosts the items so they fit in the hosting pane. Otherwise, the keyboard + /// may appear cut off on one side b/c the Pane clips instead of affecting layout. + /// 2. Provides a single selection experience where keyboard focus can move without changing selection. + /// Both the 'Space' and 'Enter' keys will trigger selection. The up/down arrow keys can move + /// keyboard focus without triggering selection. This is different than the default behavior when + /// SelectionMode == Single. The default behavior for a ListView in single selection requires using + /// the Ctrl + arrow key to move keyboard focus without triggering selection. Users won't expect + /// this type of keyboarding model on the nav menu. + /// + public class NavMenuListView : ListView + { + private SplitView _splitViewHost; + + public NavMenuListView() + { + SelectionMode = ListViewSelectionMode.Single; + IsItemClickEnabled = true; + ItemClick += ItemClickedHandler; + + // Locate the hosting SplitView control + Loaded += (s, a) => + { + var parent = VisualTreeHelper.GetParent(this); + while (parent != null && !(parent is SplitView)) + { + parent = VisualTreeHelper.GetParent(parent); + } + + if (parent != null) + { + _splitViewHost = parent as SplitView; + } + }; + } + + protected override void OnApplyTemplate() + { + base.OnApplyTemplate(); + + // Remove the entrance animation on the item containers. + for (int i = 0; i < ItemContainerTransitions.Count; i++) + { + if (ItemContainerTransitions[i] is EntranceThemeTransition) + { + ItemContainerTransitions.RemoveAt(i); + } + } + } + + /// + /// Mark the as selected and ensures everything else is not. + /// If the is null then everything is unselected. + /// + /// + public void SetSelectedItem(ListViewItem item) + { + int index = -1; + if (item != null) + { + index = IndexFromContainer(item); + } + + for (int i = 0; i < Items.Count; i++) + { + var lvi = (ListViewItem)ContainerFromIndex(i); + if (i != index) + { + lvi.IsSelected = false; + } + else if (i == index) + { + lvi.IsSelected = true; + } + } + } + + /// + /// Occurs when an item has been selected + /// + public event EventHandler ItemInvoked; + + private void ItemClickedHandler(object sender, ItemClickEventArgs e) + { + // Triggered when the item is selected using something other than a keyboard + var item = ContainerFromItem(e.ClickedItem); + InvokeItem(item); + } + + private void InvokeItem(object focusedItem) + { + SetSelectedItem(focusedItem as ListViewItem); + ItemInvoked?.Invoke(this, focusedItem as ListViewItem); + + if (_splitViewHost.IsPaneOpen && ( + _splitViewHost.DisplayMode == SplitViewDisplayMode.CompactOverlay || + _splitViewHost.DisplayMode == SplitViewDisplayMode.Overlay)) + { + _splitViewHost.IsPaneOpen = false; + } + + if (focusedItem is ListViewItem) + { + ((ListViewItem)focusedItem).Focus(FocusState.Programmatic); + } + } + } +} \ No newline at end of file diff --git a/ApartmentManager/ApartmentManager/Controls/NavMenuListView.cs b/ApartmentManager/ApartmentManager/Controls/NavMenuListView.cs deleted file mode 100644 index 9591ad1..0000000 --- a/ApartmentManager/ApartmentManager/Controls/NavMenuListView.cs +++ /dev/null @@ -1,120 +0,0 @@ -using System; -using Windows.UI.Xaml; -using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Media; -using Windows.UI.Xaml.Media.Animation; - -namespace ApartmentManager.Controls -{ - /// - /// A specialized ListView to represent the items in the navigation menu. - /// - /// - /// This class handles the following: - /// 1. Sizes the panel that hosts the items so they fit in the hosting pane. Otherwise, the keyboard - /// may appear cut off on one side b/c the Pane clips instead of affecting layout. - /// 2. Provides a single selection experience where keyboard focus can move without changing selection. - /// Both the 'Space' and 'Enter' keys will trigger selection. The up/down arrow keys can move - /// keyboard focus without triggering selection. This is different than the default behavior when - /// SelectionMode == Single. The default behavior for a ListView in single selection requires using - /// the Ctrl + arrow key to move keyboard focus without triggering selection. Users won't expect - /// this type of keyboarding model on the nav menu. - /// - public class NavMenuListView : ListView - { - private SplitView _splitViewHost; - - public NavMenuListView() - { - SelectionMode = ListViewSelectionMode.Single; - IsItemClickEnabled = true; - ItemClick += ItemClickedHandler; - - // Locate the hosting SplitView control - Loaded += (s, a) => - { - var parent = VisualTreeHelper.GetParent(this); - while (parent != null && !(parent is SplitView)) - { - parent = VisualTreeHelper.GetParent(parent); - } - - if (parent != null) - { - _splitViewHost = parent as SplitView; - } - }; - } - - protected override void OnApplyTemplate() - { - base.OnApplyTemplate(); - - // Remove the entrance animation on the item containers. - for (int i = 0; i < ItemContainerTransitions.Count; i++) - { - if (ItemContainerTransitions[i] is EntranceThemeTransition) - { - ItemContainerTransitions.RemoveAt(i); - } - } - } - - /// - /// Mark the as selected and ensures everything else is not. - /// If the is null then everything is unselected. - /// - /// - public void SetSelectedItem(ListViewItem item) - { - int index = -1; - if (item != null) - { - index = IndexFromContainer(item); - } - - for (int i = 0; i < Items.Count; i++) - { - var lvi = (ListViewItem)ContainerFromIndex(i); - if (i != index) - { - lvi.IsSelected = false; - } - else if (i == index) - { - lvi.IsSelected = true; - } - } - } - - /// - /// Occurs when an item has been selected - /// - public event EventHandler ItemInvoked; - - private void ItemClickedHandler(object sender, ItemClickEventArgs e) - { - // Triggered when the item is selected using something other than a keyboard - var item = ContainerFromItem(e.ClickedItem); - InvokeItem(item); - } - - private void InvokeItem(object focusedItem) - { - SetSelectedItem(focusedItem as ListViewItem); - ItemInvoked?.Invoke(this, focusedItem as ListViewItem); - - if (_splitViewHost.IsPaneOpen && ( - _splitViewHost.DisplayMode == SplitViewDisplayMode.CompactOverlay || - _splitViewHost.DisplayMode == SplitViewDisplayMode.Overlay)) - { - _splitViewHost.IsPaneOpen = false; - } - - if (focusedItem is ListViewItem) - { - ((ListViewItem)focusedItem).Focus(FocusState.Programmatic); - } - } - } -} \ No newline at end of file diff --git a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs index 52849aa..df38ecb 100644 --- a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs @@ -45,7 +45,6 @@ namespace ApartmentManager.Handler new MessageDialog(e.Message).ShowAsync(); } } - /// /// RESIDENT HANDLERS /// @@ -72,7 +71,6 @@ namespace ApartmentManager.Handler { try { - Resident resident = ApartmentViewModel.NewResident ?? new Resident(); resident.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; if (string.IsNullOrEmpty(resident.Picture)) @@ -97,7 +95,6 @@ namespace ApartmentManager.Handler { Resident resident = ApartmentViewModel.NewResident ?? new Resident(); resident.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; - ApiClient.DeleteData("api/residents/" + resident.ResidentId); GetApartmentResidents(); } @@ -113,7 +110,6 @@ namespace ApartmentManager.Handler { Resident resident = ApartmentViewModel.NewResident ?? new Resident(); resident.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; - ApiClient.PutData("api/residents/" + resident.ResidentId, resident); GetApartmentResidents(); } @@ -172,10 +168,8 @@ namespace ApartmentManager.Handler { Defect Defect = new Defect(); Defect.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; - var defectsFromDatabase = ApiClient.GetData("api/ApartmentDefects/" + Defect.ApartmentId); var defecttlist = JsonConvert.DeserializeObject>(defectsFromDatabase); - foreach (var defect in defecttlist) { var picturesFromDatabase = ApiClient.GetData("api/DefectPictures/" + defect.DefectId); @@ -221,11 +215,9 @@ namespace ApartmentManager.Handler defect.ApartmentId = ApartmentViewModel.UserSingleton.CurrentUser.ApartmentId; defect.Status = "New"; defect.UploadDate = DateTime.Now; - var response = ApiClient.PostData("api/defects/", defect); var defectResponse = JsonConvert.DeserializeObject(response); defect.DefectId = defectResponse.DefectId; - foreach (var picture in ApartmentViewModel.CatalogSingleton.DefectPictures) { picture.DefectId = defect.DefectId; diff --git a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs index 39f352e..689f08d 100644 --- a/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs +++ b/ApartmentManager/ApartmentManager/Singletons/CatalogSingleton.cs @@ -9,27 +9,26 @@ namespace ApartmentManager.Singletons { public class CatalogSingleton { - private static CatalogSingleton instance = new CatalogSingleton(); - - public static CatalogSingleton Instance => instance; - - + ////////// Singleton ////////// + private static CatalogSingleton _instance; + public static CatalogSingleton Instance => _instance ?? (_instance = new CatalogSingleton()); + ////////// For Apartment ////////// public Apartment Apartment { get; set; } + ////////// For Residents ////////// public ObservableCollection Residents { get; set; } + ////////// For Defects ////////// public ObservableCollection Defects { get; set; } - public ObservableCollection DefectPictures { get; set; } - public int DefectId { get; set; } - + public ObservableCollection DefectPictures { get; set; } public ObservableCollection DefectComments { get; set; } public Defect Defect { get; set; } + public int DefectId { get; set; } + ////////// Constructor ////////// private CatalogSingleton() { DefectComments = new ObservableCollection(); Residents = new ObservableCollection(); Defects = new ObservableCollection(); - DefectPictures = new ObservableCollection(); - - } - + DefectPictures = new ObservableCollection(); + } } } diff --git a/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs b/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs index 9c1542b..b84602d 100644 --- a/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs +++ b/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs @@ -17,20 +17,17 @@ namespace ApartmentManager.ViewModel { public class ApartmentViewModel : INotifyPropertyChanged { + ////////// Handler ////////// public ApartmentHandler ApartmentHandler { get; set; } + ////////// Singletons ////////// public CatalogSingleton CatalogSingleton { get; set; } public UserSingleton UserSingleton { get; set; } - - + ////////// Store Data From Interface////////// private User _newUser; private Resident _newResident; - private Defect _newDefect = new Defect(); + private Defect _newDefect; private DefectPicture _selectedDefectPicture; private DefectComments _newDefectComment; - - - - public static int ServerResponse { get; set; } ////////// Resident relay commands////////// public ICommand CreateResidentCommand { get; set; } public ICommand DeleteResidentCommand { get; set; } @@ -45,19 +42,20 @@ namespace ApartmentManager.ViewModel public ICommand CreateDefect { get; set; } public ICommand DefectInfo { get; set; } public ICommand CreateDefectComment { get; set; } + ////////// Constructor ////////// public ApartmentViewModel() { + ////////// Store Data From Interface instance ////////// NewUser = new User(); NewResident = new Resident(); - //NewDefect = new Defect(); + NewDefect = new Defect(); NewDefectComment = new DefectComments(); - SelectedDefectPicture = new DefectPicture(); + ////////// Handler ////////// ApartmentHandler = new ApartmentHandler(this); ////////// Singletons ////////// CatalogSingleton = CatalogSingleton.Instance; - UserSingleton = UserSingleton.Instance; - + UserSingleton = UserSingleton.Instance; ////////// User relay commands////////// UpdateUser = new RelayCommand(ApartmentHandler.UpdateUser); UploadUserPhoto = new RelayCommand(ApartmentHandler.UploadUserPhoto); @@ -73,7 +71,7 @@ namespace ApartmentManager.ViewModel DefectInfo = new RelayCommand(ApartmentHandler.GetDefectInfo); CreateDefectComment = new RelayCommand(ApartmentHandler.CreateDefectComment); } - + ////////// Store Data From Interface////////// public DefectComments NewDefectComment { get => _newDefectComment; @@ -119,8 +117,8 @@ namespace ApartmentManager.ViewModel OnPropertyChanged(); } } + ////////// INotifyPropertyChanged ////////// public event PropertyChangedEventHandler PropertyChanged; - [NotifyPropertyChangedInvocator] protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { -- cgit v1.2.3 From 6432c8e2f0a39c622800d6916b2854cd1c66ee03 Mon Sep 17 00:00:00 2001 From: Donatas Adamonis Date: Mon, 29 May 2017 21:50:31 +0200 Subject: asd --- .../ApartmentManager/ApartmentManager.csproj | 1 + .../ApartmentManager/Controls/NavMenuListView.cs | 120 +++++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 ApartmentManager/ApartmentManager/Controls/NavMenuListView.cs diff --git a/ApartmentManager/ApartmentManager/ApartmentManager.csproj b/ApartmentManager/ApartmentManager/ApartmentManager.csproj index 601b96b..1b3c63e 100644 --- a/ApartmentManager/ApartmentManager/ApartmentManager.csproj +++ b/ApartmentManager/ApartmentManager/ApartmentManager.csproj @@ -279,6 +279,7 @@ Designer + 14.0 diff --git a/ApartmentManager/ApartmentManager/Controls/NavMenuListView.cs b/ApartmentManager/ApartmentManager/Controls/NavMenuListView.cs new file mode 100644 index 0000000..9591ad1 --- /dev/null +++ b/ApartmentManager/ApartmentManager/Controls/NavMenuListView.cs @@ -0,0 +1,120 @@ +using System; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Media; +using Windows.UI.Xaml.Media.Animation; + +namespace ApartmentManager.Controls +{ + /// + /// A specialized ListView to represent the items in the navigation menu. + /// + /// + /// This class handles the following: + /// 1. Sizes the panel that hosts the items so they fit in the hosting pane. Otherwise, the keyboard + /// may appear cut off on one side b/c the Pane clips instead of affecting layout. + /// 2. Provides a single selection experience where keyboard focus can move without changing selection. + /// Both the 'Space' and 'Enter' keys will trigger selection. The up/down arrow keys can move + /// keyboard focus without triggering selection. This is different than the default behavior when + /// SelectionMode == Single. The default behavior for a ListView in single selection requires using + /// the Ctrl + arrow key to move keyboard focus without triggering selection. Users won't expect + /// this type of keyboarding model on the nav menu. + /// + public class NavMenuListView : ListView + { + private SplitView _splitViewHost; + + public NavMenuListView() + { + SelectionMode = ListViewSelectionMode.Single; + IsItemClickEnabled = true; + ItemClick += ItemClickedHandler; + + // Locate the hosting SplitView control + Loaded += (s, a) => + { + var parent = VisualTreeHelper.GetParent(this); + while (parent != null && !(parent is SplitView)) + { + parent = VisualTreeHelper.GetParent(parent); + } + + if (parent != null) + { + _splitViewHost = parent as SplitView; + } + }; + } + + protected override void OnApplyTemplate() + { + base.OnApplyTemplate(); + + // Remove the entrance animation on the item containers. + for (int i = 0; i < ItemContainerTransitions.Count; i++) + { + if (ItemContainerTransitions[i] is EntranceThemeTransition) + { + ItemContainerTransitions.RemoveAt(i); + } + } + } + + /// + /// Mark the as selected and ensures everything else is not. + /// If the is null then everything is unselected. + /// + /// + public void SetSelectedItem(ListViewItem item) + { + int index = -1; + if (item != null) + { + index = IndexFromContainer(item); + } + + for (int i = 0; i < Items.Count; i++) + { + var lvi = (ListViewItem)ContainerFromIndex(i); + if (i != index) + { + lvi.IsSelected = false; + } + else if (i == index) + { + lvi.IsSelected = true; + } + } + } + + /// + /// Occurs when an item has been selected + /// + public event EventHandler ItemInvoked; + + private void ItemClickedHandler(object sender, ItemClickEventArgs e) + { + // Triggered when the item is selected using something other than a keyboard + var item = ContainerFromItem(e.ClickedItem); + InvokeItem(item); + } + + private void InvokeItem(object focusedItem) + { + SetSelectedItem(focusedItem as ListViewItem); + ItemInvoked?.Invoke(this, focusedItem as ListViewItem); + + if (_splitViewHost.IsPaneOpen && ( + _splitViewHost.DisplayMode == SplitViewDisplayMode.CompactOverlay || + _splitViewHost.DisplayMode == SplitViewDisplayMode.Overlay)) + { + _splitViewHost.IsPaneOpen = false; + } + + if (focusedItem is ListViewItem) + { + ((ListViewItem)focusedItem).Focus(FocusState.Programmatic); + } + } + } +} \ No newline at end of file -- cgit v1.2.3