Skip to content

Commit

Permalink
Add filter for online streams #31
Browse files Browse the repository at this point in the history
laurencee committed Sep 23, 2017
1 parent 53b779e commit b14238f
Showing 6 changed files with 72 additions and 26 deletions.
10 changes: 5 additions & 5 deletions GlobalAssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Reflection;

// General Information about an assembly is controlled through the following
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.

@@ -14,13 +14,13 @@
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("2.9.8.0")]
[assembly: AssemblyFileVersion("2.9.8.0")]
[assembly: AssemblyVersion("2.10.0.0")]
[assembly: AssemblyFileVersion("2.10.0.0")]
16 changes: 15 additions & 1 deletion Livestream.Monitor/Model/FilterModel.cs
Original file line number Diff line number Diff line change
@@ -10,9 +10,23 @@ public class FilterModel : PropertyChangedBase
private string livestreamNameFilter;
private string selectedApiClientName;
private BindableCollection<string> apiClientNames;
private bool showOnlineOnly;

/// <summary> Simple check to know if the model is doing any filtering </summary>
public bool IsFiltering => LivestreamNameFilter != null || SelectedApiClientName != AllApiClientsFilterName;
public bool IsFiltering => LivestreamNameFilter != null ||
SelectedApiClientName != AllApiClientsFilterName ||
ShowOnlineOnly;

public bool ShowOnlineOnly
{
get { return showOnlineOnly; }
set
{
if (value == showOnlineOnly) return;
showOnlineOnly = value;
NotifyOfPropertyChange(() => ShowOnlineOnly);
}
}

public string LivestreamNameFilter
{
9 changes: 7 additions & 2 deletions Livestream.Monitor/ViewModels/HeaderViewModel.cs
Original file line number Diff line number Diff line change
@@ -112,7 +112,7 @@ public IApiClient SelectedApiClient
NotifyOfPropertyChange(() => SelectedApiClient);
}
}

public async Task AddStream()
{
if (IsNullOrWhiteSpace(StreamName) || !CanAddStream) return;
@@ -213,6 +213,11 @@ public async Task OpenChat()
await streamLauncher.OpenChat(selectedLivestream, this);
}

public void ToggleShowOnlineOnly()
{
FilterModel.ShowOnlineOnly = !FilterModel.ShowOnlineOnly;
}

public async void KeyPressed(KeyEventArgs e)
{
if (e.Key == Key.Enter && CanAddStream)
@@ -240,7 +245,7 @@ protected override void OnDeactivate(bool close)
MonitorStreamsModel.Livestreams.CollectionChanged -= LivestreamsOnCollectionChanged;
base.OnDeactivate(close);
}

private void MonitorStreamsModelOnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(MonitorStreamsModel.CanRefreshLivestreams))
28 changes: 19 additions & 9 deletions Livestream.Monitor/ViewModels/LivestreamListViewModel.cs
Original file line number Diff line number Diff line change
@@ -130,9 +130,9 @@ public async Task RefreshLivestreams()
refreshCount++;
}

/// <summary>
/// <summary>
/// Loads the selected stream through livestreamer/streamlink
/// and displays a messagebox with the loading process details
/// and displays a messagebox with the loading process details
/// </summary>
public async Task OpenStream()
{
@@ -208,7 +208,7 @@ public async Task CopyLivestreamUrl()
}
catch (Exception e)
{
await this.ShowMessageAsync("Error copying url",
await this.ShowMessageAsync("Error copying url",
$"An error occurred attempting to copy the url, please try again: {e.Message}");
}
}
@@ -323,23 +323,33 @@ private void ViewSourceOnFilter(object sender, FilterEventArgs e)
}
else
{
// quick exits for least expensive paths
if (FilterModel.ShowOnlineOnly && !livestreamModel.Live)
{
e.Accepted = false;
return;
}

var apiClientNameFilter = FilterModel.SelectedApiClientName;
var nameFilter = FilterModel.LivestreamNameFilter;
if (apiClientNameFilter != FilterModel.AllApiClientsFilterName &&
livestreamModel.ApiClient.ApiName != apiClientNameFilter)
{
e.Accepted = false;
return;
}

var nameFilter = FilterModel.LivestreamNameFilter;
bool filterNameMatch = string.IsNullOrWhiteSpace(nameFilter) ||
livestreamModel.DisplayName.Contains(nameFilter, StringComparison.OrdinalIgnoreCase) ||
livestreamModel.ChannelIdentifier.ChannelId.Contains(nameFilter, StringComparison.OrdinalIgnoreCase);

bool apiClientMatch = apiClientNameFilter == FilterModel.AllApiClientsFilterName ||
livestreamModel.ApiClient.ApiName == apiClientNameFilter;

e.Accepted = filterNameMatch && apiClientMatch;
e.Accepted = filterNameMatch;
}
}

