Skip to content

Commit

Permalink
邮箱
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Mar 7, 2012
1 parent dcd26dd commit 54280b6
Show file tree
Hide file tree
Showing 10 changed files with 392 additions and 1 deletion.
3 changes: 3 additions & 0 deletions HotPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
</ListBox.ItemContainerStyle>
</ListBox>
</controls:PivotItem>

<controls:PivotItem Header="版面分区">
</controls:PivotItem>
</controls:Pivot>
</Grid>

Expand Down
108 changes: 108 additions & 0 deletions MailboxPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<phone:PhoneApplicationPage
x:Class="sbbs_client_wp7.MailboxPage"
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:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
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="PortraitOrLandscape" 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">

<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="MailDataTemplate">
<Grid Margin="0 0 0 10">
<Rectangle Fill="{StaticResource PhoneAccentBrush}" Width="8" HorizontalAlignment="Left"/>
<StackPanel Orientation="Vertical" Margin="4 0 0 0">
<TextBlock Style="{StaticResource PhoneTextLargeStyle}" Foreground="{Binding Unread, Converter={StaticResource BoolAccentConverter}}" TextWrapping="Wrap" Text="{Binding Title}"/>
<Grid>
<TextBlock Style="{StaticResource PhoneTextSubtleStyle}" Text="{Binding Author}"/>
<TextBlock HorizontalAlignment="Right" Text="{Binding Time, Converter={StaticResource StampDateConverter}}"/>
</Grid>
</StackPanel>
</Grid>
</DataTemplate>
</phone:PhoneApplicationPage.Resources>

<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">
<!--Pivot Control-->
<controls:Pivot LoadedPivotItem="Pivot_LoadedPivotItem" x:Name="MailboxPivot" Title="虎踞龙蟠BBS">
<controls:PivotItem Header="收件箱">
<ListBox ItemsSource="{Binding InboxItems}" ItemTemplate="{StaticResource MailDataTemplate}"
SelectionChanged="Mail_Selected">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
</controls:PivotItem>

<controls:PivotItem Header="发件箱">
<ListBox ItemsSource="{Binding SentItems}" ItemTemplate="{StaticResource MailDataTemplate}"
SelectionChanged="Mail_Selected">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
</controls:PivotItem>

<controls:PivotItem Header="垃圾箱">
<ListBox ItemsSource="{Binding DeletedItems}" ItemTemplate="{StaticResource MailDataTemplate}"
SelectionChanged="Mail_Selected">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
</controls:PivotItem>
</controls:Pivot>
</Grid>

<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton IconUri="/Images/new.png" Text="新建"/>
<shell:ApplicationBarIconButton Click="Refresh_Click" IconUri="/Images/refresh.png" Text="刷新"/>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>

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

namespace sbbs_client_wp7
{
using Sbbs;

public partial class MailboxPage : PhoneApplicationPage
{
// 每页显示多少邮件
const int pageSize = 10;
// 当前页数
int currentPage = 0;

// 载入进度
private bool[] isLoading = { false, false, false };
private void SetLoading()
{
App.ViewModel.Mailbox.IsLoading = isLoading[0] | isLoading[1] | isLoading[2];
}

public MailboxPage()
{
InitializeComponent();

if (App.ViewModel.Mailbox == null)
App.ViewModel.Mailbox = new MailboxViewModel();
DataContext = App.ViewModel.Mailbox;
}

// 进入页面时根据参数切换到指定的页面
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);

if (NavigationContext.QueryString.ContainsKey("type"))
{
int type = int.Parse(NavigationContext.QueryString["type"]);
MailboxPivot.SelectedIndex = type;
}
}

// 直到切换到页面时才只刷新必要的页面
private void Pivot_LoadedPivotItem(object sender, PivotItemEventArgs e)
{
int type = (sender as Pivot).SelectedIndex;
switch (type)
{
case 0:
if (App.ViewModel.Mailbox.InboxItems != null)
return;
break;
case 1:
if (App.ViewModel.Mailbox.SentItems != null)
return;
break;
case 2:
if (App.ViewModel.Mailbox.DeletedItems != null)
return;
break;
}
LoadMailbox(type);
}

// 选中邮件
private void Mail_Selected(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count == 1)
{
// 清除选择,否则同样的项目无法点击第二次
(sender as ListBox).SelectedIndex = -1;
}
}

