Skip to content

Commit

Permalink
版面分区done
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Mar 12, 2012
1 parent f762391 commit 2ee31d0
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 2 deletions.
3 changes: 3 additions & 0 deletions HotPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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:custom="clr-namespace:CustomControls"
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"
Expand Down Expand Up @@ -86,6 +87,8 @@
</controls:PivotItem>

<controls:PivotItem Header="版面分区">
<custom:RecursiveListBox ItemsSource="{Binding SectionItems}" ItemTemplate="{StaticResource BoardDataTemplate}"
LeafItemTap="Section_Selected"/>
</controls:PivotItem>
</controls:Pivot>
</Grid>
Expand Down
49 changes: 48 additions & 1 deletion HotPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public partial class HotPage : PhoneApplicationPage
{
private bool isHotTopicsLoading;
private bool isHotBoardsLoading;
private bool isSectionsLoading;

public HotPage()
{
Expand All @@ -45,7 +46,37 @@ protected override void OnNavigatedTo(NavigationEventArgs e)

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

private void LoadSections(bool force = false)
{
if (!force)
{
// 先从本地缓存载入
ObservableCollection<BoardViewModel> sections = LocalCache.Get<ObservableCollection<BoardViewModel>>("sections");
if (sections != null)
{
App.ViewModel.Hot.SectionItems = sections;
return;
}
}

// 没有的话再从网络读取
isSectionsLoading = true;
SetLoading();
App.Service.Sections(delegate(ObservableCollection<BoardViewModel> boards, bool success, string error)
{
isSectionsLoading = false;
SetLoading();

if (boards != null)
{
// 写入缓存
LocalCache.Set<ObservableCollection<BoardViewModel>>("sections", boards);
App.ViewModel.Hot.SectionItems = boards;
}
});
}

private void LoadHotTopics()
Expand Down Expand Up @@ -110,8 +141,17 @@ private void Board_Selected(object sender, SelectionChangedEventArgs e)
{
// 清除选择,否则同样的项目无法点击第二次
(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 Section_Selected(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count == 1)
{
BoardViewModel board = e.AddedItems[0] as BoardViewModel;
this.NavigationService.Navigate(new Uri("/BoardPage.xaml?board=" + board.EnglishName + "&description=" + board.Description, UriKind.Relative));
}
}
Expand All @@ -127,6 +167,9 @@ private void Refresh_Click(object sender, EventArgs e)
case 1:
LoadHotBoards();
break;
case 2:
LoadSections(true);
break;
}
}

Expand All @@ -143,6 +186,10 @@ private void Pivot_LoadedPivotItem(object sender, PivotItemEventArgs e)
if (App.ViewModel.Hot.HotboardsItems == null)
LoadHotBoards();
break;
case 2:
if (App.ViewModel.Hot.SectionItems == null)
LoadSections();
break;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion PostPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<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" />
<TextBox x:Name="ContentText" TextWrapping="Wrap" IsEnabled="{Binding IsLoading, Converter={StaticResource BoolReverseConverter}}" Grid.Row="3" />
</Grid>
</Grid>

Expand Down
10 changes: 10 additions & 0 deletions Sbbs/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ public void Login(string username, string password, Action<string, bool, string>
wc.DownloadStringAsync(uri, new ServiceArg<string>() { Callback = callback });
}

// 全部版面
public void Sections(Action<BoardCollection, bool, string> callback)
{
WebClient wc = new WebClient();
Uri uri = new Uri(apiBase + "sections" + apiPost + "?up=1&token=" + HttpUtility.UrlEncode(Token));

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

// 获取十大
public void Topten(Action<TopicCollection, bool, string> callback)
{
Expand Down
18 changes: 18 additions & 0 deletions ViewModels/HotViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ public bool IsLoading
}
}

// 全部分区
private ObservableCollection<BoardViewModel> sectionItems;
public ObservableCollection<BoardViewModel> SectionItems
{
get
{
return sectionItems;
}
set
{
if (value != sectionItems)
{
sectionItems = value;
NotifyPropertyChanged("SectionItems");
}
}
}

// 热门版面集合
private ObservableCollection<BoardViewModel> hotboardsItems;
public ObservableCollection<BoardViewModel> HotboardsItems
Expand Down

0 comments on commit 2ee31d0

Please sign in to comment.