mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-02-05 03:50:07 +00:00
PushNotifications: add OSX implementation.
This commit is contained in:
parent
87831624cb
commit
b8b304e4cd
11 changed files with 1313 additions and 694 deletions
|
|
@ -29,7 +29,10 @@
|
|||
//==============================================================================
|
||||
MainContentComponent::MainContentComponent()
|
||||
{
|
||||
#if JUCE_ANDROID || JUCE_IOS
|
||||
setupControls();
|
||||
distributeControls();
|
||||
|
||||
#if JUCE_PUSH_NOTIFICATIONS
|
||||
addAndMakeVisible (headerLabel);
|
||||
addAndMakeVisible (mainTabs);
|
||||
addAndMakeVisible (sendButton);
|
||||
|
|
@ -40,12 +43,18 @@ MainContentComponent::MainContentComponent()
|
|||
headerLabel.setJustificationType (Justification::centred);
|
||||
notAvailableYetLabel.setJustificationType (Justification::centred);
|
||||
|
||||
#if JUCE_MAC
|
||||
StringArray tabNames { "Params1", "Params2", "Params3", "Params4" };
|
||||
#else
|
||||
StringArray tabNames { "Req. params", "Opt. params1", "Opt. params2", "Opt. params3" };
|
||||
#endif
|
||||
|
||||
const auto colour = getLookAndFeel().findColour (ResizableWindow::backgroundColourId);
|
||||
localNotificationsTabs.addTab ("Req. params", colour, &requiredParamsView, false);
|
||||
localNotificationsTabs.addTab ("Opt. params1", colour, &optionalParamsOneView, false);
|
||||
localNotificationsTabs.addTab (tabNames[0], colour, ¶msOneView, false);
|
||||
localNotificationsTabs.addTab (tabNames[1], colour, ¶msTwoView, false);
|
||||
#if JUCE_ANDROID
|
||||
localNotificationsTabs.addTab ("Opt. params2", colour, &optionalParamsTwoView, false);
|
||||
localNotificationsTabs.addTab ("Opt. params3", colour, &optionalParamsThreeView, false);
|
||||
localNotificationsTabs.addTab (tabNames[2], colour, ¶msThreeView, false);
|
||||
localNotificationsTabs.addTab (tabNames[3], colour, ¶msFourView, false);
|
||||
#endif
|
||||
localNotificationsTabs.addTab ("Aux. actions", colour, &auxActionsView, false);
|
||||
|
||||
|
|
@ -63,7 +72,7 @@ MainContentComponent::MainContentComponent()
|
|||
auxActionsView.getDeliveredNotificationsButton .addListener (this);
|
||||
auxActionsView.removeDeliveredNotifWithIdButton.addListener (this);
|
||||
auxActionsView.removeAllDeliveredNotifsButton .addListener (this);
|
||||
#if JUCE_IOS
|
||||
#if JUCE_IOS || JUCE_MAC
|
||||
auxActionsView.getPendingNotificationsButton .addListener (this);
|
||||
auxActionsView.removePendingNotifWithIdButton.addListener (this);
|
||||
auxActionsView.removeAllPendingNotifsButton .addListener (this);
|
||||
|
|
@ -74,16 +83,16 @@ MainContentComponent::MainContentComponent()
|
|||
remoteView.subscribeToSportsButton .addListener (this);
|
||||
remoteView.unsubscribeFromSportsButton.addListener (this);
|
||||
|
||||
optionalParamsThreeView.accentColourButton.addListener (this);
|
||||
optionalParamsThreeView.ledColourButton .addListener (this);
|
||||
paramControls.accentColourButton.addListener (this);
|
||||
paramControls.ledColourButton .addListener (this);
|
||||
|
||||
jassert (PushNotifications::getInstance()->areNotificationsEnabled());
|
||||
|
||||
PushNotifications::getInstance()->addListener (this);
|
||||
|
||||
#if JUCE_IOS
|
||||
optionalParamsOneView.fireInComboBox.addListener (this);
|
||||
PushNotifications::getInstance()->requestPermissionsWithSettings (getIosSettings());
|
||||
#if JUCE_IOS || JUCE_MAC
|
||||
paramControls.fireInComboBox.addListener (this);
|
||||
PushNotifications::getInstance()->requestPermissionsWithSettings (getNotificationSettings());
|
||||
#elif JUCE_ANDROID
|
||||
PushNotifications::ChannelGroup cg { "demoGroup", "demo group" };
|
||||
PushNotifications::getInstance()->setupChannels ({{ cg }}, getAndroidChannels());
|
||||
|
|
@ -95,6 +104,200 @@ MainContentComponent::~MainContentComponent()
|
|||
PushNotifications::getInstance()->removeListener (this);
|
||||
}
|
||||
|
||||
void MainContentComponent::setupControls()
|
||||
{
|
||||
auto& pc = paramControls;
|
||||
|
||||
StringArray categories { "okCategory", "okCancelCategory", "textCategory" };
|
||||
|
||||
for (const auto& c : categories)
|
||||
pc.categoryComboBox.addItem (c, pc.categoryComboBox.getNumItems() + 1);
|
||||
pc.categoryComboBox.setSelectedItemIndex (0);
|
||||
|
||||
for (int i = 1; i <= 3; ++i)
|
||||
pc.channelIdComboBox.addItem (String (i), i);
|
||||
pc.channelIdComboBox.setSelectedItemIndex (0);
|
||||
|
||||
for (int i = 0; i < 5; ++i)
|
||||
pc.iconComboBox.addItem ("icon" + String (i + 1), i + 1);
|
||||
pc.iconComboBox.setSelectedItemIndex (0);
|
||||
|
||||
#if JUCE_MAC
|
||||
pc.iconComboBox.addItem ("none", 100);
|
||||
#endif
|
||||
|
||||
pc.fireInComboBox.addItem ("Now", 1);
|
||||
|
||||
for (int i = 1; i < 11; ++i)
|
||||
pc.fireInComboBox.addItem (String (10 * i) + "seconds", i + 1);
|
||||
pc.fireInComboBox.setSelectedItemIndex (0);
|
||||
|
||||
pc.largeIconComboBox.addItem ("none", 1);
|
||||
|
||||
for (int i = 1; i < 5; ++i)
|
||||
pc.largeIconComboBox.addItem ("icon" + String (i), i + 1);
|
||||
pc.largeIconComboBox.setSelectedItemIndex (0);
|
||||
|
||||
pc.badgeIconComboBox.addItem ("none", 1);
|
||||
pc.badgeIconComboBox.addItem ("small", 2);
|
||||
pc.badgeIconComboBox.addItem ("large", 3);
|
||||
pc.badgeIconComboBox.setSelectedItemIndex (2);
|
||||
|
||||
pc.actionsComboBox.addItem ("none", 1);
|
||||
pc.actionsComboBox.addItem ("ok-cancel", 2);
|
||||
pc.actionsComboBox.addItem ("text-input", 3);
|
||||
#if JUCE_ANDROID
|
||||
pc.actionsComboBox.addItem ("ok-cancel-icons", 4);
|
||||
pc.actionsComboBox.addItem ("text-input-limited_responses", 5);
|
||||
#endif
|
||||
pc.actionsComboBox.setSelectedItemIndex (0);
|
||||
|
||||
for (int i = 0; i < 7; ++i)
|
||||
pc.badgeNumberComboBox.addItem (String (i), i + 1);
|
||||
pc.badgeNumberComboBox.setSelectedItemIndex (0);
|
||||
|
||||
#if JUCE_IOS
|
||||
String prefix = "sounds/";
|
||||
String extension = ".caf";
|
||||
#else
|
||||
String prefix;
|
||||
String extension;
|
||||
#endif
|
||||
|
||||
pc.soundToPlayComboBox.addItem ("none", 1);
|
||||
pc.soundToPlayComboBox.addItem ("default_os_sound", 2);
|
||||
pc.soundToPlayComboBox.addItem (prefix + "demonstrative" + extension, 3);
|
||||
pc.soundToPlayComboBox.addItem (prefix + "isntit" + extension, 4);
|
||||
pc.soundToPlayComboBox.addItem (prefix + "jinglebellssms" + extension, 5);
|
||||
pc.soundToPlayComboBox.addItem (prefix + "served" + extension, 6);
|
||||
pc.soundToPlayComboBox.addItem (prefix + "solemn" + extension, 7);
|
||||
pc.soundToPlayComboBox.setSelectedItemIndex (1);
|
||||
|
||||
for (int i = 0; i < 11; ++i)
|
||||
{
|
||||
pc.progressMaxComboBox .addItem (String (i * 10) + "%", i + 1);
|
||||
pc.progressCurrentComboBox.addItem (String (i * 10) + "%", i + 1);
|
||||
}
|
||||
|
||||
pc.progressMaxComboBox .setSelectedItemIndex (0);
|
||||
pc.progressCurrentComboBox.setSelectedItemIndex (0);
|
||||
|
||||
pc.notifCategoryComboBox.addItem ("unspecified", 1);
|
||||
pc.notifCategoryComboBox.addItem ("alarm", 2);
|
||||
pc.notifCategoryComboBox.addItem ("call", 3);
|
||||
pc.notifCategoryComboBox.addItem ("email", 4);
|
||||
pc.notifCategoryComboBox.addItem ("error", 5);
|
||||
pc.notifCategoryComboBox.addItem ("event", 6);
|
||||
pc.notifCategoryComboBox.addItem ("message", 7);
|
||||
pc.notifCategoryComboBox.addItem ("progress", 8);
|
||||
pc.notifCategoryComboBox.addItem ("promo", 9);
|
||||
pc.notifCategoryComboBox.addItem ("recommendation", 10);
|
||||
pc.notifCategoryComboBox.addItem ("reminder", 11);
|
||||
pc.notifCategoryComboBox.addItem ("service", 12);
|
||||
pc.notifCategoryComboBox.addItem ("social", 13);
|
||||
pc.notifCategoryComboBox.addItem ("status", 14);
|
||||
pc.notifCategoryComboBox.addItem ("system", 15);
|
||||
pc.notifCategoryComboBox.addItem ("transport", 16);
|
||||
pc.notifCategoryComboBox.setSelectedItemIndex (0);
|
||||
|
||||
for (int i = -2; i < 3; ++i)
|
||||
pc.priorityComboBox.addItem (String (i), i + 3);
|
||||
pc.priorityComboBox.setSelectedItemIndex (2);
|
||||
|
||||
pc.lockScreenVisibilityComboBox.addItem ("don't show", 1);
|
||||
pc.lockScreenVisibilityComboBox.addItem ("show partially", 2);
|
||||
pc.lockScreenVisibilityComboBox.addItem ("show completely", 3);
|
||||
pc.lockScreenVisibilityComboBox.setSelectedItemIndex (1);
|
||||
|
||||
pc.groupAlertBehaviourComboBox.addItem ("alert all", 1);
|
||||
pc.groupAlertBehaviourComboBox.addItem ("alert summary", 2);
|
||||
pc.groupAlertBehaviourComboBox.addItem ("alert children", 3);
|
||||
pc.groupAlertBehaviourComboBox.setSelectedItemIndex (0);
|
||||
|
||||
pc.timeoutAfterComboBox.addItem ("No timeout", 1);
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
pc.ledMsToBeOnComboBox .addItem (String (i * 200) + "ms", i + 1);
|
||||
pc.ledMsToBeOffComboBox .addItem (String (i * 200) + "ms", i + 1);
|
||||
pc.vibratorMsToBeOnComboBox .addItem (String (i * 500) + "ms", i + 1);
|
||||
pc.vibratorMsToBeOffComboBox.addItem (String (i * 500) + "ms", i + 1);
|
||||
pc.timeoutAfterComboBox.addItem (String (5000 + 1000 * i) + "ms", i + 2);
|
||||
}
|
||||
|
||||
pc.ledMsToBeOnComboBox .setSelectedItemIndex (5);
|
||||
pc.ledMsToBeOffComboBox .setSelectedItemIndex (5);
|
||||
pc.vibratorMsToBeOnComboBox .setSelectedItemIndex (0);
|
||||
pc.vibratorMsToBeOffComboBox.setSelectedItemIndex (0);
|
||||
pc.timeoutAfterComboBox.setSelectedItemIndex (0);
|
||||
|
||||
pc.timestampVisibilityComboBox.addItem ("off", 1);
|
||||
pc.timestampVisibilityComboBox.addItem ("on", 2);
|
||||
pc.timestampVisibilityComboBox.addItem ("chronometer", 3);
|
||||
pc.timestampVisibilityComboBox.addItem ("count down", 4);
|
||||
pc.timestampVisibilityComboBox.setSelectedItemIndex (1);
|
||||
}
|
||||
|
||||
void MainContentComponent::distributeControls()
|
||||
{
|
||||
auto& pc = paramControls;
|
||||
|
||||
paramsOneView.addRowComponent (new RowComponent (pc.identifierLabel, pc.identifierEditor));
|
||||
paramsOneView.addRowComponent (new RowComponent (pc.titleLabel, pc.titleEditor));
|
||||
paramsOneView.addRowComponent (new RowComponent (pc.bodyLabel, pc.bodyEditor, 4));
|
||||
#if JUCE_IOS
|
||||
paramsOneView.addRowComponent (new RowComponent (pc.categoryLabel, pc.categoryComboBox));
|
||||
#elif JUCE_ANDROID
|
||||
paramsOneView.addRowComponent (new RowComponent (pc.channelIdLabel, pc.channelIdComboBox));
|
||||
#endif
|
||||
#if JUCE_ANDROID || JUCE_MAC
|
||||
paramsOneView.addRowComponent (new RowComponent (pc.iconLabel, pc.iconComboBox));
|
||||
#endif
|
||||
|
||||
paramsTwoView.addRowComponent (new RowComponent (pc.subtitleLabel, pc.subtitleEditor));
|
||||
#if ! JUCE_MAC
|
||||
paramsTwoView.addRowComponent (new RowComponent (pc.badgeNumberLabel, pc.badgeNumberComboBox));
|
||||
#endif
|
||||
paramsTwoView.addRowComponent (new RowComponent (pc.soundToPlayLabel, pc.soundToPlayComboBox));
|
||||
paramsTwoView.addRowComponent (new RowComponent (pc.propertiesLabel, pc.propertiesEditor, 3));
|
||||
#if JUCE_IOS || JUCE_MAC
|
||||
paramsTwoView.addRowComponent (new RowComponent (pc.fireInLabel, pc.fireInComboBox));
|
||||
paramsTwoView.addRowComponent (new RowComponent (pc.repeatLabel, pc.repeatButton));
|
||||
#elif JUCE_ANDROID
|
||||
paramsTwoView.addRowComponent (new RowComponent (pc.largeIconLabel, pc.largeIconComboBox));
|
||||
paramsTwoView.addRowComponent (new RowComponent (pc.badgeIconLabel, pc.badgeIconComboBox));
|
||||
paramsTwoView.addRowComponent (new RowComponent (pc.tickerTextLabel, pc.tickerTextEditor));
|
||||
paramsTwoView.addRowComponent (new RowComponent (pc.autoCancelLabel, pc.autoCancelButton));
|
||||
paramsTwoView.addRowComponent (new RowComponent (pc.alertOnlyOnceLabel, pc.alertOnlyOnceButton));
|
||||
#endif
|
||||
#if JUCE_ANDROID || JUCE_MAC
|
||||
paramsTwoView.addRowComponent (new RowComponent (pc.actionsLabel, pc.actionsComboBox));
|
||||
#endif
|
||||
#if JUCE_ANDROID
|
||||
paramsThreeView.addRowComponent (new RowComponent (pc.progressMaxLabel, pc.progressMaxComboBox));
|
||||
paramsThreeView.addRowComponent (new RowComponent (pc.progressCurrentLabel, pc.progressCurrentComboBox));
|
||||
paramsThreeView.addRowComponent (new RowComponent (pc.progressIndeterminateLabel, pc.progressIndeterminateButton));
|
||||
paramsThreeView.addRowComponent (new RowComponent (pc.categoryLabel, pc.categoryComboBox));
|
||||
paramsThreeView.addRowComponent (new RowComponent (pc.priorityLabel, pc.priorityComboBox));
|
||||
paramsThreeView.addRowComponent (new RowComponent (pc.personLabel, pc.personEditor));
|
||||
paramsThreeView.addRowComponent (new RowComponent (pc.lockScreenVisibilityLabel, pc.lockScreenVisibilityComboBox));
|
||||
paramsThreeView.addRowComponent (new RowComponent (pc.groupIdLabel, pc.groupIdEditor));
|
||||
paramsThreeView.addRowComponent (new RowComponent (pc.sortKeyLabel, pc.sortKeyEditor));
|
||||
paramsThreeView.addRowComponent (new RowComponent (pc.groupSummaryLabel, pc.groupSummaryButton));
|
||||
paramsThreeView.addRowComponent (new RowComponent (pc.groupAlertBehaviourLabel, pc.groupAlertBehaviourComboBox));
|
||||
paramsFourView.addRowComponent (new RowComponent (pc.accentColourLabel, pc.accentColourButton));
|
||||
paramsFourView.addRowComponent (new RowComponent (pc.ledColourLabel, pc.ledColourButton));
|
||||
paramsFourView.addRowComponent (new RowComponent (pc.ledMsToBeOffLabel, pc.ledMsToBeOffComboBox));
|
||||
paramsFourView.addRowComponent (new RowComponent (pc.ledMsToBeOnLabel, pc.ledMsToBeOnComboBox));
|
||||
paramsFourView.addRowComponent (new RowComponent (pc.vibratorMsToBeOffLabel, pc.vibratorMsToBeOffComboBox));
|
||||
paramsFourView.addRowComponent (new RowComponent (pc.vibratorMsToBeOnLabel, pc.vibratorMsToBeOnComboBox));
|
||||
paramsFourView.addRowComponent (new RowComponent (pc.localOnlyLabel, pc.localOnlyButton));
|
||||
paramsFourView.addRowComponent (new RowComponent (pc.ongoingLabel, pc.ongoingButton));
|
||||
paramsFourView.addRowComponent (new RowComponent (pc.timestampVisibilityLabel, pc.timestampVisibilityComboBox));
|
||||
paramsFourView.addRowComponent (new RowComponent (pc.timeoutAfterLabel, pc.timeoutAfterComboBox));
|
||||
#endif
|
||||
}
|
||||
|
||||
void MainContentComponent::paint (Graphics& g)
|
||||
{
|
||||
g.fillAll (getLookAndFeel().findColour (ResizableWindow::backgroundColourId));
|
||||
|
|
@ -117,9 +320,9 @@ void MainContentComponent::buttonClicked (Button* b)
|
|||
{
|
||||
if (b == &sendButton)
|
||||
sendLocalNotification();
|
||||
else if (b == &optionalParamsThreeView.accentColourButton)
|
||||
else if (b == ¶mControls.accentColourButton)
|
||||
setupAccentColour();
|
||||
else if (b == &optionalParamsThreeView.ledColourButton)
|
||||
else if (b == ¶mControls.ledColourButton)
|
||||
setupLedColour();
|
||||
else if (b == &auxActionsView.getDeliveredNotificationsButton)
|
||||
getDeliveredNotifications();
|
||||
|
|
@ -127,7 +330,7 @@ void MainContentComponent::buttonClicked (Button* b)
|
|||
PushNotifications::getInstance()->removeDeliveredNotification (auxActionsView.deliveredNotifIdentifier.getText());
|
||||
else if (b == &auxActionsView.removeAllDeliveredNotifsButton)
|
||||
PushNotifications::getInstance()->removeAllDeliveredNotifications();
|
||||
#if JUCE_IOS
|
||||
#if JUCE_IOS || JUCE_MAC
|
||||
else if (b == &auxActionsView.getPendingNotificationsButton)
|
||||
PushNotifications::getInstance()->getPendingLocalNotifications();
|
||||
else if (b == &auxActionsView.removePendingNotifWithIdButton)
|
||||
|
|
@ -141,7 +344,10 @@ void MainContentComponent::buttonClicked (Button* b)
|
|||
|
||||
DBG ("token = " + token);
|
||||
|
||||
NativeMessageBox::showMessageBoxAsync (AlertWindow::InfoIcon, "Device token", token);
|
||||
if (token.isEmpty())
|
||||
showRemoteInstructions();
|
||||
else
|
||||
NativeMessageBox::showMessageBoxAsync (AlertWindow::InfoIcon, "Device token", token);
|
||||
}
|
||||
#if JUCE_ANDROID
|
||||
else if (b == &remoteView.sendRemoteMessageButton)
|
||||
|
|
@ -172,19 +378,15 @@ void MainContentComponent::buttonClicked (Button* b)
|
|||
|
||||
void MainContentComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
|
||||
{
|
||||
#if JUCE_IOS
|
||||
if (comboBoxThatHasChanged == &optionalParamsOneView.fireInComboBox)
|
||||
if (comboBoxThatHasChanged == ¶mControls.fireInComboBox)
|
||||
{
|
||||
const bool repeatsAllowed = optionalParamsOneView.fireInComboBox.getSelectedItemIndex() >= 6;
|
||||
const bool repeatsAllowed = paramControls.fireInComboBox.getSelectedItemIndex() >= 6;
|
||||
|
||||
optionalParamsOneView.repeatButton.setEnabled (repeatsAllowed);
|
||||
paramControls.repeatButton.setEnabled (repeatsAllowed);
|
||||
|
||||
if (! repeatsAllowed)
|
||||
optionalParamsOneView.repeatButton.setToggleState (false, NotificationType::sendNotification);
|
||||
paramControls.repeatButton.setToggleState (false, NotificationType::sendNotification);
|
||||
}
|
||||
#else
|
||||
ignoreUnused (comboBoxThatHasChanged);
|
||||
#endif
|
||||
}
|
||||
|
||||
void MainContentComponent::sendLocalNotification()
|
||||
|
|
@ -222,23 +424,32 @@ void MainContentComponent::sendLocalNotification()
|
|||
|
||||
void MainContentComponent::fillRequiredParams (PushNotifications::Notification& n)
|
||||
{
|
||||
n.identifier = requiredParamsView.identifierEditor.getText();
|
||||
n.title = requiredParamsView.titleEditor.getText();
|
||||
n.body = requiredParamsView.bodyEditor.getText();
|
||||
n.identifier = paramControls.identifierEditor.getText();
|
||||
n.title = paramControls.titleEditor.getText();
|
||||
n.body = paramControls.bodyEditor.getText();
|
||||
#if JUCE_IOS
|
||||
n.category = requiredParamsView.categories[requiredParamsView.categoryComboBox.getSelectedItemIndex()];
|
||||
#elif JUCE_ANDROID
|
||||
if (requiredParamsView.iconComboBox.getSelectedItemIndex() == 0)
|
||||
n.icon = "ic_stat_name";
|
||||
else if (requiredParamsView.iconComboBox.getSelectedItemIndex() == 1)
|
||||
n.icon = "ic_stat_name2";
|
||||
else if (requiredParamsView.iconComboBox.getSelectedItemIndex() == 2)
|
||||
n.icon = "ic_stat_name3";
|
||||
else if (requiredParamsView.iconComboBox.getSelectedItemIndex() == 3)
|
||||
n.icon = "ic_stat_name4";
|
||||
else
|
||||
n.icon = "ic_stat_name5";
|
||||
n.category = paramControls.categoryComboBox.getText();
|
||||
#elif JUCE_ANDROID || JUCE_MAC
|
||||
#if JUCE_MAC
|
||||
String prefix = "images/";
|
||||
String extension = ".png";
|
||||
#else
|
||||
String prefix;
|
||||
String extension;
|
||||
#endif
|
||||
if (paramControls.iconComboBox.getSelectedItemIndex() == 0)
|
||||
n.icon = prefix + "ic_stat_name" + extension;
|
||||
else if (paramControls.iconComboBox.getSelectedItemIndex() == 1)
|
||||
n.icon = prefix + "ic_stat_name2" + extension;
|
||||
else if (paramControls.iconComboBox.getSelectedItemIndex() == 2)
|
||||
n.icon = prefix + "ic_stat_name3" + extension;
|
||||
else if (paramControls.iconComboBox.getSelectedItemIndex() == 3)
|
||||
n.icon = prefix + "ic_stat_name4" + extension;
|
||||
else if (paramControls.iconComboBox.getSelectedItemIndex() == 4)
|
||||
n.icon = prefix + "ic_stat_name5" + extension;
|
||||
#endif
|
||||
|
||||
#if JUCE_ANDROID
|
||||
// Note: this is not strictly speaking required param, just doing it here because it is the fastest way!
|
||||
n.publicVersion = new PushNotifications::Notification();
|
||||
n.publicVersion->identifier = "blahblahblah";
|
||||
|
|
@ -247,69 +458,59 @@ void MainContentComponent::fillRequiredParams (PushNotifications::Notification&
|
|||
n.publicVersion->icon = n.icon;
|
||||
|
||||
#if __ANDROID_API__ >= 26
|
||||
n.channelId = String (requiredParamsView.channelIdComboBox.getSelectedItemIndex() + 1);
|
||||
n.channelId = String (paramControls.channelIdComboBox.getSelectedItemIndex() + 1);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void MainContentComponent::fillOptionalParamsOne (PushNotifications::Notification& n)
|
||||
{
|
||||
n.subtitle = optionalParamsOneView.subtitleEditor.getText();
|
||||
n.badgeNumber = optionalParamsOneView.badgeNumberComboBox.getSelectedItemIndex();
|
||||
n.subtitle = paramControls.subtitleEditor.getText();
|
||||
n.badgeNumber = paramControls.badgeNumberComboBox.getSelectedItemIndex();
|
||||
|
||||
if (optionalParamsOneView.soundToPlayComboBox.getSelectedItemIndex() > 0)
|
||||
n.soundToPlay = URL (optionalParamsOneView.soundToPlayComboBox.getItemText (optionalParamsOneView.soundToPlayComboBox.getSelectedItemIndex()));
|
||||
if (paramControls.soundToPlayComboBox.getSelectedItemIndex() > 0)
|
||||
n.soundToPlay = URL (paramControls.soundToPlayComboBox.getItemText (paramControls.soundToPlayComboBox.getSelectedItemIndex()));
|
||||
|
||||
n.properties = JSON::parse (optionalParamsOneView.propertiesEditor.getText());
|
||||
n.properties = JSON::parse (paramControls.propertiesEditor.getText());
|
||||
|
||||
#if JUCE_IOS
|
||||
n.triggerIntervalSec = double (optionalParamsOneView.fireInComboBox.getSelectedItemIndex() * 10);
|
||||
n.repeat = optionalParamsOneView.repeatButton.getToggleState();
|
||||
#if JUCE_IOS || JUCE_MAC
|
||||
n.triggerIntervalSec = double (paramControls.fireInComboBox.getSelectedItemIndex() * 10);
|
||||
n.repeat = paramControls.repeatButton.getToggleState();
|
||||
#elif JUCE_ANDROID
|
||||
if (optionalParamsOneView.largeIconComboBox.getSelectedItemIndex() == 1)
|
||||
if (paramControls.largeIconComboBox.getSelectedItemIndex() == 1)
|
||||
n.largeIcon = ImageFileFormat::loadFrom (BinaryData::ic_stat_name6_png, BinaryData::ic_stat_name6_pngSize);
|
||||
else if (optionalParamsOneView.largeIconComboBox.getSelectedItemIndex() == 2)
|
||||
else if (paramControls.largeIconComboBox.getSelectedItemIndex() == 2)
|
||||
n.largeIcon = ImageFileFormat::loadFrom (BinaryData::ic_stat_name7_png, BinaryData::ic_stat_name7_pngSize);
|
||||
else if (optionalParamsOneView.largeIconComboBox.getSelectedItemIndex() == 3)
|
||||
else if (paramControls.largeIconComboBox.getSelectedItemIndex() == 3)
|
||||
n.largeIcon = ImageFileFormat::loadFrom (BinaryData::ic_stat_name8_png, BinaryData::ic_stat_name8_pngSize);
|
||||
else if (optionalParamsOneView.largeIconComboBox.getSelectedItemIndex() == 4)
|
||||
else if (paramControls.largeIconComboBox.getSelectedItemIndex() == 4)
|
||||
n.largeIcon = ImageFileFormat::loadFrom (BinaryData::ic_stat_name9_png, BinaryData::ic_stat_name9_pngSize);
|
||||
else if (optionalParamsOneView.largeIconComboBox.getSelectedItemIndex() == 5)
|
||||
else if (paramControls.largeIconComboBox.getSelectedItemIndex() == 5)
|
||||
n.largeIcon = ImageFileFormat::loadFrom (BinaryData::ic_stat_name10_png, BinaryData::ic_stat_name10_pngSize);
|
||||
|
||||
n.badgeIconType = (PushNotifications::Notification::BadgeIconType) optionalParamsOneView.badgeIconComboBox.getSelectedItemIndex();
|
||||
n.tickerText = optionalParamsOneView.tickerTextEditor.getText();
|
||||
n.badgeIconType = (PushNotifications::Notification::BadgeIconType) paramControls.badgeIconComboBox.getSelectedItemIndex();
|
||||
n.tickerText = paramControls.tickerTextEditor.getText();
|
||||
|
||||
n.shouldAutoCancel = optionalParamsOneView.autoCancelButton.getToggleState();
|
||||
n.alertOnlyOnce = optionalParamsOneView.alertOnlyOnceButton.getToggleState();
|
||||
n.shouldAutoCancel = paramControls.autoCancelButton.getToggleState();
|
||||
n.alertOnlyOnce = paramControls.alertOnlyOnceButton.getToggleState();
|
||||
#endif
|
||||
|
||||
if (optionalParamsOneView.actionsComboBox.getSelectedItemIndex() == 1)
|
||||
#if JUCE_ANDROID || JUCE_MAC
|
||||
if (paramControls.actionsComboBox.getSelectedItemIndex() == 1)
|
||||
{
|
||||
PushNotifications::Notification::Action a, a2;
|
||||
a .style = PushNotifications::Notification::Action::button;
|
||||
a2.style = PushNotifications::Notification::Action::button;
|
||||
a .title = "Ok";
|
||||
a2.title = "Cancel";
|
||||
a .title = a .identifier = "Ok";
|
||||
a2.title = a2.identifier = "Cancel";
|
||||
n.actions.add (a);
|
||||
n.actions.add (a2);
|
||||
}
|
||||
else if (optionalParamsOneView.actionsComboBox.getSelectedItemIndex() == 2)
|
||||
else if (paramControls.actionsComboBox.getSelectedItemIndex() == 2)
|
||||
{
|
||||
PushNotifications::Notification::Action a, a2;
|
||||
a .title = "Ok";
|
||||
a2.title = "Cancel";
|
||||
a .style = PushNotifications::Notification::Action::button;
|
||||
a2.style = PushNotifications::Notification::Action::button;
|
||||
a .icon = "ic_stat_name4";
|
||||
a2.icon = "ic_stat_name5";
|
||||
n.actions.add (a);
|
||||
n.actions.add (a2);
|
||||
}
|
||||
else if (optionalParamsOneView.actionsComboBox.getSelectedItemIndex() == 3)
|
||||
{
|
||||
PushNotifications::Notification::Action a, a2;
|
||||
a .title = "Input Text Here";
|
||||
a2.title = "No";
|
||||
a .title = a .identifier = "Input Text Here";
|
||||
a2.title = a2.identifier = "No";
|
||||
a .style = PushNotifications::Notification::Action::text;
|
||||
a2.style = PushNotifications::Notification::Action::button;
|
||||
a .icon = "ic_stat_name4";
|
||||
|
|
@ -318,11 +519,23 @@ void MainContentComponent::fillOptionalParamsOne (PushNotifications::Notificatio
|
|||
n.actions.add (a);
|
||||
n.actions.add (a2);
|
||||
}
|
||||
else if (optionalParamsOneView.actionsComboBox.getSelectedItemIndex() == 4)
|
||||
else if (paramControls.actionsComboBox.getSelectedItemIndex() == 3)
|
||||
{
|
||||
PushNotifications::Notification::Action a, a2;
|
||||
a .title = "Input Text Here";
|
||||
a2.title = "No";
|
||||
a .title = a .identifier = "Ok";
|
||||
a2.title = a2.identifier = "Cancel";
|
||||
a .style = PushNotifications::Notification::Action::button;
|
||||
a2.style = PushNotifications::Notification::Action::button;
|
||||
a .icon = "ic_stat_name4";
|
||||
a2.icon = "ic_stat_name5";
|
||||
n.actions.add (a);
|
||||
n.actions.add (a2);
|
||||
}
|
||||
else if (paramControls.actionsComboBox.getSelectedItemIndex() == 4)
|
||||
{
|
||||
PushNotifications::Notification::Action a, a2;
|
||||
a .title = a .identifier = "Input Text Here";
|
||||
a2.title = a2.identifier = "No";
|
||||
a .style = PushNotifications::Notification::Action::text;
|
||||
a2.style = PushNotifications::Notification::Action::button;
|
||||
a .icon = "ic_stat_name4";
|
||||
|
|
@ -342,102 +555,102 @@ void MainContentComponent::fillOptionalParamsTwo (PushNotifications::Notificatio
|
|||
using Notification = PushNotifications::Notification;
|
||||
|
||||
Notification::Progress progress;
|
||||
progress.max = optionalParamsTwoView.progressMaxComboBox.getSelectedItemIndex() * 10;
|
||||
progress.current = optionalParamsTwoView.progressCurrentComboBox.getSelectedItemIndex() * 10;
|
||||
progress.indeterminate = optionalParamsTwoView.progressIndeterminateButton.getToggleState();
|
||||
progress.max = paramControls.progressMaxComboBox.getSelectedItemIndex() * 10;
|
||||
progress.current = paramControls.progressCurrentComboBox.getSelectedItemIndex() * 10;
|
||||
progress.indeterminate = paramControls.progressIndeterminateButton.getToggleState();
|
||||
|
||||
n.progress = progress;
|
||||
n.person = optionalParamsTwoView.personEditor.getText();
|
||||
n.type = Notification::Type (optionalParamsTwoView.categoryComboBox.getSelectedItemIndex());
|
||||
n.priority = Notification::Priority (optionalParamsTwoView.priorityComboBox.getSelectedItemIndex() - 2);
|
||||
n.lockScreenAppearance = Notification::LockScreenAppearance (optionalParamsTwoView.lockScreenVisibilityComboBox.getSelectedItemIndex() - 1);
|
||||
n.groupId = optionalParamsTwoView.groupIdEditor.getText();
|
||||
n.groupSortKey = optionalParamsTwoView.sortKeyEditor.getText();
|
||||
n.groupSummary = optionalParamsTwoView.groupSummaryButton.getToggleState();
|
||||
n.groupAlertBehaviour = Notification::GroupAlertBehaviour (optionalParamsTwoView.groupAlertBehaviourComboBox.getSelectedItemIndex());
|
||||
n.person = paramControls.personEditor.getText();
|
||||
n.type = Notification::Type (paramControls.categoryComboBox.getSelectedItemIndex());
|
||||
n.priority = Notification::Priority (paramControls.priorityComboBox.getSelectedItemIndex() - 2);
|
||||
n.lockScreenAppearance = Notification::LockScreenAppearance (paramControls.lockScreenVisibilityComboBox.getSelectedItemIndex() - 1);
|
||||
n.groupId = paramControls.groupIdEditor.getText();
|
||||
n.groupSortKey = paramControls.sortKeyEditor.getText();
|
||||
n.groupSummary = paramControls.groupSummaryButton.getToggleState();
|
||||
n.groupAlertBehaviour = Notification::GroupAlertBehaviour (paramControls.groupAlertBehaviourComboBox.getSelectedItemIndex());
|
||||
}
|
||||
|
||||
void MainContentComponent::fillOptionalParamsThree (PushNotifications::Notification& n)
|
||||
{
|
||||
n.accentColour = optionalParamsThreeView.accentColourButton.findColour (TextButton::buttonColourId, false);
|
||||
n.ledColour = optionalParamsThreeView.ledColourButton .findColour (TextButton::buttonColourId, false);
|
||||
n.accentColour = paramControls.accentColourButton.findColour (TextButton::buttonColourId, false);
|
||||
n.ledColour = paramControls.ledColourButton .findColour (TextButton::buttonColourId, false);
|
||||
|
||||
using Notification = PushNotifications::Notification;
|
||||
Notification::LedBlinkPattern ledBlinkPattern;
|
||||
ledBlinkPattern.msToBeOn = optionalParamsThreeView.ledMsToBeOnComboBox .getSelectedItemIndex() * 200;
|
||||
ledBlinkPattern.msToBeOff = optionalParamsThreeView.ledMsToBeOffComboBox.getSelectedItemIndex() * 200;
|
||||
ledBlinkPattern.msToBeOn = paramControls.ledMsToBeOnComboBox .getSelectedItemIndex() * 200;
|
||||
ledBlinkPattern.msToBeOff = paramControls.ledMsToBeOffComboBox.getSelectedItemIndex() * 200;
|
||||
n.ledBlinkPattern = ledBlinkPattern;
|
||||
|
||||
Array<int> vibrationPattern;
|
||||
|
||||
if (optionalParamsThreeView.vibratorMsToBeOnComboBox .getSelectedItemIndex() > 0 &&
|
||||
optionalParamsThreeView.vibratorMsToBeOffComboBox.getSelectedItemIndex() > 0)
|
||||
if (paramControls.vibratorMsToBeOnComboBox .getSelectedItemIndex() > 0 &&
|
||||
paramControls.vibratorMsToBeOffComboBox.getSelectedItemIndex() > 0)
|
||||
{
|
||||
vibrationPattern.add (optionalParamsThreeView.vibratorMsToBeOffComboBox.getSelectedItemIndex() * 500);
|
||||
vibrationPattern.add (optionalParamsThreeView.vibratorMsToBeOnComboBox .getSelectedItemIndex() * 500);
|
||||
vibrationPattern.add (2 * optionalParamsThreeView.vibratorMsToBeOffComboBox.getSelectedItemIndex() * 500);
|
||||
vibrationPattern.add (2 * optionalParamsThreeView.vibratorMsToBeOnComboBox .getSelectedItemIndex() * 500);
|
||||
vibrationPattern.add (paramControls.vibratorMsToBeOffComboBox.getSelectedItemIndex() * 500);
|
||||
vibrationPattern.add (paramControls.vibratorMsToBeOnComboBox .getSelectedItemIndex() * 500);
|
||||
vibrationPattern.add (2 * paramControls.vibratorMsToBeOffComboBox.getSelectedItemIndex() * 500);
|
||||
vibrationPattern.add (2 * paramControls.vibratorMsToBeOnComboBox .getSelectedItemIndex() * 500);
|
||||
}
|
||||
|
||||
n.vibrationPattern = vibrationPattern;
|
||||
|
||||
n.localOnly = optionalParamsThreeView.localOnlyButton.getToggleState();
|
||||
n.ongoing = optionalParamsThreeView.ongoingButton.getToggleState();
|
||||
n.timestampVisibility = Notification::TimestampVisibility (optionalParamsThreeView.timestampVisibilityComboBox.getSelectedItemIndex());
|
||||
n.localOnly = paramControls.localOnlyButton.getToggleState();
|
||||
n.ongoing = paramControls.ongoingButton.getToggleState();
|
||||
n.timestampVisibility = Notification::TimestampVisibility (paramControls.timestampVisibilityComboBox.getSelectedItemIndex());
|
||||
|
||||
if (optionalParamsThreeView.timeoutAfterComboBox.getSelectedItemIndex() > 0)
|
||||
if (paramControls.timeoutAfterComboBox.getSelectedItemIndex() > 0)
|
||||
{
|
||||
auto index = optionalParamsThreeView.timeoutAfterComboBox.getSelectedItemIndex();
|
||||
auto index = paramControls.timeoutAfterComboBox.getSelectedItemIndex();
|
||||
n.timeoutAfterMs = index * 1000 + 4000;
|
||||
}
|
||||
}
|
||||
|
||||
void MainContentComponent::setupAccentColour()
|
||||
{
|
||||
optionalParamsThreeView.accentColourSelector = new ColourSelector();
|
||||
optionalParamsThreeView.accentColourSelector->setName ("accent colour");
|
||||
optionalParamsThreeView.accentColourSelector->setCurrentColour (optionalParamsThreeView.accentColourButton.findColour (TextButton::buttonColourId));
|
||||
optionalParamsThreeView.accentColourSelector->setColour (ColourSelector::backgroundColourId, Colours::transparentBlack);
|
||||
optionalParamsThreeView.accentColourSelector->setSize (200, 200);
|
||||
optionalParamsThreeView.accentColourSelector->addComponentListener (this);
|
||||
optionalParamsThreeView.accentColourSelector->addChangeListener (this);
|
||||
paramControls.accentColourSelector = new ColourSelector();
|
||||
paramControls.accentColourSelector->setName ("accent colour");
|
||||
paramControls.accentColourSelector->setCurrentColour (paramControls.accentColourButton.findColour (TextButton::buttonColourId));
|
||||
paramControls.accentColourSelector->setColour (ColourSelector::backgroundColourId, Colours::transparentBlack);
|
||||
paramControls.accentColourSelector->setSize (200, 200);
|
||||
paramControls.accentColourSelector->addComponentListener (this);
|
||||
paramControls.accentColourSelector->addChangeListener (this);
|
||||
|
||||
CallOutBox::launchAsynchronously (optionalParamsThreeView.accentColourSelector, optionalParamsThreeView.accentColourButton.getScreenBounds(), nullptr);
|
||||
CallOutBox::launchAsynchronously (paramControls.accentColourSelector, paramControls.accentColourButton.getScreenBounds(), nullptr);
|
||||
}
|
||||
|
||||
void MainContentComponent::setupLedColour()
|
||||
{
|
||||
optionalParamsThreeView.ledColourSelector = new ColourSelector();
|
||||
optionalParamsThreeView.ledColourSelector->setName ("led colour");
|
||||
optionalParamsThreeView.ledColourSelector->setCurrentColour (optionalParamsThreeView.ledColourButton.findColour (TextButton::buttonColourId));
|
||||
optionalParamsThreeView.ledColourSelector->setColour (ColourSelector::backgroundColourId, Colours::transparentBlack);
|
||||
optionalParamsThreeView.ledColourSelector->setSize (200, 200);
|
||||
optionalParamsThreeView.ledColourSelector->addComponentListener (this);
|
||||
optionalParamsThreeView.ledColourSelector->addChangeListener (this);
|
||||
paramControls.ledColourSelector = new ColourSelector();
|
||||
paramControls.ledColourSelector->setName ("led colour");
|
||||
paramControls.ledColourSelector->setCurrentColour (paramControls.ledColourButton.findColour (TextButton::buttonColourId));
|
||||
paramControls.ledColourSelector->setColour (ColourSelector::backgroundColourId, Colours::transparentBlack);
|
||||
paramControls.ledColourSelector->setSize (200, 200);
|
||||
paramControls.ledColourSelector->addComponentListener (this);
|
||||
paramControls.ledColourSelector->addChangeListener (this);
|
||||
|
||||
CallOutBox::launchAsynchronously (optionalParamsThreeView.ledColourSelector, optionalParamsThreeView.accentColourButton.getScreenBounds(), nullptr);
|
||||
CallOutBox::launchAsynchronously (paramControls.ledColourSelector, paramControls.accentColourButton.getScreenBounds(), nullptr);
|
||||
}
|
||||
|
||||
void MainContentComponent::changeListenerCallback (ChangeBroadcaster* source)
|
||||
{
|
||||
if (source == optionalParamsThreeView.accentColourSelector)
|
||||
if (source == paramControls.accentColourSelector)
|
||||
{
|
||||
Colour c = optionalParamsThreeView.accentColourSelector->getCurrentColour();
|
||||
optionalParamsThreeView.accentColourButton.setColour (TextButton::buttonColourId, c);
|
||||
Colour c = paramControls.accentColourSelector->getCurrentColour();
|
||||
paramControls.accentColourButton.setColour (TextButton::buttonColourId, c);
|
||||
}
|
||||
else if (source == optionalParamsThreeView.ledColourSelector)
|
||||
else if (source == paramControls.ledColourSelector)
|
||||
{
|
||||
Colour c = optionalParamsThreeView.ledColourSelector->getCurrentColour();
|
||||
optionalParamsThreeView.ledColourButton.setColour (TextButton::buttonColourId, c);
|
||||
Colour c = paramControls.ledColourSelector->getCurrentColour();
|
||||
paramControls.ledColourButton.setColour (TextButton::buttonColourId, c);
|
||||
}
|
||||
}
|
||||
|
||||
void MainContentComponent::componentBeingDeleted (Component& component)
|
||||
{
|
||||
if (&component == optionalParamsThreeView.accentColourSelector)
|
||||
optionalParamsThreeView.accentColourSelector = nullptr;
|
||||
else if (&component == optionalParamsThreeView.ledColourSelector)
|
||||
optionalParamsThreeView.ledColourSelector = nullptr;
|
||||
if (&component == paramControls.accentColourSelector)
|
||||
paramControls.accentColourSelector = nullptr;
|
||||
else if (&component == paramControls.ledColourSelector)
|
||||
paramControls.ledColourSelector = nullptr;
|
||||
}
|
||||
|
||||
void MainContentComponent::handleNotification (bool isLocalNotification, const PushNotifications::Notification& n)
|
||||
|
|
@ -576,9 +789,15 @@ Array<PushNotifications::Channel> MainContentComponent::getAndroidChannels()
|
|||
return { ch1, ch2, ch3 };
|
||||
}
|
||||
|
||||
#elif JUCE_IOS
|
||||
PushNotifications::Settings MainContentComponent::getIosSettings()
|
||||
#elif JUCE_IOS || JUCE_MAC
|
||||
PushNotifications::Settings MainContentComponent::getNotificationSettings()
|
||||
{
|
||||
PushNotifications::Settings settings;
|
||||
settings.allowAlert = true;
|
||||
settings.allowBadge = true;
|
||||
settings.allowSound = true;
|
||||
|
||||
#if JUCE_IOS
|
||||
using Action = PushNotifications::Settings::Action;
|
||||
using Category = PushNotifications::Settings::Category;
|
||||
|
||||
|
|
@ -617,11 +836,8 @@ PushNotifications::Settings MainContentComponent::getIosSettings()
|
|||
textCategory.actions = { textAction };
|
||||
textCategory.sendDismissAction = true;
|
||||
|
||||
PushNotifications::Settings settings;
|
||||
settings.allowAlert = true;
|
||||
settings.allowBadge = true;
|
||||
settings.allowSound = true;
|
||||
settings.categories = { okCategory, okCancelCategory, textCategory };
|
||||
#endif
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue