diff options
-rw-r--r-- | Juick/DataTemplates/PostItemDataTemplate.xaml | 23 | ||||
-rw-r--r-- | Juick/Juick.csproj | 8 | ||||
-rw-r--r-- | Juick/UserFeed.xaml | 53 | ||||
-rw-r--r-- | Juick/UserFeed.xaml.cs | 82 | ||||
-rw-r--r-- | Juick/ViewModels/PageViewModel.cs | 2 | ||||
-rw-r--r-- | Juick/ViewModels/PostItem.cs | 3 | ||||
-rw-r--r-- | Juick/ViewModels/UserFeedViewModel.cs | 41 |
7 files changed, 204 insertions, 8 deletions
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 @@ <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:bindings="clr-namespace:Juick.Classes" - xmlns:usercontrols="clr-namespace:Juick.Controls" + xmlns:usercontrols="clr-namespace:Juick.Controls" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" > <DataTemplate x:Key="PostItemDataTemplate"> @@ -18,12 +18,21 @@ <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Image bindings:LowProfileImageLoader.UriSource="{Binding AvatarUri}" Grid.Row="0" Grid.Column="0" Margin="3" /> - <TextBlock Text="{Binding Username}" Grid.Row="0" Grid.Column="1" - Margin="5,0,5,5" VerticalAlignment="Top" - HorizontalAlignment="Left" - FontFamily="{StaticResource PhoneFontFamilySemiLight}" - FontSize="{StaticResource PhoneFontSizeLarge}" - Style="{StaticResource PhoneTextAccentStyle}" /> + <HyperlinkButton Grid.Row="0" Grid.Column="1" NavigateUri="{Binding UserfeedUri}" + > + <HyperlinkButton.Template> + <ControlTemplate TargetType="HyperlinkButton"> + <TextBlock Text="{Binding Username}" + Margin="5,0,5,5" VerticalAlignment="Top" + HorizontalAlignment="Left" + FontFamily="{StaticResource PhoneFontFamilySemiLight}" + FontSize="{StaticResource PhoneFontSizeLarge}" + Style="{StaticResource PhoneTextAccentStyle}" /> + </ControlTemplate> + </HyperlinkButton.Template> + </HyperlinkButton> + + <usercontrols:HyperLinkRichTextBox Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" TextWrapping="Wrap" HorizontalAlignment="Left" Foreground="{StaticResource PhoneForegroundBrush}" diff --git a/Juick/Juick.csproj b/Juick/Juick.csproj index 5270c65..f979405 100644 --- a/Juick/Juick.csproj +++ b/Juick/Juick.csproj @@ -107,11 +107,15 @@ <Compile Include="ThreadView.xaml.cs">
<DependentUpon>ThreadView.xaml</DependentUpon>
</Compile>
+ <Compile Include="UserFeed.xaml.cs">
+ <DependentUpon>UserFeed.xaml</DependentUpon>
+ </Compile>
<Compile Include="ViewModels\AppViewModel.cs" />
<Compile Include="ViewModels\LoginViewModel.cs" />
<Compile Include="ViewModels\PageViewModel.cs" />
<Compile Include="ViewModels\PostItem.cs" />
<Compile Include="ViewModels\ThreadViewModel.cs" />
+ <Compile Include="ViewModels\UserFeedViewModel.cs" />
<Compile Include="ViewModels\ViewModelBase.cs" />
</ItemGroup>
<ItemGroup>
@@ -143,6 +147,10 @@ <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
+ <Page Include="UserFeed.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:Compile</Generator>
+ </Page>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
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 @@ +<phone:PhoneApplicationPage + x:Class="Juick.UserFeed" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" + xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + FontFamily="{StaticResource PhoneFontFamilyNormal}" + FontSize="{StaticResource PhoneFontSizeNormal}" + Foreground="{StaticResource PhoneForegroundBrush}" + SupportedOrientations="Portrait" Orientation="Portrait" + mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480" + shell:SystemTray.IsVisible="True"> + + <!--LayoutRoot is the root grid where all page content is placed--> + <Grid x:Name="LayoutRoot" Background="Transparent" d:DataContext="{d:DesignData /SampleData/ThreadViewModelSampleData.xaml}"> + <Grid.RowDefinitions> + <RowDefinition Height="Auto"/> + <RowDefinition/> + </Grid.RowDefinitions> + + <!--TitlePanel contains the name of the application and page title--> + <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"> + <TextBlock x:Name="ApplicationTitle" Style="{StaticResource PhoneTextNormalStyle}" Text="{Binding Caption}"></TextBlock> + </StackPanel> + + <!--ContentPanel - place additional content here--> + <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> + <ListBox Margin="0,0,-12,0" ItemsSource="{Binding Items}" SelectionChanged="ListBox_SelectionChanged" DataContext="{Binding}" + ItemTemplate="{StaticResource PostItemDataTemplate}"> + <ListBox.ItemContainerStyle> + <Style TargetType="ListBoxItem"> + <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter> + </Style> + </ListBox.ItemContainerStyle> + </ListBox> + </Grid> + </Grid> + + <!--Sample code showing usage of ApplicationBar--> + <!--<phone:PhoneApplicationPage.ApplicationBar> + <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True"> + <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1"/> + <shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2"/> + <shell:ApplicationBar.MenuItems> + <shell:ApplicationBarMenuItem Text="MenuItem 1"/> + <shell:ApplicationBarMenuItem Text="MenuItem 2"/> + </shell:ApplicationBar.MenuItems> + </shell:ApplicationBar> + </phone:PhoneApplicationPage.ApplicationBar>--> + +</phone:PhoneApplicationPage> 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<PostItem>(); LoadMessagesPageCommand = new DelegateCommand<LinkUnlinkEventArgs>(CheckNewData, () => !context.IsDataLoading); - NavigateNextCommand = new DelegateCommand<SelectionChangedEventArgs>(NavigateToThread, () => true); + NavigateNextCommand = new DelegateCommand<SelectionChangedEventArgs>(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<ThreadViewModel>(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; } + } + } +} |