From 2ee31d0d9d6c6254ea34c5909117221510ee6001 Mon Sep 17 00:00:00 2001 From: Zhao Cheng Date: Mon, 12 Mar 2012 22:14:03 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E9=9D=A2=E5=88=86=E5=8C=BAdone?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HotPage.xaml | 3 +++ HotPage.xaml.cs | 49 +++++++++++++++++++++++++++++++++++++- PostPage.xaml | 2 +- Sbbs/Service.cs | 10 ++++++++ ViewModels/HotViewModel.cs | 18 ++++++++++++++ 5 files changed, 80 insertions(+), 2 deletions(-) diff --git a/HotPage.xaml b/HotPage.xaml index 2adfb7a..f4a4f4c 100644 --- a/HotPage.xaml +++ b/HotPage.xaml @@ -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" @@ -86,6 +87,8 @@ + diff --git a/HotPage.xaml.cs b/HotPage.xaml.cs index 70b816c..cc323c7 100644 --- a/HotPage.xaml.cs +++ b/HotPage.xaml.cs @@ -21,6 +21,7 @@ public partial class HotPage : PhoneApplicationPage { private bool isHotTopicsLoading; private bool isHotBoardsLoading; + private bool isSectionsLoading; public HotPage() { @@ -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 sections = LocalCache.Get>("sections"); + if (sections != null) + { + App.ViewModel.Hot.SectionItems = sections; + return; + } + } + + // 没有的话再从网络读取 + isSectionsLoading = true; + SetLoading(); + App.Service.Sections(delegate(ObservableCollection boards, bool success, string error) + { + isSectionsLoading = false; + SetLoading(); + + if (boards != null) + { + // 写入缓存 + LocalCache.Set>("sections", boards); + App.ViewModel.Hot.SectionItems = boards; + } + }); } private void LoadHotTopics() @@ -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)); } } @@ -127,6 +167,9 @@ private void Refresh_Click(object sender, EventArgs e) case 1: LoadHotBoards(); break; + case 2: + LoadSections(true); + break; } } @@ -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; } } } diff --git a/PostPage.xaml b/PostPage.xaml index 1a315dd..c380a66 100644 --- a/PostPage.xaml +++ b/PostPage.xaml @@ -66,7 +66,7 @@ - + diff --git a/Sbbs/Service.cs b/Sbbs/Service.cs index cdd13fd..06b2e16 100644 --- a/Sbbs/Service.cs +++ b/Sbbs/Service.cs @@ -41,6 +41,16 @@ public void Login(string username, string password, Action wc.DownloadStringAsync(uri, new ServiceArg() { Callback = callback }); } + // 全部版面 + public void Sections(Action callback) + { + WebClient wc = new WebClient(); + Uri uri = new Uri(apiBase + "sections" + apiPost + "?up=1&token=" + HttpUtility.UrlEncode(Token)); + + wc.DownloadStringCompleted += DownloadedAndParse; + wc.DownloadStringAsync(uri, new ServiceArg() { Callback = callback }); + } + // 获取十大 public void Topten(Action callback) { diff --git a/ViewModels/HotViewModel.cs b/ViewModels/HotViewModel.cs index 278f70d..1f0c099 100644 --- a/ViewModels/HotViewModel.cs +++ b/ViewModels/HotViewModel.cs @@ -26,6 +26,24 @@ public bool IsLoading } } + // 全部分区 + private ObservableCollection sectionItems; + public ObservableCollection SectionItems + { + get + { + return sectionItems; + } + set + { + if (value != sectionItems) + { + sectionItems = value; + NotifyPropertyChanged("SectionItems"); + } + } + } + // 热门版面集合 private ObservableCollection hotboardsItems; public ObservableCollection HotboardsItems