From 1a9bcf2f3ac5f40e8966fb365741d36906fd2e52 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 8 May 2013 16:12:45 +0400 Subject: UserFeed --- Juick/DataTemplates/PostItemDataTemplate.xaml | 23 +++++--- Juick/Juick.csproj | 8 +++ Juick/UserFeed.xaml | 53 +++++++++++++++++ Juick/UserFeed.xaml.cs | 82 +++++++++++++++++++++++++++ Juick/ViewModels/PageViewModel.cs | 2 +- Juick/ViewModels/PostItem.cs | 3 + Juick/ViewModels/UserFeedViewModel.cs | 41 ++++++++++++++ 7 files changed, 204 insertions(+), 8 deletions(-) create mode 100644 Juick/UserFeed.xaml create mode 100644 Juick/UserFeed.xaml.cs create mode 100644 Juick/ViewModels/UserFeedViewModel.cs diff --git a/Juick/DataTemplates/PostItemDataTemplate.xaml b/Juick/DataTemplates/PostItemDataTemplate.xaml index 4668a48..fc2cba8 100644 --- a/Juick/DataTemplates/PostItemDataTemplate.xaml +++ b/Juick/DataTemplates/PostItemDataTemplate.xaml @@ -1,7 +1,7 @@  @@ -18,12 +18,21 @@ - + + + + + + + + + ThreadView.xaml + + UserFeed.xaml + + @@ -142,6 +146,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + diff --git a/Juick/UserFeed.xaml b/Juick/UserFeed.xaml new file mode 100644 index 0000000..464ef09 --- /dev/null +++ b/Juick/UserFeed.xaml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Juick/UserFeed.xaml.cs b/Juick/UserFeed.xaml.cs new file mode 100644 index 0000000..bfb7128 --- /dev/null +++ b/Juick/UserFeed.xaml.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Shapes; +using Microsoft.Phone.Controls; +using Juick.ViewModels; +using Microsoft.Phone.Shell; +using System.Windows.Data; +using System.Windows.Navigation; + +namespace Juick +{ + public partial class UserFeed : PhoneApplicationPage + { + public UserFeed() + { + InitializeComponent(); + Model = new UserFeedViewModel(App.AppContext); + DataContext = Model; + Loaded += (o, args) => + { + var progressIndicator = SystemTray.ProgressIndicator; + + if (progressIndicator != null) + { + return; + } + progressIndicator = new ProgressIndicator(); + + SystemTray.SetProgressIndicator(this, progressIndicator); + + Binding binding = new Binding("IsDataLoading") { Source = App.AppContext }; + + BindingOperations.SetBinding( + progressIndicator, ProgressIndicator.IsVisibleProperty, binding); + + binding = new Binding("IsDataLoading") { Source = App.AppContext }; + + BindingOperations.SetBinding( + progressIndicator, ProgressIndicator.IsIndeterminateProperty, binding); + }; + } + + public UserFeedViewModel Model; + // When page is navigated to set data context to selected item in list + protected override void OnNavigatedTo(NavigationEventArgs e) + { + if (Model.Items.Count > 0) + return; + string _uid = ""; + if (NavigationContext.QueryString.TryGetValue("uid", out _uid)) + { + Model.Uid = int.Parse(_uid); + } + Model.RefreshData(); + } + + private void ListBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) + { + // If selected index is -1 (no selection) do nothing + if (((ListBox)sender).SelectedIndex == -1) + return; + + // Navigate to the new page + var item = Model.Items[((ListBox)sender).SelectedIndex]; + var destUri = string.Format("/ThreadView.xaml?mid={0}", item.MID); + if (item.RID > 0) + destUri += string.Format("&rid={0}", item.RID); + NavigationService.Navigate(new Uri(destUri, UriKind.Relative)); + + // Reset selected index to -1 (no selection) + ((ListBox)sender).SelectedIndex = -1; + } + } +} \ No newline at end of file diff --git a/Juick/ViewModels/PageViewModel.cs b/Juick/ViewModels/PageViewModel.cs index ce48449..0d57f6a 100644 --- a/Juick/ViewModels/PageViewModel.cs +++ b/Juick/ViewModels/PageViewModel.cs @@ -19,7 +19,7 @@ namespace Juick.ViewModels _context = context; Items = new ObservableCollection(); LoadMessagesPageCommand = new DelegateCommand(CheckNewData, () => !context.IsDataLoading); - NavigateNextCommand = new DelegateCommand(NavigateToThread, () => true); + NavigateNextCommand = new DelegateCommand(NavigateToThread, () => true); } private readonly AppViewModel _context; diff --git a/Juick/ViewModels/PostItem.cs b/Juick/ViewModels/PostItem.cs index 88f6b86..a1b4ec5 100644 --- a/Juick/ViewModels/PostItem.cs +++ b/Juick/ViewModels/PostItem.cs @@ -20,6 +20,7 @@ namespace Juick.ViewModels Status = string.Format("{0}, replies: {1}", Status, message.Replies); MessageText = HttpUtility.HtmlDecode(message.Body); + UserfeedUri = new Uri(string.Format("/UserFeed.xaml?uid={0}", message.User.Uid), UriKind.Relative); if (message.Tags != null) { MessageText = string.Join(", ", message.Tags) + Environment.NewLine + MessageText; @@ -39,6 +40,8 @@ namespace Juick.ViewModels public Uri AvatarUri {get;set;} + public Uri UserfeedUri { get; set; } + public Uri Attachment {get;set;} public string Status {get;set;} diff --git a/Juick/ViewModels/UserFeedViewModel.cs b/Juick/ViewModels/UserFeedViewModel.cs new file mode 100644 index 0000000..597687f --- /dev/null +++ b/Juick/ViewModels/UserFeedViewModel.cs @@ -0,0 +1,41 @@ +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.Windows.Shapes; +using Juick.Classes; +using JuickApi; + +namespace Juick.ViewModels +{ + public class UserFeedViewModel : PageViewModel + { + public UserFeedViewModel(AppViewModel context) : base(context) + { + + } + static readonly string CaptionPropertyName = ExpressionHelper.GetPropertyName(x => x.Caption); + + private int _uid; + public int Uid + { + get { return _uid; } + set + { + _uid = value; + RestUri = string.Format("/messages?user_id={0}", _uid); + NotifyPropertyChanged(CaptionPropertyName); + } + } + + public override string Caption + { + get { return Items.Count == 0 ? "": Items[0].Username; } + } + } +} -- cgit v1.2.3