Archived
1
0

Development 3

This commit is contained in:
Michael Gordeev
2018-06-30 23:06:15 +03:00
parent 7a98044484
commit adfc893cf6
6 changed files with 311 additions and 204 deletions
+21 -50
View File
@@ -12,6 +12,10 @@ using Windows.UI;
using Windows.UI.Xaml.Documents; using Windows.UI.Xaml.Documents;
using System.Net; using System.Net;
using System.Threading; using System.Threading;
using Windows.Data.Json;
using Windows.Storage.Streams;
using Windows.Security.Cryptography;
using Windows.Security.Cryptography.Core;
using Google.Apis.Auth.OAuth2; using Google.Apis.Auth.OAuth2;
using Google.Apis.Auth.OAuth2.Flows; using Google.Apis.Auth.OAuth2.Flows;
@@ -19,6 +23,7 @@ using Google.Apis.Services;
using Google.Apis.Util.Store; using Google.Apis.Util.Store;
using Google.Apis.YouTube.v3; using Google.Apis.YouTube.v3;
using Google.Apis.Auth.OAuth2.Responses; using Google.Apis.Auth.OAuth2.Responses;
using Windows.Storage;
namespace FoxTube namespace FoxTube
{ {
@@ -58,19 +63,27 @@ namespace FoxTube
#region Object containers #region Object containers
public bool IsLoged = false; public bool IsLoged = false;
public TokenResponse Token; public UserCredential Credential;
private UserCredential Credential;
public event EventHandler AuthorizationStateChanged; public event EventHandler AuthorizationStateChanged;
public SecretsVault() public async void Authorize()
{ {
CheckAuthorization(); try { Credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(Secrets, new[] { Google.Apis.Oauth2.v2.Oauth2Service.Scope.UserinfoProfile, YouTubeService.Scope.YoutubeForceSsl }, "user", CancellationToken.None); }
catch { }
if(Credential != null)
{
IsLoged = true;
AuthorizationStateChanged.Invoke(this, null);
}
} }
public async Task Authorize() public async void Deauthenticate()
{ {
Credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(Secrets, new[] { Google.Apis.Oauth2.v2.Oauth2Service.Scope.UserinfoProfile, YouTubeService.Scope.YoutubeForceSsl }, "user", CancellationToken.None); if(await Credential.RevokeTokenAsync(CancellationToken.None))
AuthorizationStateChanged.Invoke(this, null); {
Credential = null;
AuthorizationStateChanged.Invoke(this, null);
}
} }
public async void CheckAuthorization() public async void CheckAuthorization()
@@ -83,49 +96,7 @@ namespace FoxTube
if (token == null) if (token == null)
IsLoged = false; IsLoged = false;
else else
{ Authorize();
IsLoged = true;
Credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(Secrets, new[] { Google.Apis.Oauth2.v2.Oauth2Service.Scope.UserinfoProfile, YouTubeService.Scope.YoutubeForceSsl }, "user", CancellationToken.None);
AuthorizationStateChanged.Invoke(this, null);
}
}
#endregion
#region User credentials
private List<UserCredential> credentials = new List<UserCredential>(); //Test variable simulating actual credentials storage
public void AddAccount()
{
credentials.Add(
new UserCredential(
new AuthorizationCodeFlow(
new GoogleAuthorizationCodeFlow.Initializer()
{
ClientSecrets = Secrets,
DataStore = null //TO-DO: Replace with new PasswordsVaultDataStore()
}),
"userId",
new TokenResponse()
{
AccessToken = "done",
ExpiresInSeconds = 1,
IdToken = "done",
TokenType = "done",
RefreshToken = "done",
Scope = "youtube"
}));
}
public void DeleteAccount(int index)
{
credentials.RemoveAt(index);
}
public UserCredential RetrieveAccount(int index)
{
return credentials[index];
} }
#endregion #endregion
} }
+30
View File
@@ -0,0 +1,30 @@
<UserControl
x:Class="FoxTube.Controls.SuggestionsQueries"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:FoxTube.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="450"
d:DesignWidth="350">
<Grid Background="WhiteSmoke" Name="grid">
<StackPanel Width="350">
<StackPanel Width="350" Name="searchStandby" Visibility="Visible" Margin="10">
<TextBlock Text="Loading results... Please, wait."/>
<ProgressBar IsIndeterminate="True"/>
</StackPanel>
<StackPanel Name="suggestions"/>
<StackPanel>
<StackPanel Orientation="Horizontal" Margin="10,0,10,0">
<TextBlock Foreground="Gray" Text="History"/>
<Line VerticalAlignment="Center" X1="0" X2="500" StrokeThickness="2" Stroke="Gray" Margin="5,0,0,0"/>
</StackPanel>
<StackPanel Name="history">
</StackPanel>
</StackPanel>
</StackPanel>
</Grid>
</UserControl>
+113
View File
@@ -0,0 +1,113 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using System.Xml;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.UI;
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;
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
namespace FoxTube.Controls
{
public sealed partial class SuggestionsQueries : UserControl
{
ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
List<string> lastRequests = new List<string>();
public SuggestionsQueries()
{
this.InitializeComponent();
for (int k = 0; k < 5; k++)
if (settings.Values["history" + k] != null)
lastRequests.Add((string)settings.Values["history" + k]);
}
private void Item_Click(object sender, RoutedEventArgs e)
{
string term = (sender as Button).Content as string;
if (!lastRequests.Contains(term))
AddToHistory(term);
Methods.MainPage.GoToSearch(term);
}
public async void BuildList(string keyword)
{
(grid.Children[0] as StackPanel).Visibility = Visibility.Visible;
searchStandby.Visibility = Visibility.Visible;
suggestions.Children.Clear();
foreach(string s in lastRequests)
{
Button item = new Button()
{
HorizontalAlignment = HorizontalAlignment.Stretch,
HorizontalContentAlignment = HorizontalAlignment.Left,
Background = new SolidColorBrush(Colors.Transparent),
Content = s
};
item.Click += Item_Click;
history.Children.Add(item);
}
XmlDocument doc = new XmlDocument();
await Task.Run(() =>
{
doc.Load(string.Format("http://suggestqueries.google.com/complete/search?output=toolbar&hl={0}&q={1}",
(settings.Values["region"] as string)[0] + (settings.Values["region"] as string)[1],
keyword));
});
if(doc["toplevel"].HasChildNodes)
for (int k = 0; k < 5; k++)
try
{
Button item = new Button()
{
HorizontalAlignment = HorizontalAlignment.Stretch,
HorizontalContentAlignment = HorizontalAlignment.Left,
Background = new SolidColorBrush(Colors.Transparent),
Content = doc["toplevel"].ChildNodes[k]["suggestion"].GetAttribute("data")
};
item.Click += Item_Click;
suggestions.Children.Add(item);
} catch { break; }
else
suggestions.Children.Add(new Button()
{
Content = "No suggestions found.",
IsEnabled = false,
Foreground = new SolidColorBrush(Colors.Gray),
Background = new SolidColorBrush(Colors.Transparent)
});
searchStandby.Visibility = Visibility.Collapsed;
}
public void AddToHistory(string keyword)
{
lastRequests.Insert(0, keyword);
if (lastRequests.Count > 5)
lastRequests.RemoveAt(5);
for(int k = 0; k < 5; k++)
try { settings.Values["history" + k] = lastRequests[k]; }
catch { settings.Values.Add("history" + k, lastRequests[k]); }
}
public void Hide()
{
(grid.Children[0] as StackPanel).Visibility = Visibility.Collapsed;
}
}
}
+12 -5
View File
@@ -100,6 +100,9 @@
<Compile Include="Controls\CommentCard.xaml.cs"> <Compile Include="Controls\CommentCard.xaml.cs">
<DependentUpon>CommentCard.xaml</DependentUpon> <DependentUpon>CommentCard.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Controls\SuggestionsQueries.xaml.cs">
<DependentUpon>SuggestionsQueries.xaml</DependentUpon>
</Compile>
<Compile Include="Pages\Channel.xaml.cs"> <Compile Include="Pages\Channel.xaml.cs">
<DependentUpon>Channel.xaml</DependentUpon> <DependentUpon>Channel.xaml</DependentUpon>
</Compile> </Compile>
@@ -231,6 +234,10 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="Controls\SuggestionsQueries.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Pages\Channel.xaml"> <Page Include="Pages\Channel.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
@@ -313,19 +320,19 @@
<Version>1.0.1</Version> <Version>1.0.1</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Google.Apis"> <PackageReference Include="Google.Apis">
<Version>1.34.0</Version> <Version>1.30.0-beta02</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Google.Apis.Auth"> <PackageReference Include="Google.Apis.Auth">
<Version>1.34.0</Version> <Version>1.30.0-beta02</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Google.Apis.Core"> <PackageReference Include="Google.Apis.Core">
<Version>1.34.0</Version> <Version>1.30.0-beta02</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Google.Apis.Oauth2.v2"> <PackageReference Include="Google.Apis.Oauth2.v2">
<Version>1.34.0.1134</Version> <Version>1.29.2.994</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Google.Apis.YouTube.v3"> <PackageReference Include="Google.Apis.YouTube.v3">
<Version>1.34.0.1226</Version> <Version>1.29.2.1006</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform"> <PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.1.5</Version> <Version>6.1.5</Version>
+27 -24
View File
@@ -19,10 +19,9 @@
Width="50" Height="50" Width="50" Height="50"
FontFamily="Segoe MDL2 Assets" FontSize="20" Content="&#xE700;" FontFamily="Segoe MDL2 Assets" FontSize="20" Content="&#xE700;"
Foreground="White" Background="Red" Foreground="White" Background="Red"
Grid.Column="0"
Click="menuButton_Click" Click="menuButton_Click"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/> HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
<TextBlock Grid.Column="1" Text="Home" FontSize="20" FontWeight="Bold" Margin="5, 0, 0, 0" HorizontalAlignment="Left" VerticalAlignment="Center" Foreground="White" Name="headerText"/> <TextBlock Text="FoxTube" FontSize="20" FontWeight="Bold" Margin="5, 0, 0, 0" HorizontalAlignment="Left" VerticalAlignment="Center" Foreground="White" Name="headerText"/>
</StackPanel> </StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
@@ -31,7 +30,7 @@
FontFamily="Segoe MDL2 Assets" Content="&#xED0D;" Foreground="White" FontFamily="Segoe MDL2 Assets" Content="&#xED0D;" Foreground="White"
Width="50" Height="50" Background="Transparent"/> Width="50" Height="50" Background="Transparent"/>
<Popup Margin="0,50,0,0" Name="notificationPane" Width="350" Height="400" IsOpen="False" IsLightDismissEnabled="True"/> <Popup HorizontalAlignment="Right" Margin="0,50,0,0" Name="notificationPane" Width="350" Height="450" IsOpen="False" IsLightDismissEnabled="True"/>
</Grid> </Grid>
<Button Name="feedback" ToolTipService.ToolTip="Send feedback" Click="feedback_Click" <Button Name="feedback" ToolTipService.ToolTip="Send feedback" Click="feedback_Click"
@@ -44,12 +43,23 @@
<Button.Flyout> <Button.Flyout>
<MenuFlyout> <MenuFlyout>
<MenuFlyoutItem Text="Sign in with existing account" Name="signIn" Click="signIn_Click"/> <MenuFlyoutItem Text="Sign in with existing account" Name="signIn" Click="signIn_Click"/>
<MenuFlyoutItem Text="Create a new Google account" Name="createAccount" Click="createAccount_Click"/> <MenuFlyoutItem Text="Create new Google account" Name="createAccount" Click="createAccount_Click"/>
</MenuFlyout> </MenuFlyout>
</Button.Flyout> </Button.Flyout>
</Button> </Button>
<Grid> <Button Width="50" Background="Transparent" Height="50" Visibility="Collapsed" Name="avatar" ToolTipService.ToolTip="My account">
<PersonPicture Width="30"/>
<Button.Flyout>
<MenuFlyout>
<MenuFlyoutItem Text="My channel"/>
<MenuFlyoutSeparator/>
<MenuFlyoutItem Text="Log out"/>
</MenuFlyout>
</Button.Flyout>
</Button>
<!--<Grid>
<Button Width="50" Background="Transparent" Height="50" Visibility="Collapsed" Name="LoggedAvatar" ToolTipService.ToolTip="My account" Click="LoggedAvatar_Click"> <Button Width="50" Background="Transparent" Height="50" Visibility="Collapsed" Name="LoggedAvatar" ToolTipService.ToolTip="My account" Click="LoggedAvatar_Click">
<PersonPicture Width="30"/> <PersonPicture Width="30"/>
</Button> </Button>
@@ -82,26 +92,16 @@
<Button HorizontalAlignment="Stretch" HorizontalContentAlignment="Left" Background="Transparent" Content="Log out"/> <Button HorizontalAlignment="Stretch" HorizontalContentAlignment="Left" Background="Transparent" Content="Log out"/>
</StackPanel> </StackPanel>
</Popup> </Popup>
</Grid> </Grid>-->
<Grid> <Grid>
<TextBox KeyUp="searchField_KeyUp" Name="searchField" ToolTipService.ToolTip="Search" Margin="4" Width="350" Height="42" Padding="10,10,45,0" PlaceholderText="Search" BorderThickness="0" Background="#7FFFFFFF" Text="Random encounters" TextChanged="searchField_TextChanged" LostFocus="searchField_LostFocus"/> <TextBox KeyUp="searchField_KeyUp" Name="searchField" ToolTipService.ToolTip="Search" Margin="4" Width="350" Height="42" Padding="10,10,45,0" PlaceholderText="Search" BorderThickness="0" Background="#7FFFFFFF" Text="DAGames" TextChanged="searchField_TextChanged" GotFocus="searchField_GotFocus"/>
<Button Name="searchButton" HorizontalAlignment="Right" Click="searchButton_Click" <Button Name="searchButton" HorizontalAlignment="Right" Click="searchButton_Click"
Width="42" Height="42" Margin="4" Width="42" Height="42" Margin="4"
Background="Transparent" Background="Transparent"
FontFamily="Segoe MDL2 Assets" Content="&#xE11A;" FontSize="20" Foreground="Black"/> FontFamily="Segoe MDL2 Assets" Content="&#xE11A;" FontSize="20" Foreground="Black"/>
<Popup Margin="0,50,0,0" Name="searchSuggestions" IsOpen="True" Visibility="Collapsed"> <Popup Margin="0,50,0,0" Name="searchSuggestions" IsOpen="False" Width="350" IsLightDismissEnabled="True"/>
<StackPanel Background="WhiteSmoke" Width="350">
<StackPanel Width="350" Name="searchStandby" Visibility="Visible" Margin="10">
<TextBlock Text="Loading results... Please, wait."/>
<ProgressBar IsIndeterminate="True"/>
</StackPanel>
<ListBox Name="searchSuggestionsList" Visibility="Visible" SelectionChanged="searchSuggestionsList_SelectionChanged">
</ListBox>
</StackPanel>
</Popup>
</Grid> </Grid>
</StackPanel> </StackPanel>
</Grid> </Grid>
@@ -133,6 +133,12 @@
<TextBlock Style="{StaticResource MenuItem}" Text="Watch later"/> <TextBlock Style="{StaticResource MenuItem}" Text="Watch later"/>
</StackPanel> </StackPanel>
</ListBoxItem> </ListBoxItem>
<ListBoxItem Name="subscriptionsMenu" Visibility="Collapsed">
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource ItemIcon}" Text="&#xE716;"/>
<TextBlock Style="{StaticResource MenuItem}" Text="Subscriptions"/>
</StackPanel>
</ListBoxItem>
</ListBox> </ListBox>
<ListBox RelativePanel.Below="topHamburger" Name="subscriptionsHamburger" Visibility="Visible"> <ListBox RelativePanel.Below="topHamburger" Name="subscriptionsHamburger" Visibility="Visible">
@@ -142,14 +148,11 @@
<Line Name="subsMenuStroke" X1="0" Y1="10" X2="300" Y2="10" Stroke="Gray" StrokeThickness="2"/> <Line Name="subsMenuStroke" X1="0" Y1="10" X2="300" Y2="10" Stroke="Gray" StrokeThickness="2"/>
</StackPanel> </StackPanel>
</ListBoxItem> </ListBoxItem>
<ListBoxItem IsEnabled="False" Name="subsLogErr" Visibility="Visible" VerticalContentAlignment="Top"> <ListBoxItem IsEnabled="False" Name="subsLogErr" Visibility="Visible" HorizontalContentAlignment="Center">
<TextBlock FontFamily="Default, Segoe MDL2 Assets" Text="Press &#xE1E2; and add an account to see your featured channels and another useful stuff here" HorizontalTextAlignment="Center" Width="225" Foreground="Gray" TextWrapping="WrapWholeWords"/> <TextBlock FontFamily="Default, Segoe MDL2 Assets" Text="Press &#xE1E2; and add an account to see your featured channels and another useful stuff here" HorizontalTextAlignment="Center" Width="225" Foreground="Gray" TextWrapping="WrapWholeWords"/>
</ListBoxItem> </ListBoxItem>
<ListBoxItem> <ListBoxItem IsEnabled="False" Name="subsNull" Visibility="Collapsed" HorizontalContentAlignment="Center" Padding="0">
<StackPanel Orientation="Horizontal"> <TextBlock Text="You don't have any subscriptions" Width="225" Foreground="Gray" TextWrapping="WrapWholeWords"/>
<PersonPicture Height="25" Margin="0,0,17,0"/>
<TextBlock Style="{StaticResource MenuItem}" VerticalAlignment="Center" Text="Channel name"/>
</StackPanel>
</ListBoxItem> </ListBoxItem>
</ListBox> </ListBox>
+107 -124
View File
@@ -34,6 +34,9 @@ using System.Globalization;
using Windows.ApplicationModel.Core; using Windows.ApplicationModel.Core;
using Windows.System; using Windows.System;
using Windows.UI.Xaml.Documents; using Windows.UI.Xaml.Documents;
using Google.Apis.Oauth2.v2;
using Google.Apis.Oauth2.v2.Data;
using FoxTube.Controls;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
@@ -56,9 +59,12 @@ namespace FoxTube
RightPaneState paneState = RightPaneState.Full; RightPaneState paneState = RightPaneState.Full;
bool isForcedCollapsed = false; bool isForcedCollapsed = false;
List<Subscription> subscriptions = new List<Subscription>();
ApplicationDataContainer settings = ApplicationData.Current.LocalSettings; ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
NotificationsCenter notificationsCenter = new NotificationsCenter(); NotificationsCenter notificationsCenter = new NotificationsCenter();
SuggestionsQueries suggestions = new SuggestionsQueries();
public MainPage() public MainPage()
{ {
this.InitializeComponent(); this.InitializeComponent();
@@ -94,8 +100,60 @@ namespace FoxTube
Vault.AuthorizationStateChanged += Vault_AuthorizationStateChanged; Vault.AuthorizationStateChanged += Vault_AuthorizationStateChanged;
} }
private void Vault_AuthorizationStateChanged(object sender, EventArgs e) private async void Vault_AuthorizationStateChanged(object sender, EventArgs e)
{ {
if(Vault.IsLoged)
{
account.Visibility = Visibility.Collapsed;
try
{
Userinfoplus info = await new Oauth2Service(new BaseClientService.Initializer()
{
HttpClientInitializer = Vault.Credential,
ApplicationName = "FoxTube",
}).Userinfo.Get().ExecuteAsync();
(avatar.Content as PersonPicture).ProfilePicture = new BitmapImage(new Uri(info.Picture));
ToolTipService.SetToolTip(avatar, new ToolTip() { Content = string.Format("{0} ({1})", info.Name, info.Email) });
}
catch { }
avatar.Visibility = Visibility.Visible;
historyMenu.Visibility = Visibility.Visible;
likedMenu.Visibility = Visibility.Visible;
watchLaterMenu.Visibility = Visibility.Visible;
subscriptionsMenu.Visibility = Visibility.Visible;
subsLogErr.Visibility = Visibility.Collapsed;
channelMenu.Visibility = Visibility.Visible;
SubscriptionsResource.ListRequest request = SecretsVault.Service.Subscriptions.List("snippet,contentDetails");
request.Mine = true;
request.MaxResults = 10;
SubscriptionListResponse response = await request.ExecuteAsync();
if (response.Items.Count == 0)
subsNull.Visibility = Visibility.Visible;
else
foreach (Subscription s in response.Items)
try
{
subscriptions.Add(s);
StackPanel panel = new StackPanel() { Orientation = Orientation.Horizontal };
panel.Children.Add(new PersonPicture()
{
Height = 25,
Margin = new Thickness(0, 0, 17, 0),
ProfilePicture = new BitmapImage(new Uri(s.Snippet.Thumbnails.Medium.Url))
});
panel.Children.Add(new TextBlock()
{
VerticalAlignment = VerticalAlignment.Center,
Text = s.Snippet.Title
});
subscriptionsHamburger.Items.Add(new ListBoxItem() { Content = panel });
}
catch { }
}
Debug.WriteLine("--<!!!Authorized!!!>--"); Debug.WriteLine("--<!!!Authorized!!!>--");
} }
@@ -103,6 +161,8 @@ namespace FoxTube
{ {
base.OnNavigatedTo(e); base.OnNavigatedTo(e);
SetTitleBar(); SetTitleBar();
Vault.CheckAuthorization();
} }
private void SetTitleBar() private void SetTitleBar()
@@ -202,7 +262,7 @@ namespace FoxTube
private void notificationMenu_Click(object sender, RoutedEventArgs e) private void notificationMenu_Click(object sender, RoutedEventArgs e)
{ {
notificationMenu.Content = ""; notificationMenu.Content = "";
if (content.Width >= 500) if (Window.Current.Bounds.Width >= 500)
{ {
notificationPane.Child = notificationsCenter; notificationPane.Child = notificationsCenter;
notificationPane.IsOpen = !notificationPane.IsOpen; notificationPane.IsOpen = !notificationPane.IsOpen;
@@ -238,7 +298,19 @@ namespace FoxTube
catMenuStroke.Y1 = catMenuStroke.Y2 = 0; catMenuStroke.Y1 = catMenuStroke.Y2 = 0;
catMenuStroke.X2 = 40; catMenuStroke.X2 = 40;
categoriesTitle.Height = 2; categoriesTitle.Height = 2;
subsLogErr.Visibility = Visibility.Collapsed; if (Vault.IsLoged)
{
if (subscriptions.Count == 0)
{
subsNull.Visibility = Visibility.Collapsed;
subsMenuStroke.Visibility = Visibility.Collapsed;
}
}
else
{
subsLogErr.Visibility = Visibility.Collapsed;
subsMenuStroke.Visibility = Visibility.Collapsed;
}
} catch { } } catch { }
} }
@@ -255,15 +327,22 @@ namespace FoxTube
catMenuStroke.Y1 = subsMenuStroke.Y2 = 10; catMenuStroke.Y1 = subsMenuStroke.Y2 = 10;
catMenuStroke.X2 = 300; catMenuStroke.X2 = 300;
categoriesTitle.Height = 17; categoriesTitle.Height = 17;
subsLogErr.Visibility = Visibility.Visible; if (Vault.IsLoged)
{
if (subscriptions.Count == 0)
{
subsNull.Visibility = Visibility.Visible;
subsMenuStroke.Visibility = Visibility.Visible;
}
}
else
{
subsLogErr.Visibility = Visibility.Visible;
subsMenuStroke.Visibility = Visibility.Visible;
}
} catch { } } catch { }
} }
private void LoggedAvatar_Click(object sender, RoutedEventArgs e)
{
AccountManagement.IsOpen = true;
}
private async void createAccount_Click(object sender, RoutedEventArgs e) private async void createAccount_Click(object sender, RoutedEventArgs e)
{ {
await Launcher.LaunchUriAsync(new Uri("https://accounts.google.com/signup/v2/webcreateaccount?ManageAccount&flowName=GlifWebSignIn&flowEntry=SignUp")); await Launcher.LaunchUriAsync(new Uri("https://accounts.google.com/signup/v2/webcreateaccount?ManageAccount&flowName=GlifWebSignIn&flowEntry=SignUp"));
@@ -277,97 +356,21 @@ namespace FoxTube
private void searchField_TextChanged(object sender, TextChangedEventArgs e) private void searchField_TextChanged(object sender, TextChangedEventArgs e)
{ {
if (searchField.Text.Length > 2) if (searchField.Text.Length > 2)
suggestions.BuildList(searchField.Text);
else
suggestions.Hide();
}
private void searchField_GotFocus(object sender, RoutedEventArgs e)
{
suggestions.Hide();
if (Window.Current.Bounds.Width >= 500)
{ {
searchSuggestions.Visibility = Visibility.Visible; searchSuggestions.Child = suggestions;
buildSearchSuggestionsTree(searchField.Text); searchSuggestions.IsOpen = !searchSuggestions.IsOpen;
} }
else searchField_LostFocus(this, null); else
} popupPlaceholder.Content = suggestions;
async void buildSearchSuggestionsTree(string keyword)
{
searchSuggestionsList.Items.Clear();
searchStandby.Visibility = Visibility.Visible;
searchSuggestionsList.Visibility = Visibility.Collapsed;
XmlDocument doc = new XmlDocument();
await Task.Run(() =>
{
doc.Load(string.Format("http://suggestqueries.google.com/complete/search?output=toolbar&hl={0}&q={1}", (settings.Values["region"] as string)[0] + (settings.Values["region"] as string)[1], keyword));
});
for (int k = 0; k < 5; k++)
try
{
searchSuggestionsList.Items.Add(new ListBoxItem()
{
Content = doc["toplevel"].ChildNodes[k]["suggestion"].GetAttribute("data")
});
}
catch (NullReferenceException)
{
searchSuggestionsList.Items.Clear();
searchSuggestionsList.Items.Add(new ListBoxItem()
{
Content = "No suggestions found.",
IsEnabled = false,
Foreground = new SolidColorBrush(Colors.Gray)
});
}
/*ListBoxItem separator = new ListBoxItem()
{
Padding = new Thickness(0),
IsEnabled = false
};
StackPanel stack = new StackPanel() { Orientation = Orientation.Horizontal };
stack.Children.Add(new TextBlock()
{
Foreground = new SolidColorBrush(Colors.Gray),
Text = "Previous requests",
FontSize = 12,
Margin = new Thickness(0),
Padding = new Thickness(0, 0, 5, 0)
});
stack.Children.Add(new Line()
{
X1 = 0,
X2 = 250,
Y1 = 10,
Y2 = 10,
Stroke = new SolidColorBrush(Colors.Gray),
StrokeThickness = 2
});
separator.Content = stack;
searchSuggestionsList.Items.Add(separator);
if (settings.Values["history0"] != null)
for (int k = 0; k < 5; k++)
try
{
searchSuggestionsList.Items.Add(new ListBoxItem()
{
Content = settings.Values["history" + k]
});
}
catch (NullReferenceException)
{
break;
}
else searchSuggestionsList.Items.Add(new ListBoxItem()
{
Content = "You have no previous requests.",
Foreground = new SolidColorBrush(Colors.Gray),
IsEnabled = false
});*/
searchStandby.Visibility = Visibility.Collapsed;
searchSuggestionsList.Visibility = Visibility.Visible;
}
private void searchField_LostFocus(object sender, RoutedEventArgs e)
{
searchSuggestions.Visibility = Visibility.Collapsed;
} }
private void searchButton_Click(object sender, RoutedEventArgs e) private void searchButton_Click(object sender, RoutedEventArgs e)
@@ -376,38 +379,18 @@ namespace FoxTube
StartSearch(searchField.Text); StartSearch(searchField.Text);
} }
public void GoToSearch(string keyword)
{
searchField.Text = keyword;
StartSearch(keyword);
}
private async void StartSearch(string keyword) private async void StartSearch(string keyword)
{ {
content.Navigate(typeof(Search)); content.Navigate(typeof(Search));
topHamburger.SelectedItem = null; topHamburger.SelectedItem = null;
bottomHaburger.SelectedItem = null; bottomHaburger.SelectedItem = null;
/*{
List<string> history = new List<string>();
for(int k = 0; k < 5; k++)
try
{
history.Add(settings.Values["history" + k].ToString());
}
catch(NullReferenceException)
{
break;
}
history.Insert(0, keyword);
if (history.Count > 5)
history.RemoveAt(5);
for(int k = 0; k < history.Count; k++)
try
{
settings.Values["history" + k] = history[k];
}
catch (NullReferenceException)
{
settings.Values.Add("history" + k, keyword);
}
}*/
YouTubeService ytService = SecretsVault.IsAuthorized ? SecretsVault.Service : SecretsVault.NoAuthService; YouTubeService ytService = SecretsVault.IsAuthorized ? SecretsVault.Service : SecretsVault.NoAuthService;
var searchListRequest = ytService.Search.List("snippet"); var searchListRequest = ytService.Search.List("snippet");