summaryrefslogtreecommitdiff
path: root/Juick
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2012-03-10 22:14:25 +0400
committerGravatar Vitaly Takmazov2012-03-10 22:14:25 +0400
commit2b387fb5626a57e3a6473eed66816df80152cd49 (patch)
tree0b2f2ede5dcc79c1adbb8b64c2296aaeed1416fb /Juick
parent4a664984f58b00493a61cb19fafc0ca01d35b930 (diff)
refactoring, tags
Diffstat (limited to 'Juick')
-rw-r--r--Juick/Api/Message.cs2
-rw-r--r--Juick/App.xaml.cs25
-rw-r--r--Juick/Juick.csproj2
-rw-r--r--Juick/MainPage.xaml8
-rw-r--r--Juick/MainPage.xaml.cs24
-rw-r--r--Juick/SampleData/MainViewModelSampleData.xaml3
-rw-r--r--Juick/ThreadView.xaml.cs12
-rw-r--r--Juick/ViewModels/MessageListViewModelBase.cs95
-rw-r--r--Juick/ViewModels/MessageViewModel.cs16
-rw-r--r--Juick/ViewModels/ThreadViewModel.cs72
10 files changed, 160 insertions, 99 deletions
diff --git a/Juick/Api/Message.cs b/Juick/Api/Message.cs
index 07cc874..e5b5611 100644
--- a/Juick/Api/Message.cs
+++ b/Juick/Api/Message.cs
@@ -20,7 +20,7 @@ namespace Juick.Api
public int Rid { get; set; }
public string Body { get; set; }
public User User { get; set; }
- public DateTime Timestamp { get; set; }
+ public string Timestamp { get; set; }
public int Replies { get; set; }
public List<string> Tags { get; set; }
public Photo Photo { get; set; }
diff --git a/Juick/App.xaml.cs b/Juick/App.xaml.cs
index 69dbe16..4057483 100644
--- a/Juick/App.xaml.cs
+++ b/Juick/App.xaml.cs
@@ -11,18 +11,29 @@ namespace Juick
{
public partial class App : Application
{
- private static MainViewModel viewModel = null;
+ private static MessageListViewModelBase _myfeed = null;
/// <summary>
- /// A static ViewModel used by the views to bind against.
+ /// A static _myfeed used by the views to bind against.
/// </summary>
- /// <returns>The MainViewModel object.</returns>
- public static MainViewModel ViewModel
+ /// <returns>The MessageListViewModelBase object.</returns>
+ public static MessageListViewModelBase MyFeedView
{
get
{
// Delay creation of the view model until necessary
- return viewModel ?? (viewModel = new MainViewModel());
+ return _myfeed ?? (_myfeed = new MessageListViewModelBase());
+ }
+ }
+
+ private static MessageListViewModelBase _last;
+
+ public static MessageListViewModelBase LastView
+ {
+ get
+ {
+ return _last ??
+ (_last = new MessageListViewModelBase {RestUri = "/messages?1=1&rnd=" + Environment.TickCount});
}
}
@@ -93,9 +104,9 @@ namespace Juick
private void Application_Activated(object sender, ActivatedEventArgs e)
{
// Ensure that application state is restored appropriately
- if (!App.ViewModel.IsDataLoaded)
+ if (!App.MyFeedView.IsDataLoaded)
{
- App.ViewModel.LoadData();
+ App.MyFeedView.LoadData();
}
}
diff --git a/Juick/Juick.csproj b/Juick/Juick.csproj
index 38e7a21..5460de0 100644
--- a/Juick/Juick.csproj
+++ b/Juick/Juick.csproj
@@ -93,7 +93,7 @@
<DependentUpon>ThreadView.xaml</DependentUpon>
</Compile>
<Compile Include="ViewModels\MessageViewModel.cs" />
- <Compile Include="ViewModels\MainViewModel.cs" />
+ <Compile Include="ViewModels\MessageListViewModelBase.cs" />
<Compile Include="ViewModels\ThreadViewModel.cs" />
</ItemGroup>
<ItemGroup>
diff --git a/Juick/MainPage.xaml b/Juick/MainPage.xaml
index 7c19bc1..3895188 100644
--- a/Juick/MainPage.xaml
+++ b/Juick/MainPage.xaml
@@ -12,7 +12,7 @@
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
- SupportedOrientations="Portrait" Orientation="Portrait"
+ SupportedOrientations="PortraitOrLandscape" Orientation="Portrait"
shell:SystemTray.IsVisible="False">
<FrameworkElement.Resources>
<ResourceDictionary>
@@ -30,7 +30,7 @@
<!--Use 'Orientation="Horizontal"' to enable a panel that lays out horizontally-->
<controls:PanoramaItem x:Name="MainPanoramaItem" Header="My feed" Margin="0, -40, 0, 0">
<!--Double line list with image placeholder and text wrapping-->
- <ListBox Margin="0,0,-12,0" ItemsSource="{Binding MyFeed}" SelectionChanged="ListBoxSelectionChanged">
+ <ListBox x:Name="Home" Margin="0,0,-12,0" ItemsSource="{Binding Items}" SelectionChanged="ListBoxSelectionChanged">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
@@ -79,7 +79,7 @@
</controls:PanoramaItem>
<controls:PanoramaItem x:Name="LastPanoramaItem" Header="Last" Margin="0, -40, 0, 0">
<!--Double line list with image placeholder and text wrapping-->
- <ListBox Margin="0,0,-12,0" ItemsSource="{Binding Last}" SelectionChanged="LastBoxSelectionChanged">
+ <ListBox x:Name="Last" Margin="0,0,-12,0" ItemsSource="{Binding Items}" SelectionChanged="LastBoxSelectionChanged">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
@@ -128,7 +128,7 @@
</Grid>
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
- <shell:ApplicationBarIconButton IconUri="/Images/appbar_button0.png" Text="New message" Click="ApplicationBarIconButtonClick1"/>
+ <shell:ApplicationBarIconButton IconUri="/Images/appbar_button0.png" Text="New post" Click="ApplicationBarIconButtonClick1"/>
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Refresh" Click="ApplicationBarIconButtonClick" />
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Sign out" Click="ApplicationBarMenuItemClick" />
diff --git a/Juick/MainPage.xaml.cs b/Juick/MainPage.xaml.cs
index 1654c1b..a7ba541 100644
--- a/Juick/MainPage.xaml.cs
+++ b/Juick/MainPage.xaml.cs
@@ -22,19 +22,24 @@ namespace Juick
InitializeComponent();
// Set the data context of the listbox control to the sample data
- DataContext = App.ViewModel;
+ Home.DataContext = App.MyFeedView;
+ Last.DataContext = App.LastView;
Loaded += MainPage_Loaded;
}
- // Load data for the ViewModel MyFeed
+ // Load data for the _viewModelBase Items
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
- if (!App.ViewModel.IsDataLoaded)
+ if (!App.MyFeedView.IsDataLoaded)
{
if (string.IsNullOrEmpty(App.Account.Credentials.UserName))
NavigationService.Navigate(new Uri("/LoginView.xaml", UriKind.Relative));
else
- App.ViewModel.LoadData();
+ {
+ App.MyFeedView.LoadData();
+ App.LastView.LoadData();
+ }
+
}
}
@@ -45,7 +50,7 @@ namespace Juick
return;
// Navigate to the new page
- NavigationService.Navigate(new Uri("/ThreadView.xaml?mid=" + App.ViewModel.MyFeed[((ListBox)sender).SelectedIndex].MID, UriKind.Relative));
+ NavigationService.Navigate(new Uri("/ThreadView.xaml?mid=" + App.MyFeedView.Items[((ListBox)sender).SelectedIndex].MID, UriKind.Relative));
// Reset selected index to -1 (no selection)
((ListBox)sender).SelectedIndex = -1;
@@ -58,7 +63,7 @@ namespace Juick
return;
// Navigate to the new page
- NavigationService.Navigate(new Uri(string.Format("/ThreadView.xaml?mid={0}&last=true", App.ViewModel.Last[((ListBox)sender).SelectedIndex].MID), UriKind.Relative));
+ NavigationService.Navigate(new Uri(string.Format("/ThreadView.xaml?mid={0}&last=true", App.LastView.Items[((ListBox)sender).SelectedIndex].MID), UriKind.Relative));
// Reset selected index to -1 (no selection)
((ListBox)sender).SelectedIndex = -1;
@@ -104,9 +109,10 @@ namespace Juick
private void ApplicationBarIconButtonClick(object sender, EventArgs e)
{
- App.ViewModel.MyFeed.Clear();
- App.ViewModel.Last.Clear();
- App.ViewModel.LoadData();
+ App.MyFeedView.Items.Clear();
+ App.LastView.Items.Clear();
+ App.MyFeedView.LoadData();
+ App.LastView.LoadData();
}
private void ApplicationBarMenuItemClick(object sender, EventArgs e)
diff --git a/Juick/SampleData/MainViewModelSampleData.xaml b/Juick/SampleData/MainViewModelSampleData.xaml
index 431ac33..c7b8bf8 100644
--- a/Juick/SampleData/MainViewModelSampleData.xaml
+++ b/Juick/SampleData/MainViewModelSampleData.xaml
@@ -1,8 +1,7 @@
<ViewModels:MainViewModel
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:local="clr-namespace:Juick" xmlns:ViewModels="clr-namespace:Juick.ViewModels"
- SampleProperty="Sample Text Property Value">
+ xmlns:local="clr-namespace:Juick" xmlns:ViewModels="clr-namespace:Juick.ViewModels">
<ViewModels:MainViewModel.MyFeed>
<ViewModels:MessageViewModel Username="design one" MessageText="Maecenas praesent accumsan bibendum" Status="Maecenas praesent accumsan bibendum dictumst eleifend facilisi faucibus habitant inceptos interdum lobortis nascetur"/>
diff --git a/Juick/ThreadView.xaml.cs b/Juick/ThreadView.xaml.cs
index c984dd1..eac9813 100644
--- a/Juick/ThreadView.xaml.cs
+++ b/Juick/ThreadView.xaml.cs
@@ -12,11 +12,11 @@ namespace Juick
public ThreadView()
{
InitializeComponent();
- model = new ThreadViewModel();
- DataContext = model;
+ Model = new ThreadViewModel();
+ DataContext = Model;
}
- public ThreadViewModel model;
+ public ThreadViewModel Model;
// When page is navigated to set data context to selected item in list
protected override void OnNavigatedTo(NavigationEventArgs e)
@@ -31,8 +31,8 @@ namespace Juick
if (NavigationContext.QueryString.TryGetValue("mid", out _mid))
{
int MID = int.Parse(_mid);
- model.Root = last ? App.ViewModel.Last.Single(i => i.MID == MID) : App.ViewModel.MyFeed.Single(i => i.MID == MID);
- model.LoadData();
+ Model.Mid = last ? App.LastView.Items.Single(i => i.MID == MID).MID : App.MyFeedView.Items.Single(i => i.MID == MID).MID;
+ Model.LoadData();
}
}
@@ -43,7 +43,7 @@ namespace Juick
return;
// Navigate to the new page
- var item = model.Items[((ListBox) sender).SelectedIndex];
+ var item = Model.Items[((ListBox) sender).SelectedIndex];
var destUri = string.Format("/NewPostView.xaml?mid={0}", item.MID);
if (item.RID > 0)
destUri += string.Format("&rid={0}", item.RID);
diff --git a/Juick/ViewModels/MessageListViewModelBase.cs b/Juick/ViewModels/MessageListViewModelBase.cs
new file mode 100644
index 0000000..6bbfd55
--- /dev/null
+++ b/Juick/ViewModels/MessageListViewModelBase.cs
@@ -0,0 +1,95 @@
+using System;
+using System.ComponentModel;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Net;
+using System.Runtime.Serialization.Json;
+using System.Collections.ObjectModel;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Media.Imaging;
+using Juick.Api;
+using RestSharp;
+
+namespace Juick.ViewModels
+{
+ public class MessageListViewModelBase : INotifyPropertyChanged
+ {
+ public MessageListViewModelBase()
+ {
+ this.Items = new ObservableCollection<MessageViewModel>();
+ }
+
+ public string RestUri { get; set; }
+
+ /// <summary>
+ /// A collection for MessageViewModel objects.
+ /// </summary>
+ public ObservableCollection<MessageViewModel> Items { get; private set; }
+
+ public bool IsDataLoaded
+ {
+ get;
+ private set;
+ }
+
+ /// <summary>
+ /// Creates and adds a few MessageViewModel objects into the Items collection.
+ /// </summary>
+ public void LoadData()
+ {
+ if (string.IsNullOrEmpty(RestUri))
+ {
+ RestUri = "/home?1=1" + "&rnd=" + Environment.TickCount;
+ }
+ var request = new RestRequest(RestUri);
+ App.Client.Authenticator = new HttpBasicAuthenticator(App.Account.Credentials.UserName, App.Account.Credentials.Password);
+ App.Client.ExecuteAsync<List<Message>>(request, response =>
+ {
+ if (response.StatusCode != HttpStatusCode.OK)
+ {
+ MessageBox.Show(response.StatusCode.ToString());
+ return;
+ }
+
+ var messages = response.Data;
+ Items.Clear();
+ messages.ForEach(post =>
+ {
+ var item = new MessageViewModel(post)
+ {
+ Status =
+ string.Format(
+ "Posted on: {0}, replies: {1}",
+ post.Timestamp,
+ post.Replies)
+ };
+ Items.Add(item);
+ var imageUri = new Uri(string.Format("http://i.juick.com/as/{0}.png", post.User.Uid), UriKind.Absolute);
+ item.UserAvatar = new BitmapImage
+ {
+ UriSource = imageUri
+ };
+ if (post.Photo != null)
+ {
+ item.Attachment = new BitmapImage { UriSource = new Uri(post.Photo.Small, UriKind.Absolute) };
+ }
+
+ });
+ NotifyPropertyChanged("Items");
+ });
+ }
+
+
+ public event PropertyChangedEventHandler PropertyChanged;
+ public void NotifyPropertyChanged(String propertyName)
+ {
+ PropertyChangedEventHandler handler = PropertyChanged;
+ if (null != handler)
+ {
+ handler(this, new PropertyChangedEventArgs(propertyName));
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Juick/ViewModels/MessageViewModel.cs b/Juick/ViewModels/MessageViewModel.cs
index 3a324c4..e120c5d 100644
--- a/Juick/ViewModels/MessageViewModel.cs
+++ b/Juick/ViewModels/MessageViewModel.cs
@@ -2,6 +2,7 @@
using System.ComponentModel;
using System.Net;
using System.Windows.Media.Imaging;
+using System.Linq;
using Juick.Api;
namespace Juick.ViewModels
@@ -19,10 +20,15 @@ namespace Juick.ViewModels
RID = message.Rid;
Username = message.User.UName;
MessageText = HttpUtility.HtmlDecode(message.Body);
+
+ if (message.Tags != null)
+ {
+ MessageText = string.Join(", ", message.Tags) + Environment.NewLine + MessageText;
+ }
}
private int _mid;
/// <summary>
- /// Sample ViewModel property; this property is used in the view to display its value using a Binding.
+ /// Sample _viewModelBase property; this property is used in the view to display its value using a Binding.
/// </summary>
/// <returns></returns>
public int MID
@@ -43,7 +49,7 @@ namespace Juick.ViewModels
private int _rid;
/// <summary>
- /// Sample ViewModel property; this property is used in the view to display its value using a Binding.
+ /// Sample _viewModelBase property; this property is used in the view to display its value using a Binding.
/// </summary>
/// <returns></returns>
public int RID
@@ -63,7 +69,7 @@ namespace Juick.ViewModels
}
private string _username;
/// <summary>
- /// Sample ViewModel property; this property is used in the view to display its value using a Binding.
+ /// Sample _viewModelBase property; this property is used in the view to display its value using a Binding.
/// </summary>
/// <returns></returns>
public string Username
@@ -112,7 +118,7 @@ namespace Juick.ViewModels
private string _messageText;
/// <summary>
- /// Sample ViewModel property; this property is used in the view to display its value using a Binding.
+ /// Sample _viewModelBase property; this property is used in the view to display its value using a Binding.
/// </summary>
/// <returns></returns>
public string MessageText
@@ -133,7 +139,7 @@ namespace Juick.ViewModels
private string _status;
/// <summary>
- /// Sample ViewModel property; this property is used in the view to display its value using a Binding.
+ /// Sample _viewModelBase property; this property is used in the view to display its value using a Binding.
/// </summary>
/// <returns></returns>
public string Status
diff --git a/Juick/ViewModels/ThreadViewModel.cs b/Juick/ViewModels/ThreadViewModel.cs
index a929700..e1f8152 100644
--- a/Juick/ViewModels/ThreadViewModel.cs
+++ b/Juick/ViewModels/ThreadViewModel.cs
@@ -1,73 +1,17 @@
using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.ComponentModel;
-using System.IO;
-using System.Net;
-using System.Net.Browser;
-using System.Runtime.Serialization.Json;
-using System.Windows.Media.Imaging;
-using Juick.Api;
-using RestSharp;
namespace Juick.ViewModels
{
- public class ThreadViewModel : INotifyPropertyChanged
+ public class ThreadViewModel : MessageListViewModelBase
{
- public ThreadViewModel()
+ private int _mid;
+ public int Mid
{
- this.Items = new ObservableCollection<MessageViewModel>();
- }
-
- /// <summary>
- /// A collection for MessageViewModel objects.
- /// </summary>
- public ObservableCollection<MessageViewModel> Items { get; private set; }
-
- public bool IsDataLoaded
- {
- get;
- private set;
- }
-
- public MessageViewModel Root { get; set; }
-
- /// <summary>
- /// Creates and adds a few MessageViewModel objects into the MyFeed collection.
- /// </summary>
- public void LoadData()
- {
- var request = new RestRequest("/thread?mid={mid}" + "&rnd=" + Environment.TickCount);
- request.AddUrlSegment("mid", string.Format("{0}",Root.MID));
- App.Client.Authenticator = new HttpBasicAuthenticator(App.Account.Credentials.UserName, App.Account.Credentials.Password);
- App.Client.ExecuteAsync<List<Message>>(request, response =>
- {
- var messages = response.Data;
- Items.Clear();
- messages.ForEach(post =>
- {
- var item = new MessageViewModel(post);
- Items.Add(item);
- var imageUri = new Uri(string.Format("http://i.juick.com/as/{0}.png", post.User.Uid), UriKind.Absolute);
- item.UserAvatar = new BitmapImage
- {
- UriSource = imageUri
- };
- item.NotifyPropertyChanged("UserAvatar");
- });
- IsDataLoaded = true;
- NotifyPropertyChanged("Items");
-
- });
- }
-
- public event PropertyChangedEventHandler PropertyChanged;
- private void NotifyPropertyChanged(String propertyName)
- {
- PropertyChangedEventHandler handler = PropertyChanged;
- if (null != handler)
- {
- handler(this, new PropertyChangedEventArgs(propertyName));
+ get { return _mid; }
+ set
+ {
+ _mid = value;
+ RestUri = string.Format("/thread?mid={0}", _mid) + "&rnd=" + Environment.TickCount;
}
}
}