Skip to content

Commit

Permalink
发帖done
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Mar 4, 2012
1 parent 418714b commit 13dff92
Show file tree
Hide file tree
Showing 21 changed files with 327 additions and 16 deletions.
6 changes: 1 addition & 5 deletions App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@
<TextBlock Style="{StaticResource PhoneTextAccentStyle}" Text="{Binding Author}"/>
<TextBlock HorizontalAlignment="Right" Text="{Binding Time, Converter={StaticResource StampDateConverter}}"/>
</Grid>
<RichTextBox Margin="-12 0 0 8">
<Paragraph>
<Run Text="{Binding Content}"/>
</Paragraph>
</RichTextBox>
<TextBlock Text="{Binding Content}" TextWrapping="Wrap" FontSize="{StaticResource PhoneFontSizeMedium}" Margin="0 0 0 12"/>
</StackPanel>
</DataTemplate>

Expand Down
2 changes: 1 addition & 1 deletion BoardPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@

<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="False">
<shell:ApplicationBarIconButton IconUri="/Images/new.png" Text="发帖"/>
<shell:ApplicationBarIconButton Click="NewPost_Click" IconUri="/Images/new.png" Text="发帖"/>
<shell:ApplicationBarIconButton Click="Refresh_Click" IconUri="/Images/refresh.png" Text="刷新"/>
<!--<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Text="MenuItem 1"/>
Expand Down
14 changes: 13 additions & 1 deletion BoardPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);

if (this.NavigationContext.QueryString.ContainsKey("board"))
// 从发帖页面返回,且需要刷新
if (App.ViewModel.CurrentBoard.NeedRefresh)
{
App.ViewModel.CurrentBoard.NeedRefresh = false;
Refresh_Click(null, null);
}
// 浏览版面
else if (this.NavigationContext.QueryString.ContainsKey("board"))
{
string board = this.NavigationContext.QueryString["board"];
// 跳转到其他版面时清空并重载
Expand All @@ -56,6 +63,11 @@ private void Refresh_Click(object sender, EventArgs e)
LoadTopics();
}

private void NewPost_Click(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/PostPage.xaml?board=" + App.ViewModel.CurrentBoard.EnglishName, UriKind.Relative));
}

private void LoadMore_Click(object sender, RoutedEventArgs e)
{
App.ViewModel.CurrentBoard.IsLoaded = false;
Expand Down
Binary file added Images/addcomment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/attach.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/send.text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 6 additions & 4 deletions MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,15 @@
<Setter Property="Margin" Value="5"/>
</Style>
</toolkit:WrapPanel.Resources>


<local:Tile Title="登录" MouseLeftButtonUp="Login_Click" Visibility="{Binding IsLogin, Converter={StaticResource BoolVisibleConverter}, ConverterParameter=True}"/>
<local:Tile Title="热门版面"/>
<local:Tile Title="分区热点"/>
<local:Tile Title="版面分区"/>
<local:Tile Title="最近浏览"/>
<local:Tile Title="登录" MouseLeftButtonUp="Login_Click" Visibility="{Binding IsLogin, Converter={StaticResource BoolVisibleConverter}, ConverterParameter=True}"/>
<local:Tile Title="注册" Visibility="{Binding IsLogin, Converter={StaticResource BoolVisibleConverter}, ConverterParameter=True}"/>
<local:Tile Title="我的信箱" Visibility="{Binding IsLogin, Converter={StaticResource BoolVisibleConverter}}"/>
<local:Tile Title="设置" Visibility="{Binding IsLogin, Converter={StaticResource BoolVisibleConverter}}"/>
<local:Tile Title="设置"/>
<local:Tile Title="注册" Visibility="{Binding IsLogin, Converter={StaticResource BoolVisibleConverter}, ConverterParameter=True}"/>
<local:Tile Title="关于"/>
</toolkit:WrapPanel>
</controls:PanoramaItem>
Expand Down
1 change: 1 addition & 0 deletions MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ private void LoadFavorates()
if (error != null)
return;

App.ViewModel.FavoratesDirectory.Clear();
App.ViewModel.FavoratesItems = boards;
});
}
Expand Down
80 changes: 80 additions & 0 deletions PostPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<phone:PhoneApplicationPage
x:Class="sbbs_client_wp7.PostPage"
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:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
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="696" d:DesignWidth="480"
toolkit:TiltEffect.IsTiltEnabled="True"
shell:SystemTray.Opacity="{Binding IsLoading, Converter={StaticResource LoadedOpacityConerter}, ConverterParameter=true}"
shell:SystemTray.IsVisible="True">

