Skip to content

Commit

Permalink
收藏夹目录支持
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Mar 3, 2012
1 parent 439f8bf commit 418714b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 12 deletions.
5 changes: 4 additions & 1 deletion App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ private void Application_Deactivated(object sender, DeactivatedEventArgs e)
// This code will not execute when the application is deactivated
private void Application_Closing(object sender, ClosingEventArgs e)
{
LocalCache.Set<ObservableCollection<BoardViewModel>>("Favorates", ViewModel.FavoratesItems);
if (ViewModel.FavoratesDirectory.First != null)
LocalCache.Set<ObservableCollection<BoardViewModel>>("Favorates", ViewModel.FavoratesDirectory.First.Value);
else
LocalCache.Set<ObservableCollection<BoardViewModel>>("Favorates", ViewModel.FavoratesItems);
LocalCache.Set<ObservableCollection<TopicViewModel>>("Topten", ViewModel.ToptenItems);
}

Expand Down
25 changes: 15 additions & 10 deletions MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,27 @@ private void RefreshFavorates_Click(object sender, MouseButtonEventArgs e)
}

// 点击收藏夹

private void Favorates_Selected(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count == 1)
{
ListBox list = sender as ListBox;
BoardViewModel board = e.AddedItems[0] as BoardViewModel;
// 收藏夹目录暂时不管
if (board.Leaf != true)

// 收藏夹目录
if (board.Leaf != true && board.EnglishName != "..")
{
App.ViewModel.FavoratesDirectory.AddLast(App.ViewModel.FavoratesItems);
App.ViewModel.FavoratesItems = board.Boards;
return;
}
else if (board.EnglishName == "..")
{
App.ViewModel.FavoratesItems = App.ViewModel.FavoratesDirectory.Last.Value;
App.ViewModel.FavoratesDirectory.RemoveLast();
return;
}

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

Expand Down Expand Up @@ -119,14 +132,6 @@ private void LoadFavorates()
if (error != null)
return;

// 对目录版面进行处理
foreach (BoardViewModel board in boards)
{
if (!board.Leaf) {
board.EnglishName = board.Description;
board.Description = "[目录]";
}
}
App.ViewModel.FavoratesItems = boards;
});
}
Expand Down
18 changes: 18 additions & 0 deletions Sbbs/BoardViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class BoardViewModel : INotifyPropertyChanged
private uint users;
private uint count;
private bool leaf = true;
private ObservableCollection<BoardViewModel> boards;

[DataMember(Name = "name")]
public string EnglishName
Expand Down Expand Up @@ -118,6 +119,23 @@ public bool Leaf
}
}

[DataMember(Name = "boards")]
public ObservableCollection<BoardViewModel> Boards
{
get
{
return boards;
}
set
{
if (value != boards)
{
boards = value;
NotifyPropertyChanged("Boards");
}
}
}

public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String propertyName)
{
Expand Down
2 changes: 1 addition & 1 deletion Sbbs/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void Topten(Action<TopicCollection, bool, string> callback)
public void Favorates(Action<BoardCollection, bool, string> callback)
{
WebClient wc = new WebClient();
Uri uri = new Uri(apiBase + "fav/list" + apiPost + "?token=" + HttpUtility.UrlEncode(Token));
Uri uri = new Uri(apiBase + "fav/list" + apiPost + "?up=1&token=" + HttpUtility.UrlEncode(Token));

wc.DownloadStringCompleted += DownloadedAndParse<BoardCollection, BoardsResponse>;
wc.DownloadStringAsync(uri, new ServiceArg<BoardCollection>() { Callback = callback });
Expand Down
3 changes: 3 additions & 0 deletions ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public MainViewModel()
// 初始化
CurrentBoard = new CurrentBoardViewModel();
CurrentTopic = new CurrentTopicViewModel();
FavoratesDirectory = new LinkedList<ObservableCollection<BoardViewModel>>();
}

// 十大热帖
Expand Down Expand Up @@ -95,6 +96,8 @@ public ObservableCollection<BoardViewModel> FavoratesItems
}
}
}
// --收藏夹浏览栈
public LinkedList<ObservableCollection<BoardViewModel>> FavoratesDirectory { get; set; }

// 当前版面
public CurrentBoardViewModel CurrentBoard { get; set; }
Expand Down

0 comments on commit 418714b

Please sign in to comment.