Skip to content

Commit

Permalink
fixed crash when searching collection
Browse files Browse the repository at this point in the history
code refectoring
  • Loading branch information
DineshSolanki committed Jan 17, 2021
1 parent 9edde39 commit 1c50b31
Show file tree
Hide file tree
Showing 16 changed files with 182 additions and 182 deletions.
2 changes: 1 addition & 1 deletion FoliCon/Models/IgdbJotTrackerStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class IgdbJotTrackerStore : BindableBase, ITokenStore
{
private TwitchAccessToken _currentToken;
private TwitchAccessToken CurrentToken { get => _currentToken; set => SetProperty(ref _currentToken, value); }
public IgdbJotTrackerStore()
public IgdbJotTrackerStore()
{
Services.Tracker.Configure<IgdbJotTrackerStore>()
.Property(p => p._currentToken)
Expand Down
2 changes: 1 addition & 1 deletion FoliCon/Modules/DArt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public async Task<DArtBrowseResult> Browse(string query, int offset = 0)
"&limit=20&access_token=" + ClientAccessToken;
using var response = await Services.HttpC.GetAsync(new Uri(url));
var jsonData = await response.Content.ReadAsStringAsync();
var serializerSettings = new JsonSerializerSettings {NullValueHandling = NullValueHandling.Ignore};
var serializerSettings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
var result = JsonConvert.DeserializeObject<DArtBrowseResult>(jsonData, serializerSettings);
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion FoliCon/Modules/DialogServiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ public static void ShowAboutBox(this IDialogService dialogService, Action<IDialo
{
dialogService.ShowDialog("AboutBox", new DialogParameters(), callBack);
}

}
}
28 changes: 14 additions & 14 deletions FoliCon/Modules/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public static string WithoutExt(this string str)
{
return Path.GetFileNameWithoutExtension(str);
}
/// <summary>
/// https://stackoverflow.com/a/15275682/8076598
/// </summary>
public static IEnumerable<T> OrderBySequence<T, TId>(
this IEnumerable<T> source,
IEnumerable<TId> order,
Func<T, TId> idSelector)
/// <summary>
/// https://stackoverflow.com/a/15275682/8076598
/// </summary>
public static IEnumerable<T> OrderBySequence<T, TId>(
this IEnumerable<T> source,
IEnumerable<TId> order,
Func<T, TId> idSelector)
{
var lookup = source.ToLookup(idSelector, t => t);
foreach (var id in order)
Expand All @@ -29,12 +29,12 @@ public static IEnumerable<T> OrderBySequence<T, TId>(
}
}
}
/// <summary>
/// https://stackoverflow.com/a/13257600/8076598
/// </summary>
public static ObservableCollection<T> ToObservableCollection<T>(this IEnumerable<T> col)
{
return new(col);
}
/// <summary>
/// https://stackoverflow.com/a/13257600/8076598
/// </summary>
public static ObservableCollection<T> ToObservableCollection<T>(this IEnumerable<T> col)
{
return new(col);
}
}
}
8 changes: 4 additions & 4 deletions FoliCon/Modules/FocusExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static class FocusExtension
{
public static bool GetIsFocused(DependencyObject depObj)
{
return (bool) depObj.GetValue(IsFocusedProperty);
return (bool)depObj.GetValue(IsFocusedProperty);
}

public static void SetIsFocused(DependencyObject depObj, bool isFocused)
Expand All @@ -47,14 +47,14 @@ private static void OnIsFocusedPropertyChanged(DependencyObject depObj, Dependen
{
if (!(depObj is UIElement element)) return;
// Don't care about false values.
if (!(bool) args.NewValue) return;
if (!(bool)args.NewValue) return;
// only focusable if these two are true
// optional to raise exception if they aren't rather than just ignoring.
//if (element.Focusable && element.IsVisible)
if (!element.Focusable) return;
var action = new Action(() => element.Dispatcher.BeginInvoke((Action) (() => element.Focus())));
var action = new Action(() => element.Dispatcher.BeginInvoke((Action)(() => element.Focus())));
Task.Factory.StartNew(action);
var action2 = new Action(() => element.Dispatcher.BeginInvoke((Action) (() => Keyboard.Focus(element))));
var action2 = new Action(() => element.Dispatcher.BeginInvoke((Action)(() => Keyboard.Focus(element))));
Task.Factory.StartNew(action2);
FocusManager.SetFocusedElement(FocusManager.GetFocusScope(element), element);
}
Expand Down
6 changes: 3 additions & 3 deletions FoliCon/Modules/FolderDragDropHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class FolderDragDropHelper
{
public static bool GetIsFileDragDropEnabled(DependencyObject obj)
{
return (bool) obj.GetValue(IsFileDragDropEnabledProperty);
return (bool)obj.GetValue(IsFileDragDropEnabledProperty);
}

public static void SetIsFileDragDropEnabled(DependencyObject obj, bool value)
Expand All @@ -24,7 +24,7 @@ public static void SetIsFileDragDropEnabled(DependencyObject obj, bool value)

public static bool GetFileDragDropTarget(DependencyObject obj)
{
return (bool) obj.GetValue(FileDragDropTargetProperty);
return (bool)obj.GetValue(FileDragDropTargetProperty);
}

public static void SetFileDragDropTarget(DependencyObject obj, bool value)
Expand Down Expand Up @@ -66,7 +66,7 @@ private static void OnDrop(object sender, DragEventArgs dragEventArgs)
// if (_dragEventArgs.Data.GetDataPresent(DataFormats.FileDrop))
// {

fileTarget.OnFileDrop((string[]) dragEventArgs.Data.GetData(DataFormats.FileDrop), ((Control) sender).Name );
fileTarget.OnFileDrop((string[])dragEventArgs.Data.GetData(DataFormats.FileDrop), ((Control)sender).Name);

// }
}
Expand Down
22 changes: 11 additions & 11 deletions FoliCon/Modules/IGDBClass.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System;
using FoliCon.Models;
using IGDB;
using IGDB.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Diagnostics.Contracts;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using FoliCon.Models;
using IGDB;
using IGDB.Models;

namespace FoliCon.Modules
{
Expand Down Expand Up @@ -54,13 +54,13 @@ public static ObservableCollection<ListItem> ExtractGameDetailsIntoListItem(Game
{
var items = new ObservableCollection<ListItem>();
foreach (var (mediaName, year, overview, poster) in from item in result
let mediaName = item.Name
let year = item.FirstReleaseDate != null ? item.FirstReleaseDate.Value.Year.ToString() : ""
let overview = item.Summary
let poster = item.Cover != null
? "https://" + ImageHelper.GetImageUrl(item.Cover.Value.ImageId, ImageSize.HD720).Substring(2)
: null
select (mediaName, year, overview, poster))
let mediaName = item.Name
let year = item.FirstReleaseDate != null ? item.FirstReleaseDate.Value.Year.ToString() : ""
let overview = item.Summary
let poster = item.Cover != null
? "https://" + ImageHelper.GetImageUrl(item.Cover.Value.ImageId, ImageSize.HD720).Substring(2)
: null
select (mediaName, year, overview, poster))
{
items.Add(new ListItem(mediaName, year, "", overview, poster));
}
Expand Down
86 changes: 43 additions & 43 deletions FoliCon/Modules/TMDB.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using FoliCon.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Globalization;
using System.IO;
using System.Threading.Tasks;
using FoliCon.Models;
using TMDbLib.Client;
using TMDbLib.Objects.General;
using TMDbLib.Objects.Search;
Expand Down Expand Up @@ -83,25 +83,25 @@ public static ObservableCollection<ListItem> ExtractResourceDetailsIntoListItem(
switch (mediaType)
{
case MediaType.Tv:
{
var res = (SearchTv) item;
mediaName = res.Name;
year = res.FirstAirDate != null ? res.FirstAirDate.Value.Year.ToString() : "";
rating = res.VoteAverage.ToString(CultureInfo.CurrentCulture);
overview = res.Overview;
poster = res.PosterPath != null ? SmallPosterBase + res.PosterPath : null;
break;
}
{
var res = (SearchTv)item;
mediaName = res.Name;
year = res.FirstAirDate != null ? res.FirstAirDate.Value.Year.ToString() : "";
rating = res.VoteAverage.ToString(CultureInfo.CurrentCulture);
overview = res.Overview;
poster = res.PosterPath != null ? SmallPosterBase + res.PosterPath : null;
break;
}
case MediaType.Movie:
{
var res = (SearchMovie) item;
mediaName = res.Title;
year = res.ReleaseDate != null ? res.ReleaseDate.Value.Year.ToString() : "";
rating = res.VoteAverage.ToString(CultureInfo.CurrentCulture);
overview = res.Overview;
poster = res.PosterPath != null ? SmallPosterBase + res.PosterPath : null;
break;
}
{
var res = (SearchMovie)item;
mediaName = res.Title;
year = res.ReleaseDate != null ? res.ReleaseDate.Value.Year.ToString() : "";
rating = res.VoteAverage.ToString(CultureInfo.CurrentCulture);
overview = res.Overview;
poster = res.PosterPath != null ? SmallPosterBase + res.PosterPath : null;
break;
}
}

items.Add(new ListItem(mediaName, year, rating, overview, poster));
Expand Down Expand Up @@ -145,22 +145,22 @@ public void ResultPicked(dynamic result, string resultType, string fullFolderPat
string posterUrl = string.Concat(PosterBase, result.PosterPath);
if (resultType == MediaTypes.Tv)
{
var pickedResult = (SearchTv) result;
var pickedResult = (SearchTv)result;
var year = pickedResult.FirstAirDate != null ? pickedResult.FirstAirDate.Value.Year.ToString() : "";
Util.AddToPickedListDataTable(_listDataTable, localPosterPath, pickedResult.Name,
pickedResult.VoteAverage.ToString(CultureInfo.CurrentCulture), fullFolderPath, folderName,
year);
}
else if (resultType == MediaTypes.Movie)
{
var pickedResult = (SearchMovie) result;
var pickedResult = (SearchMovie)result;
var year = pickedResult.ReleaseDate != null ? pickedResult.ReleaseDate.Value.Year.ToString() : "";
Util.AddToPickedListDataTable(_listDataTable, localPosterPath, pickedResult.Title,
pickedResult.VoteAverage.ToString(CultureInfo.CurrentCulture), fullFolderPath, folderName, year);
}
else if (resultType == MediaTypes.Collection)
{
var searchResult = (SearchCollection) result;
var searchResult = (SearchCollection)result;
Util.AddToPickedListDataTable(_listDataTable, localPosterPath, searchResult.Name, "", fullFolderPath,
folderName);
}
Expand All @@ -170,27 +170,27 @@ public void ResultPicked(dynamic result, string resultType, string fullFolderPat
switch (mediaType)
{
case MediaType.Tv:
{
SearchTv pickedResult = result;
var year = pickedResult.FirstAirDate != null
? pickedResult.FirstAirDate.Value.Year.ToString()
: "";
Util.AddToPickedListDataTable(_listDataTable, localPosterPath, pickedResult.Name,
pickedResult.VoteAverage.ToString(CultureInfo.CurrentCulture), fullFolderPath, folderName,
year);
break;
}
{
SearchTv pickedResult = result;
var year = pickedResult.FirstAirDate != null
? pickedResult.FirstAirDate.Value.Year.ToString()
: "";
Util.AddToPickedListDataTable(_listDataTable, localPosterPath, pickedResult.Name,
pickedResult.VoteAverage.ToString(CultureInfo.CurrentCulture), fullFolderPath, folderName,
year);
break;
}
case MediaType.Movie:
{
SearchMovie pickedResult = result;
var year = pickedResult.ReleaseDate != null
? pickedResult.ReleaseDate.Value.Year.ToString()
: "";
Util.AddToPickedListDataTable(_listDataTable, localPosterPath, pickedResult.Title,
pickedResult.VoteAverage.ToString(CultureInfo.CurrentCulture), fullFolderPath, folderName,
year);
break;
}
{
SearchMovie pickedResult = result;
var year = pickedResult.ReleaseDate != null
? pickedResult.ReleaseDate.Value.Year.ToString()
: "";
Util.AddToPickedListDataTable(_listDataTable, localPosterPath, pickedResult.Title,
pickedResult.VoteAverage.ToString(CultureInfo.CurrentCulture), fullFolderPath, folderName,
year);
break;
}
}
}

Expand Down
Loading

0 comments on commit 1c50b31

Please sign in to comment.