Archived
1
0

Development 128

This commit is contained in:
Michael Gordeev
2018-09-05 20:05:28 +03:00
parent 866b4ef373
commit 9c9b56a669
10 changed files with 275 additions and 158 deletions
+13 -9
View File
@@ -172,6 +172,7 @@ namespace FoxTube.Pages
playlistRequest = SecretsVault.Service.Search.List("id");
playlistRequest.ChannelId = channelId;
playlistRequest.Order = SearchResource.ListRequest.OrderEnum.Date;
playlistRequest.Type = "playlist";
playlistRequest.MaxResults = 48;
@@ -276,18 +277,21 @@ namespace FoxTube.Pages
private void AutoSuggestBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
{
if (content.Items.Count == 4)
(((content.Items[3] as PivotItem).Content as Frame).Content as Search).Initialize(new SearchParameters(item.Id, search.Text));
else
if(search.Text.Length > 2)
{
content.Items.Add(new PivotItem()
if (content.Items.Count == 4)
((content.Items[3] as PivotItem).Content as Frame).Navigate(typeof(Search), new SearchParameters(search.Text, item.Id));
else
{
Content = new Frame()
});
((content.Items[3] as PivotItem).Content as Frame).Navigate(typeof(Search), new SearchParameters(item.Id, search.Text));
}
content.Items.Add(new PivotItem()
{
Content = new Frame()
});
((content.Items[3] as PivotItem).Content as Frame).Navigate(typeof(Search), new SearchParameters(search.Text, item.Id));
}
content.SelectedIndex = 3;
content.SelectedIndex = 3;
}
}
private void refresh_Click(object sender, RoutedEventArgs e)
+29 -13
View File
@@ -41,6 +41,8 @@ using FoxTube.Pages;
using Microsoft.Toolkit.Uwp.UI.Controls;
using Windows.ApplicationModel;
using System.Net;
using Windows.UI.Popups;
using Windows.Networking.Connectivity;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
@@ -303,18 +305,10 @@ namespace FoxTube
SecretsVault.Deauthenticate();
}
public void GoToSearch(string keyword = null)
public void GoToSearch(SearchParameters args)
{
if(keyword != null)
search.Text = keyword;
if (!string.IsNullOrWhiteSpace(search.Text))
{
if (!(content.Content is Search))
content.Navigate(typeof(Search), search.Text);
else if ((content.Content as Search).Term != search.Text)
(content.Content as Search).Initialize(search.Text);
}
MinimizeAsInitializer();
content.Navigate(typeof(Search), args);
}
public void GoToChannel(string id)
@@ -323,8 +317,30 @@ namespace FoxTube
content.Navigate(typeof(ChannelPage), id);
}
public void GoToVideo(string id, string playlistId = null)
public async void GoToVideo(string id, string playlistId = null)
{
var connection = NetworkInformation.GetInternetConnectionProfile().GetConnectionCost();
if ((bool)settings.Values["moblieWarning"] && (connection.NetworkCostType == NetworkCostType.Fixed || connection.NetworkCostType == NetworkCostType.Variable))
{
bool cancel = false;
MessageDialog dialog = new MessageDialog("You are on metered connection now. Additional charges may apply. Do you want to continue?")
{
DefaultCommandIndex = 2,
CancelCommandIndex = 1
};
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) =>
{
//TO-DO: Adding video to "Watch later"
cancel = true;
}));
await dialog.ShowAsync();
if (cancel)
return;
}
nav.IsPaneOpen = false;
videoPlaceholder.Content = null;
@@ -421,7 +437,7 @@ namespace FoxTube
private void search_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
{
GoToSearch();
GoToSearch(new SearchParameters(search.Text));
}
private void search_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
+3 -3
View File
@@ -46,9 +46,9 @@
</ComboBox>
<ComboBox Visibility="Collapsed" Name="duration" Header="Duration" Width="150" SelectedIndex="0">
<ComboBoxItem Content="Any"/>
<ComboBoxItem Content="Short (&#x3C; 4 minutes)"/>
<ComboBoxItem Content="Medium"/>
<ComboBoxItem Content="Long (&#x3E; 20 minutes)"/>
<ComboBoxItem Content="Medium"/>
<ComboBoxItem Content="Short (&#x3C; 4 minutes)"/>
</ComboBox>
</GridView>
<StackPanel Orientation="Horizontal">
@@ -65,7 +65,7 @@
</Flyout>
</Button.Flyout>
</Button>
<Button Content="Apply" Margin="10,0,0,10" Click="AppBarButton_Click"/>
<Button Content="Apply" Margin="10,0,0,10" Name="apply" Click="apply_Click"/>
</StackPanel>
</StackPanel>
<pages:VideoGrid/>
+60 -125
View File
@@ -29,8 +29,7 @@ namespace FoxTube
/// </summary>
public sealed partial class Search : Page
{
public string Term;
string channelId = null;
public SearchParameters Parameters;
SearchResource.ListRequest request;
string nextToken;
ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
@@ -67,7 +66,7 @@ namespace FoxTube
break;
case "youtube#channel":
if(channelId == null)
if(Parameters.Channel == null)
list.Add(new ChannelCard(result.Id.ChannelId, result.Snippet.LiveBroadcastContent));
break;
@@ -85,39 +84,31 @@ namespace FoxTube
loading.Error("NullReferenceException", "Unable to initialize search. Search term is not stated.");
else
{
if (e.Parameter is string)
Initialize(e.Parameter as string);
else if (e.Parameter is SearchParameters)
if (e.Parameter is SearchParameters)
Initialize(e.Parameter as SearchParameters);
else
loading.Error("ArgumentException", "Wrong search parameters");
loading.Error("ArgumentException", "Wrong parameter");
}
}
public void Initialize(SearchParameters arg)
public async void Initialize(SearchParameters arg, bool forceInitialization = false)
{
Initialize(arg.Term, channel: arg.ChannelId);
}
public async void Initialize(string term, bool forceInitialization = false, string channel = null)
{
if (term == Term && !forceInitialization)
if (Parameters != null && arg.Term == Parameters.Term && !forceInitialization)
return;
loading.Refresh();
try
//try
{
Term = term;
Parameters = arg;
request = SecretsVault.Service.Search.List("id,snippet");
if (!string.IsNullOrWhiteSpace(channel))
if (!string.IsNullOrWhiteSpace(arg.Channel))
{
channelId = channel;
request.ChannelId = channel;
request.ChannelId = arg.Channel;
(type.Items[2] as ComboBoxItem).Visibility = Visibility.Collapsed;
(grid.Children[1] as CommandBar).Visibility = Visibility.Collapsed;
}
request.Q = term;
request.Q = arg.Term;
request.SafeSearch = (SearchResource.ListRequest.SafeSearchEnum)(int)settings.Values["safeSearch"];
try
{
@@ -128,32 +119,36 @@ namespace FoxTube
request.RelevanceLanguage = settings.Values["region"].ToString().ToLower();
}
request.MaxResults = 48;
request.Order = Order;
request.Type = Type;
request.PublishedAfter = Date;
if(type.SelectedIndex == 1)
try
{
request.VideoDuration = Duration;
if (features.SelectedItems.Count > 0)
{
request.Type = "video";
type.SelectedIndex = 1;
if (features.SelectedItems.Contains(features.Items[0]))
request.VideoDefinition = SearchResource.ListRequest.VideoDefinitionEnum.High;
if (features.SelectedItems.Contains(features.Items[1]))
request.VideoDimension = SearchResource.ListRequest.VideoDimensionEnum.Value3d;
if (features.SelectedItems.Contains(features.Items[2]))
request.VideoCaption = SearchResource.ListRequest.VideoCaptionEnum.ClosedCaption;
if (features.SelectedItems.Contains(features.Items[3]))
request.EventType = SearchResource.ListRequest.EventTypeEnum.Live;
if (features.SelectedItems.Contains(features.Items[4]))
request.VideoLicense = SearchResource.ListRequest.VideoLicenseEnum.CreativeCommon;
}
request.Order = (SearchResource.ListRequest.OrderEnum)arg.Filter.GetParameter(SearchParameters.Filters.Enumerations.ConversionType.Order);
request.Type = (string)arg.Filter.GetParameter(SearchParameters.Filters.Enumerations.ConversionType.Type);
request.PublishedAfter = (DateTime)arg.Filter.GetParameter(SearchParameters.Filters.Enumerations.ConversionType.Date);
request.VideoDefinition = (SearchResource.ListRequest.VideoDefinitionEnum)arg.Filter.GetParameter(SearchParameters.Filters.Enumerations.ConversionType.HD);
request.VideoDimension = (SearchResource.ListRequest.VideoDimensionEnum)arg.Filter.GetParameter(SearchParameters.Filters.Enumerations.ConversionType.ThreeD);
request.VideoCaption = (SearchResource.ListRequest.VideoCaptionEnum)arg.Filter.GetParameter(SearchParameters.Filters.Enumerations.ConversionType.Captions);
request.EventType = (SearchResource.ListRequest.EventTypeEnum)arg.Filter.GetParameter(SearchParameters.Filters.Enumerations.ConversionType.LiveEvent);
request.VideoLicense = (SearchResource.ListRequest.VideoLicenseEnum)arg.Filter.GetParameter(SearchParameters.Filters.Enumerations.ConversionType.CreativeCommons);
}
catch { }
order.SelectedIndex = (int)Parameters.Filter.Order;
type.SelectedIndex = (int)Parameters.Filter.Type;
duration.SelectedIndex = (int)Parameters.Filter.Duration;
if (Parameters.Filter.HD)
features.SelectedItems.Add(features.Items[0]);
if (Parameters.Filter.Is3D)
features.SelectedItems.Add(features.Items[1]);
if (Parameters.Filter.Captions)
features.SelectedItems.Add(features.Items[2]);
if (Parameters.Filter.LiveEvent)
features.SelectedItems.Add(features.Items[3]);
if (Parameters.Filter.CreativeCommons)
features.SelectedItems.Add(features.Items[4]);
SearchListResponse response = await request.ExecuteAsync();
searchTerm.Text = $"Search results for: {Term}";
searchTerm.Text = $"Search results for: {Parameters.Term}";
resultsCount.Text = $"Found: {SetResults(response.PageInfo.TotalResults)} item(s)";
if (!string.IsNullOrWhiteSpace(response.NextPageToken))
nextToken = response.NextPageToken;
@@ -166,14 +161,14 @@ namespace FoxTube
loading.Close();
}
catch (System.Net.Http.HttpRequestException)
/*catch (System.Net.Http.HttpRequestException)
{
loading.Error("System.Net.Http.HttpRequestException", "Unable to connect to Google servers.", true);
}
catch (Exception e)
{
loading.Error(e.GetType().ToString(), e.Message);
}
}*/
}
private void toggleFilters_Click(object sender, RoutedEventArgs e)
@@ -181,96 +176,18 @@ namespace FoxTube
if(filters.Visibility == Visibility.Collapsed)
{
filters.Visibility = Visibility.Visible;
toggleFilters.Content = "Hide filters ";
toggleFilters.Content = "Hide filters \xE014";
}
else
{
filters.Visibility = Visibility.Collapsed;
toggleFilters.Content = "Show filters ";
}
}
SearchResource.ListRequest.OrderEnum Order
{
get
{
switch (order.SelectedIndex)
{
case 1:
return SearchResource.ListRequest.OrderEnum.Date;
case 2:
return SearchResource.ListRequest.OrderEnum.ViewCount;
case 3:
return SearchResource.ListRequest.OrderEnum.Rating;
case 4:
return SearchResource.ListRequest.OrderEnum.Title;
default:
return SearchResource.ListRequest.OrderEnum.Relevance;
}
}
}
string Type
{
get
{
switch(type.SelectedIndex)
{
case 1:
return "video";
case 2:
return "channel";
case 3:
return "playlist";
default:
return "video,channel,playlist";
}
}
}
DateTime? Date
{
get
{
switch(date.SelectedIndex)
{
case 1:
return DateTime.Now.Subtract(TimeSpan.FromHours(1));
case 2:
return DateTime.Now.Subtract(TimeSpan.FromDays(1));
case 3:
return DateTime.Now.Subtract(TimeSpan.FromDays(7));
case 4:
return DateTime.Now.Subtract(TimeSpan.FromDays(31));
case 5:
return DateTime.Now.Subtract(TimeSpan.FromDays(365));
default:
return null;
}
}
}
SearchResource.ListRequest.VideoDurationEnum Duration
{
get
{
switch (type.SelectedIndex)
{
case 1:
return SearchResource.ListRequest.VideoDurationEnum.Short__;
case 2:
return SearchResource.ListRequest.VideoDurationEnum.Medium;
case 3:
return SearchResource.ListRequest.VideoDurationEnum.Long__;
default:
return SearchResource.ListRequest.VideoDurationEnum.Any;
}
toggleFilters.Content = "Show filters \xE015";
}
}
private void AppBarButton_Click(object sender, RoutedEventArgs e)
{
Initialize(Term, true, channelId);
Initialize(Parameters, true);
}
private async void more_Clicked()
@@ -302,6 +219,8 @@ namespace FoxTube
{
duration.Visibility = Visibility.Collapsed;
featBtn.Visibility = Visibility.Collapsed;
duration.SelectedIndex = 0;
features.SelectedItems.Clear();
}
}
catch (NullReferenceException) { }
@@ -311,5 +230,21 @@ namespace FoxTube
{
await Launcher.LaunchUriAsync(new Uri($"https://www.youtube.com/results?search_query={searchTerm}"));
}
private void apply_Click(object sender, RoutedEventArgs e)
{
Parameters.Filter.HD = features.SelectedItems.Contains(features.Items[0]);
Parameters.Filter.Is3D = features.SelectedItems.Contains(features.Items[1]);
Parameters.Filter.Captions = features.SelectedItems.Contains(features.Items[2]);
Parameters.Filter.LiveEvent = features.SelectedItems.Contains(features.Items[3]);
Parameters.Filter.CreativeCommons = features.SelectedItems.Contains(features.Items[4]);
Parameters.Filter.Order = (SearchParameters.Filters.Enumerations.Order)order.SelectedIndex;
Parameters.Filter.Type = (SearchParameters.Filters.Enumerations.Type)type.SelectedIndex;
Parameters.Filter.Date = (SearchParameters.Filters.Enumerations.Date)date.SelectedIndex;
Parameters.Filter.Duration = (SearchParameters.Filters.Enumerations.Duration)duration.SelectedIndex;
Methods.MainPage.GoToSearch(Parameters);
}
}
}
+2 -2
View File
@@ -37,8 +37,8 @@
<ComboBoxItem Content="240p"/>
<ComboBoxItem Content="144p"/>
</ComboBox>
<ToggleSwitch x:Uid="/General/metered" OnContent="Notify when playing on metered connection" OffContent="Notify when playing on metered connection" Name="mobileWarning" Toggled="notification_IsEnabledChanged"/>
<ToggleSwitch x:Uid="/General/autoplay" OnContent="Play videos automatically" OffContent="Play videos automatically" Name="autoplay" Toggled="notification_IsEnabledChanged"/>
<ToggleSwitch x:Uid="/General/metered" OnContent="Notify when playing on metered connection" OffContent="Notify when playing on metered connection" Name="mobileWarning" Toggled="mobileWarning_Toggled"/>
<ToggleSwitch x:Uid="/General/autoplay" OnContent="Play videos automatically" OffContent="Play videos automatically" Name="autoplay" Toggled="autoplay_Toggled"/>
<TextBlock x:Uid="/General/notifications" Text="Notifications" FontSize="22"/>
<ToggleSwitch x:Uid="/General/newVideo" Name="newVideo" OnContent="Notify when someone of your subscriptions uploaded new video" OffContent="Notify when someone of your subscriptions uploaded new video" Toggled="notification_IsEnabledChanged"/>
+11 -2
View File
@@ -79,11 +79,20 @@ namespace FoxTube.Pages.SettingsPages
settings.Values["quality"] = quality.SelectedIndex;
}
private void mobileWarning_Toggled(object sender, RoutedEventArgs e)
{
settings.Values["moblieWarning"] = mobileWarning.IsOn;
}
private void autoplay_Toggled(object sender, RoutedEventArgs e)
{
settings.Values["videoAutoplay"] = autoplay.IsOn;
}
private void notification_IsEnabledChanged(object sender, RoutedEventArgs e)
{
settings.Values["newVideoNotification"] = newVideo.IsOn;
settings.Values["moblieWarning"] = mobileWarning.IsOn;
settings.Values["videoAutoplay"] = autoplay.IsOn;
}
private void region_SelectionChanged(object sender, SelectionChangedEventArgs e)