Archived
1
0
This repository has been archived on 2026-04-22. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
FoxTube/FoxTube/MainPage.xaml.cs
T
2019-11-10 21:34:01 +03:00

112 lines
4.7 KiB
C#

using FoxTube.Core.Controllers;
using FoxTube.Helpers;
using FoxTube.Views;
using System;
using Windows.ApplicationModel.Core;
using Windows.Foundation.Metadata;
using Windows.UI;
using Windows.UI.Popups;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace FoxTube
{
public sealed partial class MainPage : Page
{
static MainPage Current { get; set; }
public MainPage()
{
Current = this;
InitializeComponent();
// TODO: Remove this
content.Navigate(typeof(Home));
Window.Current.SetTitleBar(AppTitleBar);
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
ApplicationViewTitleBar titleBar = ApplicationView.GetForCurrentView().TitleBar;
titleBar.ButtonBackgroundColor = Colors.Transparent;
titleBar.ButtonHoverForegroundColor = Colors.White;
titleBar.ButtonPressedForegroundColor = Colors.White;
titleBar.ButtonHoverBackgroundColor = Color.FromArgb(50, 255, 255, 255);
titleBar.ButtonPressedBackgroundColor = Color.FromArgb(20, 255, 255, 255);
if (Application.Current.RequestedTheme == ApplicationTheme.Dark)
titleBar.ButtonForegroundColor = Colors.White;
else
titleBar.ForegroundColor = Colors.Black;
LeaveFeedback.Visibility = Utils.HasFeedbackHub ? Visibility.Visible : Visibility.Collapsed;
RemoveAds.Visibility = StoreInterop.AdsDisabled ? Visibility.Collapsed : Visibility.Visible;
if (!StoreInterop.AdsDisabled)
RemoveAds.Content += $" ({StoreInterop.Price})";
}
void NavigationView_DisplayModeChanged(Microsoft.UI.Xaml.Controls.NavigationView sender, Microsoft.UI.Xaml.Controls.NavigationViewDisplayModeChangedEventArgs args)
{
Thickness currMargin = AppTitleBar.Margin;
AppTitleBar.Margin = new Thickness(
sender.CompactPaneLength * (sender.DisplayMode == Microsoft.UI.Xaml.Controls.NavigationViewDisplayMode.Minimal ? 2 : 1),
currMargin.Top,
currMargin.Right,
currMargin.Bottom);
UpdateAppTitleMargin(sender);
}
void NavigationView_PaneClosing(Microsoft.UI.Xaml.Controls.NavigationView sender, Microsoft.UI.Xaml.Controls.NavigationViewPaneClosingEventArgs args) =>
UpdateAppTitleMargin(sender);
void NavigationView_PaneOpening(Microsoft.UI.Xaml.Controls.NavigationView sender, object args) =>
UpdateAppTitleMargin(sender);
void UpdateAppTitleMargin(Microsoft.UI.Xaml.Controls.NavigationView sender)
{
const int smallLeftIndent = 4, largeLeftIndent = 12;
if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 7))
{
AppTitle.TranslationTransition = new Vector3Transition();
if (sender.DisplayMode == Microsoft.UI.Xaml.Controls.NavigationViewDisplayMode.Expanded && sender.IsPaneOpen)
AppTitle.Translation = new System.Numerics.Vector3(smallLeftIndent, 0, 0);
else
AppTitle.Translation = new System.Numerics.Vector3(largeLeftIndent, 0, 0);
}
else
{
Thickness currMargin = AppTitle.Margin;
if (sender.DisplayMode == Microsoft.UI.Xaml.Controls.NavigationViewDisplayMode.Expanded && sender.IsPaneOpen)
AppTitle.Margin = new Thickness(smallLeftIndent, currMargin.Top, currMargin.Right, currMargin.Bottom);
else
AppTitle.Margin = new Thickness(largeLeftIndent, currMargin.Top, currMargin.Right, currMargin.Bottom);
}
}
void LeaveFeedback_Click(object sender, RoutedEventArgs e) =>
Utils.OpenFeedbackHub();
async void RemoveAds_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
{
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)
{
}
}
}