1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

ScopedMessageBox: Replace old AlertWindow uses with new API

This commit is contained in:
reuk 2023-02-22 20:54:45 +00:00
parent 79ed81c24a
commit 39a731de46
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C
55 changed files with 893 additions and 677 deletions

View file

@ -185,21 +185,25 @@ public:
{ PushNotifications::getInstance()->removeAllPendingLocalNotifications(); };
#endif
remoteView.getDeviceTokenButton.onClick = []
remoteView.getDeviceTokenButton.onClick = [this]
{
String token = PushNotifications::getInstance()->getDeviceToken();
DBG ("token = " + token);
if (token.isEmpty())
{
showRemoteInstructions();
}
else
NativeMessageBox::showAsync (MessageBoxOptions()
{
auto options = MessageBoxOptions()
.withIconType (MessageBoxIconType::InfoIcon)
.withTitle ("Device token")
.withMessage (token)
.withButton ("OK"),
nullptr);
.withButton ("OK");
messageBox = NativeMessageBox::showScopedAsync (options, nullptr);
}
};
#if JUCE_ANDROID
@ -313,12 +317,12 @@ private:
String requiredFields = "all required fields";
#endif
NativeMessageBox::showAsync (MessageBoxOptions()
auto options = MessageBoxOptions()
.withIconType (MessageBoxIconType::InfoIcon)
.withTitle ("Incorrect notifications setup")
.withMessage ("Please make sure that " + requiredFields + " are set.")
.withButton ("OK"),
nullptr);
.withButton ("OK");
messageBox = NativeMessageBox::showScopedAsync (options, nullptr);
return;
}
@ -565,14 +569,14 @@ private:
{
ignoreUnused (isLocalNotification);
NativeMessageBox::showAsync (MessageBoxOptions()
auto options = MessageBoxOptions()
.withIconType (MessageBoxIconType::InfoIcon)
.withTitle ("Received notification")
.withMessage ("ID: " + n.identifier
+ ", title: " + n.title
+ ", body: " + n.body)
.withButton ("OK"),
nullptr);
.withButton ("OK");
messageBox = NativeMessageBox::showScopedAsync (options, nullptr);
}
void handleNotificationAction (bool isLocalNotification,
@ -582,7 +586,7 @@ private:
{
ignoreUnused (isLocalNotification);
NativeMessageBox::showAsync (MessageBoxOptions()
auto options = MessageBoxOptions()
.withIconType (MessageBoxIconType::InfoIcon)
.withTitle ("Received notification action")
.withMessage ("ID: " + n.identifier
@ -590,22 +594,22 @@ private:
+ ", body: " + n.body
+ ", action: " + actionIdentifier
+ ", optionalResponse: " + optionalResponse)
.withButton ("OK"),
nullptr);
.withButton ("OK");
messageBox = NativeMessageBox::showScopedAsync (options, nullptr);
PushNotifications::getInstance()->removeDeliveredNotification (n.identifier);
}
void localNotificationDismissedByUser (const PushNotifications::Notification& n) override
{
NativeMessageBox::showAsync (MessageBoxOptions()
auto options = MessageBoxOptions()
.withIconType (MessageBoxIconType::InfoIcon)
.withTitle ("Notification dismissed by a user")
.withMessage ("ID: " + n.identifier
+ ", title: " + n.title
+ ", body: " + n.body)
.withButton ("OK"),
nullptr);
.withButton ("OK");
messageBox = NativeMessageBox::showScopedAsync (options, nullptr);
}
void deliveredNotificationsListReceived (const Array<PushNotifications::Notification>& notifs) override
@ -615,12 +619,12 @@ private:
for (auto& n : notifs)
text << "(" << n.identifier << ", " << n.title << ", " << n.body << "), ";
NativeMessageBox::showAsync (MessageBoxOptions()
auto options = MessageBoxOptions()
.withIconType (MessageBoxIconType::InfoIcon)
.withTitle ("Received notification list")
.withMessage (text)
.withButton ("OK"),
nullptr);
.withButton ("OK");
messageBox = NativeMessageBox::showScopedAsync (options, nullptr);
}
void pendingLocalNotificationsListReceived (const Array<PushNotifications::Notification>& notifs) override
@ -630,54 +634,54 @@ private:
for (auto& n : notifs)
text << "(" << n.identifier << ", " << n.title << ", " << n.body << "), ";
NativeMessageBox::showAsync (MessageBoxOptions()
auto options = MessageBoxOptions()
.withIconType (MessageBoxIconType::InfoIcon)
.withTitle ("Pending notification list")
.withMessage (text)
.withButton ("OK"),
nullptr);
.withButton ("OK");
messageBox = NativeMessageBox::showScopedAsync (options, nullptr);
}
void deviceTokenRefreshed (const String& token) override
{
NativeMessageBox::showAsync (MessageBoxOptions()
auto options = MessageBoxOptions()
.withIconType (MessageBoxIconType::InfoIcon)
.withTitle ("Device token refreshed")
.withMessage (token)
.withButton ("OK"),
nullptr);
.withButton ("OK");
messageBox = NativeMessageBox::showScopedAsync (options, nullptr);
}
#if JUCE_ANDROID
void remoteNotificationsDeleted() override
{
NativeMessageBox::showAsync (MessageBoxOptions()
auto options = MessageBoxOptions()
.withIconType (MessageBoxIconType::InfoIcon)
.withTitle ("Remote notifications deleted")
.withMessage ("Some of the pending messages were removed!")
.withButton ("OK"),
nullptr);
.withButton ("OK");
messageBox = NativeMessageBox::showScopedAsync (options, nullptr);
}
void upstreamMessageSent (const String& messageId) override
{
NativeMessageBox::showAsync (MessageBoxOptions()
auto options = MessageBoxOptions()
.withIconType (MessageBoxIconType::InfoIcon)
.withTitle ("Upstream message sent")
.withMessage ("Message id: " + messageId)
.withButton ("OK"),
nullptr);
.withButton ("OK");
messageBox = NativeMessageBox::showScopedAsync (options, nullptr);
}
void upstreamMessageSendingError (const String& messageId, const String& error) override
{
NativeMessageBox::showAsync (MessageBoxOptions()
auto options = MessageBoxOptions()
.withIconType (MessageBoxIconType::InfoIcon)
.withTitle ("Upstream message sending error")
.withMessage ("Message id: " + messageId
+ "\nerror: " + error)
.withButton ("OK"),
nullptr);
.withButton ("OK");
messageBox = NativeMessageBox::showScopedAsync (options, nullptr);
}
static Array<PushNotifications::Channel> getAndroidChannels()
@ -1207,8 +1211,8 @@ private:
struct DemoTabbedComponent : public TabbedComponent
{
explicit DemoTabbedComponent (TabbedButtonBar::Orientation orientation)
: TabbedComponent (orientation)
DemoTabbedComponent (PushNotificationsDemo& demoIn, TabbedButtonBar::Orientation orientation)
: TabbedComponent (orientation), demo (demoIn)
{
}
@ -1216,27 +1220,28 @@ private:
{
if (! showedRemoteInstructions && newCurrentTabName == "Remote")
{
PushNotificationsDemo::showRemoteInstructions();
demo.showRemoteInstructions();
showedRemoteInstructions = true;
}
}
private:
bool showedRemoteInstructions = false;
PushNotificationsDemo& demo;
};
static void showRemoteInstructions()
void showRemoteInstructions()
{
#if JUCE_IOS || JUCE_MAC
NativeMessageBox::showAsync (MessageBoxOptions()
auto options = MessageBoxOptions()
.withIconType (MessageBoxIconType::InfoIcon)
.withTitle ("Remote Notifications instructions")
.withMessage ("In order to be able to test remote notifications "
"ensure that the app is signed and that you register "
"the bundle ID for remote notifications in "
"Apple Developer Center.")
.withButton ("OK"),
nullptr);
.withButton ("OK");
messageBox = NativeMessageBox::showScopedAsync (options, nullptr);
#endif
}
@ -1246,10 +1251,11 @@ private:
AuxActionsView auxActionsView;
TabbedComponent localNotificationsTabs { TabbedButtonBar::TabsAtTop };
RemoteView remoteView;
DemoTabbedComponent mainTabs { TabbedButtonBar::TabsAtTop };
DemoTabbedComponent mainTabs { *this, TabbedButtonBar::TabsAtTop };
TextButton sendButton { "Send!" };
Label notAvailableYetLabel { "notAvailableYetLabel",
"Push Notifications feature is not available on this platform yet!" };
ScopedMessageBox messageBox;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PushNotificationsDemo)