Skip to content

Commit

Permalink
code cleanup, global toggle buttons , bossview height slider
Browse files Browse the repository at this point in the history
  • Loading branch information
tensei committed Feb 25, 2017
1 parent 6675121 commit c961c67
Show file tree
Hide file tree
Showing 18 changed files with 184 additions and 105 deletions.
6 changes: 6 additions & 0 deletions GbfRaidfinder/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
<setting name="Width" serializeAs="String">
<value>1000</value>
</setting>
<setting name="BossViewHeight" serializeAs="String">
<value>400</value>
</setting>
<setting name="GlobalCopy" serializeAs="String">
<value>True</value>
</setting>
</GbfRaidfinder.Properties.Settings>
</userSettings>
</configuration>
3 changes: 2 additions & 1 deletion GbfRaidfinder/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ namespace GbfRaidfinder {
/// </summary>
public partial class App : Application {
private void AppStartup(object sender, StartupEventArgs args) {
if (!Debugger.IsAttached)
if (!Debugger.IsAttached) {
ExceptionHandler.AddGlobalHandlers();
}

var container = new UnityContainer();
container.RegisterType<Raids>();
Expand Down
8 changes: 5 additions & 3 deletions GbfRaidfinder/Common/ExceptionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ internal static class ExceptionHandler {
public static void AddGlobalHandlers() {
AppDomain.CurrentDomain.UnhandledException += (sender, args) => {
try {
if (!Directory.Exists(LogsPath))
if (!Directory.Exists(LogsPath)) {
Directory.CreateDirectory(LogsPath);
}

var filePath = Path.Combine(LogsPath,
$"UnhandledException_{DateTime.Now.ToShortDateString().Replace("/", "-")}.json");

File.AppendAllText(filePath,
JsonConvert.SerializeObject(args.ExceptionObject, Formatting.Indented) + "\r\n\r\n");
} catch {
}
catch {
// ignored
}
};
}
}
}
}
2 changes: 1 addition & 1 deletion GbfRaidfinder/Common/LoginController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class LoginController : ILoginController {
public LoginController(ISettingsController settingsController) {
_settingsController = settingsController;
}

public string Pin { get; set; }

public async Task<ITwitterCredentials> StartNewLogin() {
Expand Down
43 changes: 19 additions & 24 deletions GbfRaidfinder/Factorys/ControllerFactory.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GbfRaidfinder.Common;
using GbfRaidfinder.Common;
using GbfRaidfinder.Interfaces;

namespace GbfRaidfinder.Factorys {
public class ControllerFactory {
private readonly ISettingsController _settingsController;
private readonly ITweetObserver _tweetObserver;
private readonly IRaidsController _raidsController;
private readonly IRaidlistController _raidlistController;
public ControllerFactory(ISettingsController settingsController, ITweetObserver tweetObserver,
public ControllerFactory(ISettingsController settingsController, ITweetObserver tweetObserver,
IRaidsController raidsController, IRaidlistController raidlistController) {
_settingsController = settingsController;
_tweetObserver = tweetObserver;
_raidsController = raidsController;
_raidlistController = raidlistController;
GetSettingsController = settingsController;
GetTweetObserver = tweetObserver;
GetRaidsController = raidsController;
GetRaidlistController = raidlistController;

_settingsController.Load();
_raidsController.Load();
_raidlistController.Load();
GetSettingsController.Load();
GetRaidsController.Load();
GetRaidlistController.Load();
}

public ISettingsController GetSettingsController => _settingsController;
public IRaidsController GetRaidsController => _raidsController;
public IRaidlistController GetRaidlistController => _raidlistController;
public ITweetObserver GetTweetObserver => _tweetObserver;
public ILoginController CreateLoginController => new LoginController(_settingsController);
public ISettingsController GetSettingsController { get; }

public IRaidsController GetRaidsController { get; }

public IRaidlistController GetRaidlistController { get; }

public ITweetObserver GetTweetObserver { get; }

public ILoginController CreateLoginController => new LoginController(GetSettingsController);
}
}
}
3 changes: 0 additions & 3 deletions GbfRaidfinder/Interfaces/ITweetObserver.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System;
using Tweetinvi.Core.Streaming;
using Tweetinvi.Events;
using Tweetinvi.Models;
using Tweetinvi.Streaming;

Expand Down
45 changes: 34 additions & 11 deletions GbfRaidfinder/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
mc:Ignorable="d"
Closing="MainWindow_OnClosing"
Title="Granblue Fantasy Raidfinder"

TextElement.FontWeight="Medium"
TextElement.FontSize="14"
FontFamily="pack://application:,,,/MaterialDesignThemes.Wpf;component/Resources/Roboto/#Roboto,Helvetica,Arial"

Height="{Binding Source={x:Static properties:Settings.Default},
Path=Height}"
Width="{Binding Source={x:Static properties:Settings.Default},
Expand Down Expand Up @@ -75,24 +74,48 @@
</Grid>
</materialDesign:DrawerHost.LeftDrawerContent>
<Grid>
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">
<ItemsControl x:Name="itemsControl" ItemsSource="{Binding Follows}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<materialDesign:ColorZone Grid.Row="0" Padding="6">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Center">
<TextBlock>Global Copy</TextBlock>
<ToggleButton Margin="5,0" IsChecked="{Binding Settings.GlobalCopy}"
ToolTip="Enable/Disable Auto Copy globally" />
<TextBlock>Global Sound</TextBlock>
<ToggleButton Margin="5,0" IsChecked="{Binding Settings.GlobalSound}"
ToolTip="Enable/Disable Auto Copy globally" />
</StackPanel>
<TextBlock Grid.Column="2">Raid height</TextBlock>
<Slider Grid.Column="3" Margin="5,0" x:Name="slider"
Maximum="{Binding ActualHeight, ElementName=Itemscontrol, Mode=OneWay}" Minimum="100"
Value="400" />
</Grid>
</materialDesign:ColorZone>
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Auto">
<ItemsControl ItemsSource="{Binding Follows}" VerticalAlignment="Stretch">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel HorizontalAlignment="Stretch" Orientation="Horizontal" IsItemsHost="True" />
<WrapPanel HorizontalAlignment="Stretch" IsItemsHost="True" Orientation="Vertical" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<views:BossView BorderThickness="0,0,1,0"
Height="{Binding ActualHeight, ElementName=itemsControl, Mode=OneWay}"
MaxHeight="{Binding ActualHeight, ElementName=itemsControl, Mode=OneWay}"
BorderBrush="Black" />
<views:BossView x:Name="Bossview" BorderThickness="0,0,1,1"
BorderBrush="Black" Height="{Binding Value, ElementName=slider}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
<ToggleButton Style="{StaticResource MaterialDesignActionToggleButton}"
<ToggleButton Grid.Row="1" Style="{StaticResource MaterialDesignActionToggleButton}"
IsChecked="False" Margin="16" Height="50" Width="50"
x:Name="MenuToggleButton" HorizontalAlignment="Right"
VerticalAlignment="Bottom">
Expand All @@ -103,7 +126,7 @@
<materialDesign:PackIcon Kind="ArrowLeft" />
</materialDesign:ToggleButtonAssist.OnContent>
</ToggleButton>
<tb:TaskbarIcon x:Name="TaskbarNotifyIcon" IconSource="Assets/testicon.ico" />
<tb:TaskbarIcon Grid.Row="0" x:Name="TaskbarNotifyIcon" IconSource="Assets/testicon.ico" />
</Grid>
</materialDesign:DrawerHost>
</materialDesign:DialogHost>
Expand Down
4 changes: 3 additions & 1 deletion GbfRaidfinder/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.ComponentModel;
using GbfRaidfinder.Data;
using GbfRaidfinder.Factorys;
using GbfRaidfinder.Interfaces;
using GbfRaidfinder.Properties;
Expand All @@ -16,11 +15,14 @@ public MainWindow(ITweetProcessor tweetProcessor, ControllerFactory controllerFa
_controllerFactory = controllerFactory;
InitializeComponent();
DataContext = new MainViewModel(tweetProcessor, controllerFactory);
slider.Value = Settings.Default.BossViewHeight;
}


private void MainWindow_OnClosing(object sender, CancelEventArgs e) {
Settings.Default.Height = Height;
Settings.Default.Width = Width;
Settings.Default.BossViewHeight = slider.Value;
Settings.Default.Save();
_controllerFactory.GetSettingsController.Save();
_controllerFactory.GetRaidlistController.Save();
Expand Down
8 changes: 4 additions & 4 deletions GbfRaidfinder/Models/FollowModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Linq;
using System.Windows;
using System.Windows.Input;
using GbfRaidfinder.Data;
using GbfRaidfinder.Interfaces;
using GbfRaidfinder.Twitter;
using GbfRaidfinder.ViewModels;
Expand All @@ -14,8 +13,7 @@
namespace GbfRaidfinder.Models {
[ImplementPropertyChanged]
public class FollowModel {
[JsonIgnore]
public readonly ObservableCollection<TweetInfo> TweetInfos = new ObservableCollection<TweetInfo>();
[JsonIgnore] public readonly ObservableCollection<TweetInfo> TweetInfos = new ObservableCollection<TweetInfo>();

public FollowModel(string jp, string en, string image) {
English = en;
Expand All @@ -31,8 +29,10 @@ public FollowModel(string jp, string en, string image) {
public bool ImageVisibility { get; set; }
public bool AutoCopy { get; set; }
public bool Sound { get; set; }

[JsonIgnore]
public List<SoundFileModel> SoundFiles => GetSoundFiles();

public SoundFileModel SelectedSoundFile { get; set; }
public int SelectedSoundFileIndex { get; set; }

Expand All @@ -41,7 +41,7 @@ public FollowModel(string jp, string en, string image) {

[JsonIgnore]
public ICommand CopyCommand { get; }

private void Copy(ITweetInfo tweetInfo) {
Clipboard.SetText(tweetInfo.Id);
tweetInfo.Clicked = !tweetInfo.Clicked;
Expand Down
11 changes: 9 additions & 2 deletions GbfRaidfinder/Models/SettingsModel.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
using System.Collections.Generic;
using System.ComponentModel;
using Newtonsoft.Json;
using PropertyChanged;

namespace GbfRaidfinder.Models {
[ImplementPropertyChanged]
public class SettingsModel {
public string AccessToken { get; set; }
public string AccessTokenSecret { get; set; }

public Dictionary<string, string> Raids { get; set; } = new Dictionary<string, string>();
[DefaultValue(true), JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public bool GlobalCopy { get; set; } = true;

[DefaultValue(true), JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public bool GlobalSound { get; set; } = true;
}
}
2 changes: 1 addition & 1 deletion GbfRaidfinder/Models/SoundFileModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ public class SoundFileModel {
public string Name { get; set; }
public string Path { get; set; }
}
}
}
24 changes: 24 additions & 0 deletions GbfRaidfinder/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions GbfRaidfinder/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@
<Setting Name="Width" Type="System.Double" Scope="User">
<Value Profile="(Default)">1000</Value>
</Setting>
<Setting Name="BossViewHeight" Type="System.Double" Scope="User">
<Value Profile="(Default)">400</Value>
</Setting>
<Setting Name="GlobalCopy" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>
2 changes: 1 addition & 1 deletion GbfRaidfinder/Twitter/TweetInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
namespace GbfRaidfinder.Twitter {
[ImplementPropertyChanged]
public class TweetInfo : ITweetInfo {
public string Text { get; set; }
public string User { get; set; }
public string Boss { get; set; }
public string Time { get; set; }
public string Id { get; set; }
public string Language { get; set; }
public bool Clicked { get; set; }
public string Text { get; set; }
}
}
8 changes: 3 additions & 5 deletions GbfRaidfinder/Twitter/TweetObserver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,25 @@
using GbfRaidfinder.Interfaces;
using PropertyChanged;
using Tweetinvi;
using Tweetinvi.Events;
using Tweetinvi.Exceptions;
using Tweetinvi.Models;
using Tweetinvi.Streaming;

namespace GbfRaidfinder.Twitter {
[ImplementPropertyChanged]
public class TweetObserver : ITweetObserver {
public IFilteredStream Stream { get; }
private readonly ISettingsController _settingsController;

public TweetObserver(ISettingsController settingsController) {
Stream = Tweetinvi.Stream.CreateFilteredStream();
_settingsController = settingsController;
}

public IFilteredStream Stream { get; }

public bool Running { get; set; }

public void Run(ITwitterCredentials userCredentials) {

RateLimit.RateLimitTrackerMode = RateLimitTrackerMode.TrackOnly;
Stream.Credentials = userCredentials;
for (var i = 5; i < 151; i += 5) {
Expand All @@ -33,7 +32,7 @@ public void Run(ITwitterCredentials userCredentials) {
//stream.AddTrack("Lv");
Start();
}

private async void Start() {
await Task.Delay(3000);
try {
Expand All @@ -51,6 +50,5 @@ private async void Start() {
Running = false;
}
}

}
}
4 changes: 1 addition & 3 deletions GbfRaidfinder/Twitter/TweetProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Text.RegularExpressions;
using GbfRaidfinder.Interfaces;
using Tweetinvi.Models;

Expand Down
Loading

0 comments on commit c961c67

Please sign in to comment.