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 65611ff commit dcd26dd
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 11 deletions.
11 changes: 9 additions & 2 deletions HotPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<!--Pivot Control-->
<controls:Pivot Title="虎踞龙蟠BBS">
<controls:Pivot x:Name="HotPivot" LoadedPivotItem="Pivot_LoadedPivotItem" Title="虎踞龙蟠BBS">
<!--Pivot item one-->
<controls:PivotItem Header="分区热点">
<toolkit:LongListSelector SelectionChanged="LongListSelector_SelectionChanged" ItemsSource="{Binding TopicsGroupItems}" ItemTemplate="{StaticResource TopicDataTemplate}">
Expand Down Expand Up @@ -75,7 +75,14 @@

<!--Pivot item two-->
<controls:PivotItem Header="热门版面">
<Grid/>
<ListBox ItemsSource="{Binding HotboardsItems}" ItemTemplate="{StaticResource BoardDataTemplate}"
SelectionChanged="Board_Selected">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
</controls:PivotItem>
</controls:Pivot>
</Grid>
Expand Down
65 changes: 56 additions & 9 deletions HotPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace sbbs_client_wp7
public partial class HotPage : PhoneApplicationPage
{
private bool isHotTopicsLoading;
private bool isHotBoardsLoading;

public HotPage()
{
Expand All @@ -30,26 +31,21 @@ public HotPage()
DataContext = App.ViewModel.Hot;
}

// 进入页面时根据参数切换到指定的页面
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 (App.ViewModel.Hot.TopicsGroupItems == null)
LoadHotTopics();
break;
}
HotPivot.SelectedIndex = type;
}
}

private void SetLoading()
{
App.ViewModel.Hot.IsLoading = isHotTopicsLoading;
App.ViewModel.Hot.IsLoading = isHotTopicsLoading | isHotBoardsLoading;
}

private void LoadHotTopics()
Expand Down Expand Up @@ -77,6 +73,20 @@ private void LoadHotTopics()
});
}

private void LoadHotBoards()
{
isHotBoardsLoading = true;
SetLoading();
App.Service.HotBoards(delegate(ObservableCollection<BoardViewModel> boards, bool success, string error)
{
isHotBoardsLoading = false;
SetLoading();

if (boards != null)
App.ViewModel.Hot.HotboardsItems = boards;
});
}

private void LongListSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count == 1)
Expand All @@ -94,9 +104,46 @@ private void LongListSelector_SelectionChanged(object sender, SelectionChangedEv
}
}

private void Board_Selected(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count == 1)
{
// 清除选择,否则同样的项目无法点击第二次
(sender as ListBox).SelectedIndex = -1;
BoardViewModel board = e.AddedItems[0] as BoardViewModel;

this.NavigationService.Navigate(new Uri("/BoardPage.xaml?board=" + board.EnglishName + "&description=" + board.Description, UriKind.Relative));
}
}

// 刷新按钮
private void Refresh_Click(object sender, EventArgs e)
{
LoadHotTopics();
switch (HotPivot.SelectedIndex)
{
case 0:
LoadHotTopics();
break;
case 1:
LoadHotBoards();
break;
}
}

// 直到切换到页面时才只刷新必要的页面
private void Pivot_LoadedPivotItem(object sender, PivotItemEventArgs e)
{
switch ((sender as Pivot).SelectedIndex)
{
case 0:
if (App.ViewModel.Hot.TopicsGroupItems == null)
LoadHotTopics();
break;
case 1:
if (App.ViewModel.Hot.HotboardsItems == null)
LoadHotBoards();
break;
}
}
}
}
10 changes: 10 additions & 0 deletions Sbbs/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ public void HotTopics(Action<ObservableCollection<HotTopicsViewModel>, bool, str
wc.DownloadStringAsync(uri, new ServiceArg<ObservableCollection<HotTopicsViewModel>>() { Callback = callback });
}

// 热门版面
public void HotBoards(Action<BoardCollection, bool, string> callback)
{
WebClient wc = new WebClient();
Uri uri = new Uri(apiBase + "hot/boards" + apiPost);

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

// 发帖
public void TopicPost(string board, int reid, string title, string content, Action<TopicViewModel, bool, string> callback)
{
Expand Down

0 comments on commit dcd26dd

Please sign in to comment.