forked from duchuule/vba10
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPurchasePage.xaml.cpp
217 lines (168 loc) · 6.39 KB
/
PurchasePage.xaml.cpp
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
//
// PurchasePage.xaml.cpp
// Implementation of the PurchasePage class
//
#include "pch.h"
#include "PurchasePage.xaml.h"
#include "App.xaml.h"
#include "AdControl.xaml.h"
using namespace VBA10;
using namespace Platform;
using namespace Platform::Collections;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Controls::Primitives;
using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;
using namespace Windows::UI::Popups;
using namespace Windows::ApplicationModel::Store;
using namespace Concurrency;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
PurchasePage::PurchasePage()
{
InitializeComponent();
if (App::HasAds)
{
AdControl^ adControl = ref new AdControl();
LayoutRoot->Children->Append(adControl);
adControl->SetValue(Grid::RowProperty, 2);
}
}
void PurchasePage::OnNavigatedTo(NavigationEventArgs^ /* e */)
{
this->txtLoading->Visibility = Windows::UI::Xaml::Visibility::Visible;
create_task(CurrentApp::LoadListingInformationAsync())
.then([this](task<ListingInformation^> tli)
{
try
{
auto loader = Windows::ApplicationModel::Resources::ResourceLoader::GetForViewIndependentUse();
ListingInformation^ li = tli.get();
Vector<ProductItem^>^ picItems = ref new Vector<ProductItem^>();
String^ key;
String^ imageLink;
String^ status = "";
String^ pname = "";
Windows::UI::Xaml::Visibility buyButtonVisibility = Windows::UI::Xaml::Visibility::Collapsed;
//get premium + no ads
key = "noads_premium";
imageLink = "/Assets/noad_plus_icon.png";
if (li->ProductListings->HasKey(key))
{
auto pListing = li->ProductListings->Lookup(key);
status = CurrentApp::LicenseInformation->ProductLicenses->Lookup(key)->IsActive ? loader->GetString("PurchasedThankText") : pListing->FormattedPrice;
buyButtonVisibility = CurrentApp::LicenseInformation->ProductLicenses->Lookup(key)->IsActive ? Windows::UI::Xaml::Visibility::Collapsed : Windows::UI::Xaml::Visibility::Visible;
pname = pListing->Name;
}
else
{
status = loader->GetString("ProductNotAvailableText");
buyButtonVisibility = Windows::UI::Xaml::Visibility::Collapsed;
pname = "No Ads + Premium Features";
}
ProductItem^ pitem1 = ref new ProductItem();
pitem1->imgLink = imageLink;
pitem1->Name = pname;
pitem1->Status = status;
pitem1->key = key;
pitem1->BuyNowButtonVisible = buyButtonVisibility;
picItems->Append(pitem1);
//get no ads
key = "removeads";
imageLink = "/Assets/noad_icon.png";
if (li->ProductListings->HasKey(key))
{
auto pListing = li->ProductListings->Lookup(key);
status = CurrentApp::LicenseInformation->ProductLicenses->Lookup(key)->IsActive ? loader->GetString("PurchasedThankText") : pListing->FormattedPrice;
buyButtonVisibility = CurrentApp::LicenseInformation->ProductLicenses->Lookup(key)->IsActive ? Windows::UI::Xaml::Visibility::Collapsed : Windows::UI::Xaml::Visibility::Visible;
pname = pListing->Name;
}
else
{
status = loader->GetString("ProductNotAvailableText");
buyButtonVisibility = Windows::UI::Xaml::Visibility::Collapsed;
pname = "Remove ads";
}
ProductItem^ pitem2 = ref new ProductItem();
pitem2->imgLink = imageLink;
pitem2->Name = pname;
pitem2->Status = status;
pitem2->key = key;
pitem2->BuyNowButtonVisible = buyButtonVisibility;
picItems->Append(pitem2);
//get premium feature
key = "premiumfeatures";
imageLink = "/Assets/plus_sign.png";
if (li->ProductListings->HasKey(key))
{
auto pListing = li->ProductListings->Lookup(key);
status = CurrentApp::LicenseInformation->ProductLicenses->Lookup(key)->IsActive ? loader->GetString("PurchasedThankText") : pListing->FormattedPrice;
buyButtonVisibility = CurrentApp::LicenseInformation->ProductLicenses->Lookup(key)->IsActive ? Windows::UI::Xaml::Visibility::Collapsed : Windows::UI::Xaml::Visibility::Visible;
pname = pListing->Name;
}
else
{
status = loader->GetString("ProductNotAvailableText");
buyButtonVisibility = Windows::UI::Xaml::Visibility::Collapsed;
pname = "Premium Features";
}
ProductItem^ pitem3 = ref new ProductItem();
pitem3->imgLink = imageLink;
pitem3->Name = pname;
pitem3->Status = status;
pitem3->key = key;
pitem3->BuyNowButtonVisible = buyButtonVisibility;
picItems->Append(pitem3);
this->pics->ItemsSource = picItems;
}
catch (Exception^)
{
txtError->Visibility = Windows::UI::Xaml::Visibility::Visible;
}
txtLoading->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
}, task_continuation_context::use_current());
}
void PurchasePage::ButtonBuyNow_Clicked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
Button^ btn = (Button^)sender;
String^ key = (String^)btn->Tag;
if (!CurrentApp::LicenseInformation->ProductLicenses->Lookup(key)->IsActive)
{
create_task(CurrentApp::RequestProductPurchaseAsync(key))
.then([key, this](task<PurchaseResults^> tresult)
{
try
{
PurchaseResults^ result = tresult.get();
//int test = result->Status;
//reread license
App::CheckProductLicense();
if (CurrentApp::LicenseInformation->ProductLicenses->Lookup(key)->IsActive)
{
auto loader = Windows::ApplicationModel::Resources::ResourceLoader::GetForViewIndependentUse();
//prompt user to restart app if it's ad removal
if (key == "removeads" || key == "noads_premium")
{
MessageDialog ^dialog = ref new MessageDialog(loader->GetString("PurchaseSuccessNoAdsText"));
dialog->ShowAsync();
}
if (key == "premiumfeatures")
{
MessageDialog ^dialog = ref new MessageDialog(loader->GetString("PurchaseSuccessText"));
dialog->ShowAsync();
}
this->OnNavigatedTo(nullptr);
}
}
catch (Exception^)
{ }
}, task_continuation_context::use_current());
}
}
void PurchasePage::loadProductsBtn_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
}