/
MessagingService.cs
141 lines (116 loc) · 4.47 KB
/
MessagingService.cs
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using System;
using Xamarin.Forms;
namespace FormsToolkit
{
/// <summary>
/// Messaging service implementation
/// </summary>
public class MessagingService : IMessagingService
{
/// <summary>
/// Subscribe the specified message and callback.
/// </summary>
/// <param name="message">Message.</param>
/// <param name="callback">Callback.</param>
public void Subscribe(string message, Action<IMessagingService> callback) =>
MessagingCenter.Subscribe<MessagingService>(this, message, callback);
/// <summary>
/// Subscribe the specified message and callback.
/// </summary>
/// <param name="message">Message.</param>
/// <param name="callback">Callback.</param>
/// <typeparam name="T">The 1st type parameter.</typeparam>
public void Subscribe<TArgs>(string message, Action<IMessagingService, TArgs> callback) =>
MessagingCenter.Subscribe<MessagingService, TArgs>(this, message, callback);
/// <summary>
/// Sends the message.
/// </summary>
/// <param name="message">Message.</param>
public void SendMessage(string message) =>
MessagingCenter.Send<MessagingService>(this, message);
/// <summary>
/// Sends the message.
/// </summary>
/// <param name="message">Message.</param>
/// <param name="args">Arguments.</param>
/// <typeparam name="T">The 1st type parameter.</typeparam>
public void SendMessage<TArgs>(string message, TArgs args) =>
MessagingCenter.Send<MessagingService, TArgs>(this, message, args);
/// <summary>
/// Unsubscribe the specified message.
/// </summary>
/// <param name="message">Message.</param>
public void Unsubscribe (string message) =>
MessagingCenter.Unsubscribe<MessagingService>(this, message);
/// <summary>
/// Unsubscribe the specified message and args.
/// </summary>
/// <param name="message">Message.</param>
/// <param name="args">Arguments.</param>
/// <typeparam name="T">The 1st type parameter.</typeparam>
public void Unsubscribe<TArgs> (string message) =>
MessagingCenter.Unsubscribe<MessagingService, TArgs>(this, message);
static MessagingService instance = null;
/// <summary>
/// Gets the instance of the Messaging Service
/// </summary>
public static MessagingService Current => (instance ?? (instance = new MessagingService()));
}
/// <summary>
/// Messaging service question.
/// </summary>
public class MessagingServiceQuestion
{
/// <summary>
/// Gets or sets the title.
/// </summary>
/// <value>The title.</value>
public string Title {get;set;}
/// <summary>
/// Gets or sets the question.
/// </summary>
/// <value>The question.</value>
public string Question { get; set; }
/// <summary>
/// Gets or sets the positive button text.
/// </summary>
/// <value>The positive.</value>
public string Positive { get; set; }
/// <summary>
/// Gets or sets the negative button text
/// </summary>
/// <value>The negative.</value>
public string Negative { get; set; }
/// <summary>
/// Gets or sets the OnCompleted Action<bool>.
/// </summary>
/// <value>The OnCompleted Action<bool>.</value>
public Action<bool> OnCompleted { get; set; }
}
/// <summary>
/// Messaging service alert.
/// </summary>
public class MessagingServiceAlert
{
/// <summary>
/// Gets or sets the title.
/// </summary>
/// <value>The title.</value>
public string Title {get;set;}
/// <summary>
/// Gets or sets the message.
/// </summary>
/// <value>The message.</value>
public string Message { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this instance cancel/OK text.
/// </summary>
/// <value><c>true</c> if this instance cancel; otherwise, <c>false</c>.</value>
public string Cancel { get; set; }
/// <summary>
/// Gets or sets the OnCompleted Action.
/// </summary>
/// <value>The OnCompleted Action.</value>
public Action OnCompleted { get; set; }
}
}