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 0000000..c7b16cb Binary files /dev/null and b/main/MyFriendsAround.WP7/icons/anonymousIcon.png differ diff --git a/main/MyFriendsAround.WP7/icons/appbar.feature.settings.rest.png b/main/MyFriendsAround.WP7/icons/appbar.feature.settings.rest.png new file mode 100644 index 0000000..899b983 Binary files /dev/null and b/main/MyFriendsAround.WP7/icons/appbar.feature.settings.rest.png differ diff --git a/main/MyFriendsAround.Web/Controllers/HomeController.cs b/main/MyFriendsAround.Web/Controllers/HomeController.cs index 5644890..39eaae7 100644 --- a/main/MyFriendsAround.Web/Controllers/HomeController.cs +++ b/main/MyFriendsAround.Web/Controllers/HomeController.cs @@ -8,7 +8,7 @@ using MyFriendsAround.Data.BLL; namespace MyFriendsAround.Web.Controllers { - [HandleError] + //[HandleError] public class HomeController : Controller { public ActionResult Index() diff --git a/main/MyFriendsAround.Web/MyFriendsAround.Web.csproj b/main/MyFriendsAround.Web/MyFriendsAround.Web.csproj index 56f7c92..cc5ff59 100644 --- a/main/MyFriendsAround.Web/MyFriendsAround.Web.csproj +++ b/main/MyFriendsAround.Web/MyFriendsAround.Web.csproj @@ -52,6 +52,10 @@ + + ..\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 @@