Archived
1
0

SafeSearch & Location-based search

This commit is contained in:
Michael Gordeev
2018-06-08 12:02:20 +03:00
parent f97cebb958
commit dbcaef11c7
8 changed files with 152 additions and 20 deletions
+4 -2
View File
@@ -58,11 +58,13 @@
<PivotItem Margin="0,-48,0,0">
<Grid Padding="10">
<ProgressRing Name="playlistRing" Width="100" Height="100" Foreground="Red" IsActive="True"/>
<StackPanel Visibility="Collapsed" Name="playlistPane">
<StackPanel Visibility="Visible" Name="playlistPane">
<TextBlock FontSize="28" Text="Playlists"/>
<StackPanel Name="playlists">
</StackPanel>
<HyperlinkButton Name="showMorePlaylists" Click="showMorePlaylists_Click" Content="Show more" HorizontalAlignment="Center" FontSize="20" Foreground="Red"/>
<ProgressBar Name="showMorePlaylistsProgressBar" IsIndeterminate="True" Foreground="Red" Visibility="Collapsed"/>
</StackPanel>
</Grid>
</PivotItem>
+9 -1
View File
@@ -18,6 +18,7 @@ using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Text;
using Windows.Storage;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
@@ -28,6 +29,7 @@ namespace FoxTube
/// </summary>
public sealed partial class Channel : Page
{
ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
public string channelId;
public Google.Apis.YouTube.v3.Data.Channel item;
VideoGrid videoGrid = new VideoGrid();
@@ -76,7 +78,7 @@ namespace FoxTube
videos.Children.Add(videoGrid);
foreach(Google.Apis.YouTube.v3.Data.SearchResult vid in response2.Items)
foreach(SearchResult vid in response2.Items)
{
VideoCard vCard = new VideoCard(vid.Id.VideoId);
videoGrid.AddCards(vCard);
@@ -103,6 +105,7 @@ namespace FoxTube
searchListRequest.Q = searchField.Text;
searchListRequest.ChannelId = channelId;
searchListRequest.MaxResults = 25;
searchListRequest.SafeSearch = (SearchResource.ListRequest.SafeSearchEnum)(int)settings.Values["safeSearch"];
var response = await searchListRequest.ExecuteAsync();
@@ -168,5 +171,10 @@ namespace FoxTube
else if (content.SelectedIndex == 2)
toAbout.FontWeight = FontWeights.Bold;
}
private void showMorePlaylists_Click(object sender, RoutedEventArgs e)
{
}
}
}
+10 -10
View File
@@ -7,40 +7,40 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Name="grid">
<Grid.RowDefinitions>
<RowDefinition Height="47"/>
<RowDefinition Height="0"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Background="Red">
<StackPanel Orientation="Horizontal" Margin="10,0,10,0">
<HyperlinkButton Name="toRecommended" Click="toVideos_Click" Foreground="White" Margin="0,0,10,0">
<HyperlinkButton Name="toRecommended" Click="toRecommended_Click" Foreground="White" Margin="0,0,10,0">
<TextBlock Text="Recommended"/>
</HyperlinkButton>
<HyperlinkButton Name="toTrending" Click="toVideos_Click" Foreground="White" Margin="0,0,10,0">
<HyperlinkButton Name="toTrending" Click="toTrending_Click" Foreground="White" Margin="0,0,10,0">
<TextBlock Text="Trending"/>
</HyperlinkButton>
<HyperlinkButton Name="tosubs" Click="toVideos_Click" Foreground="White" Margin="0,0,10,0">
<HyperlinkButton Name="tosubs" Click="tosubs_Click" Foreground="White" Margin="0,0,10,0">
<TextBlock Text="Subscriptions"/>
</HyperlinkButton>
</StackPanel>
</Grid>
<Grid Grid.Row="1">
<ScrollViewer Margin="0,0,0,50">
<Pivot>
<PivotItem>
<Pivot Name="pivot">
<PivotItem Margin="0,-48,0,0">
</PivotItem>
<PivotItem>
<PivotItem Margin="0,-48,0,0">
</PivotItem>
<PivotItem >
<PivotItem Margin="0,-48,0,0">
</PivotItem>
</Pivot>
</ScrollViewer>
<CommandBar VerticalAlignment="Bottom">
<AppBarButton Icon="Refresh" Content="Refresh page"/>
<AppBarButton Icon="Refresh" Label="Refresh page" Name="refresh" Click="refresh_Click"/>
</CommandBar>
</Grid>
</Grid>
+65
View File
@@ -12,6 +12,11 @@ using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.Globalization;
using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;
using Windows.Storage;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
@@ -25,6 +30,66 @@ namespace FoxTube
public Home()
{
this.InitializeComponent();
Initialize();
}
public async void Initialize()
{
#region Vairables declaring
VideoGrid videoGrid = new VideoGrid();
string reg = (ApplicationData.Current.LocalSettings.Values["region"] as string).ToUpper().Remove(0, 3);
#endregion
pivot.Items.Clear();
grid.RowDefinitions[0].Height = new GridLength(0);
#region Request-Response
VideosResource.ListRequest request = SecretsVault.YoutubeService.Videos.List("snippet,contentDetails,statistics");
request.Chart = VideosResource.ListRequest.ChartEnum.MostPopular;
request.RegionCode = reg;
request.MaxResults = 48;
VideoListResponse response = await request.ExecuteAsync();
#endregion
foreach (Google.Apis.YouTube.v3.Data.Video vid in response.Items)
{
VideoCard vCard = new VideoCard(vid.Id);
videoGrid.AddCards(vCard);
}
pivot.Items.Add(new PivotItem()
{
Margin = new Thickness(0,-48,0,0),
Name = "trending",
Content = videoGrid
});
/*if((Parent as MainPage).Logged)
{
grid.RowDefinitions[0].Height = new GridLength(47);
//TO-DO: Add initializing recommended and subscriptions tabs
}*/
}
private void toRecommended_Click(object sender, RoutedEventArgs e)
{
}
private void toTrending_Click(object sender, RoutedEventArgs e)
{
}
private void tosubs_Click(object sender, RoutedEventArgs e)
{
}
private void refresh_Click(object sender, RoutedEventArgs e)
{
Initialize();
}
}
}
+5 -1
View File
@@ -86,7 +86,9 @@ namespace FoxTube
settings.Values.Add("volume", 100);
if (settings.Values["region"] == null)
settings.Values.Add("region", CultureInfo.CurrentCulture);
settings.Values.Add("region", CultureInfo.CurrentCulture.Name);
if (settings.Values["safeSearch"] == null)
settings.Values.Add("safeSearch", 0);
content.Navigate(typeof(Home));
}
@@ -507,7 +509,9 @@ namespace FoxTube
var searchListRequest = ytService.Search.List("snippet");
searchListRequest.Q = keyword;
searchListRequest.SafeSearch = (SearchResource.ListRequest.SafeSearchEnum)(int)settings.Values["safeSearch"];
searchListRequest.MaxResults = 25;
searchListRequest.RelevanceLanguage = settings.Values["region"].ToString().Remove(2).ToLower();
var response = await searchListRequest.ExecuteAsync();
+41 -1
View File
@@ -6,6 +6,7 @@ using System.Threading.Tasks;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using Google.Apis.YouTube.v3;
using Google.Apis.Auth.OAuth2.Flows;
namespace FoxTube
{
@@ -39,7 +40,7 @@ namespace FoxTube
{
return new YouTubeService(new BaseClientService.Initializer()
{
ApiKey = SecretsVault.YoutubeApi,
ApiKey = YoutubeApi,
ApplicationName = "FoxTube"
});
}
@@ -49,6 +50,7 @@ namespace FoxTube
{
get
{
//new UserCredential(new AuthorizationCodeFlow(new AuthorizationCodeFlow.Initializer("", "")), "userId", new Google.Apis.Auth.OAuth2.Responses.TokenResponse() { } )
return new ClientSecrets()
{
ClientId = "349735264870-2ekqlm0a4mkg3mmrfcv90s3qp3o15dq0.apps.googleusercontent.com",
@@ -56,5 +58,43 @@ namespace FoxTube
};
}
}
#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 AuthorizationCodeFlow.Initializer("https://accounts.google.com/o/oauth2/v2/auth", "https://www.googleapis.com/oauth2/v4/token")),
"",
new Google.Apis.Auth.OAuth2.Responses.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
#region Authorization service functions
#endregion
}
}
+6 -4
View File
@@ -17,7 +17,7 @@
<PivotItem Margin="0,-48,0,0">
<StackPanel Orientation="Vertical" Margin="10">
<TextBlock Text="Preferences" FontSize="28"/>
<TextBlock Text="Region &#x26; language" FontSize="22"/>
<TextBlock Text="Region &#x26; search" FontSize="22"/>
<ComboBox Header="App interface language" MinWidth="250" Name="language" SelectionChanged="language_SelectionChanged">
<ComboBoxItem Content="English"/>
<ComboBoxItem Content="Russian"/>
@@ -26,9 +26,11 @@
<TextBlock FontFamily="Segoe MDL2 Assets" FontWeight="Bold" Text="&#xE7BA;" FontSize="30" Foreground="OrangeRed"/>
<TextBlock FontFamily="Default" FontWeight="Bold" Text="Reopen the app to apply settings" Foreground="OrangeRed" VerticalAlignment="Center"/>
</StackPanel>
<ComboBox Header="Region (for targeted content)" MinWidth="250" Name="region" SelectionChanged="region_SelectionChanged">
<ComboBoxItem Content="English"/>
<ComboBoxItem Content="Russian"/>
<ComboBox Header="Region (for targeted content)" MinWidth="250" Name="region" SelectionChanged="region_SelectionChanged"/>
<ComboBox Header="SafeSearch" MinWidth="250" Name="safeSearch" SelectionChanged="safeSearch_SelectionChanged">
<ComboBoxItem Content="Moderate"/>
<ComboBoxItem Content="None"/>
<ComboBoxItem Content="Strict"/>
</ComboBox>
<TextBlock Text="Playback" FontSize="22"/>
<ComboBox Margin="0,0,0,10" Width="250" Header="Default video playback quality" Name="quality" SelectionChanged="quality_SelectionChanged">
+12 -1
View File
@@ -48,8 +48,14 @@ namespace FoxTube
mobileWarning.IsOn = (bool)settings.Values["moblieWarning"];
autoplay.IsOn = (bool)settings.Values["videoAutoplay"];
safeSearch.SelectedIndex = (int)settings.Values["safeSearch"];
foreach (CultureInfo culture in CultureInfo.GetCultures(CultureTypes.AllCultures))
{
region.Items.Add(culture.DisplayName);
if (culture.Name == (string)settings.Values["region"])
region.SelectedIndex = region.Items.Count - 1;
}
}
private void language_SelectionChanged(object sender, SelectionChangedEventArgs e)
@@ -135,7 +141,12 @@ namespace FoxTube
private void region_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
settings.Values["region"] = CultureInfo.GetCultures(CultureTypes.AllCultures)[region.SelectedIndex];
settings.Values["region"] = CultureInfo.GetCultures(CultureTypes.AllCultures)[region.SelectedIndex].Name;
}
private void safeSearch_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
settings.Values["safeSearch"] = safeSearch.SelectedIndex;
}
}
}