Archived
1
0

Everything is fucked up

This commit is contained in:
Michael Gordeev
2018-12-23 10:59:26 +03:00
parent 8432271b32
commit 0b63679678
18 changed files with 218 additions and 870 deletions
-4
View File
@@ -2,12 +2,8 @@
x:Class="FoxTube.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:FoxTube"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ads="using:Microsoft.Advertising.WinRT.UI"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:pages="using:FoxTube.Pages"
xmlns:Windows10version1803="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract, 6)"
mc:Ignorable="d"
SizeChanged="Page_SizeChanged"
+107 -76
View File
@@ -9,47 +9,36 @@ using Windows.UI.Xaml.Navigation;
using System.Diagnostics;
using Windows.UI.Notifications;
using Windows.UI.Xaml.Media.Imaging;
using Windows.Storage;
using System.Xml;
using Google.Apis.YouTube.v3.Data;
using System.Globalization;
using Windows.ApplicationModel.Core;
using Windows.System;
using Google.Apis.Oauth2.v2;
using Google.Apis.Oauth2.v2.Data;
using FoxTube.Controls;
using FoxTube.Pages;
using Windows.ApplicationModel;
using System.Net;
using Windows.UI.Popups;
using Windows.Networking.Connectivity;
using Windows.UI.Core;
using System.IO;
using Newtonsoft.Json;
using Google.Apis.YouTube.v3;
// 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 enum Sender { Menu, Frame, None }
/// <summary>
/// Main app's layout
/// </summary>
public sealed partial class MainPage : Page
{
Sender s = Sender.None;
public MainPage()
{
this.InitializeComponent();
InitializeComponent();
//Comparing current version with last recorded version. If doesn't match, poping up changelog notification
PackageVersion ver = Package.Current.Id.Version;
if (settings.Values["ver"] == null)
settings.Values.Add("ver", $"{ver.Major}.{ver.Minor}");
if((string)settings.Values["ver"] != $"{ver.Major}.{ver.Minor}")
if(SettingsStorage.Version != $"{ver.Major}.{ver.Minor}")
{
try
{
@@ -59,9 +48,12 @@ namespace FoxTube
ToastNotificationManager.CreateToastNotifier().Show(FoxTube.Background.Notification.GetChangelogToast(e.GetAttribute("version")));
settings.Values["ver"] = $"{ver.Major}.{ver.Minor}";
SettingsStorage.Version = $"{ver.Major}.{ver.Minor}";
}
catch
{
Debug.WriteLine("Unable to retrieve changelog");
}
catch { }
}
SecretsVault.AuthorizationStateChanged += AuthorizationStateChanged;
@@ -73,20 +65,6 @@ namespace FoxTube
DownloadAgent.Initialize();
SetTitleBar();
Initialize();
}
public async void Initialize()
{
bool[] notificationsSettings = new bool[] { (bool)settings.Values["newVideoNotification"], (bool)settings.Values["devNews"] };
await FileIO.WriteTextAsync(
await ApplicationData.Current.RoamingFolder.CreateFileAsync("notifications.json", CreationCollisionOption.ReplaceExisting),
JsonConvert.SerializeObject(notificationsSettings));
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
}
public Video GetCurrentItem()
@@ -109,10 +87,17 @@ namespace FoxTube
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = false;
}
/// <summary>
/// Invoked when subscriptions are edited to edit menu
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
private void SecretsVault_SubscriptionsChanged(object sender, params object[] args)
{
if ((string)args[0] == "add" && nav.MenuItems.Count < 19)
{
subsHeader.Visibility = Visibility.Visible;
Subscription s = args[1] as Subscription;
StackPanel panel = new StackPanel()
{
@@ -134,12 +119,37 @@ namespace FoxTube
});
}
else if ((string)args[0] == "remove" && (int)args[1] < 10)
{
nav.MenuItems.RemoveAt((int)args[1] + 9);
if(SecretsVault.Subscriptions.Count >= 10)
{
Subscription s = SecretsVault.Subscriptions[9];
StackPanel panel = new StackPanel()
{
Orientation = Orientation.Horizontal,
Padding = new Thickness(5)
};
panel.Children.Add(new PersonPicture()
{
Height = 20,
Margin = new Thickness(-5, 0, 15, 0),
ProfilePicture = new BitmapImage(new Uri(s.Snippet.Thumbnails.Medium.Url))
});
panel.Children.Add(new TextBlock() { Text = s.Snippet.Title });
nav.MenuItems.Add(new NavigationViewItem()
{
Content = panel,
Name = (nav.MenuItems.Count - 9).ToString(),
Padding = new Thickness(-5)
});
}
}
}
private async void AuthorizationStateChanged()
private async void AuthorizationStateChanged(object sender, params object[] e)
{
if(SecretsVault.IsAuthorized)
if(e[0] as bool? == true)
{
account.Visibility = Visibility.Collapsed;
try
@@ -158,7 +168,6 @@ namespace FoxTube
toHistory.Visibility = Visibility.Visible;
toLiked.Visibility = Visibility.Visible;
toLater.Visibility = Visibility.Visible;
subsHeader.Visibility = Visibility.Visible;
if (SecretsVault.Subscriptions.Count > 0)
{
@@ -189,7 +198,7 @@ namespace FoxTube
catch { continue; }
}
}
else
else if (e[0] as bool? == false)
{
account.Visibility = Visibility.Visible;
avatar.Visibility = Visibility.Collapsed;
@@ -206,6 +215,25 @@ namespace FoxTube
for(int k = 9; k < nav.MenuItems.Count; k++)
nav.MenuItems.RemoveAt(k);
}
else
{
MessageDialog dialog = new MessageDialog("We were unabled to retrieve your account information due to weak internet connection or Google servers' problems. PLease, try again later", "Failed to connect");
dialog.Commands.Add(new UICommand("Try again", (command) =>
{
SecretsVault.Authorize();
}));
dialog.Commands.Add(new UICommand("Quit", (command) =>
{
Methods.CloseApp();
}));
dialog.Commands.Add(new UICommand("Close"));
dialog.CancelCommandIndex = 1;
dialog.DefaultCommandIndex = 0;
await dialog.ShowAsync();
}
content.Navigate(typeof(Home));
@@ -241,14 +269,11 @@ namespace FoxTube
public void GoToSearch(SearchParameters args)
{
nav.IsPaneOpen = false;
MinimizeAsInitializer();
content.Navigate(typeof(Search), args);
}
public void GoToChannel(string id)
{
Debug.WriteLine($"Channel id: {id}");
MinimizeAsInitializer();
content.Navigate(typeof(ChannelPage), id);
}
@@ -258,7 +283,7 @@ namespace FoxTube
try
{
var connection = NetworkInformation.GetInternetConnectionProfile().GetConnectionCost();
if ((bool)settings.Values["moblieWarning"] && (connection.NetworkCostType == NetworkCostType.Fixed || connection.NetworkCostType == NetworkCostType.Variable))
if (SettingsStorage.CheckConnection && (connection.NetworkCostType == NetworkCostType.Fixed || connection.NetworkCostType == NetworkCostType.Variable))
{
MessageDialog dialog = new MessageDialog("You are on metered connection now. Additional charges may apply. Do you want to continue?")
{
@@ -267,36 +292,33 @@ namespace FoxTube
};
dialog.Commands.Add(new UICommand("Yes"));
dialog.Commands.Add(new UICommand("No", (command) => cancel = true));
dialog.Commands.Add(new UICommand("Add to 'Watch later' playlist", (command) =>
{
try
if(SecretsVault.IsAuthorized)
dialog.Commands.Add(new UICommand("Add to 'Watch later' playlist", (command) =>
{
if (!SecretsVault.IsAuthorized)
SecretsVault.CheckAuthorization(false);
if (!SecretsVault.IsAuthorized)
throw new Exception("Not authenticated");
PlaylistItem item = new PlaylistItem()
try
{
Snippet = new PlaylistItemSnippet()
PlaylistItem item = new PlaylistItem()
{
ResourceId = new ResourceId()
Snippet = new PlaylistItemSnippet()
{
Kind = "youtube#video",
VideoId = id
},
PlaylistId = "WL"
}
};
ResourceId = new ResourceId()
{
Kind = "youtube#video",
VideoId = id
},
PlaylistId = "WL"
}
};
SecretsVault.Service.PlaylistItems.Insert(item, "snippet").Execute();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
}
cancel = true;
}));
SecretsVault.Service.PlaylistItems.Insert(item, "snippet").Execute();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
}
cancel = true;
}));
await dialog.ShowAsync();
}
}
@@ -309,18 +331,16 @@ namespace FoxTube
Fullscreen(false);
videoPlaceholder.Navigate(typeof(VideoPage), new string[2] { id, playlistId });
nav.Header = "Video";
}
public void GoToDeveloper(string id)
{
MinimizeAsInitializer();
content.Navigate(typeof(Settings), $"inbox&{id}");
}
public void GoToPlaylist(string id)
{
Debug.WriteLine($"Playlist id: {id}");
MinimizeAsInitializer();
content.Navigate(typeof(PlaylistPage), id);
}
@@ -361,6 +381,21 @@ namespace FoxTube
nav.IsBackEnabled = true;
else
nav.IsBackEnabled = false;
Dictionary<Type, Action> switchCase = new Dictionary<Type, Action>()
{
{ typeof(Settings), () => nav.Header = "Settings" },
{ typeof(ChannelPage), () => nav.Header = "Channel" },
{ typeof(PlaylistPage), () => nav.Header = "Playlist" },
{ typeof(Search), () => nav.Header = "Search" },
{ typeof(Subscriptions), () => nav.Header = "Subscriptions" },
{ typeof(History), () => nav.Header = "History" },
{ typeof(Home), () => nav.Header = "Home" },
{ typeof(Downloads), () => nav.Header = "Downloads" }
};
try { switchCase[content.SourcePageType](); }
catch { }
}
public void MaximizeVideo()
@@ -372,6 +407,9 @@ namespace FoxTube
videoPlaceholder.Margin = new Thickness(0);
nav.IsBackEnabled = true;
if (videoPlaceholder.Content != null)
nav.Header = "Video";
}
public void Fullscreen(bool on)
@@ -640,11 +678,6 @@ namespace FoxTube
MinimizeAsInitializer();
}
private void toChannel_Click(object sender, RoutedEventArgs e)
{
GoToChannel(SecretsVault.UserChannel.Id);
}
private void nav_BackRequested(NavigationView sender, NavigationViewBackRequestedEventArgs args)
{
if (videoPlaceholder.Content != null)
@@ -653,8 +686,6 @@ namespace FoxTube
CloseVideo();
else if (videoPlaceholder.HorizontalAlignment == HorizontalAlignment.Stretch)
MinimizeAsInitializer();
else
content.GoBack();
}
else
content.GoBack();
@@ -1,54 +0,0 @@
<Page
x:Class="FoxTube.Pages.SettingsPages.Translate"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:FoxTube"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<StackPanel Orientation="Vertical" Margin="10">
<TextBlock Text="Help us translate this app" FontSize="28"/>
<TextBlock TextWrapping="WrapWholeWords" Text="You can help us make this app even better by contributing to its development by translating this app. You can choose a brand new language to translate or edit mistakes in existing translations." Margin="0,0,0,10"/>
<StackPanel BorderThickness="2" BorderBrush="OrangeRed" MaxWidth="500" HorizontalAlignment="Left" Margin="0,0,0,10" Padding="0,0,0,3">
<TextBlock Foreground="OrangeRed" FontWeight="SemiBold" TextWrapping="WrapWholeWords" Text="Attention! This tool is used to help us to provide our app to more people from other countries. Please, don't send not done language packs. Thanks in advance ;)" Margin="5"/>
</StackPanel>
<TextBlock Text="It's quite simple:" Margin="0,0,0,10"/>
<ComboBox Header="1. Choose language you want to translate" PlaceholderText="Choose language..." Name="LangList" Margin="0,0,0,10" MinWidth="350" SelectionChanged="LangList_SelectionChanged"/>
<TextBlock Text="2. Import language pack file to your PC" Margin="0,0,0,10"/>
<Button Content="Export to PC (.xml)" Margin="0,0,0,10" Name="export" Click="export_Click" IsEnabled="False"/>
<TextBlock TextWrapping="WrapWholeWords" Text="3. Open file with any text editor you want (Notepad, Wordpad, Notepad++, VS Code, etc.)" Margin="0,0,0,10"/>
<TextBlock TextWrapping="WrapWholeWords" Text="4. Edit file by translating nececcary words and sentences" Margin="0,0,0,10"/>
<TextBlock Text="5. Upload final package to our servers" Margin="0,0,0,10"/>
<StackPanel Name="submitNotification" Visibility="Collapsed" BorderThickness="2" BorderBrush="OrangeRed" Width="350" HorizontalAlignment="Left" Margin="0,0,0,10" Padding="0,0,0,3">
<TextBlock Foreground="OrangeRed" FontWeight="SemiBold" Text="Attention! Once you submitted this language pack you won't be able to contribute to the language anymore. Think twice before continuing" TextWrapping="WrapWholeWords" Margin="5"/>
</StackPanel>
<Button Content="Choose file to upload" Margin="-1,0,0,10" HorizontalAlignment="Left" VerticalAlignment="Top" Name="upload" IsEnabled="False" Click="upload_Click"/>
<ProgressBar Width="250" HorizontalAlignment="Left" IsIndeterminate="True" Name="uploadingProgress" Visibility="Collapsed"/>
<TextBlock TextWrapping="WrapWholeWords" Text="It takes about 2-3 weeks to process new language pack and include it to the next update" Margin="0,0,0,10"/>
<TextBlock Text="Thank you for your help &#x1F61A;"/>
<TextBlock Text="Best wishes,"/>
<TextBlock Text=" XFox"/>
<StackPanel Orientation="Horizontal" BorderBrush="Green" BorderThickness="5" Margin="0,10,30,0" Visibility="Collapsed" Name="greenResult">
<TextBlock FontFamily="Segoe MDL2 Assets" Text="&#xE76E;" FontSize="40" Foreground="Green" Margin="5"/>
<StackPanel>
<TextBlock Text="Your language pack has been sent!" Foreground="Green" FontWeight="Bold" FontSize="20"/>
<TextBlock Text="Thank you! It's very imortant for us. Thank you for helping us making the app better" Foreground="Green"/>
</StackPanel>
</StackPanel>
<StackPanel Orientation="Horizontal" BorderBrush="OrangeRed" BorderThickness="5" Margin="0,10,30,0" Visibility="Collapsed" Name="denied">
<TextBlock FontFamily="Segoe MDL2 Assets" Text="&#xE7BA;" FontSize="40" Foreground="OrangeRed" Margin="5"/>
<StackPanel>
<TextBlock Text="You have already contributed to this language" Foreground="OrangeRed" FontWeight="Bold" FontSize="20"/>
<TextBlock Text="To prevent spaming our mailbox we allow our users to contribute to each language only 1 time" Foreground="OrangeRed"/>
</StackPanel>
</StackPanel>
</StackPanel>
</Grid>
</Page>
@@ -1,125 +0,0 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
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 Windows.Storage.Pickers;
using Windows.Storage;
using System.Net.Mail;
using System.Net;
using Windows.UI.Popups;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
namespace FoxTube.Pages.SettingsPages
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class Translate : Page
{
ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
int selectedLanguage;
public Translate()
{
this.InitializeComponent();
foreach (CultureInfo culture in CultureInfo.GetCultures(CultureTypes.AllCultures))
LangList.Items.Add(culture.DisplayName);
}
private async void export_Click(object sender, RoutedEventArgs e)
{
FileSavePicker picker = new FileSavePicker();
picker.CommitButtonText = "Export";
picker.DefaultFileExtension = ".xml";
picker.SuggestedFileName = "foxtube_langpack_" + CultureInfo.GetCultures(CultureTypes.AllCultures)[selectedLanguage];
picker.SuggestedStartLocation = PickerLocationId.Desktop;
picker.FileTypeChoices.Add("Language pack scheme", new List<string>() { ".xml" });
StorageFile file = await picker.PickSaveFileAsync();
if(file != null)
await FileIO.WriteTextAsync(file, GetPackage(selectedLanguage));
}
private void LangList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
selectedLanguage = LangList.SelectedIndex;
greenResult.Visibility = Visibility.Collapsed;
denied.Visibility = Visibility.Collapsed;
if (settings.Values[CultureInfo.GetCultures(CultureTypes.AllCultures)[selectedLanguage] + "_sent"] == null)
{
export.IsEnabled = true;
upload.IsEnabled = true;
submitNotification.Visibility = Visibility.Visible;
}
else
{
export.IsEnabled = false;
upload.IsEnabled = false;
denied.Visibility = Visibility.Visible;
}
}
private async void upload_Click(object sender, RoutedEventArgs e)
{
FileOpenPicker picker = new FileOpenPicker()
{
CommitButtonText = "Upload",
SuggestedStartLocation = PickerLocationId.Desktop
};
picker.FileTypeFilter.Clear();
picker.FileTypeFilter.Add(".xml");
StorageFile file = await picker.PickSingleFileAsync();
if (file != null)
{
MailMessage msg = new MailMessage();
msg.To.Add("foxgameofficial+foxtube@gmail.com");
msg.From = new MailAddress("foxgameofficial+foxtube@gmail.com");
msg.Subject = "FoxTube language pack contribution";
msg.Body = string.Format("Language: {0}\nLanguage code: {1}", CultureInfo.GetCultures(CultureTypes.AllCultures)[selectedLanguage].EnglishName, CultureInfo.GetCultures(CultureTypes.AllCultures)[selectedLanguage]);
msg.Attachments.Add(new Attachment(file.Path));
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
client.Credentials = SecretsVault.EmailCredential;
upload.IsEnabled = false;
export.IsEnabled = false;
uploadingProgress.Visibility = Visibility.Visible;
try
{
client.Send(msg);
greenResult.Visibility = Visibility.Visible;
submitNotification.Visibility = Visibility.Collapsed;
settings.Values.Add(CultureInfo.GetCultures(CultureTypes.AllCultures)[selectedLanguage] + "_sent", true);
}
catch
{
MessageDialog message = new MessageDialog("We were unable to send your feedback due to connection problems or internal server error. Please, try again later.", "Failed to send your feedback");
await message.ShowAsync();
export.IsEnabled = true;
upload.IsEnabled = true;
}
uploadingProgress.Visibility = Visibility.Collapsed;
}
}
public string GetPackage(int cultureIndex)
{
return "langpack";
}
}
}
+2 -4
View File
@@ -20,8 +20,6 @@ using FoxTube.Controls;
using YoutubeExplode.Models.MediaStreams;
using YoutubeExplode;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
namespace FoxTube.Pages
{
public enum Rating { None, Like, Dislike }
@@ -42,7 +40,7 @@ namespace FoxTube.Pages
}
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// Video page
/// </summary>
public sealed partial class VideoPage : Page
{
@@ -175,7 +173,7 @@ namespace FoxTube.Pages
license.Text = "Standard YouTube License";
else license.Text = "Creative Commons Attribution license (reuse allowed)";
VideoCategoriesResource.ListRequest categoryRequest = SecretsVault.NoAuthService.VideoCategories.List("snippet");
VideoCategoriesResource.ListRequest categoryRequest = SecretsVault.Service.VideoCategories.List("snippet");
categoryRequest.Id = item.Snippet.CategoryId;
category.Text = (await categoryRequest.ExecuteAsync()).Items[0].Snippet.Title;