Updated StoreInterop class and ads appearing conditions
This commit is contained in:
@@ -1,24 +1,38 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Windows.Services.Store;
|
||||||
|
|
||||||
namespace FoxTube.Core.Controllers
|
namespace FoxTube.Core.Controllers
|
||||||
{
|
{
|
||||||
public static class StoreInterop
|
public static class StoreInterop
|
||||||
{
|
{
|
||||||
public static bool AdsDisabled => false;
|
public static bool AdsDisabled { get; private set; } = true;
|
||||||
public static string GetProPrice()
|
public static string Price { get; private set; }
|
||||||
|
|
||||||
|
public static async Task UpdateStoreState()
|
||||||
{
|
{
|
||||||
return "$4.99";
|
StoreProductQueryResult requset = await StoreContext.GetDefault().GetAssociatedStoreProductsAsync(new[] { "Durable" });
|
||||||
|
|
||||||
|
if (requset.Products["9NP1QK556625"].IsInUserCollection)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Price = requset.Products["9NP1QK556625"].Price.FormattedPrice;
|
||||||
|
AdsDisabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void PurchaseApp()
|
public static async Task<bool> PurchaseApp()
|
||||||
{
|
{
|
||||||
if (!AdsDisabled)
|
StorePurchaseResult request = await StoreContext.GetDefault().RequestPurchaseAsync("9NP1QK556625");
|
||||||
// TODO: Add purchase validation
|
|
||||||
return;
|
switch (request.Status)
|
||||||
|
{
|
||||||
|
case StorePurchaseStatus.AlreadyPurchased:
|
||||||
|
case StorePurchaseStatus.Succeeded:
|
||||||
|
AdsDisabled = true;
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,6 +123,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Class1.cs" />
|
<Compile Include="Class1.cs" />
|
||||||
<Compile Include="Controllers\StoreInterop.cs" />
|
<Compile Include="Controllers\StoreInterop.cs" />
|
||||||
|
<Compile Include="Helpers.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -130,6 +131,9 @@
|
|||||||
<Version>6.2.9</Version>
|
<Version>6.2.9</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Models\" />
|
||||||
|
</ItemGroup>
|
||||||
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' ">
|
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' ">
|
||||||
<VisualStudioVersion>14.0</VisualStudioVersion>
|
<VisualStudioVersion>14.0</VisualStudioVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FoxTube.Core
|
||||||
|
{
|
||||||
|
public static class Helpers
|
||||||
|
{
|
||||||
|
public static Uri ToUri(this string str) =>
|
||||||
|
string.IsNullOrWhiteSpace(str) ? null : new Uri(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-2
@@ -1,4 +1,5 @@
|
|||||||
using Windows.ApplicationModel.Activation;
|
using FoxTube.Core.Controllers;
|
||||||
|
using Windows.ApplicationModel.Activation;
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
|
|
||||||
namespace FoxTube
|
namespace FoxTube
|
||||||
@@ -8,8 +9,10 @@ namespace FoxTube
|
|||||||
public App() =>
|
public App() =>
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
protected override void OnLaunched(LaunchActivatedEventArgs e)
|
protected override async void OnLaunched(LaunchActivatedEventArgs e)
|
||||||
{
|
{
|
||||||
|
await StoreInterop.UpdateStoreState();
|
||||||
|
|
||||||
if (!e.PrelaunchActivated && Window.Current.Content == null)
|
if (!e.PrelaunchActivated && Window.Current.Content == null)
|
||||||
Window.Current.Content = new MainPage();
|
Window.Current.Content = new MainPage();
|
||||||
Window.Current.Activate();
|
Window.Current.Activate();
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using FoxTube.Controls.Cards;
|
using FoxTube.Controls.Cards;
|
||||||
|
using FoxTube.Core.Controllers;
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
|
|
||||||
@@ -16,7 +17,7 @@ namespace FoxTube.Controls
|
|||||||
{
|
{
|
||||||
empty.Opacity = 0;
|
empty.Opacity = 0;
|
||||||
|
|
||||||
if (ItemsCount % 5 == 0 && ItemsCount > 0)
|
if (!StoreInterop.AdsDisabled && ItemsCount % 5 == 0 && ItemsCount > 0)
|
||||||
Items.Add(new AdvertCard());
|
Items.Add(new AdvertCard());
|
||||||
Items.Add(item);
|
Items.Add(item);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Microsoft.Services.Store.Engagement;
|
using Microsoft.Services.Store.Engagement;
|
||||||
using System;
|
using System;
|
||||||
|
using Windows.ApplicationModel.Core;
|
||||||
|
|
||||||
namespace FoxTube.Helpers
|
namespace FoxTube.Helpers
|
||||||
{
|
{
|
||||||
@@ -12,5 +13,11 @@ namespace FoxTube.Helpers
|
|||||||
if(HasFeedbackHub)
|
if(HasFeedbackHub)
|
||||||
await StoreServicesFeedbackLauncher.GetDefault().LaunchAsync();
|
await StoreServicesFeedbackLauncher.GetDefault().LaunchAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void CloseApp() =>
|
||||||
|
CoreApplication.Exit();
|
||||||
|
|
||||||
|
public static async void RestartApp(string args = "") =>
|
||||||
|
await CoreApplication.RequestRestartAsync(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using System;
|
|||||||
using Windows.ApplicationModel.Core;
|
using Windows.ApplicationModel.Core;
|
||||||
using Windows.Foundation.Metadata;
|
using Windows.Foundation.Metadata;
|
||||||
using Windows.UI;
|
using Windows.UI;
|
||||||
|
using Windows.UI.Popups;
|
||||||
using Windows.UI.ViewManagement;
|
using Windows.UI.ViewManagement;
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
@@ -41,7 +42,7 @@ namespace FoxTube
|
|||||||
LeaveFeedback.Visibility = Utils.HasFeedbackHub ? Visibility.Visible : Visibility.Collapsed;
|
LeaveFeedback.Visibility = Utils.HasFeedbackHub ? Visibility.Visible : Visibility.Collapsed;
|
||||||
RemoveAds.Visibility = StoreInterop.AdsDisabled ? Visibility.Collapsed : Visibility.Visible;
|
RemoveAds.Visibility = StoreInterop.AdsDisabled ? Visibility.Collapsed : Visibility.Visible;
|
||||||
if (!StoreInterop.AdsDisabled)
|
if (!StoreInterop.AdsDisabled)
|
||||||
RemoveAds.Content += $" ({StoreInterop.GetProPrice()})";
|
RemoveAds.Content += $" ({StoreInterop.Price})";
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavigationView_DisplayModeChanged(Microsoft.UI.Xaml.Controls.NavigationView sender, Microsoft.UI.Xaml.Controls.NavigationViewDisplayModeChangedEventArgs args)
|
void NavigationView_DisplayModeChanged(Microsoft.UI.Xaml.Controls.NavigationView sender, Microsoft.UI.Xaml.Controls.NavigationViewDisplayModeChangedEventArgs args)
|
||||||
@@ -88,8 +89,19 @@ namespace FoxTube
|
|||||||
void LeaveFeedback_Click(object sender, RoutedEventArgs e) =>
|
void LeaveFeedback_Click(object sender, RoutedEventArgs e) =>
|
||||||
Utils.OpenFeedbackHub();
|
Utils.OpenFeedbackHub();
|
||||||
|
|
||||||
void RemoveAds_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e) =>
|
async void RemoveAds_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
|
||||||
StoreInterop.PurchaseApp();
|
{
|
||||||
|
bool success = await StoreInterop.PurchaseApp();
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
MessageDialog dialog = new MessageDialog("Thanks for purchasing full version of the app (^∇^) In order to complete changes we need to reopen it. But you can do it later (some elements may be broken)", "Thank you for your purchase!");
|
||||||
|
dialog.Commands.Add(new UICommand("Restart", (command) => Utils.RestartApp()));
|
||||||
|
dialog.Commands.Add(new UICommand("Later"));
|
||||||
|
dialog.CancelCommandIndex = 1;
|
||||||
|
dialog.DefaultCommandIndex = 0;
|
||||||
|
await dialog.ShowAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void Navigate(Type pageType)
|
public static void Navigate(Type pageType)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user