Subversion Repository Public Repository

Nextrek

Diff Revisions 659 vs 660 for /Android/SmartCharging/SmartCharging_WP/SmartCharging/StandardUserLoggedInPage.xaml.cs

Diff revisions: vs.
  @@ -1,9 +1,12 @@
1 1 using SmartCharging.Common;
2 + using SmartCharging.DataModel;
3 + using SmartCharging.Net;
2 4 using System;
3 5 using System.Collections.Generic;
4 6 using System.IO;
5 7 using System.Linq;
6 8 using System.Runtime.InteropServices.WindowsRuntime;
9 + using Windows.ApplicationModel.Resources;
7 10 using Windows.Foundation;
8 11 using Windows.Foundation.Collections;
9 12 using Windows.Graphics.Display;
  @@ -28,6 +31,10 @@
28 31 {
29 32 private NavigationHelper navigationHelper;
30 33 private ObservableDictionary defaultViewModel = new ObservableDictionary();
34 + private SmartChargeAPI SMA;
35 + private ErrorHandler errorHandler;
36 + private ResourceLoader resourceLoader;
37 + private SiteType selectedSiteType;
31 38
32 39 public StandardUserLoggedInPage()
33 40 {
  @@ -36,6 +43,9 @@
36 43 this.navigationHelper = new NavigationHelper(this);
37 44 this.navigationHelper.LoadState += this.NavigationHelper_LoadState;
38 45 this.navigationHelper.SaveState += this.NavigationHelper_SaveState;
46 + this.SMA = SmartChargeAPI.Instance;
47 + this.errorHandler = new ErrorHandler();
48 + resourceLoader = ResourceLoader.GetForCurrentView("Resources");
39 49 }
40 50
41 51 /// <summary>
  @@ -66,8 +76,27 @@
66 76 /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
67 77 /// a dictionary of state preserved by this page during an earlier
68 78 /// session. The state will be null the first time a page is visited.</param>
69 - private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
79 + private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
70 80 {
81 + User user = SMA.user;
82 + if (user == null)
83 + {
84 + await this.errorHandler.ShowError(resourceLoader.GetString("LoginNeededMessage"));
85 + }
86 + else {
87 + if (user.UserType == USER_TYPE.Owner)
88 + {
89 + this.ManageSiteButton.Visibility = Visibility.Visible;
90 + }
91 + else
92 + {
93 + this.ManageSiteButton.Visibility = Visibility.Collapsed;
94 + }
95 +
96 + }
97 +
98 + List<SiteType> types = await this.SMA.getSiteTypesList();
99 + this.SiteTypeList.ItemsSource = types;
71 100 }
72 101
73 102 /// <summary>
  @@ -117,7 +146,7 @@
117 146 private void RechargeNowButton_Tapped(object sender, TappedRoutedEventArgs e)
118 147 {
119 148 var aw = Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
120 - () => this.Frame.Navigate(typeof(MapPage)));
149 + () => this.Frame.Navigate(typeof(MapPage), this.selectedSiteType));
121 150 }
122 151
123 152 private void ManageSiteButton_Tapped(object sender, TappedRoutedEventArgs e)
  @@ -125,5 +154,23 @@
125 154 var aw = Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
126 155 () => this.Frame.Navigate(typeof(ManageSitePage)));
127 156 }
157 +
158 + private void ListBoxItem_Tapped(object sender, TappedRoutedEventArgs e)
159 + {
160 + this.SiteTypeButton.Flyout.Hide();
161 + SiteType selected = ((Control)sender).DataContext as SiteType;
162 + this.SiteTypeButton.Content = "Tipologia locale : " + selected.Label;
163 + this.selectedSiteType = selected;
164 + }
165 +
166 + private void showLoading()
167 + {
168 + this.Loader.Visibility = Visibility.Visible;
169 + }
170 +
171 + private void hideLoading()
172 + {
173 + this.Loader.Visibility = Visibility.Collapsed;
174 + }
128 175 }
129 176 }