-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageCenterPage.xaml.cs
More file actions
92 lines (75 loc) · 2.52 KB
/
MessageCenterPage.xaml.cs
File metadata and controls
92 lines (75 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System.Windows.Input;
using AirshipDotNet;
using AirshipDotNet.MessageCenter;
using AirshipDotNet.MessageCenter.Controls;
using Microsoft.Maui.Controls;
namespace MauiSample;
public partial class MessageCenterPage : ContentPage
{
public ICommand RefreshCommand { private set; get; }
public MessageCenterPage()
{
InitializeComponent();
RefreshCommand = new Command(
execute: () => Refresh(),
canExecute: () => !refreshView.IsRefreshing
);
}
protected override async void OnAppearing()
{
refreshView.BindingContext = this;
await RefreshAsync();
}
public void Refresh()
{
// Fire and forget the async refresh
_ = RefreshAsync();
}
private async Task RefreshAsync()
{
try
{
var messages = await AirshipDotNet.Airship.MessageCenter.GetMessages();
// Example: Filter or style messages based on read status
var unreadCount = messages.Count(m => !m.IsRead);
Console.WriteLine($"Loaded {messages.Count} messages ({unreadCount} unread)");
listView.ItemsSource = messages;
refreshView.IsRefreshing = false;
}
catch (Exception ex)
{
Console.WriteLine($"Error refreshing messages: {ex.Message}");
refreshView.IsRefreshing = false;
}
}
void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
var message = e.SelectedItem as Message;
var messagePage = new MessagePage
{
MessageId = message.MessageId
};
messagePage.LoadStarted += onLoadStarted;
messagePage.LoadFinished += onLoadFinished;
messagePage.Closed += onClosed;
messagePage.LoadFailed += onLoadFailed;
Navigation.PushAsync(messagePage);
}
private void onLoadStarted(object sender, MessageLoadStartedEventArgs e)
{
Console.WriteLine("MessageCenterPage onLoadStarted was reached.");
}
private void onLoadFinished(object sender, MessageLoadFinishedEventArgs e)
{
Console.WriteLine("MessageCenterPage onLoaded was reached.");
}
private void onClosed(object sender, MessageClosedEventArgs e)
{
Console.WriteLine("MessageCenterPage onClosed was reached.");
Navigation.PopAsync();
}
private void onLoadFailed(object sender, MessageLoadFailedEventArgs e)
{
Console.WriteLine($"MessageCenterPage onLoadFailed was reached: {e.Error}");
}
}