Skip to content

Commit

Permalink
分区热点
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Mar 5, 2012
1 parent 66413e7 commit 6ef081a
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 26 deletions.
64 changes: 50 additions & 14 deletions HotPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,66 @@
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
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">

<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 Title="虎踞龙蟠BBS">
<!--Pivot item one-->
<controls:PivotItem Header="分区热点">
<ListBox ItemsSource="{Binding Topics}" ItemTemplate="{StaticResource TopicDataTemplate}">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
<toolkit:LongListSelector SelectionChanged="LongListSelector_SelectionChanged" ItemsSource="{Binding TopicsGroupItems}" ItemTemplate="{StaticResource TopicDataTemplate}">
<toolkit:LongListSelector.GroupHeaderTemplate>
<DataTemplate>
<Border Margin="0 0 0 10" Background="{StaticResource PhoneAccentBrush}">
<TextBlock Text="{Binding Title}" Foreground="White" Style="{StaticResource PhoneTextLargeStyle}"/>
</Border>
</DataTemplate>
</toolkit:LongListSelector.GroupHeaderTemplate>
<toolkit:LongListSelector.GroupItemTemplate>
<DataTemplate>
<Border Width="480" Height="60" Margin="0 0 0 10" Background="{StaticResource PhoneAccentBrush}">
<TextBlock Text="{Binding Title}" Foreground="White" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
</Border>
</DataTemplate>
</toolkit:LongListSelector.GroupItemTemplate>
<toolkit:LongListSelector.GroupItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel HorizontalAlignment="Stretch"/>
</ItemsPanelTemplate>
</toolkit:LongListSelector.GroupItemsPanel>
</toolkit:LongListSelector>
</controls:PivotItem>

<!--Pivot item two-->
Expand All @@ -41,12 +82,7 @@

<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton x:Name="appbar_button1" IconUri="/Images/appbar_button1.png" Text="Button 1"/>
<shell:ApplicationBarIconButton x:Name="appbar_button2" IconUri="/Images/appbar_button2.png" Text="Button 2"/>
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem x:Name="menuItem1" Text="MenuItem 1"/>
<shell:ApplicationBarMenuItem x:Name="menuItem2" Text="MenuItem 2"/>
</shell:ApplicationBar.MenuItems>
<shell:ApplicationBarIconButton IconUri="/Images/refresh.png" Text="刷新"/>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>

Expand Down
73 changes: 73 additions & 0 deletions HotPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,94 @@
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 System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Collections.ObjectModel;

namespace sbbs_client_wp7
{
using Sbbs;

public partial class HotPage : PhoneApplicationPage
{
private HotViewModel viewModel = new HotViewModel();
private bool isHotTopicsLoading = true;

public HotPage()
{
InitializeComponent();

DataContext = viewModel;
}

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

if (NavigationContext.QueryString.ContainsKey("type"))
{
int type = int.Parse(NavigationContext.QueryString["type"]);
switch (type)
{
case 0:
if (viewModel.TopicsGroupItems == null)
LoadHotTopics();
break;
}
}
}

private void SetLoading()
{
viewModel.IsLoading = isHotTopicsLoading;
}

private void LoadHotTopics()
{
isHotTopicsLoading = true;
SetLoading();
App.Service.HotTopics(delegate(ObservableCollection<HotTopicsViewModel> topics, bool success, string error)
{
isHotTopicsLoading = false;
SetLoading();

if (topics != null)
{
ObservableCollection<TopicsGroupViewModel> newGroup = new ObservableCollection<TopicsGroupViewModel>();
foreach (HotTopicsViewModel hot in topics)
{
TopicsGroupViewModel newItem = new TopicsGroupViewModel(hot.Description);
foreach (TopicViewModel topic in hot.Topics)
newItem.Add(topic);
newGroup.Add(newItem);
}

viewModel.TopicsGroupItems = newGroup;
}
});
}

private void LongListSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count == 1)
{
// 清除选择,否则同样的项目无法点击第二次
(sender as LongListSelector).SelectedItem = null;
LongListSelector.LongListSelectorItem item = e.AddedItems[0] as LongListSelector.LongListSelectorItem;
TopicViewModel topic = item.Item as TopicViewModel;

// 清除未读
topic.Unread = false;

NavigationService.Navigate(
new Uri("/TopicPage.xaml?board=" + topic.Board + "&id=" + topic.Id + "&title=" + HttpUtility.UrlEncode(topic.Title), UriKind.Relative));
}
}
}
}
6 changes: 3 additions & 3 deletions MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@

