271 lines
12 KiB
C#
271 lines
12 KiB
C#
using FoxTube.Core.Helpers;
|
|
using FoxTube.Core.Models;
|
|
using Google.Apis.YouTube.v3.Data;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
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;
|
|
using Windows.UI.Xaml.Navigation;
|
|
|
|
namespace FoxTube
|
|
{
|
|
public sealed partial class MainPage : Page
|
|
{
|
|
public static MainPage Current { get; set; }
|
|
public MainPage()
|
|
{
|
|
Current = this;
|
|
InitializeComponent();
|
|
|
|
if (Settings.Theme == 0)
|
|
RequestedTheme = ElementTheme.Light;
|
|
else if (Settings.Theme == 1)
|
|
RequestedTheme = ElementTheme.Dark;
|
|
|
|
Navigate(typeof(Views.Home));
|
|
|
|
Window.Current.SetTitleBar(AppTitleBar);
|
|
|
|
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
|
|
|
|
ApplicationViewTitleBar titleBar = ApplicationView.GetForCurrentView().TitleBar;
|
|
titleBar.ButtonBackgroundColor = Colors.Transparent;
|
|
titleBar.ButtonHoverBackgroundColor = Color.FromArgb(50, 255, 255, 255);
|
|
titleBar.ButtonPressedBackgroundColor = Color.FromArgb(20, 255, 255, 255);
|
|
|
|
if (RequestedTheme == ElementTheme.Default)
|
|
titleBar.ButtonForegroundColor =
|
|
titleBar.ButtonHoverForegroundColor =
|
|
titleBar.ButtonPressedForegroundColor = Application.Current.RequestedTheme == ApplicationTheme.Dark ? Colors.White : Colors.Black;
|
|
else
|
|
titleBar.ButtonForegroundColor =
|
|
titleBar.ButtonHoverForegroundColor =
|
|
titleBar.ButtonPressedForegroundColor = RequestedTheme == ElementTheme.Dark ? Colors.White : Colors.Black;
|
|
|
|
LeaveFeedback.Visibility = Feedback.HasFeedbackHub ? Visibility.Visible : Visibility.Collapsed;
|
|
RemoveAds.Visibility = StoreInterop.AdsDisabled ? Visibility.Collapsed : Visibility.Visible;
|
|
if (!StoreInterop.AdsDisabled)
|
|
RemoveAds.Content += $" ({StoreInterop.Price})";
|
|
|
|
if (Settings.PromptReview)
|
|
Feedback.PromptReview();
|
|
if (Settings.PromptFeedback)
|
|
Feedback.PromptFeedback();
|
|
}
|
|
|
|
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) =>
|
|
Feedback.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. Or you can do it later (but 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) =>
|
|
Navigate(pageType, null);
|
|
|
|
public static void Navigate(Type pageType, object param)
|
|
{
|
|
if (pageType == Current.content.CurrentSourcePageType && param == (Current.content.Content as PageView).Parameter)
|
|
return;
|
|
// TODO: Add navigation logic for videos
|
|
Current.content.Navigate(pageType, param);
|
|
}
|
|
|
|
public static void SetHeader(string title) =>
|
|
Current.title.Text = title;
|
|
|
|
void Content_Navigated(object sender, NavigationEventArgs e)
|
|
{
|
|
refresh.Visibility = (e.Content is IRefreshable) ? Visibility.Visible : Visibility.Collapsed;
|
|
NavigationViewControl.IsBackEnabled = content.CanGoBack;
|
|
title.Text = (e.Content as PageView).Header ?? "FoxTube";
|
|
switch(e.SourcePageType.Name)
|
|
{
|
|
case "Home":
|
|
NavigationViewControl.SelectedItem = home;
|
|
break;
|
|
case "Settings":
|
|
NavigationViewControl.SelectedItem = NavigationViewControl.SettingsItem;
|
|
break;
|
|
case "Subscriptions":
|
|
NavigationViewControl.SelectedItem = subscriptions;
|
|
break;
|
|
default:
|
|
NavigationViewControl.SelectedItem = null;
|
|
break;
|
|
}
|
|
}
|
|
|
|
void Refresh_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (video.Content != null)
|
|
(video.Content as IRefreshable)?.RefreshPage();
|
|
else
|
|
(content.Content as IRefreshable)?.RefreshPage();
|
|
}
|
|
|
|
void AutoSuggestBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
|
|
{
|
|
if (sender.Text.Length < 3 || args.Reason != AutoSuggestionBoxTextChangeReason.UserInput)
|
|
return;
|
|
|
|
// TODO: Load suggestions
|
|
|
|
// TODO: Remove
|
|
sender.ItemsSource = new List<SearchSuggestion>
|
|
{
|
|
new SearchSuggestion("Suggestion 0"),
|
|
new SearchSuggestion("Suggestion 1"),
|
|
new SearchSuggestion("Suggestion 2"),
|
|
new SearchSuggestion("Suggestion 3"),
|
|
new SearchSuggestion("Suggestion 4"),
|
|
new SearchSuggestion("History entry 0", true),
|
|
new SearchSuggestion("History entry 1", true),
|
|
new SearchSuggestion("History entry 2", true)
|
|
};
|
|
}
|
|
|
|
void AutoSuggestBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
|
|
{
|
|
if (args.QueryText.Length < 3)
|
|
return;
|
|
// TODO: Go to search
|
|
Navigate(typeof(Views.Search));
|
|
}
|
|
|
|
void NavigationViewControl_BackRequested(Microsoft.UI.Xaml.Controls.NavigationView sender, Microsoft.UI.Xaml.Controls.NavigationViewBackRequestedEventArgs args)
|
|
{
|
|
// TODO: Add backward navigation logic for videos
|
|
if (content.CanGoBack)
|
|
content.GoBack();
|
|
}
|
|
|
|
void NavigationViewControl_ItemInvoked(Microsoft.UI.Xaml.Controls.NavigationView sender, Microsoft.UI.Xaml.Controls.NavigationViewItemInvokedEventArgs args)
|
|
{
|
|
if (args.IsSettingsInvoked)
|
|
Navigate(typeof(Views.Settings));
|
|
else
|
|
switch((args.InvokedItemContainer as Microsoft.UI.Xaml.Controls.NavigationViewItem).Name)
|
|
{
|
|
case "home":
|
|
Navigate(typeof(Views.Home));
|
|
break;
|
|
case "subscriptions":
|
|
Navigate(typeof(Views.Subscriptions));
|
|
break;
|
|
case "history":
|
|
break;
|
|
case "liked":
|
|
break;
|
|
case "wl":
|
|
break;
|
|
case "download":
|
|
break;
|
|
case "music":
|
|
break;
|
|
case "sports":
|
|
break;
|
|
case "movies":
|
|
break;
|
|
case "news":
|
|
break;
|
|
case "live":
|
|
break;
|
|
case "spotlight":
|
|
break;
|
|
case "vr":
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
if(UsersControl.Authorized)
|
|
{
|
|
for (int i = NavigationViewControl.MenuItems.IndexOf(subscriptions); i < NavigationViewControl.MenuItems.IndexOf(categoriesHeader); i++)
|
|
(NavigationViewControl.MenuItems[i] as FrameworkElement).Visibility = Visibility.Visible;
|
|
|
|
for (int i = NavigationViewControl.MenuItems.IndexOf(categoriesHeader); i < NavigationViewControl.MenuItems.Count; i++)
|
|
(NavigationViewControl.MenuItems[i] as FrameworkElement).Visibility = Visibility.Collapsed;
|
|
|
|
foreach (Subscription i in UsersControl.CurrentUser.Subscriptions)
|
|
NavigationViewControl.MenuItems.Insert(NavigationViewControl.MenuItems.IndexOf(categoriesHeader), i);
|
|
}
|
|
else
|
|
{
|
|
IEnumerable<object> subs = from i in NavigationViewControl.MenuItems
|
|
where string.IsNullOrWhiteSpace((i as FrameworkElement).Name)
|
|
select i;
|
|
|
|
foreach (object i in subs)
|
|
NavigationViewControl.MenuItems.Remove(i);
|
|
|
|
for (int i = NavigationViewControl.MenuItems.IndexOf(subscriptions); i < NavigationViewControl.MenuItems.IndexOf(categoriesHeader); i++)
|
|
(NavigationViewControl.MenuItems[i] as FrameworkElement).Visibility = Visibility.Collapsed;
|
|
|
|
for (int i = NavigationViewControl.MenuItems.IndexOf(categoriesHeader); i < NavigationViewControl.MenuItems.Count; i++)
|
|
(NavigationViewControl.MenuItems[i] as FrameworkElement).Visibility = Visibility.Visible;
|
|
}
|
|
}
|
|
}
|
|
}
|