Skip to content

Commit

Permalink
收藏夹登录登出时相关处理
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Mar 14, 2012
1 parent 90c24b5 commit b52d45b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
7 changes: 3 additions & 4 deletions App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ public App()
// This code will not execute when the application is reactivated
private void Application_Launching(object sender, LaunchingEventArgs e)
{
// 载入上一次的数据状态
ViewModel.ToptenItems = LocalCache.Get<ObservableCollection<TopicViewModel>>("Topten");
// 从缓存中载入收藏夹和十大
App.ViewModel.FavoratesItems = LocalCache.Get<ObservableCollection<BoardViewModel>>("Favorates");
App.ViewModel.ToptenItems = LocalCache.Get<ObservableCollection<TopicViewModel>>("Topten");
}

// Code to execute when the application is activated (brought to foreground)
Expand All @@ -106,14 +107,12 @@ private void Application_Activated(object sender, ActivatedEventArgs e)
// This code will not execute when the application is closing
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
LocalCache.Set<ObservableCollection<TopicViewModel>>("Topten", ViewModel.ToptenItems);
}

// Code to execute when the application is closing (eg, user hit Back)
// This code will not execute when the application is deactivated
private void Application_Closing(object sender, ClosingEventArgs e)
{
LocalCache.Set<ObservableCollection<TopicViewModel>>("Topten", ViewModel.ToptenItems);
}

// Code to execute if a navigation fails
Expand Down
6 changes: 6 additions & 0 deletions Controls/RecursiveListBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e
}
}

public void Refresh()
{
ItemsSource = DataContext as CollectionType;
history.Clear();
}

public RecursiveListBox()
{
DefaultStyleKey = typeof(RecursiveListBox);
Expand Down
9 changes: 4 additions & 5 deletions MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
isFirstLoading = false;

// 先从缓存中载入
App.ViewModel.FavoratesItems = LocalCache.Get<ObservableCollection<BoardViewModel>>("Favorates");

// 延迟两秒后开始刷新
// 延迟两秒后开始刷新全部
DispatcherTimer timer = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(2) };
timer.Tick += delegate(object s, EventArgs arg)
{
Expand Down Expand Up @@ -162,6 +159,7 @@ private void Topten_Selected(object sender, SelectionChangedEventArgs e)
// 载入收藏夹
private void LoadFavorates()
{
MessageBox.Show("IsLogin: " + App.ViewModel.IsLogin);
// 登录时载入收藏夹,未登陆时清空
if (App.ViewModel.IsLogin)
{
Expand All @@ -179,7 +177,7 @@ private void LoadFavorates()
{
App.ViewModel.IsFavoratesLoaded = true;
LocalCache.Set<ObservableCollection<BoardViewModel>>("Favorates", null);
App.ViewModel.FavoratesItems.Clear();
App.ViewModel.FavoratesItems = null;
}
}

Expand All @@ -193,6 +191,7 @@ public void LoadTopten()
return;

// 刷新十大
LocalCache.Set<ObservableCollection<TopicViewModel>>("Topten", topics);
App.ViewModel.ToptenItems = topics;
});
}
Expand Down
6 changes: 3 additions & 3 deletions ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ public bool IsLogin
}
set
{
// 启动所有登录钩子
LoginChanged(this, value);

// 注销时清除Token
if (value == false)
{
Expand All @@ -128,6 +125,9 @@ public bool IsLogin
}

NotifyPropertyChanged("IsLogin");

// 启动所有登录钩子
LoginChanged(this, value);
}
}
// 是否正在登录中
Expand Down

0 comments on commit b52d45b

Please sign in to comment.