private void OnLivestreamsRefreshComplete(object sender, EventArgs eventArgs)
{
// We only really care about sorting online livestreams so this causes the sort descriptions to be applied immediately
// We only really care about sorting online livestreams so this causes the sort descriptions to be applied immediately
ViewSource.View.Refresh();
}

21 changes: 19 additions & 2 deletions Livestream.Monitor/Views/HeaderView.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<UserControl x:Class="Livestream.Monitor.Views.HeaderView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:viewModels="clr-namespace:Livestream.Monitor.ViewModels"
@@ -12,9 +12,26 @@
<StackPanel Orientation="Horizontal">
<!-- Filtering monitored streams -->
<TextBlock Text="Filter:" VerticalAlignment="Center" Margin="2" FontWeight="Bold" />
<TextBox x:Name="FilterModel_LivestreamNameFilter" controls:TextBoxHelper.Watermark="name..." Margin="2" Width="100"
<TextBox x:Name="FilterModel_LivestreamNameFilter" controls:TextBoxHelper.Watermark="name..." Margin="2" Width="100"
controls:TextBoxHelper.ClearTextButton="True" />
<ComboBox x:Name="FilterModel_ApiClientNames" Margin="2" />
<ToggleButton x:Name="ToggleShowOnlineOnly" Margin="2"
ToolTip="Toggle show online streams only">
<Image Height="13" RenderOptions.BitmapScalingMode="HighQuality">
<Image.Style>
<Style TargetType="{x:Type Image}">
<Style.Triggers>
<DataTrigger Binding="{Binding FilterModel.ShowOnlineOnly}" Value="true">
<Setter Property="Source" Value="/Livestream.Monitor;component/Images/Live.png"/>
</DataTrigger>
<DataTrigger Binding="{Binding FilterModel.ShowOnlineOnly}" Value="false">
<Setter Property="Source" Value="/Livestream.Monitor;component/Images/Offline.png"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
</ToggleButton>

<!-- Open Chat & Set Stream Quality -->
<Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" Margin="5,2" />
14 changes: 7 additions & 7 deletions Livestream.Monitor/Views/LivestreamListView.xaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<UserControl x:Class="Livestream.Monitor.Views.LivestreamListView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
mc:Ignorable="d"
xmlns:cal="http://www.caliburnproject.org"
xmlns:viewModels="clr-namespace:Livestream.Monitor.ViewModels"
xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
@@ -20,9 +20,9 @@
<ContextMenu x:Key="ContextMenu" cal:Action.TargetWithoutContext="{Binding Source={x:Reference LayoutControl}, Path=DataContext}">
<MenuItem Header="Remove Stream" cal:Message.Attach="[Click] = [RemoveLivestream]" />
<MenuItem Header="Copy Stream URL" cal:Message.Attach="[Click] = [CopyLivestreamUrl]" />
<MenuItem Header="Open in Vod Viewer" IsEnabled="{Binding ApiClient.HasVodViewerSupport}"
<MenuItem Header="Open in Vod Viewer" IsEnabled="{Binding ApiClient.HasVodViewerSupport}"
cal:Message.Attach="[Click] = [GotoVodViewer]" />
<MenuItem Header="Enable Notifications" cal:Message.Attach="[Click] = [ToggleNotify()]"
<MenuItem Header="Enable Notifications" cal:Message.Attach="[Click] = [ToggleNotify()]"
IsChecked="{Binding DontNotify, Converter={StaticResource InvertedBoolenConverter}}"
ToolTip="Untick this to prevent popup notifications about this stream coming online or showing up as a popular stream"/>
</ContextMenu>
@@ -45,11 +45,11 @@
<DataGridTemplateColumn Header="Live">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Name="MyImage" Source="/Livestream.Monitor;component/Images/Live.png" Width="15"
<Image Name="IsLiveImage" Source="/Livestream.Monitor;component/Images/Live.png" Width="15"
RenderOptions.BitmapScalingMode="HighQuality" RenderOptions.EdgeMode="Aliased" />
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Live}" Value="False">
<Setter TargetName="MyImage" Property="Source" Value="/Livestream.Monitor;component/Images/Offline.png"/>
<Setter TargetName="IsLiveImage" Property="Source" Value="/Livestream.Monitor;component/Images/Offline.png"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
@@ -67,7 +67,7 @@
<!-- TODO nice tile layout with the tiles containing the image and the text to the right of the tile -->
</DataTemplate>
</Grid.Resources>

<ContentControl x:Name="LayoutControl" Content="{Binding}">
<ContentControl.Style>
<Style TargetType="ContentControl">

0 comments on commit b14238f

Please sign in to comment.