Skip to content

Commit

Permalink
Merge pull request #133 from Code52/rework-popout-feature
Browse files Browse the repository at this point in the history
customize popout fade timeout
  • Loading branch information
hnrkndrssn authored Apr 17, 2017
2 parents b741586 + 369c211 commit 4d12250
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/Carnac.Logic/KeysController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,29 @@
using System.Reactive.Disposables;
using System.Reactive.Linq;
using Carnac.Logic.Models;
using SettingsProviderNet;

namespace Carnac.Logic
{
public class KeysController : IDisposable
{
static readonly TimeSpan FiveSeconds = TimeSpan.FromSeconds(5);
static readonly TimeSpan OneSecond = TimeSpan.FromSeconds(1);
readonly TimeSpan fadeOutDelay;
readonly ObservableCollection<Message> messages;
readonly IMessageProvider messageProvider;
readonly IConcurrencyService concurrencyService;
readonly SingleAssignmentDisposable actionSubscription = new SingleAssignmentDisposable();

public KeysController(ObservableCollection<Message> messages, IMessageProvider messageProvider, IConcurrencyService concurrencyService)
public KeysController(ObservableCollection<Message> messages, IMessageProvider messageProvider, IConcurrencyService concurrencyService, ISettingsProvider settingsProvider)
{
this.messages = messages;
this.messageProvider = messageProvider;
this.concurrencyService = concurrencyService;
}

var settings = settingsProvider.GetSettings<PopupSettings>();
fadeOutDelay = TimeSpan.FromSeconds(settings.ItemFadeDelay);
}

public void Start()
{
var messageStream = messageProvider.GetMessageStream().Publish();
Expand All @@ -38,7 +42,7 @@ public void Start()
});

var fadeOutMessageSeq = messageStream
.Delay(FiveSeconds, concurrencyService.Default)
.Delay(fadeOutDelay, concurrencyService.Default)
.Select(m => m.FadeOut())
.Publish();

Expand Down
4 changes: 4 additions & 0 deletions src/Carnac.Logic/Models/PopupSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public class PopupSettings : NotifyPropertyChanged
[DefaultValue(0.5)]
public double ItemOpacity { get; set; }

[DefaultValue(5)]
public double ItemFadeDelay { get; set; }

[DefaultValue("Black")]
public string ItemBackgroundColor { get; set; }

Expand Down Expand Up @@ -49,6 +52,7 @@ protected void OnLeftChanged(EventArgs e)

[NotifyProperty(AlsoNotifyFor = new[] { "Margins" })]
public int TopOffset { get; set; }

[NotifyProperty(AlsoNotifyFor = new[] { "Margins" })]
public int BottomOffset { get; set; }

Expand Down
25 changes: 24 additions & 1 deletion src/Carnac.Tests/KeysControllerFacts.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
using Carnac.Logic;
using Carnac.Logic.KeyMonitor;
Expand All @@ -10,6 +12,8 @@
using Shouldly;
using Xunit;
using Message = Carnac.Logic.Models.Message;
using SettingsProviderNet;
using Carnac.Tests.ViewModels;

namespace Carnac.Tests
{
Expand All @@ -33,7 +37,13 @@ KeysController CreateKeysController(IObservable<Message> messageStream)
var concurrencyService = Substitute.For<IConcurrencyService>();
concurrencyService.MainThreadScheduler.Returns(testScheduler);
concurrencyService.Default.Returns(testScheduler);
return new KeysController(messages, messageProvider, concurrencyService);

var settingsService = Substitute.For<ISettingsProvider>();
var popupSettings = new PopupSettings();
popupSettings.ItemFadeDelay = GetDefaultFadeDelay(popupSettings);
settingsService.GetSettings<PopupSettings>().Returns(popupSettings);

return new KeysController(messages, messageProvider, concurrencyService, settingsService);
}

[Fact]
Expand Down Expand Up @@ -135,5 +145,18 @@ IObservable<Message> SingleMessageAt100Ticks()
ReactiveTest.OnNext(MessageAOnNextTick, messageA)
);
}

double GetDefaultFadeDelay(PopupSettings settings)
{
AttributeCollection attributes =
TypeDescriptor.GetProperties(settings)["ItemFadeDelay"].Attributes;
DefaultValueAttribute myAttribute =
(DefaultValueAttribute)attributes[typeof(DefaultValueAttribute)];

double fadeDelay;
double.TryParse(myAttribute.Value.ToString(), out fadeDelay);
return fadeDelay;
}

}
}
2 changes: 1 addition & 1 deletion src/Carnac/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected override void OnStartup(StartupEventArgs e)
keyShowView = new KeyShowView(keyShowViewModel);
keyShowView.Show();

carnac = new KeysController(keyShowViewModel.Messages, messageProvider, new ConcurrencyService());
carnac = new KeysController(keyShowViewModel.Messages, messageProvider, new ConcurrencyService(), settingsProvider);
carnac.Start();

base.OnStartup(e);
Expand Down
7 changes: 7 additions & 0 deletions src/Carnac/UI/PreferencesView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@
<TextBox Foreground="White" Text="{Binding Settings.ItemOpacity}" />
</ui:PreferencesField.SecondaryControl>
</ui:PreferencesField>
<ui:PreferencesField Header="Popup Fade Delay (sec)">
<Slider Value="{Binding Settings.ItemFadeDelay}" IsSnapToTickEnabled="True"
LargeChange="2" Maximum="50" Minimum="1" SmallChange="1" TickFrequency="1" />
<ui:PreferencesField.SecondaryControl>
<TextBox Foreground="White" Text="{Binding Settings.ItemFadeDelay}" />
</ui:PreferencesField.SecondaryControl>
</ui:PreferencesField>
<ui:PreferencesField Header="Font Size">
<Slider Value="{Binding Settings.FontSize}" IsSnapToTickEnabled="True"
LargeChange="2" Maximum="48" Minimum="8" SmallChange="1" TickFrequency="1" />
Expand Down

0 comments on commit 4d12250

Please sign in to comment.