<shell:SystemTray.ProgressIndicator>
<shell:ProgressIndicator Text="载入中..."
IsVisible="{Binding IsLoading}"
IsIndeterminate="{Binding IsLoading}"/>
</shell:SystemTray.ProgressIndicator>

<toolkit:TransitionService.NavigationInTransition>
<toolkit:NavigationInTransition>
<toolkit:NavigationInTransition.Backward>
<toolkit:TurnstileTransition Mode="BackwardIn"/>
</toolkit:NavigationInTransition.Backward>
<toolkit:NavigationInTransition.Forward>
<toolkit:TurnstileTransition Mode="ForwardIn"/>
</toolkit:NavigationInTransition.Forward>
</toolkit:NavigationInTransition>
</toolkit:TransitionService.NavigationInTransition>
<toolkit:TransitionService.NavigationOutTransition>
<toolkit:NavigationOutTransition>
<toolkit:NavigationOutTransition.Backward>
<toolkit:TurnstileTransition Mode="BackwardOut"/>
</toolkit:NavigationOutTransition.Backward>
<toolkit:NavigationOutTransition.Forward>
<toolkit:TurnstileTransition Mode="ForwardOut"/>
</toolkit:NavigationOutTransition.Forward>
</toolkit:NavigationOutTransition>
</toolkit:TransitionService.NavigationOutTransition>

<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="Board" Text="版面" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="TypeTitle" Text="发帖" Margin="9,-7,0,0" Foreground="{StaticResource PhoneAccentBrush}" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
</StackPanel>

<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="标题" Style="{StaticResource PhoneTextGroupHeaderStyle}" />
<TextBox x:Name="TitleText" IsEnabled="{Binding IsLoading, Converter={StaticResource BoolReverseConverter}}" Grid.Row="1" />
<TextBlock Text="内容" Grid.Row="2" Style="{StaticResource PhoneTextGroupHeaderStyle}" />
<TextBox x:Name="ContentText" IsEnabled="{Binding IsLoading, Converter={StaticResource BoolReverseConverter}}" Grid.Row="3" />
</Grid>
</Grid>

<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton Click="Post_Click" IconUri="/Images/send.text.png" Text="发帖"/>
<shell:ApplicationBarIconButton IconUri="/Images/attach.png" Text="附件"/>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>

</phone:PhoneApplicationPage>
76 changes: 76 additions & 0 deletions PostPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using System.Collections.ObjectModel;
using Microsoft.Phone.Controls;

namespace sbbs_client_wp7
{
using Sbbs;

public partial class PostPage : PhoneApplicationPage
{
private string board;
private int reid = 0;
private LoadingViewModel viewModel = new LoadingViewModel();

public PostPage()
{
InitializeComponent();

DataContext = viewModel;
}

protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);

if (this.NavigationContext.QueryString.ContainsKey("reid"))
{
string title = this.NavigationContext.QueryString["title"];
if (title.Length > 3 && title.Substring(0, 3) == "Re:")
TitleText.Text = title;
else
TitleText.Text = "Re: " + title;

TypeTitle.Text = "回复";
Board.Text = board = this.NavigationContext.QueryString["board"];
reid = int.Parse(this.NavigationContext.QueryString["reid"]);
}
else
{
TypeTitle.Text = "发帖";
Board.Text = board = this.NavigationContext.QueryString["board"];
}
}

private void Post_Click(object sender, EventArgs e)
{
viewModel.IsLoading = true;

App.Service.TopicPost(board, reid, TitleText.Text, ContentText.Text, delegate(ObservableCollection<TopicViewModel> topics, bool success, string error)
{
viewModel.IsLoading = false;
if (!success)
MessageBox.Show("网络错误");
else if (error != null)
MessageBox.Show(error);
else
{
// 跳转到版面时标记刷新
if (reid == 0)
App.ViewModel.CurrentBoard.NeedRefresh = true;
// 跳转到话题时直接在最后添加
else
App.ViewModel.CurrentTopic.Topics.Add(topics[0]);

NavigationService.GoBack();
}
});
}
}
}
2 changes: 1 addition & 1 deletion Sbbs/Response.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class Response
}

