Skip to content

Commit

Permalink
文章禁止选择,延迟更新
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Mar 4, 2012
1 parent daa2aa1 commit 62a967f
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 15 deletions.
6 changes: 2 additions & 4 deletions BoardSettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
base.OnNavigatedTo(e);

// 恢复选择
int[] modeMap = { 0, 1, 2, 2 };
ignoreSelection = true;
Mode.SelectedIndex = modeMap[App.Service.BoardMode];
Mode.SelectedIndex = App.Service.BoardMode % 3;
}

private bool ignoreSelection = true; // 永远忽略第一次选择(由系统触发)
Expand All @@ -44,8 +43,7 @@ private void Mode_SelectionChanged(object sender, SelectionChangedEventArgs e)
ListPicker list = sender as ListPicker;

// 设置并保存模式
int[] modeMap = { 0, 1, 3};
int mode = modeMap[list.SelectedIndex];
int mode = list.SelectedIndex;

if (mode != App.Service.BoardMode)
{
Expand Down
2 changes: 1 addition & 1 deletion MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
toolkit:TiltEffect.IsTiltEnabled="True">

<shell:SystemTray.ProgressIndicator>
<shell:ProgressIndicator Text="载入中..."
<shell:ProgressIndicator Text="更新中..."
IsVisible="{Binding IsDataLoaded, Converter={StaticResource BoolReverseConverter}}"
IsIndeterminate="{Binding IsDataLoaded, Converter={StaticResource BoolReverseConverter}}"/>
</shell:SystemTray.ProgressIndicator>
Expand Down
20 changes: 17 additions & 3 deletions MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace sbbs_client_wp7
{
using Sbbs;
using System.Collections.ObjectModel;
using System.Windows.Threading;

public partial class MainPage : PhoneApplicationPage
{
Expand All @@ -38,12 +39,25 @@ public MainPage()
}

// Load data for the ViewModel Items
private bool isFirstLoading = true;
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
if (!App.ViewModel.IsDataLoaded)
// 启动时延迟2秒更新
if (isFirstLoading)
{
LoadTopten();
LoadFavorates();
isFirstLoading = false;

// 延迟两秒后开始刷新
DispatcherTimer timer = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(2) };
timer.Tick += delegate(object s, EventArgs arg)
{
App.ViewModel.IsDataLoaded = false; // 标记开始更新

LoadTopten();
LoadFavorates();
timer.Stop();
};
timer.Start();
}
}

Expand Down
4 changes: 2 additions & 2 deletions PostPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private void Post_Click(object sender, EventArgs e)
{
viewModel.IsLoading = true;

App.Service.TopicPost(board, reid, TitleText.Text, ContentText.Text, delegate(ObservableCollection<TopicViewModel> topics, bool success, string error)
App.Service.TopicPost(board, reid, TitleText.Text, ContentText.Text, delegate(TopicViewModel topic, bool success, string error)
{
viewModel.IsLoading = false;
if (!success)
Expand All @@ -66,7 +66,7 @@ private void Post_Click(object sender, EventArgs e)
App.ViewModel.CurrentBoard.NeedRefresh = true;
// 跳转到话题时直接在最后添加
else
App.ViewModel.CurrentTopic.Topics.Add(topics[0]);
App.ViewModel.CurrentTopic.Topics.Add(topic);

NavigationService.GoBack();
}
Expand Down
16 changes: 16 additions & 0 deletions Sbbs/Response.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ public ObservableCollection<TopicViewModel> Root
}
}

// 返回单个主题
[DataContract]
public class TopicResponse : Response, IResponse<TopicViewModel>
{
[DataMember(Name = "topic")]
public TopicViewModel topic;

public TopicViewModel Root
{
get
{
return topic;
}
}
}

// 返回版面集合
// 符合类型: 收藏夹
[DataContract]
Expand Down
6 changes: 3 additions & 3 deletions Sbbs/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ public void Topic(string board, int id, int start, int limit, Action<TopicCollec
}

// 发帖
public void TopicPost(string board, int reid, string title, string content, Action<TopicCollection, bool, string> callback)
public void TopicPost(string board, int reid, string title, string content, Action<TopicViewModel, bool, string> callback)
{
WebClient wc = new WebClient();
Uri uri = new Uri(apiBase + "topic/post" + apiPost + "?type=2&token=" + HttpUtility.UrlEncode(Token) + "&board=" + board + "&reid=" + reid
+ "&title=" + HttpUtility.UrlEncode(title) + "&content=" + HttpUtility.UrlEncode(content));

wc.DownloadStringCompleted += DownloadedAndParse<TopicCollection, TopicsResponse>;
wc.DownloadStringAsync(uri, new ServiceArg<TopicCollection>() { Callback = callback });
wc.DownloadStringCompleted += DownloadedAndParse<TopicViewModel, TopicResponse>;
wc.DownloadStringAsync(uri, new ServiceArg<TopicViewModel>() { Callback = callback });
}

// 下载完成后分析JSON数据然后调用回调函数
Expand Down
3 changes: 2 additions & 1 deletion TopicPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
<ScrollViewer Grid.Row="1" Margin="12,0,12,0">
<StackPanel>
<ListBox ItemsSource="{Binding Topics}" ItemTemplate="{StaticResource ContentDataTemplate}"
ScrollViewer.VerticalScrollBarVisibility="Disabled">
ScrollViewer.VerticalScrollBarVisibility="Disabled"
SelectionChanged="ListBox_SelectionChanged">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
Expand Down
6 changes: 6 additions & 0 deletions TopicPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,11 @@ private void LoadTopics()
App.ViewModel.CurrentTopic.Topics = topics;
});
}

private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if ((sender as ListBox).SelectedIndex != -1)
(sender as ListBox).SelectedIndex = -1;
}
}
}
2 changes: 1 addition & 1 deletion ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public bool IsLogining
public event LoginChangedHandler LoginChanged;

// 数据是否全部载入完毕
private bool isDataLoaded;
private bool isDataLoaded = true; // 初始时假装更新完毕,进入程序后再开始更新
public bool IsDataLoaded
{
get
Expand Down

0 comments on commit 62a967f

Please sign in to comment.