Skip to content

Commit

Permalink
信箱载入更多和刷新
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Mar 7, 2012
1 parent 54280b6 commit 73a8604
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 40 deletions.
File renamed without changes.
File renamed without changes.
66 changes: 42 additions & 24 deletions MailboxPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,36 +64,54 @@
<!--Pivot Control-->
<controls:Pivot LoadedPivotItem="Pivot_LoadedPivotItem" x:Name="MailboxPivot" Title="虎踞龙蟠BBS">
<controls:PivotItem Header="收件箱">
<ListBox ItemsSource="{Binding InboxItems}" ItemTemplate="{StaticResource MailDataTemplate}"
SelectionChanged="Mail_Selected">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
<ScrollViewer>
<StackPanel>
<ListBox ItemsSource="{Binding InboxItems}" ItemTemplate="{StaticResource MailDataTemplate}"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
SelectionChanged="Mail_Selected">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
<Button Visibility="Collapsed" Margin="-12 0" x:Name="LoadMore1" Content="载入更多" Click="LoadMore_Click"/>
</StackPanel>
</ScrollViewer>
</controls:PivotItem>

<controls:PivotItem Header="发件箱">
<ListBox ItemsSource="{Binding SentItems}" ItemTemplate="{StaticResource MailDataTemplate}"
SelectionChanged="Mail_Selected">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
<ScrollViewer>
<StackPanel>
<ListBox ItemsSource="{Binding SentItems}" ItemTemplate="{StaticResource MailDataTemplate}"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
SelectionChanged="Mail_Selected">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
<Button Visibility="Collapsed" Margin="-12 0" x:Name="LoadMore2" Content="载入更多" Click="LoadMore_Click"/>
</StackPanel>
</ScrollViewer>
</controls:PivotItem>

<controls:PivotItem Header="垃圾箱">
<ListBox ItemsSource="{Binding DeletedItems}" ItemTemplate="{StaticResource MailDataTemplate}"
SelectionChanged="Mail_Selected">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
<ScrollViewer>
<StackPanel>
<ListBox ItemsSource="{Binding DeletedItems}" ItemTemplate="{StaticResource MailDataTemplate}"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
SelectionChanged="Mail_Selected">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
<Button Visibility="Collapsed" Margin="-12 0" x:Name="LoadMore3" Content="载入更多" Click="LoadMore_Click"/>
</StackPanel>
</ScrollViewer>
</controls:PivotItem>
</controls:Pivot>
</Grid>
Expand Down
76 changes: 64 additions & 12 deletions MailboxPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,21 @@ private void SetLoading()
App.ViewModel.Mailbox.IsLoading = isLoading[0] | isLoading[1] | isLoading[2];
}

// 载入按钮集合
Button[] LoadMore = { null, null, null };

public MailboxPage()
{
InitializeComponent();

if (App.ViewModel.Mailbox == null)
App.ViewModel.Mailbox = new MailboxViewModel();

DataContext = App.ViewModel.Mailbox;

LoadMore[0] = LoadMore1;
LoadMore[1] = LoadMore2;
LoadMore[2] = LoadMore3;
}

// 进入页面时根据参数切换到指定的页面
Expand Down Expand Up @@ -82,28 +90,65 @@ private void Mail_Selected(object sender, SelectionChangedEventArgs e)
}

// 加载指定的信箱
private void LoadMailbox(int type)
private void LoadMailbox(int type, bool append = false)
{
isLoading[type] = true;
SetLoading();
App.Service.MailBox(type, currentPage * pageSize, pageSize, delegate(ObservableCollection<TopicViewModel> mails, bool success, string error)
int loadPage = append ? currentPage + 1 : currentPage;
App.Service.MailBox(type, loadPage * pageSize, pageSize, delegate(ObservableCollection<TopicViewModel> mails, bool success, string error)
{
isLoading[type] = false;
SetLoading();

if (mails != null)
{
switch (type)
// 直接覆盖
if (!append)
{
case 0:
App.ViewModel.Mailbox.InboxItems = mails;
break;
case 1:
App.ViewModel.Mailbox.SentItems = mails;
break;
case 2:
App.ViewModel.Mailbox.DeletedItems = mails;
break;
switch (type)
{
case 0:
App.ViewModel.Mailbox.InboxItems = mails;
break;
case 1:
App.ViewModel.Mailbox.SentItems = mails;
break;
case 2:
App.ViewModel.Mailbox.DeletedItems = mails;
break;
}
}
// 或者接在后面
else
{
switch (type)
{
case 0:
foreach (TopicViewModel mail in mails)
App.ViewModel.Mailbox.InboxItems.Add(mail);
break;
case 1:
foreach (TopicViewModel mail in mails)
App.ViewModel.Mailbox.SentItems.Add(mail);
break;
case 2:
foreach (TopicViewModel mail in mails)
App.ViewModel.Mailbox.DeletedItems.Add(mail);
break;
}
++currentPage;
}

// 判断是否显示下一页
if (mails.Count < pageSize)
{
LoadMore[type].Visibility = Visibility.Collapsed;
LoadMore[type].IsEnabled = false;
}
else
{
LoadMore[type].Visibility = Visibility.Visible;
LoadMore[type].IsEnabled = true;
}
}
});
Expand All @@ -112,7 +157,14 @@ private void LoadMailbox(int type)
// 刷新按钮
private void Refresh_Click(object sender, EventArgs e)
{
currentPage = 0;
LoadMailbox(MailboxPivot.SelectedIndex);
}

// 载入更多
private void LoadMore_Click(object sender, RoutedEventArgs e)
{
LoadMailbox(MailboxPivot.SelectedIndex, true);
}
}
}
4 changes: 2 additions & 2 deletions ValueConverters/StampDateConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
if (date.Year == now.Year && date.Month == now.Month && date.Day == now.Day)
return date.ToString("HH:mm", culture);
else if (date.Year == now.Year)
return date.ToString("MM月d日 HH:mm", culture);
return date.ToString("M月d日 HH:mm", culture);
else
return date.ToString("yyyy年MM月d日", culture);
return date.ToString("yyyy年M月d日", culture);
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
Expand Down
4 changes: 2 additions & 2 deletions sbbs-client-wp7.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<Compile Include="SettingsPage.xaml.cs">
<DependentUpon>SettingsPage.xaml</DependentUpon>
</Compile>
<Compile Include="Tile.xaml.cs">
<Compile Include="Controls\Tile.xaml.cs">
<DependentUpon>Tile.xaml</DependentUpon>
</Compile>
<Compile Include="TopicPage.xaml.cs">
Expand Down Expand Up @@ -169,7 +169,7 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Tile.xaml">
<Page Include="Controls\Tile.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
Expand Down

0 comments on commit 73a8604

Please sign in to comment.