From 833083ca0e29521b1fab4ea8889c5628cd7d8666 Mon Sep 17 00:00:00 2001 From: Claudiu Farcas Date: Wed, 30 Mar 2011 02:25:27 +0300 Subject: [PATCH] Settings Page (in work) Fixing Web hosting in Azure --- .../Entities/FriendExt.cs | 14 +- .../FriendsRepository.cs | 16 +- .../MyFriendsAround.BLL.csproj | 1 + main/MyFriendsAround.WP7/App.xaml.cs | 10 +- .../MyFriendsAround.WP7.csproj | 15 +- .../Utils/IsolatedStorageHelper.cs | 55 +++++++ .../ViewModel/MainViewModel.cs | 148 +++++++++++++++++- ...AboutViewModel.cs => SettingsViewModel.cs} | 4 +- .../ViewModel/ViewModelLocator.cs | 6 +- main/MyFriendsAround.WP7/Views/AboutPage.xaml | 35 ----- main/MyFriendsAround.WP7/Views/MainPage.xaml | 91 +++++++---- .../Views/SettingsPage.xaml | 83 ++++++++++ ...AboutPage.xaml.cs => SettingsPage.xaml.cs} | 4 +- .../icons/anonymousIcon.png | Bin 0 -> 2120 bytes .../icons/appbar.feature.settings.rest.png | Bin 0 -> 543 bytes .../Controllers/HomeController.cs | 2 +- .../MyFriendsAround.Web.csproj | 8 +- .../Views/Shared/_Layout.cshtml | 2 +- main/MyFriendsAround.Web/Web.config | 7 +- main/MyFriendsAround.Web/myfriends.svc.cs | 16 ++ .../ServiceConfiguration.cscfg | 2 +- 21 files changed, 414 insertions(+), 105 deletions(-) create mode 100644 main/MyFriendsAround.WP7/Utils/IsolatedStorageHelper.cs rename main/MyFriendsAround.WP7/ViewModel/{AboutViewModel.cs => SettingsViewModel.cs} (90%) delete mode 100644 main/MyFriendsAround.WP7/Views/AboutPage.xaml create mode 100644 main/MyFriendsAround.WP7/Views/SettingsPage.xaml rename main/MyFriendsAround.WP7/Views/{AboutPage.xaml.cs => SettingsPage.xaml.cs} (79%) create mode 100644 main/MyFriendsAround.WP7/icons/anonymousIcon.png create mode 100644 main/MyFriendsAround.WP7/icons/appbar.feature.settings.rest.png diff --git a/main/MyFriendsAround.Common/Entities/FriendExt.cs b/main/MyFriendsAround.Common/Entities/FriendExt.cs index e159441..87bcd4a 100644 --- a/main/MyFriendsAround.Common/Entities/FriendExt.cs +++ b/main/MyFriendsAround.Common/Entities/FriendExt.cs @@ -7,16 +7,10 @@ namespace MyFriendsAround.Common.Entities { public partial class Friend { - public virtual double Latitude - { - get; - set; - } - public virtual double Longitude - { - get; - set; - } + public virtual double Latitude { get; set; } + public virtual double Longitude { get; set; } + public virtual string PictureUrl { get; set; } + } } diff --git a/main/MyFriendsAround.Data.BLL/FriendsRepository.cs b/main/MyFriendsAround.Data.BLL/FriendsRepository.cs index 5709466..1a5c004 100644 --- a/main/MyFriendsAround.Data.BLL/FriendsRepository.cs +++ b/main/MyFriendsAround.Data.BLL/FriendsRepository.cs @@ -12,11 +12,16 @@ namespace MyFriendsAround.Data.BLL public static class FriendsRepository { public static List GetFriends() - { + { + return GetFriends(0, 50); + } + + public static List GetFriends(int skip, int take) + { using (MyFriendsModelContainer ctx = new MyFriendsModelContainer()) { ctx.ContextOptions.ProxyCreationEnabled = false; - List list = ctx.Friends.ToList(); + List list = ctx.Friends.OrderByDescending(f=> f.LastUpdated).Skip(skip).Take(take).ToList(); list.ForEach((f) => { SqlGeometry geom = SqlGeometry.Parse(f.LocationStr); @@ -59,5 +64,12 @@ namespace MyFriendsAround.Data.BLL return success; } } + + public static bool UpdatePicture(string userId, byte[] userPicture) + { + + return false; + } + } } diff --git a/main/MyFriendsAround.Data.BLL/MyFriendsAround.BLL.csproj b/main/MyFriendsAround.Data.BLL/MyFriendsAround.BLL.csproj index dd0890b..e542600 100644 --- a/main/MyFriendsAround.Data.BLL/MyFriendsAround.BLL.csproj +++ b/main/MyFriendsAround.Data.BLL/MyFriendsAround.BLL.csproj @@ -47,6 +47,7 @@ ..\Libs\Sql\Microsoft.SqlServer.Types.dll + True diff --git a/main/MyFriendsAround.WP7/App.xaml.cs b/main/MyFriendsAround.WP7/App.xaml.cs index 202d2aa..ecc04e9 100644 --- a/main/MyFriendsAround.WP7/App.xaml.cs +++ b/main/MyFriendsAround.WP7/App.xaml.cs @@ -89,21 +89,21 @@ namespace MyFriendsAround.WP7 { Container.Instance.RegisterInstance(new MainViewModel(), "MainViewModel"); } - AboutViewModel aboutModel = this.RetrieveFromIsolatedStorage(); - if (aboutModel != null) + SettingsViewModel settingsModel = this.RetrieveFromIsolatedStorage(); + if (settingsModel != null) { - Container.Instance.RegisterInstance(aboutModel, "AboutViewModel"); + Container.Instance.RegisterInstance(settingsModel, "SettingsViewModel"); } else { - Container.Instance.RegisterInstance(new AboutViewModel(), "AboutViewModel"); + Container.Instance.RegisterInstance(new SettingsViewModel(), "SettingsViewModel"); } } private void SaveModel() { this.SaveToIsolatedStorage(Container.Instance.Resolve("MainViewModel")); - this.SaveToIsolatedStorage(Container.Instance.Resolve("AboutViewModel")); + this.SaveToIsolatedStorage(Container.Instance.Resolve("SettingsViewModel")); } diff --git a/main/MyFriendsAround.WP7/MyFriendsAround.WP7.csproj b/main/MyFriendsAround.WP7/MyFriendsAround.WP7.csproj index a622537..7eddc51 100644 --- a/main/MyFriendsAround.WP7/MyFriendsAround.WP7.csproj +++ b/main/MyFriendsAround.WP7/MyFriendsAround.WP7.csproj @@ -141,11 +141,12 @@ + Code - - AboutPage.xaml + + SettingsPage.xaml Code @@ -161,7 +162,7 @@ - + @@ -176,7 +177,7 @@ MSBuild:Compile Designer - + Designer MSBuild:Compile @@ -197,6 +198,12 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + Always diff --git a/main/MyFriendsAround.WP7/Utils/IsolatedStorageHelper.cs b/main/MyFriendsAround.WP7/Utils/IsolatedStorageHelper.cs new file mode 100644 index 0000000..94dced0 --- /dev/null +++ b/main/MyFriendsAround.WP7/Utils/IsolatedStorageHelper.cs @@ -0,0 +1,55 @@ +using System; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Ink; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.IO; +using System.IO.IsolatedStorage; +using Microsoft.Phone; +using System.Windows.Media.Imaging; + +namespace MyFriendsAround.WP7.Utils +{ + public class IsolatedStorageHelper + { + + public static void SaveToLocalStorage(string imageFileName, string imageFolder, byte[] content) + { + if (content == null) + { + return; + } + + var isoFile = IsolatedStorageFile.GetUserStoreForApplication(); + if (!isoFile.DirectoryExists(imageFolder)) + { + isoFile.CreateDirectory(imageFolder); + } + + string filePath = Path.Combine(imageFolder, imageFileName); + using (var stream = isoFile.CreateFile(filePath)) + { + stream.Write(content, 0, content.Length); + } + } + + public static WriteableBitmap LoadFromLocalStorage(string imageFileName, string imageFolder) + { + var isoFile = IsolatedStorageFile.GetUserStoreForApplication(); + if (!isoFile.DirectoryExists(imageFolder)) + { + isoFile.CreateDirectory(imageFolder); + } + string filePath = Path.Combine(imageFolder, imageFileName); + using (var imageStream = isoFile.OpenFile(filePath, FileMode.Open, FileAccess.Read)) + { + var imageSource = PictureDecoder.DecodeJpeg(imageStream); + return imageSource; + } + } + } +} diff --git a/main/MyFriendsAround.WP7/ViewModel/MainViewModel.cs b/main/MyFriendsAround.WP7/ViewModel/MainViewModel.cs index 386c31c..85e1bb2 100644 --- a/main/MyFriendsAround.WP7/ViewModel/MainViewModel.cs +++ b/main/MyFriendsAround.WP7/ViewModel/MainViewModel.cs @@ -2,17 +2,23 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Device.Location; +using System.IO; using System.Net; using System.Security; using System.ServiceModel.Channels; using System.Windows; +using System.Windows.Controls; using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using Coding4Fun.Phone.Controls; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Messaging; using GalaSoft.MvvmLight.Threading; using Hammock; using Hammock.Serialization; +using Microsoft.Phone; using Microsoft.Phone.Controls; using Microsoft.Silverlight.Testing; using MyFriendsAround.Common.Entities; @@ -20,6 +26,7 @@ using MyFriendsAround.WP7.Service; using MyFriendsAround.WP7.Utils; using MyFriendsAround.WP7.Views; using Newtonsoft.Json; +using Microsoft.Phone.Tasks; namespace MyFriendsAround.WP7.ViewModel { @@ -53,6 +60,14 @@ namespace MyFriendsAround.WP7.ViewModel } } + public string PageNameSettings + { + get + { + return "Settings"; + } + } + /// /// Initializes a new instance of the MainViewModel class. /// @@ -61,8 +76,12 @@ namespace MyFriendsAround.WP7.ViewModel // PublishLocationCommand = new RelayCommand(() => PublishLocationAction()); DisplayAboutCommand = new RelayCommand(() => DisplayAbout()); - NavigateToAboutCommand = new RelayCommand(() => NavigateToAbout()); + NavigateToSettingsCommand = new RelayCommand(() => NavigateToSettings()); RefreshFriendsCommand = new RelayCommand(() => RefreshFriends()); + ShowAboutCommand = new RelayCommand(() => ShowAbout()); + SaveMySettingsCommand = new RelayCommand(() => SaveMySettings()); + CancelMySettingsCommand = new RelayCommand(() => CancelMySettings()); + ChoosePhotoCommand = new RelayCommand(() => ChoosePhoto()); if (IsInDesignMode) { @@ -75,16 +94,115 @@ namespace MyFriendsAround.WP7.ViewModel } + private void ChoosePhoto() + { + //choose photo + ShowCameraCaptureTask(); + //ShowPhotoChooserTask(); + } + + private void ShowPhotoChooserTask() + { + var photoChooserTask = new PhotoChooserTask(); + photoChooserTask.Completed += cameraTask_Completed; + photoChooserTask.Show(); + } + + private void ShowCameraCaptureTask() + { + var cameraTask = new CameraCaptureTask(); + cameraTask.Completed += cameraTask_Completed; + cameraTask.Show(); + } + + private void cameraTask_Completed(object sender, PhotoResult e) + { + if (e.TaskResult == TaskResult.OK) + { + // Get the image temp file from e.OriginalFileName. + // Get the image temp stream from e.ChosenPhoto. + // Don't keep either the stream or rely on the temp + // file name as they may be vanished! + + // Store the image bytes. + byte[] _imageBytes = new byte[e.ChosenPhoto.Length]; + e.ChosenPhoto.Read(_imageBytes, 0, _imageBytes.Length); + + // Seek back so we can create an image. + e.ChosenPhoto.Seek(0, SeekOrigin.Begin); + + // Create an image from the stream. + var imageSource = PictureDecoder.DecodeJpeg(e.ChosenPhoto); + MyPicture = imageSource; + } + } + + /// + /// The property's name. + /// + public const string MyPicturePropertyName = "MyPicture"; + private BitmapSource _myPicture = new BitmapImage(new Uri("/icons/anonymousIcon.png", UriKind.RelativeOrAbsolute)); + + /// + /// Gets the MyPicture property. + /// + public BitmapSource MyPicture + { + get + { + return _myPicture; + } + + set + { + if (_myPicture == value) + { + return; + } + + var oldValue = _myPicture; + _myPicture = value; + + // Update bindings, no broadcast + RaisePropertyChanged(MyPicturePropertyName); + + // Update bindings and broadcast change using GalaSoft.MvvmLight.Messenging + RaisePropertyChanged(MyPicturePropertyName, oldValue, value, true); + } + } + + + private void CancelMySettings() + { + //navigate back + this.PageNav.GoBack(); + } + + private void SaveMySettings() + { + //save settings locally and on the server + } + + private void ShowAbout() + { + // + var aboutPrompt = new AboutPrompt(); + aboutPrompt.Title = "About"; + aboutPrompt.Body = Environment.NewLine + "Created by Claudiu Farcas" + Environment.NewLine + Environment.NewLine + "@claudiufarcas" + Environment.NewLine + Environment.NewLine + "Please visit" + Environment.NewLine + Environment.NewLine + "http://www.vorienteering.com"; + aboutPrompt.VersionNumber = "1.0"; + aboutPrompt.Show(); + } + private void RefreshFriends() { IsBusy = true; ServiceAgent.GetFriends(this.GetFriendsResult); } - private void NavigateToAbout() + private void NavigateToSettings() { // - this.PageNav.NavigateTo(new Uri("/Views/AboutPage.xaml", UriKind.Relative)); + this.PageNav.NavigateTo(new Uri("/Views/SettingsPage.xaml", UriKind.Relative)); } @@ -193,8 +311,13 @@ namespace MyFriendsAround.WP7.ViewModel public ICommand PublishLocationCommand { get; set; } public ICommand DisplayAboutCommand { get; set; } - public ICommand NavigateToAboutCommand { get; set; } + public ICommand NavigateToSettingsCommand { get; set; } public ICommand RefreshFriendsCommand { get; set; } + public ICommand ShowAboutCommand { get; set; } + public ICommand SaveMySettingsCommand { get; set; } + public ICommand CancelMySettingsCommand { get; set; } + public ICommand ChoosePhotoCommand { get; set; } + /// @@ -228,6 +351,11 @@ namespace MyFriendsAround.WP7.ViewModel get { return "About"; } } + public string AppBarTextSettings + { + get { return "Settings"; } + } + public string AppBarTextPublish { get { return "Publish"; } @@ -238,6 +366,18 @@ namespace MyFriendsAround.WP7.ViewModel get { return "Refresh"; } } + public string AppBarTextSaveSettings + { + get { return "Save"; } + } + + public string AppBarTextCancelSettings + { + get { return "Cancel"; } + } + + + ////public override void Cleanup() ////{ //// // Clean up if needed diff --git a/main/MyFriendsAround.WP7/ViewModel/AboutViewModel.cs b/main/MyFriendsAround.WP7/ViewModel/SettingsViewModel.cs similarity index 90% rename from main/MyFriendsAround.WP7/ViewModel/AboutViewModel.cs rename to main/MyFriendsAround.WP7/ViewModel/SettingsViewModel.cs index bc435ac..19e23d6 100644 --- a/main/MyFriendsAround.WP7/ViewModel/AboutViewModel.cs +++ b/main/MyFriendsAround.WP7/ViewModel/SettingsViewModel.cs @@ -21,7 +21,7 @@ using Newtonsoft.Json; namespace MyFriendsAround.WP7.ViewModel { - public class AboutViewModel : ViewModelBase + public class SettingsViewModel : ViewModelBase { public string ApplicationTitle { @@ -43,7 +43,7 @@ namespace MyFriendsAround.WP7.ViewModel /// /// Initializes a new instance of the MainViewModel class. /// - public AboutViewModel() + public SettingsViewModel() { if (IsInDesignMode) { diff --git a/main/MyFriendsAround.WP7/ViewModel/ViewModelLocator.cs b/main/MyFriendsAround.WP7/ViewModel/ViewModelLocator.cs index c411286..3a42d0d 100644 --- a/main/MyFriendsAround.WP7/ViewModel/ViewModelLocator.cs +++ b/main/MyFriendsAround.WP7/ViewModel/ViewModelLocator.cs @@ -91,11 +91,11 @@ namespace MyFriendsAround.WP7.ViewModel /// /// Gets the About property. /// - public AboutViewModel About + public SettingsViewModel Settings { get { - AboutViewModel aboutViewModel = GetViewModel("AboutViewModel"); + SettingsViewModel aboutViewModel = GetViewModel("SettingsViewModel"); return aboutViewModel; } } @@ -108,7 +108,7 @@ namespace MyFriendsAround.WP7.ViewModel { MainViewModel mainViewModel = GetViewModel("MainViewModel"); mainViewModel.Cleanup(); - AboutViewModel aboutViewModel = GetViewModel("AboutViewModel"); + SettingsViewModel aboutViewModel = GetViewModel("SettingsViewModel"); aboutViewModel.Cleanup(); } diff --git a/main/MyFriendsAround.WP7/Views/AboutPage.xaml b/main/MyFriendsAround.WP7/Views/AboutPage.xaml deleted file mode 100644 index 106895a..0000000 --- a/main/MyFriendsAround.WP7/Views/AboutPage.xaml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/main/MyFriendsAround.WP7/Views/MainPage.xaml b/main/MyFriendsAround.WP7/Views/MainPage.xaml index 9bde0da..5a41441 100644 --- a/main/MyFriendsAround.WP7/Views/MainPage.xaml +++ b/main/MyFriendsAround.WP7/Views/MainPage.xaml @@ -51,23 +51,12 @@ - - - - - + Grid.Row="0" VerticalAlignment="Stretch" + Grid.RowSpan="2" + Margin="0"> - @@ -116,21 +95,67 @@ IsIndeterminate="{Binding Path=IsBusy}" /> + + + + + + + + + + + + + + + + + + BarOpacity="0.8"> - + - + diff --git a/main/MyFriendsAround.WP7/Views/SettingsPage.xaml b/main/MyFriendsAround.WP7/Views/SettingsPage.xaml new file mode 100644 index 0000000..dc16018 --- /dev/null +++ b/main/MyFriendsAround.WP7/Views/SettingsPage.xaml @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/main/MyFriendsAround.WP7/Views/AboutPage.xaml.cs b/main/MyFriendsAround.WP7/Views/SettingsPage.xaml.cs similarity index 79% rename from main/MyFriendsAround.WP7/Views/AboutPage.xaml.cs rename to main/MyFriendsAround.WP7/Views/SettingsPage.xaml.cs index 1d5c596..ed5bc41 100644 --- a/main/MyFriendsAround.WP7/Views/AboutPage.xaml.cs +++ b/main/MyFriendsAround.WP7/Views/SettingsPage.xaml.cs @@ -13,9 +13,9 @@ using Microsoft.Phone.Controls; namespace MyFriendsAround.WP7.Views { - public partial class AboutPage : PhoneApplicationPage + public partial class SettingsPage : PhoneApplicationPage { - public AboutPage() + public SettingsPage() { InitializeComponent(); } diff --git a/main/MyFriendsAround.WP7/icons/anonymousIcon.png b/main/MyFriendsAround.WP7/icons/anonymousIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..c7b16cb35daa3869280211b9e28ab6bb79100fca GIT binary patch literal 2120 zcmeHH`B&137yY=KA!<3_!f{3&og6i_Qcq4grKTe;k%pQskZ zZG%f%;RY^R4SE5qjhz4b$567^z_i_bOwXb z+uO@zGW+`aSS(h5fB(S1z~JEE(9qEE@GzUr=5RP%E_Y;PWOQ_NY;0_Ne4NMQO-xKo zPEJluO@03Sd3t)9&*uvSf|;3_+1c5-xw-lI`Gtjr#l^*?r6r+IxV*e95{blO@yg1I zL?V$&rK_u}GMP*+mn#&CFJHc_t*x!EuWxK@Y;JBUmCCKHt?ljY9drI)|C-2N3Rv_Ei>J4;BMS7;pkkKf{Mh2M+<0>ZCckF$e$1)0V>*g4rbA9YE( zuoJ2ZA5Zt7P;cRLC2|z1PjgRon-HhDy?sCY7?T&`T8YpP!dYtXhnlW!Z|A;#$xBWB z?PT%R&Avgi5$p(WjsKcwVPU1f+RB)&3O%vVVLckWO^BTfWkr)e(=$Cise5;GZk*hcY}S=lqOM55{Z3N`5s!vu!)oj@rM8 z4pb+?rW0PpJDw_GS$hM)!GoxX5TRFoty@vV!a=x~>MSbF-+EYbVNW41#qhd%XzIn< z{>(cPZ9{~mv4@eltpQpdnwgTydTXH*%|Vu>K+}3|1>9EVv^ocv{q-m>F6pLat1%Nn zdqFd}*jWWC{V8ul-Az%%thscRP{6N&+0OrJXzcZ6d81o13 zZ+VKqZTEj!JO~S~v&4k&*|yJGu=ZgLYPuXVbh~jJ28xR=e!QTj>KXYDf^fV3Mz1K( z)!?plJmZ}e`SLh9i?${vX!xsIFGo_JWbfN>`n}D=o_|9RCka45pKPMGw8|GWyPp5#{iFr;$Zb0vwnqY%Ri|b*S{bo zUAvg!6$aSYU*&vfVrIPv@o_X#awe?s!xIcUwDD^=cWs+e@-T;AYpAEFYC@?YHr^R*l%tM) zpaq&OQrypnXi!qa|Mv6k&xveaE$tVc&^q7<`gcsu-y$U_6||>K`rl{>P!$qt{aDd` zg?ci)c6+*DkasQEQyYsh?YhPhHQQJL|E@CSq}-B2)I2@R-uQ{*X!+1qP!~S>2*jw> z7k8M6nv*59Z!{ax1oB4zVlAQxGtRfo)z=cN!GD;D+wF4K5_xT45v+x1hQAbiq4E*$0lE3w{@R9MnC` z6r`6(A7JxUPiVQodB^(Yoq0O9osO-Nez~uNsi(2}M~&U2Qxco2Q?Bl2pU%M1fIuoM zR;^ml7_~vp=jboX>q|IKzZBuVvzm4H?0DWcG0xA~?wo(-?#EDcB$R#G0lNt4rV>kr zRaf|>tlzwl$q}=Nd+~#BcG^*0zJjy8%u6!nC(0$xNO%!*;-l#~|2sc@ZwWbVu${HT zAjd5|?#8!eKV&{wq?Inc@JM*acZV}u)_XH3{u6{1-oD!M + + ..\Libs\Sql\Microsoft.SqlServer.Types.dll + True + @@ -99,7 +103,9 @@ - + + Designer + Web.config diff --git a/main/MyFriendsAround.Web/Views/Shared/_Layout.cshtml b/main/MyFriendsAround.Web/Views/Shared/_Layout.cshtml index 1c8a044..5b288f0 100644 --- a/main/MyFriendsAround.Web/Views/Shared/_Layout.cshtml +++ b/main/MyFriendsAround.Web/Views/Shared/_Layout.cshtml @@ -11,7 +11,7 @@