158 lines
4.5 KiB
C#
158 lines
4.5 KiB
C#
using System;
|
|
using Windows.UI.Xaml.Controls;
|
|
|
|
namespace FoxTube.Controls
|
|
{
|
|
public sealed partial class MainFrame : UserControl
|
|
{
|
|
public static MainFrame Current { get; private set; }
|
|
|
|
public event NavigatingOccured Navigating;
|
|
public event NavigationOccured Navigated;
|
|
|
|
public bool CanGoBack => !VideoMinimized || content.CanGoBack;
|
|
public bool IsVideoOpened { get; } = false;
|
|
public bool VideoMinimized => video.Width != double.NaN;
|
|
public Type SourcePageType => content.SourcePageType;
|
|
|
|
public MainFrame()
|
|
{
|
|
InitializeComponent();
|
|
Current = this;
|
|
}
|
|
|
|
public void NavigateTo(Type pageType, object parameter = null)
|
|
{
|
|
if (content.SourcePageType == pageType && parameter == (content.FrameContent as INavigationPage).Parameter)
|
|
return;
|
|
|
|
content.Navigate(pageType, parameter);
|
|
|
|
if (video.FrameContent != null && !VideoMinimized)
|
|
MinimizeVideo();
|
|
|
|
Navigating?.Invoke(pageType, parameter);
|
|
}
|
|
|
|
public void Refresh()
|
|
{
|
|
content.Refresh();
|
|
Navigating?.Invoke(SourcePageType, (content.Content as ViewModel).Parameter);
|
|
}
|
|
|
|
#region Video control methods
|
|
public void OpenVideo(string id, string playlistId = null, bool incognito = false)
|
|
{
|
|
/*if (VideoMinimized)
|
|
MaximizeVideo();
|
|
|
|
video.Navigate(typeof(VideoPage), (id, playlistId, incognito));
|
|
|
|
MainPage.Current.UpdateView();*/
|
|
}
|
|
|
|
public void MinimizeVideo(bool player = false)
|
|
{
|
|
/*if (video.FrameContent == null)
|
|
return;
|
|
|
|
video.Margin = new Thickness(0, 0, 25, 50);
|
|
video.HorizontalAlignment = HorizontalAlignment.Right;
|
|
video.VerticalAlignment = VerticalAlignment.Bottom;
|
|
video.Width = 432;
|
|
|
|
if (!player)
|
|
(video.FrameContent as VideoPage).Minimize();
|
|
|
|
MainPage.Current.UpdateView();*/
|
|
}
|
|
|
|
public void MaximizeVideo(bool player = false)
|
|
{
|
|
/*if (video.FrameContent == null)
|
|
return;
|
|
|
|
video.Margin = new Thickness(0);
|
|
video.VerticalAlignment = VerticalAlignment.Stretch;
|
|
video.HorizontalAlignment = HorizontalAlignment.Stretch;
|
|
video.Width = double.NaN;
|
|
|
|
if (!player)
|
|
(video.FrameContent as VideoPage).Maximize();
|
|
|
|
MainPage.Current.UpdateView();*/
|
|
}
|
|
|
|
public void CloseVideo()
|
|
{
|
|
/*if (ApplicationView.GetForCurrentView().IsFullScreenMode)
|
|
ApplicationView.GetForCurrentView().ExitFullScreenMode();
|
|
|
|
video.FrameContent = null;
|
|
video.ClearHistory();
|
|
|
|
if (VideoMinimized)
|
|
MaximizeVideo();
|
|
|
|
GC.Collect();
|
|
|
|
MainPage.Current.UpdateView();*/
|
|
}
|
|
|
|
public void RefreshVideo()
|
|
{
|
|
/*if (video.FrameContent == null)
|
|
return;
|
|
|
|
if (VideoMinimized)
|
|
MaximizeVideo();
|
|
|
|
video.Refresh();
|
|
|
|
Methods.MainPage.UpdateView();*/
|
|
}
|
|
#endregion
|
|
|
|
public void AuthorizationChanged(bool isAuthorized)
|
|
{
|
|
//TODO: Uncomment this
|
|
/*switch (isAuthorized)
|
|
{
|
|
case true:
|
|
if (content.FrameContent == null)
|
|
NavigateTo(typeof(Home));
|
|
else if (!content.SourcePageType.Name.Belongs("Downloads", "Settings"))
|
|
content.Refresh();
|
|
break;
|
|
|
|
case false:
|
|
NavigateTo(typeof(Home));
|
|
|
|
content.ClearHistory();
|
|
video.ClearHistory();
|
|
break;
|
|
}
|
|
|
|
RefreshVideo();*/
|
|
}
|
|
|
|
public void BackRequested()
|
|
{
|
|
if (video.FrameContent != null && !VideoMinimized)
|
|
{
|
|
if (video.CanGoBack)
|
|
video.GoBack();
|
|
else if (video.State != LoadingScreenState.Loaded)
|
|
CloseVideo();
|
|
else
|
|
MinimizeVideo();
|
|
}
|
|
else if (content.CanGoBack)
|
|
content.GoBack();
|
|
}
|
|
|
|
void Content_Navigated(System.Collections.IList pivotCollection, int? selectedPivot) =>
|
|
Navigated?.Invoke(pivotCollection, selectedPivot);
|
|
}
|
|
}
|