// 返回主题集合
// 符合类型: 十大
// 符合类型: 十大,版面
[DataContract]
public class TopicsResponse : Response, IResponse<ObservableCollection<TopicViewModel>>
{
Expand Down
11 changes: 11 additions & 0 deletions Sbbs/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ public void Topic(string board, int id, int start, int limit, Action<TopicCollec
wc.DownloadStringAsync(uri, new ServiceArg<TopicCollection>() { Callback = callback });
}

// 发帖
public void TopicPost(string board, int reid, string title, string content, Action<TopicCollection, bool, string> callback)
{
WebClient wc = new WebClient();
Uri uri = new Uri(apiBase + "topic/post" + apiPost + "?type=2&token=" + HttpUtility.UrlEncode(Token) + "&board=" + board + "&reid=" + reid
+ "&title=" + HttpUtility.UrlEncode(title) + "&content=" + HttpUtility.UrlEncode(content));

wc.DownloadStringCompleted += DownloadedAndParse<TopicCollection, TopicsResponse>;
wc.DownloadStringAsync(uri, new ServiceArg<TopicCollection>() { Callback = callback });
}

// 下载完成后分析JSON数据然后调用回调函数
// C为返回类型,比如TopicCollection
// R为JSON的Response类型
Expand Down
45 changes: 45 additions & 0 deletions SettingsPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<phone:PhoneApplicationPage
x:Class="sbbs_client_wp7.SettingsPage"
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">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</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" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>

<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"></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>
23 changes: 23 additions & 0 deletions SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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;

namespace sbbs_client_wp7
{
public partial class SettingsPage : PhoneApplicationPage
{
public SettingsPage()
{
InitializeComponent();
}
}
}
2 changes: 1 addition & 1 deletion TopicPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@

<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton IconUri="/Images/new.png" Text="回复"/>
<shell:ApplicationBarIconButton Click="Reply_Click" IconUri="/Images/addcomment.png" Text="回复"/>
<shell:ApplicationBarIconButton Click="Refresh_Click" IconUri="/Images/refresh.png" Text="刷新"/>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
Expand Down
6 changes: 6 additions & 0 deletions TopicPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ private void Refresh_Click(object sender, EventArgs e)
LoadTopics();
}

private void Reply_Click(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/PostPage.xaml?title=" + HttpUtility.UrlEncode(App.ViewModel.CurrentTopic.Title) + "&board=" + App.ViewModel.CurrentTopic.Board
+ "&reid=" + App.ViewModel.CurrentTopic.Id, UriKind.Relative));
}

private void LoadTopics()
{
App.ViewModel.CurrentTopic.IsLoaded = false;
Expand Down
3 changes: 2 additions & 1 deletion ValueConverters/LoadedOpacityConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public class LoadedOpacityConerter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (bool)value ? 0 : 0.5;
bool reverse = parameter != null;
return ((bool)value ^ reverse)? 0 : 0.5;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
Expand Down
4 changes: 2 additions & 2 deletions ValueConverters/StampDateConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
{
DateTime date = new DateTime(1970, 1, 1, 0, 0, 0, 0);
date = date.AddSeconds((int)value).ToLocalTime();
DateTime now = new DateTime();
DateTime now = DateTime.Now;

if (date.Year == now.Year && date.Month == now.Month && date.Day == now.Day)
return date.ToString("HH:mm", culture);
else if (date.Year == now.Year)
return date.ToString("MM月d日 HH:mm", culture);
else
return date.ToString("yyyy MM月d日", culture);
return date.ToString("yyyy年MM月d日", culture);
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
Expand Down
3 changes: 3 additions & 0 deletions ViewModels/CurrentBoardViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class CurrentBoardViewModel : INotifyPropertyChanged
private bool isLoaded;
private ObservableCollection<TopicViewModel> topics;

// 全局变量,用于标记跳转到版面时是否需要刷新
public bool NeedRefresh { get; set; }

public string EnglishName
{
get
Expand Down
Loading

0 comments on commit 13dff92

Please sign in to comment.