<local:Tile Title="登录" Src="/Images/Tiles/pen.png" Tap="Login_Tap" Visibility="{Binding IsLogin, Converter={StaticResource BoolVisibleConverter}, ConverterParameter=True}"/>
<local:Tile Title="分区热点" Tap="HotTopics_Tap" Src="/Images/Tiles/board.png"/>
<local:Tile Title="热门版面" Src="/Images/Tiles/list.png"/>
<local:Tile Title="版面分区" Src="/Images/Tiles/folder.png"/>
<local:Tile Title="最近浏览" Src="/Images/Tiles/history.png"/>
<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="搜索" Src="/Images/Tiles/search.png"/>
<local:Tile Title="注册" Src="/Images/Tiles/cup.png" Visibility="{Binding IsLogin, Converter={StaticResource BoolVisibleConverter}, ConverterParameter=True}"/>
Expand Down
18 changes: 17 additions & 1 deletion MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,27 @@ private void RefreshFavorates_Tap(object sender, System.Windows.Input.GestureEve
// 分区热点
private void HotTopics_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
NavigationService.Navigate(new Uri("/HotPage.xaml?type=0", UriKind.RelativeOrAbsolute));
}

// 热门版面
private void HotBoards_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
NavigationService.Navigate(new Uri("/HotPage.xaml?type=1", UriKind.RelativeOrAbsolute));
}

// 版面分区
private void Sections_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
NavigationService.Navigate(new Uri("/HotPage.xaml?type=2", UriKind.RelativeOrAbsolute));
}

// 浏览历史
private void History_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
}

// 点击收藏夹

private void Favorates_Selected(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count == 1)
Expand Down
2 changes: 1 addition & 1 deletion PostPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
shell:SystemTray.IsVisible="True">

<shell:SystemTray.ProgressIndicator>
<shell:ProgressIndicator Text="载入中..."
<shell:ProgressIndicator Text="发布中..."
IsVisible="{Binding IsLoading}"
IsIndeterminate="{Binding IsLoading}"/>
</shell:SystemTray.ProgressIndicator>
Expand Down
16 changes: 16 additions & 0 deletions Sbbs/Response.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ public ObservableCollection<BoardViewModel> Root
}
}

// 返回首页热点
[DataContract]
public class HotTopicsResponse : Response, IResponse<ObservableCollection<HotTopicsViewModel>>
{
[DataMember(Name = "topics")]
public ObservableCollection<HotTopicsViewModel> topics;

public ObservableCollection<HotTopicsViewModel> Root
{
get
{
return topics;
}
}
}

// 返回用户认证Token
[DataContract]
public class TokenResponse : Response, IResponse<string>
Expand Down
10 changes: 10 additions & 0 deletions Sbbs/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ public void Topic(string board, int id, int start, int limit, Action<TopicCollec
wc.DownloadStringAsync(uri, new ServiceArg<TopicCollection>() { Callback = callback });
}

// 首页热点
public void HotTopics(Action<ObservableCollection<HotTopicsViewModel>, bool, string> callback)
{
WebClient wc = new WebClient();
Uri uri = new Uri(apiBase + "hot/topics" + apiPost);

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

// 发帖
public void TopicPost(string board, int reid, string title, string content, Action<TopicViewModel, bool, string> callback)
{
Expand Down
61 changes: 55 additions & 6 deletions Sbbs/TopicsGroupViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,65 @@
namespace sbbs_client_wp7.Sbbs
{
[DataContract]
public class TopicsGroupViewModel : ObservableCollection<TopicViewModel>
public class HotTopicsViewModel : INotifyPropertyChanged
{
private string description;
private ObservableCollection<TopicViewModel> topics;

[DataMember(Name = "description")]
public string Title { get; set; }

public string Description
{
get
{
return description;
}
set
{
if (value != description)
{
description = value;
NotifyPropertyChanged("Description");
}
}
}

[DataMember(Name = "topics")]
public ObservableCollection<TopicViewModel> Topics { get; set; }
public ObservableCollection<TopicViewModel> Topics
{
get
{
return topics;
}
set
{
if (value != topics)
{
topics = value;
NotifyPropertyChanged("Topics");
}
}
}

public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (null != handler)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}

public class TopicsGroupViewModel : ObservableCollection<TopicViewModel>
{
public TopicsGroupViewModel(string name)
{
this.Title = name;
}

public string Title { get; set; }

public bool HasItems
{
get
Expand All @@ -26,7 +77,5 @@ private set
{
}
}

// 将ObservableCollection的全部元素操作转向Topics
}
}
2 changes: 1 addition & 1 deletion ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public MainViewModel()
{
// 载入保存的设置
App.Service.Token = LocalCache.Get<string>("Token");
App.Service.BoardMode = LocalCache.Get<int>("BoardMode", 3);
App.Service.BoardMode = LocalCache.Get<int>("BoardMode", 2);

// 初始化
CurrentBoard = new CurrentBoardViewModel();
Expand Down

0 comments on commit 6ef081a

Please sign in to comment.