Skip to content

Commit

Permalink
AppNotificationBuilder - ProgressBar (#2780)
Browse files Browse the repository at this point in the history
* First iteration

* Fix formatting issues

* Remove all references to toast

* Add ProgressBar

* Remove getters and other nits

* Add XML outputs for all examples

* Update examples and fix missing png

* Add limitations

* Add ArgumentSerializer and rename APIs

* Fix some nits

* Fix audio ctors

* Add Deserializer functions and example

* Apply review changes

* Update AppNotificationBuilder-spec.md

* Initial commit

* Working on it

* Add AppNotificationContent

* Current impl

* Working on unit tests

* Added unit tests

* Add Audio tests

* Update APITests.cpp

* Remove spec from PR

* Rename AppNotification Builder API to match specs (#2766)

* Renaming to match specs

* Adding latest changes to specs

* Code cleanup

* Updating to reflect latest changes to the specs doc

Co-authored-by: Eric Langlois <[email protected]>

* Initial implementation

* Update the spec with BuildNotification

* Remove unused files

* Add copyright to all files

* Update AppNotificationBuilder.idl

Adding copyright notice

* Update pch.cpp

Adding copyright notice

* Update WindowsAppRuntime_DLL.vcxproj

Removing references to fmt lib

* Update packages.config

Removing reference to fmt

* Update AppNotificationBuilder.cpp

Removing fmt since we won't be using and to unblock the build pipelines

* Fixing build break

* Addressing comments

* Update error codes with messages

* Add helper file

* Add SetTimestamp impl

* Add AppNotificationAudioLooping

* Add IsSupported to attributes

* Don't mix binding and value states

* Code cleanup

* Using printf as it is the norm for the builder

* look proper

* spacing

* Reorder functions in idl to help github track changes properly

* Keeping all progressBar tests together

* PR feedback

Co-authored-by: Paul Purifoy <[email protected]>
Co-authored-by: Paul Purifoy <[email protected]>
Co-authored-by: Eric Langlois <[email protected]>
  • Loading branch information
4 people authored Aug 4, 2022
1 parent 3d9830d commit 5e4961a
Show file tree
Hide file tree
Showing 8 changed files with 334 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,13 @@ namespace winrt::Microsoft::Windows::AppNotifications::Builder::implementation
return *this;
}

winrt::Microsoft::Windows::AppNotifications::Builder::AppNotificationBuilder AppNotificationBuilder::AddProgressBar(AppNotificationProgressBar const& value)
{
m_progressBarList.push_back(value);

return *this;
}

winrt::Microsoft::Windows::AppNotifications::Builder::AppNotificationBuilder AppNotificationBuilder::AddTextBox(hstring id)
{
ThrowIfMaxInputItemsExceeded();
Expand Down Expand Up @@ -347,28 +354,40 @@ namespace winrt::Microsoft::Windows::AppNotifications::Builder::implementation
return m_useButtonStyle ? L" useButtonStyle='true'" : L"";
}

winrt::Microsoft::Windows::AppNotifications::AppNotification AppNotificationBuilder::BuildNotification()
std::wstring AppNotificationBuilder::GetProgressBars()
{
std::wstring xmlResult{};
xmlResult.reserve(c_maxAppNotificationPayload);
std::wstring result{};
for (auto progressBar : m_progressBarList)
{
result.append(progressBar.as<winrt::Windows::Foundation::IStringable>().ToString());
}

return result;
}

winrt::Microsoft::Windows::AppNotifications::AppNotification AppNotificationBuilder::BuildNotification()
{
// Build the button string and fill m_useButtonStyle
std::wstring actions{ GetActions() };

xmlResult.append(L"<toast");
xmlResult.append(m_timeStamp);
xmlResult.append(GetDuration());
xmlResult.append(GetScenario());
xmlResult.append(GetArguments());
xmlResult.append(GetButtonStyle());
xmlResult.append(L"><visual><binding template='ToastGeneric'>");
xmlResult.append(GetText());
xmlResult.append(m_attributionText);
xmlResult.append(GetImages());
xmlResult.append(L"</binding></visual>");
xmlResult.append(m_audio.c_str());
xmlResult.append(actions);
xmlResult.append(L"</toast>");
auto xmlResult{ wil::str_printf<std::wstring>(L"%ls%ls%ls%ls%ls%ls%ls%ls%ls%ls%ls%ls%ls%ls%ls",
L"<toast",
m_timeStamp.c_str(),
GetDuration().c_str(),
GetScenario().c_str(),
GetArguments().c_str(),
GetButtonStyle().c_str(),
L"><visual><binding template='ToastGeneric'>",
GetText().c_str(),
m_attributionText.c_str(),
GetImages().c_str(),
GetProgressBars().c_str(),
L"</binding></visual>",
m_audio.c_str(),
actions.c_str(),
L"</toast>") };

THROW_HR_IF_MSG(E_INVALIDARG, xmlResult.size() > c_maxAppNotificationPayload, "Maximum payload size exceeded");

winrt::Microsoft::Windows::AppNotifications::AppNotification appNotification{ xmlResult };
appNotification.Tag(m_tag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ namespace winrt::Microsoft::Windows::AppNotifications::Builder::implementation
// Adds a button to the AppNotificationBuilder
winrt::Microsoft::Windows::AppNotifications::Builder::AppNotificationBuilder AddButton(AppNotificationButton const& value);

winrt::Microsoft::Windows::AppNotifications::Builder::AppNotificationBuilder AddProgressBar(AppNotificationProgressBar const& value);

winrt::Microsoft::Windows::AppNotifications::Builder::AppNotificationBuilder AddComboBox(AppNotificationComboBox const& value);

winrt::Microsoft::Windows::AppNotifications::Builder::AppNotificationBuilder SetTag(winrt::hstring const& value);
Expand All @@ -72,6 +74,7 @@ namespace winrt::Microsoft::Windows::AppNotifications::Builder::implementation
std::wstring GetText();
std::wstring GetImages();
std::wstring GetActions();
std::wstring GetProgressBars();

std::wstring m_timeStamp{};
AppNotificationDuration m_duration{ AppNotificationDuration::Default };
Expand All @@ -85,6 +88,7 @@ namespace winrt::Microsoft::Windows::AppNotifications::Builder::implementation
winrt::hstring m_audio{};
winrt::Windows::Foundation::Collections::IMap<winrt::hstring, winrt::hstring> m_arguments{ winrt::single_threaded_map<winrt::hstring, winrt::hstring>() };
std::vector<AppNotificationButton> m_buttonList{};
std::vector<AppNotificationProgressBar> m_progressBarList{};
std::vector<std::wstring> m_textBoxList{};
std::vector<AppNotificationComboBox> m_comboBoxList{};
winrt::hstring m_tag{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Microsoft.Windows.AppNotifications.Builder
AppNotificationTextProperties SetLanguage(String value);
AppNotificationTextProperties SetIncomingCallAlignment();
AppNotificationTextProperties SetMaxLines(Int32 value);
}
};

enum AppNotificationButtonStyle
{
Expand Down Expand Up @@ -65,6 +65,33 @@ namespace Microsoft.Windows.AppNotifications.Builder
AppNotificationButton SetInvokeUri(Windows.Foundation.Uri protocolUri, String targetAppId);
};

runtimeclass AppNotificationProgressBar
{
// AppNotificationProgressBar binds to AppNotificationProgressData so the AppNotification will
// receive every update to the status and value. In the WinAppSDK, these binding
// values are static, so developers won't need to define these binding values
// themselves.
AppNotificationProgressBar();

// Setting these properties will remove the data binding with a static value
String Title;
String Status;
Double Value;
String ValueStringOverride;

AppNotificationProgressBar SetTitle(String value);
AppNotificationProgressBar BindTitle();

AppNotificationProgressBar SetStatus(String value);
AppNotificationProgressBar BindStatus();

AppNotificationProgressBar SetValue(Double value);
AppNotificationProgressBar BindValue();

AppNotificationProgressBar SetValueStringOverride(String value);
AppNotificationProgressBar BindValueStringOverride();
};

runtimeclass AppNotificationComboBox
{
AppNotificationComboBox(String id);
Expand Down Expand Up @@ -193,6 +220,8 @@ namespace Microsoft.Windows.AppNotifications.Builder

AppNotificationBuilder AddComboBox(AppNotificationComboBox value);

AppNotificationBuilder AddProgressBar(AppNotificationProgressBar value);

// Constructs a WindowsAppSDK AppNotification object with the XML payload
Microsoft.Windows.AppNotifications.AppNotification BuildNotification();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@
<ItemGroup>
<ClCompile Include="$(MSBuildThisFileDirectory)AppNotificationBuilder.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)AppNotificationButton.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)AppNotificationProgressBar.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)AppNotificationComboBox.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)AppNotificationTextProperties.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MSBuildThisFileDirectory)AppNotificationBuilder.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)AppNotificationBuilderUtility.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)AppNotificationButton.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)AppNotificationProgressBar.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)AppNotificationComboBox.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)AppNotificationTextProperties.h" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#include "pch.h"
#include "AppNotificationProgressBar.h"
#include "Microsoft.Windows.AppNotifications.Builder.AppNotificationProgressBar.g.cpp"

namespace winrt::Microsoft::Windows::AppNotifications::Builder::implementation
{
AppNotificationProgressBar::AppNotificationProgressBar()
:m_titleBindMode{ BindMode::NotSet },
m_statusBindMode{ BindMode::NotSet },
m_valueBindMode{ BindMode::NotSet },
m_valueStringOverrideBindMode{ BindMode::NotSet }
{};

void AppNotificationProgressBar::Title(winrt::hstring const& value)
{
m_title = value;
m_titleBindMode = BindMode::Value;
}

void AppNotificationProgressBar::Status(winrt::hstring const& value)
{
m_status = value;
m_statusBindMode = BindMode::Value;
}

void AppNotificationProgressBar::Value(double value)
{
THROW_HR_IF_MSG(E_INVALIDARG, value < 0.0 || value > 1.0, "You must provide a value between 0.0 and 1.0");

m_value = value;
m_valueBindMode = BindMode::Value;
}

void AppNotificationProgressBar::ValueStringOverride(winrt::hstring const& value)
{
m_valueStringOverride = value;
m_valueStringOverrideBindMode = BindMode::Value;
}

winrt::Microsoft::Windows::AppNotifications::Builder::AppNotificationProgressBar AppNotificationProgressBar::SetTitle(winrt::hstring const& value)
{
Title(value);

return *this;
}

winrt::Microsoft::Windows::AppNotifications::Builder::AppNotificationProgressBar AppNotificationProgressBar::BindTitle()
{
m_titleBindMode = BindMode::Bind;

return *this;
}

winrt::Microsoft::Windows::AppNotifications::Builder::AppNotificationProgressBar AppNotificationProgressBar::SetStatus(winrt::hstring const& value)
{
Status(value);

return *this;
}

winrt::Microsoft::Windows::AppNotifications::Builder::AppNotificationProgressBar AppNotificationProgressBar::BindStatus()
{
m_statusBindMode = BindMode::Bind;

return *this;
}

winrt::Microsoft::Windows::AppNotifications::Builder::AppNotificationProgressBar AppNotificationProgressBar::SetValue(double value)
{
Value(value);

return *this;
}

winrt::Microsoft::Windows::AppNotifications::Builder::AppNotificationProgressBar AppNotificationProgressBar::BindValue()
{
m_valueBindMode = BindMode::Bind;

return *this;
}

winrt::Microsoft::Windows::AppNotifications::Builder::AppNotificationProgressBar AppNotificationProgressBar::SetValueStringOverride(winrt::hstring const& value)
{
ValueStringOverride(value);

return *this;
}

winrt::Microsoft::Windows::AppNotifications::Builder::AppNotificationProgressBar AppNotificationProgressBar::BindValueStringOverride()
{
m_valueStringOverrideBindMode = BindMode::Bind;

return *this;
}

winrt::hstring AppNotificationProgressBar::ToString()
{
auto title{ wil::str_printf<std::wstring>(L" title='%ls'", m_titleBindMode == BindMode::Value ? m_title.c_str() : L"{progressTitle}") };
auto status{ wil::str_printf<std::wstring>(L" status='%ls'", m_statusBindMode == BindMode::Value ? m_status.c_str() : L"{progressStatus}") };
auto value{ wil::str_printf<std::wstring>(L" value='%ls'", m_valueBindMode == BindMode::Value ? wil::str_printf<std::wstring>(L"%g", m_value).c_str() : L"{progressValue}") };
auto valueStringOverride{ wil::str_printf < std::wstring>(L" valueStringOverride='%ls'", m_valueStringOverrideBindMode == BindMode::Value ? m_valueStringOverride.c_str() : L"{progressValueString}") };

return wil::str_printf<std::wstring>(L"<progress%ls%ls%ls%ls/>",
m_titleBindMode == BindMode::NotSet ? L"" :title.c_str(),
status.c_str(),
value.c_str(),
m_valueStringOverrideBindMode == BindMode::NotSet ? L"" : valueStringOverride.c_str()).c_str();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#pragma once
#include "Microsoft.Windows.AppNotifications.Builder.AppNotificationProgressBar.g.h"

namespace winrt::Microsoft::Windows::AppNotifications::Builder::implementation
{

struct AppNotificationProgressBar : AppNotificationProgressBarT<AppNotificationProgressBar, winrt::Windows::Foundation::IStringable>
{
AppNotificationProgressBar();

// Properties
void Title(winrt::hstring const& value);
winrt::hstring Title() { return m_title; };

void Status(winrt::hstring const& value);
winrt::hstring Status() { return m_status; };

void Value(double value);
double Value() { return m_value; };

void ValueStringOverride(winrt::hstring const& value);
winrt::hstring ValueStringOverride() { return m_valueStringOverride; };

// Fluent setters
winrt::Microsoft::Windows::AppNotifications::Builder::AppNotificationProgressBar SetTitle(winrt::hstring const& value);
winrt::Microsoft::Windows::AppNotifications::Builder::AppNotificationProgressBar BindTitle();

winrt::Microsoft::Windows::AppNotifications::Builder::AppNotificationProgressBar SetStatus(winrt::hstring const& value);
winrt::Microsoft::Windows::AppNotifications::Builder::AppNotificationProgressBar BindStatus();

winrt::Microsoft::Windows::AppNotifications::Builder::AppNotificationProgressBar SetValue(double value);
winrt::Microsoft::Windows::AppNotifications::Builder::AppNotificationProgressBar BindValue();

winrt::Microsoft::Windows::AppNotifications::Builder::AppNotificationProgressBar SetValueStringOverride(winrt::hstring const& value);
winrt::Microsoft::Windows::AppNotifications::Builder::AppNotificationProgressBar BindValueStringOverride();

// IStringable
winrt::hstring ToString();

private:
enum class BindMode {NotSet, Bind, Value};

BindMode m_titleBindMode;
winrt::hstring m_title;
BindMode m_statusBindMode;
winrt::hstring m_status;
BindMode m_valueBindMode;
double m_value;
BindMode m_valueStringOverrideBindMode;
winrt::hstring m_valueStringOverride;
};
}
namespace winrt::Microsoft::Windows::AppNotifications::Builder::factory_implementation
{
struct AppNotificationProgressBar : AppNotificationProgressBarT<AppNotificationProgressBar, implementation::AppNotificationProgressBar>
{
};
}
Loading

0 comments on commit 5e4961a

Please sign in to comment.