// 加载指定的信箱
private void LoadMailbox(int type)
{
isLoading[type] = true;
SetLoading();
App.Service.MailBox(type, currentPage * pageSize, pageSize, delegate(ObservableCollection<TopicViewModel> mails, bool success, string error)
{
isLoading[type] = false;
SetLoading();

if (mails != null)
{
switch (type)
{
case 0:
App.ViewModel.Mailbox.InboxItems = mails;
break;
case 1:
App.ViewModel.Mailbox.SentItems = mails;
break;
case 2:
App.ViewModel.Mailbox.DeletedItems = mails;
break;
}
}
});
}

// 刷新按钮
private void Refresh_Click(object sender, EventArgs e)
{
LoadMailbox(MailboxPivot.SelectedIndex);
}
}
}
2 changes: 1 addition & 1 deletion MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
<local:Tile Title="热门版面" Tap="HotBoards_Tap" Src="/Images/Tiles/list.png"/>
<local:Tile Title="版面分区" Tap="Sections_Tap" Src="/Images/Tiles/folder.png"/>
<local:Tile Title="最近浏览" Tap="History_Tap" Src="/Images/Tiles/history.png"/>
<local:Tile Title="我的信箱" Src="/Images/Tiles/mailbox.png" Visibility="{Binding IsLogin, Converter={StaticResource BoolVisibleConverter}}"/>
<local:Tile Title="我的信箱" Tap="Mail_Tap" Src="/Images/Tiles/mailbox.png" Visibility="{Binding IsLogin, Converter={StaticResource BoolVisibleConverter}}"/>
<local:Tile Title="搜索" Src="/Images/Tiles/search.png"/>
<local:Tile Title="注册" Src="/Images/Tiles/cup.png" Visibility="{Binding IsLogin, Converter={StaticResource BoolVisibleConverter}, ConverterParameter=True}"/>
<local:Tile Title="关于" Src="/Images/Tiles/love.png"/>
Expand Down
6 changes: 6 additions & 0 deletions MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ private void Sections_Tap(object sender, System.Windows.Input.GestureEventArgs e
NavigationService.Navigate(new Uri("/HotPage.xaml?type=2", UriKind.RelativeOrAbsolute));
}

// 我的邮箱
private void Mail_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
NavigationService.Navigate(new Uri("/MailboxPage.xaml?type=0", UriKind.RelativeOrAbsolute));
}

// 浏览历史
private void History_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
Expand Down
32 changes: 32 additions & 0 deletions Sbbs/Response.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,38 @@ public TopicViewModel Root
}
}
}

// 返回邮件集合
[DataContract]
public class MailsResponse : Response, IResponse<ObservableCollection<TopicViewModel>>
{
[DataMember(Name = "mails")]
public ObservableCollection<TopicViewModel> mails;

public ObservableCollection<TopicViewModel> Root
{
get
{
return mails;
}
}
}

// 返回单封邮件
[DataContract]
public class MailResponse : Response, IResponse<TopicViewModel>
{
[DataMember(Name = "mail")]
public TopicViewModel mail;

public TopicViewModel Root
{
get
{
return mail;
}
}
}

// 返回版面集合
// 符合类型: 收藏夹
Expand Down
20 changes: 20 additions & 0 deletions Sbbs/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,26 @@ public void TopicPost(string board, int reid, string title, string content, Acti
wc.DownloadStringAsync(uri, new ServiceArg<TopicViewModel>() { Callback = callback });
}

// 邮箱内容
public void MailBox(int type, int start, int limit, Action<TopicCollection, bool, string> callback)
{
WebClient wc = new WebClient();
Uri uri = new Uri(apiBase + "mailbox/get" + apiPost + "?token=" + HttpUtility.UrlEncode(Token) + "&start=" + start + "&limit=" + limit + "&type=" + type);

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

// 单封邮件
public void Mail(int type, int id, Action<TopicViewModel, bool, string> callback)
{
WebClient wc = new WebClient();
Uri uri = new Uri(apiBase + "mail/get" + apiPost + "?token=" + HttpUtility.UrlEncode(Token) + "&type=" + type + "&id=" + id);

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

// 下载完成后分析JSON数据然后调用回调函数
// C为返回类型,比如TopicCollection
// R为JSON的Response类型
Expand Down
Loading

0 comments on commit 54280b6

Please sign in to comment.