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
2018-04-20 19:28:39 +03:00

268 lines
9.6 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.Diagnostics;
using Microsoft.Toolkit.Uwp.Notifications;
using Windows.UI.Notifications;
using Windows.UI.Xaml.Media.Imaging;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace FoxTube
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
List<Notification> notifications = new List<Notification>();
public MainPage()
{
this.InitializeComponent();
content.Navigate(typeof(Home));
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
SetTitleBar();
}
private void SetTitleBar()
{
var titleBar = ApplicationView.GetForCurrentView().TitleBar;
titleBar.BackgroundColor = titleBar.ButtonBackgroundColor = Colors.Red;
titleBar.ForegroundColor = titleBar.ButtonForegroundColor = Colors.White;
titleBar.ButtonHoverBackgroundColor = Colors.IndianRed;
titleBar.ButtonPressedBackgroundColor = Colors.DarkRed;
}
private void menuButton_Click(object sender, RoutedEventArgs e)
{
menu.IsPaneOpen = !menu.IsPaneOpen;
//AddNotification(new Notification("Internal notification", "Menu state has been changed", DateTime.Now, NotificationType.Update));
}
public void AddNotification(Notification notification , bool needNotify = true)
{
notificationMenu.Content = "";
notifications.Add(notification);
noNotifText.Visibility = Visibility.Collapsed;
notificationPanel.Visibility = Visibility.Visible;
StackPanel stack = new StackPanel();
stack.Orientation = Orientation.Horizontal;
stack.Children.Add(new PersonPicture()
{
Height = 50,
HorizontalAlignment = HorizontalAlignment.Left,
Margin = new Thickness(0, 0, 10, 0),
VerticalAlignment = VerticalAlignment.Top,
ProfilePicture = new BitmapImage(new Uri(notification.Avatar))
});
StackPanel stackPanel = new StackPanel();
//Channel
stackPanel.Children.Add(new TextBlock()
{
FontSize = 14,
FontStyle = Windows.UI.Text.FontStyle.Italic,
Foreground = new SolidColorBrush(Colors.Gray),
Text = notification.Header
});
//Content
stackPanel.Children.Add(new TextBlock()
{
TextWrapping = TextWrapping.WrapWholeWords,
Text = notification.message,
});
//Time
stackPanel.Children.Add(new TextBlock()
{
FontSize = 13,
Foreground = new SolidColorBrush(Colors.Gray),
Text = notification.returnTimecode()
});
stack.Children.Add(stackPanel);
notificationArray.Items.Add(new ListBoxItem()
{
Padding = new Thickness(10),
MinHeight = 80,
Content = stack
});
//Sending notification
if(needNotify)
{
if(notification.Type == NotificationType.Update)
{
ToastContent toast = new ToastContent()
{
Visual = new ToastVisual()
{
BindingGeneric = new ToastBindingGeneric()
{
Children =
{
new AdaptiveText()
{
Text = notification.Header,
HintMaxLines = 2
},
new AdaptiveText()
{
Text = notification.message
}
},
HeroImage = new ToastGenericHeroImage()
{
Source = notification.Thumbnail
},
AppLogoOverride = new ToastGenericAppLogo()
{
Source = notification.Avatar,
HintCrop = ToastGenericAppLogoCrop.Circle
}
}
},
Actions = new ToastActionsCustom()
{
Buttons =
{
new ToastButton("View full post", "action=viewupdatenotification")
{
ActivationType = ToastActivationType.Foreground
},
new ToastButton("Manage notifications", "action=notificationsettings")
{
ActivationType = ToastActivationType.Foreground
}
}
},
Launch = "action=viewupdatenotification"
};
ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(toast.GetXml()));
}
}
}
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
try
{
if(topHamburger.SelectedItem != null)
bottomHaburger.SelectedItem = null;
MenuSelectionChanged();
} catch { }
}
private void bottomHaburgerSelectionChanged(object sender, SelectionChangedEventArgs e)
{
try
{
if(bottomHaburger.SelectedItem != null)
topHamburger.SelectedItem = null;
MenuSelectionChanged();
} catch { }
}
private void MenuSelectionChanged()
{
if(topHamburger.SelectedIndex == 0)
{
content.Navigate(typeof(Home));
headerText.Text = "Home";
menu.DisplayMode = SplitViewDisplayMode.CompactInline;
menu.IsPaneOpen = true;
}
else if (bottomHaburger.SelectedIndex == 3)
{
content.Navigate(typeof(Settings));
headerText.Text = "Settings";
menu.DisplayMode = SplitViewDisplayMode.CompactOverlay;
menu.IsPaneOpen = false;
}
else if (bottomHaburger.SelectedIndex == 0)
{
content.Navigate(typeof(Channel));
headerText.Text = "Channel overview";
menu.DisplayMode = SplitViewDisplayMode.CompactOverlay;
menu.IsPaneOpen = false;
}
else if (bottomHaburger.SelectedIndex == 2)
{
switch(content.SourcePageType)
{
}
topHamburger.SelectedIndex = 0;
}
}
private void notification_Click(object sender, RoutedEventArgs e)
{
notificationPane.IsOpen = !notificationPane.IsOpen;
notificationMenu.Content = "";
}
private void clearNotifications_Click(object sender, RoutedEventArgs e)
{
notifications.Clear();
notificationArray.Items.Clear();
noNotifText.Visibility = Visibility.Visible;
notificationPanel.Visibility = Visibility.Collapsed;
}
private void refresh_Click(object sender, RoutedEventArgs e)
{
Type t = content.CurrentSourcePageType;
content.Navigate(t);
}
private void feddback_Click(object sender, RoutedEventArgs e)
{
bottomHaburger.SelectedIndex = 3;
Settings s = content.Content as Settings;
s.content.Navigate(typeof(Feedback));
}
private void menu_PaneClosed(SplitView sender, object args)
{
try
{
subsMenuTitle.Visibility = Visibility.Collapsed;
subsMenuStroke.X2 = 40;
subsMenuStroke.Y1 = subsMenuStroke.Y2 = 0;
subscriptionsTitle.Height = 2;
subsLogErr.Visibility = Visibility.Collapsed;
} catch { }
}
private void menu_PaneOpened(SplitView sender, object args)
{
try
{
subsMenuTitle.Visibility = Visibility.Visible;
subsMenuStroke.X2 = 165;
subsMenuStroke.Y1 = subsMenuStroke.Y2 = 10;
subscriptionsTitle.Height = 17;
subsLogErr.Visibility = Visibility.Visible;
} catch { }
}
}
}