summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Juick/Api/Message.cs15
-rw-r--r--Juick/Api/User.cs6
-rw-r--r--Juick/Juick.csproj10
-rw-r--r--Juick/MainPage.xaml60
-rw-r--r--Juick/SampleData/MainViewModelSampleData.xaml12
-rw-r--r--Juick/ViewModels/MainViewModel.cs49
-rw-r--r--Juick/ViewModels/MessageViewModel.cs33
-rw-r--r--Juick/ViewModels/ThreadViewModel.cs11
8 files changed, 104 insertions, 92 deletions
diff --git a/Juick/Api/Message.cs b/Juick/Api/Message.cs
index b4d4ddc..07cc874 100644
--- a/Juick/Api/Message.cs
+++ b/Juick/Api/Message.cs
@@ -14,14 +14,15 @@ using System.Runtime.Serialization.Json;
namespace Juick.Api
{
- [DataContract]
public class Message
{
- [DataMember] public int mid;
- [DataMember] public int rid;
- [DataMember] public string body;
- [DataMember] public User user;
- [DataMember] public DateTime timestamp;
- [DataMember] public int replies;
+ public int Mid { get; set; }
+ public int Rid { get; set; }
+ public string Body { get; set; }
+ public User User { get; set; }
+ public DateTime Timestamp { get; set; }
+ public int Replies { get; set; }
+ public List<string> Tags { get; set; }
+ public Photo Photo { get; set; }
}
}
diff --git a/Juick/Api/User.cs b/Juick/Api/User.cs
index f7bd6eb..cd823eb 100644
--- a/Juick/Api/User.cs
+++ b/Juick/Api/User.cs
@@ -12,10 +12,10 @@ using System.Windows.Shapes;
namespace Juick.Api
{
- [DataContract]
public class User
{
- [DataMember] public int uid;
- [DataMember] public string uname;
+ public int Uid { get; set; }
+ public string UName { get; set; }
+ public string Fullname { get; set; }
}
}
diff --git a/Juick/Juick.csproj b/Juick/Juick.csproj
index 73d65c1..38e7a21 100644
--- a/Juick/Juick.csproj
+++ b/Juick/Juick.csproj
@@ -52,8 +52,14 @@
<Reference Include="Microsoft.Phone.Controls" />
<Reference Include="Microsoft.Phone.Interop" />
<Reference Include="Microsoft.Xna.Framework" />
+ <Reference Include="Newtonsoft.Json">
+ <HintPath>..\packages\Newtonsoft.Json.4.0.8\lib\sl4-windowsphone71\Newtonsoft.Json.dll</HintPath>
+ </Reference>
<Reference Include="Newtonsoft.Json.WindowsPhone, Version=4.0.2.0, Culture=neutral, processorArchitecture=MSIL" />
- <Reference Include="RestSharp.WindowsPhone, Version=102.0.0.0, Culture=neutral, processorArchitecture=MSIL" />
+ <Reference Include="RestSharp.WindowsPhone, Version=102.7.0.0, Culture=neutral, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\packages\RestSharp.102.7\lib\sl4-wp71\RestSharp.WindowsPhone.dll</HintPath>
+ </Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Servicemodel.Web" />
<Reference Include="System.Windows" />
@@ -66,6 +72,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Api\Message.cs" />
+ <Compile Include="Api\Photo.cs" />
<Compile Include="Api\User.cs" />
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
@@ -116,6 +123,7 @@
</Page>
</ItemGroup>
<ItemGroup>
+ <None Include="packages.config" />
<None Include="Properties\AppManifest.xml" />
<None Include="Properties\WMAppManifest.xml" />
</ItemGroup>
diff --git a/Juick/MainPage.xaml b/Juick/MainPage.xaml
index 84e7bd7..7c19bc1 100644
--- a/Juick/MainPage.xaml
+++ b/Juick/MainPage.xaml
@@ -22,11 +22,11 @@
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
-
+
<!--Panorama control-->
<controls:Panorama Title="Juick" FontSize="20">
-
-
+
+
<!--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-->
@@ -39,16 +39,17 @@
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="{StaticResource PhoneForegroundBrush}" BorderThickness="0 0 0 1">
- <Grid >
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="Auto" />
- <ColumnDefinition Width="*" />
- </Grid.ColumnDefinitions>
- <Grid.RowDefinitions>
- <RowDefinition Height="Auto" />
- <RowDefinition Height="Auto" />
- <RowDefinition Height="Auto" />
- </Grid.RowDefinitions>
+ <Grid >
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="Auto" />
+ <ColumnDefinition Width="*" />
+ </Grid.ColumnDefinitions>
+ <Grid.RowDefinitions>
+ <RowDefinition Height="Auto" />
+ <RowDefinition Height="Auto" />
+ <RowDefinition Height="Auto" />
+ <RowDefinition Height="Auto" />
+ </Grid.RowDefinitions>
<Image Source="{Binding UserAvatar}" 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"
@@ -63,13 +64,14 @@
Style="{StaticResource PhoneTextNormalStyle}"
Margin="5,0,5,5" VerticalAlignment="Top"
TextWrapping="Wrap" HorizontalAlignment="Left"/>
- <TextBlock Text="{Binding Status}" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2"
+ <Image Source="{Binding Attachment}" Grid.Row="2" Grid.Column="0" Margin="3" Grid.ColumnSpan="2" />
+ <TextBlock Text="{Binding Status}" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2"
Foreground="{StaticResource PhoneForegroundBrush}"
Style="{StaticResource PhoneTextAccentStyle}"
FontSize="{StaticResource PhoneFontSizeSmall}"
Margin="5,0,5,5" VerticalAlignment="Top"
TextWrapping="Wrap" HorizontalAlignment="Left"/>
- </Grid>
+ </Grid>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
@@ -86,16 +88,17 @@
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="{StaticResource PhoneForegroundBrush}" BorderThickness="0 0 0 1">
- <Grid>
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="Auto" />
- <ColumnDefinition Width="*" />
- </Grid.ColumnDefinitions>
- <Grid.RowDefinitions>
- <RowDefinition Height="Auto" />
- <RowDefinition Height="Auto" />
- <RowDefinition Height="Auto" />
- </Grid.RowDefinitions>
+ <Grid>
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="Auto" />
+ <ColumnDefinition Width="*" />
+ </Grid.ColumnDefinitions>
+ <Grid.RowDefinitions>
+ <RowDefinition Height="Auto" />
+ <RowDefinition Height="Auto" />
+ <RowDefinition Height="Auto" />
+ <RowDefinition Height="Auto" />
+ </Grid.RowDefinitions>
<Image Source="{Binding UserAvatar}" 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"
@@ -103,18 +106,19 @@
FontFamily="{StaticResource PhoneFontFamilySemiLight}"
FontSize="{StaticResource PhoneFontSizeLarge}"
Style="{StaticResource PhoneTextAccentStyle}" />
- <TextBlock Text="{Binding MessageText}" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
+ <TextBlock Text="{Binding MessageText}" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
Foreground="{StaticResource PhoneForegroundBrush}"
Style="{StaticResource PhoneTextNormalStyle}"
Margin="5,0,5,5" VerticalAlignment="Top"
TextWrapping="Wrap" HorizontalAlignment="Left"/>
- <TextBlock Text="{Binding Status}" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2"
+ <Image Source="{Binding Attachment}" Grid.Row="2" Grid.Column="0" Margin="3" Grid.ColumnSpan="2" />
+ <TextBlock Text="{Binding Status}" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2"
Foreground="{StaticResource PhoneForegroundBrush}"
Style="{StaticResource PhoneTextAccentStyle}"
FontSize="{StaticResource PhoneFontSizeSmall}"
Margin="5,0,5,5" VerticalAlignment="Top"
TextWrapping="Wrap" HorizontalAlignment="Left"/>
- </Grid>
+ </Grid>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
diff --git a/Juick/SampleData/MainViewModelSampleData.xaml b/Juick/SampleData/MainViewModelSampleData.xaml
index 736a16e..431ac33 100644
--- a/Juick/SampleData/MainViewModelSampleData.xaml
+++ b/Juick/SampleData/MainViewModelSampleData.xaml
@@ -5,12 +5,12 @@
SampleProperty="Sample Text Property Value">
<ViewModels:MainViewModel.MyFeed>
- <local:MessageViewModel Username="design one" MessageText="Maecenas praesent accumsan bibendum" Status="Maecenas praesent accumsan bibendum dictumst eleifend facilisi faucibus habitant inceptos interdum lobortis nascetur"/>
- <local:MessageViewModel Username="design two" MessageText="Dictumst eleifend facilisi faucibus" Status="Pharetra placerat pulvinar sagittis senectus sociosqu suscipit torquent ultrices vehicula volutpat maecenas praesent"/>
- <local:MessageViewModel Username="design three" MessageText="Habitant inceptos interdum lobortis" Status="Accumsan bibendum dictumst eleifend facilisi faucibus habitant inceptos interdum lobortis nascetur pharetra placerat"/>
- <local:MessageViewModel Username="design four" MessageText="Nascetur pharetra placerat pulvinar" Status="Pulvinar sagittis senectus sociosqu suscipit torquent ultrices vehicula volutpat maecenas praesent accumsan bibendum"/>
- <local:MessageViewModel Username="design five" MessageText="Sagittis senectus sociosqu suscipit" Status="Dictumst eleifend facilisi faucibus habitant inceptos interdum lobortis nascetur pharetra placerat pulvinar sagittis"/>
- <local:MessageViewModel Username="design six" MessageText="Torquent ultrices vehicula volutpat" Status="Senectus sociosqu suscipit torquent ultrices vehicula volutpat maecenas praesent accumsan bibendum dictumst eleifend"/>
+ <ViewModels:MessageViewModel Username="design one" MessageText="Maecenas praesent accumsan bibendum" Status="Maecenas praesent accumsan bibendum dictumst eleifend facilisi faucibus habitant inceptos interdum lobortis nascetur"/>
+ <ViewModels:MessageViewModel Username="design two" MessageText="Dictumst eleifend facilisi faucibus" Status="Pharetra placerat pulvinar sagittis senectus sociosqu suscipit torquent ultrices vehicula volutpat maecenas praesent"/>
+ <ViewModels:MessageViewModel Username="design three" MessageText="Habitant inceptos interdum lobortis" Status="Accumsan bibendum dictumst eleifend facilisi faucibus habitant inceptos interdum lobortis nascetur pharetra placerat"/>
+ <ViewModels:MessageViewModel Username="design four" MessageText="Nascetur pharetra placerat pulvinar" Status="Pulvinar sagittis senectus sociosqu suscipit torquent ultrices vehicula volutpat maecenas praesent accumsan bibendum"/>
+ <ViewModels:MessageViewModel Username="design five" MessageText="Sagittis senectus sociosqu suscipit" Status="Dictumst eleifend facilisi faucibus habitant inceptos interdum lobortis nascetur pharetra placerat pulvinar sagittis"/>
+ <ViewModels:MessageViewModel Username="design six" MessageText="Torquent ultrices vehicula volutpat" Status="Senectus sociosqu suscipit torquent ultrices vehicula volutpat maecenas praesent accumsan bibendum dictumst eleifend"/>
</ViewModels:MainViewModel.MyFeed>
</ViewModels:MainViewModel> \ No newline at end of file
diff --git a/Juick/ViewModels/MainViewModel.cs b/Juick/ViewModels/MainViewModel.cs
index 23ff020..ed244d7 100644
--- a/Juick/ViewModels/MainViewModel.cs
+++ b/Juick/ViewModels/MainViewModel.cs
@@ -45,18 +45,16 @@ namespace Juick.ViewModels
{
var request = new RestRequest("/home?1=1" + "&rnd=" + Environment.TickCount);
App.Client.Authenticator = new HttpBasicAuthenticator(App.Account.Credentials.UserName, App.Account.Credentials.Password);
- App.Client.ExecuteAsync(request, response =>
+ App.Client.ExecuteAsync<List<Message>>(request, response =>
{
if (response.StatusCode != HttpStatusCode.OK)
{
MessageBox.Show(response.StatusCode.ToString());
return;
}
- var ser = new DataContractJsonSerializer(typeof (List<Message>));
-
- var messages =
- ser.ReadObject(new MemoryStream(response.RawBytes)) as List<Message>;
- MyFeed.Clear();
+
+ var messages = response.Data;
+ MyFeed.Clear();
messages.ForEach(post =>
{
var item = new MessageViewModel(post)
@@ -64,16 +62,14 @@ namespace Juick.ViewModels
Status =
string.Format(
"Posted on: {0}, replies: {1}",
- post.
- timestamp,
- post.
- replies)
+ post.Timestamp,
+ post.Replies)
};
MyFeed.Add(item);
var imageRequest =
new RestRequest(
string.Format("/as/{0}.png",
- post.user.uid));
+ post.User.Uid));
App.AvatarClient.ExecuteAsync(
imageRequest, restResponse =>
{
@@ -88,15 +84,12 @@ namespace Juick.ViewModels
NotifyPropertyChanged("MyFeed");
});
- var lastrequest = new RestRequest("/messages?1=1" + "&rnd=" + Environment.TickCount);
- App.Client.ExecuteAsync(lastrequest, response =>
+ var lastrequest = new RestRequest("/messages?1=1&media=all" + "&rnd=" + Environment.TickCount);
+ App.Client.ExecuteAsync<List<Message>>(lastrequest, response =>
{
- var ser = new DataContractJsonSerializer(typeof(List<Message>));
- using (var ms = new MemoryStream(response.RawBytes))
- {
- var messages =
- (List<Message>)ser.ReadObject(ms);
- if (messages == null) return;
+
+ var messages = response.Data;
+ if (messages.Count == 0) return;
Last.Clear();
messages.ForEach(post =>
{
@@ -105,16 +98,14 @@ namespace Juick.ViewModels
Status =
string.Format(
"Posted on: {0}, replies: {1}",
- post.
- timestamp,
- post.
- replies)
+ post.Timestamp,
+ post.Replies)
};
Last.Add(item);
var imageRequest =
new RestRequest(
string.Format("/as/{0}.png",
- post.user.uid));
+ post.User.Uid));
App.AvatarClient.ExecuteAsync(
imageRequest, restResponse =>
{
@@ -124,10 +115,16 @@ namespace Juick.ViewModels
item.
NotifyPropertyChanged
("UserAvatar");
- });
+ });
+ if (post.Photo != null)
+ {
+ item.Attachment = new BitmapImage {UriSource = new Uri(post.Photo.Small, UriKind.Absolute)};
+ item.NotifyPropertyChanged("Attachment");
+ }
+
});
NotifyPropertyChanged("Last");
- }
+
});
}
diff --git a/Juick/ViewModels/MessageViewModel.cs b/Juick/ViewModels/MessageViewModel.cs
index 8620ab3..3a324c4 100644
--- a/Juick/ViewModels/MessageViewModel.cs
+++ b/Juick/ViewModels/MessageViewModel.cs
@@ -1,19 +1,10 @@
using System;
using System.ComponentModel;
-using System.Diagnostics;
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.Media.Imaging;
-using System.Windows.Shapes;
using Juick.Api;
-namespace Juick
+namespace Juick.ViewModels
{
public class MessageViewModel : INotifyPropertyChanged
{
@@ -24,10 +15,10 @@ namespace Juick
public MessageViewModel(Message message)
{
- MID = message.mid;
- RID = message.rid;
- Username = message.user.uname;
- MessageText = HttpUtility.HtmlDecode(message.body);
+ MID = message.Mid;
+ RID = message.Rid;
+ Username = message.User.UName;
+ MessageText = HttpUtility.HtmlDecode(message.Body);
}
private int _mid;
/// <summary>
@@ -105,6 +96,20 @@ namespace Juick
}
}
+ private BitmapImage _attach;
+ public BitmapImage Attachment
+ {
+ get { return _attach; }
+ set
+ {
+ if (value != _attach)
+ {
+ _attach = value;
+ NotifyPropertyChanged("Attachment");
+ }
+ }
+ }
+
private string _messageText;
/// <summary>
/// Sample ViewModel property; this property is used in the view to display its value using a Binding.
diff --git a/Juick/ViewModels/ThreadViewModel.cs b/Juick/ViewModels/ThreadViewModel.cs
index bff72b7..80d8b3e 100644
--- a/Juick/ViewModels/ThreadViewModel.cs
+++ b/Juick/ViewModels/ThreadViewModel.cs
@@ -40,12 +40,9 @@ namespace Juick.ViewModels
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(request, response =>
+ App.Client.ExecuteAsync<List<Message>>(request, response =>
{
- using (var responseStream = new MemoryStream(response.RawBytes))
- {
- var ser = new DataContractJsonSerializer(typeof (List<Message>));
- var messages = (List<Message>) ser.ReadObject(responseStream);
+ var messages = response.Data;
Items.Clear();
messages.ForEach(post =>
{
@@ -54,7 +51,7 @@ namespace Juick.ViewModels
var imageRequest =
new RestRequest(
string.Format("/as/{0}.png",
- post.user.uid));
+ post.User.Uid));
App.AvatarClient.ExecuteAsync(
imageRequest, restResponse =>
{
@@ -68,7 +65,7 @@ namespace Juick.ViewModels
});
IsDataLoaded = true;
NotifyPropertyChanged("Items");
- }
+
});
}