Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodrr committed Apr 3, 2019
1 parent 148234f commit 8c8c4bd
Show file tree
Hide file tree
Showing 11 changed files with 182 additions and 138 deletions.
2 changes: 1 addition & 1 deletion BreadPlayer.Views.UWP/DataSources/ArtistDataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ArtistDataSource : IIncrementalSource<Artist>
public Task<IEnumerable<Artist>> GetPagedItemsAsync(int pageIndex, int pageSize, CancellationToken cancellationToken = default(CancellationToken))
{
return SharedLogic.Instance.AlbumArtistService.GetRangeOfArtistsAsync(pageIndex * pageSize, pageSize);
}
}
}
public class AlbumDataSource : IIncrementalSource<Album>
{
Expand Down
2 changes: 1 addition & 1 deletion BreadPlayer.Views.UWP/Helpers/LibraryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static async Task<IEnumerable<Mediafile>> GetSongsFromFolderAsync(Storage
string message = ex.Message + "||" + ex.InnerException;
BLogger.E("Error while importing folder.", ex);
await SharedLogic.Instance.NotificationManager.ShowMessageAsync(message);
}
}
return tempList.DistinctBy(f => f.OrginalFilename);
}
public static async Task ImportFolderIntoLibraryAsync(StorageFolder folder)
Expand Down
2 changes: 1 addition & 1 deletion BreadPlayer.Views.UWP/Shell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@
Storyboard.TargetProperty="Opacity"
From="0"
To="1"
Duration="0:0:1" />
Duration="0:0:0.5" />
</Storyboard>
</VisualState.Storyboard>
</VisualState>
Expand Down
238 changes: 121 additions & 117 deletions BreadPlayer.Views.UWP/Themes/DataTemplates.xaml

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions BreadPlayer.Views.UWP/ViewModels/AlbumArtistViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ await Task.Run(() =>
AlbumName = mediafile.Album,
AlbumArt = string.IsNullOrEmpty(mediafile?.AttachedPicture) ? null : mediafile?.AttachedPicture
};

albums.Add(album);
}
if (artists.All(t => t.Name != mediafile.LeadArtist))
Expand Down Expand Up @@ -150,14 +149,14 @@ public void LoadArtists()
ArtistsCollection.OnStartLoading = () => RecordsLoading = true;
ArtistsCollection.OnEndLoading = () =>
{
RecordsLoading = false;
RecordsLoading = false;
};
ArtistsCollection.OnError = (ex) => RecordsLoading = false;
}

private async void ArtistsCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if(e.Action == NotifyCollectionChangedAction.Add && e.NewItems != null)
if (e.Action == NotifyCollectionChangedAction.Add && e.NewItems != null)
{
await CacheArtists(e.NewItems.Cast<Artist>()).ConfigureAwait(false);
}
Expand Down Expand Up @@ -185,7 +184,7 @@ private async Task CacheArtists(IEnumerable<Artist> artists)
break;
}
var collectionArtist = ArtistsCollection.FirstOrDefault(t => t.Name == artist.Name);
if(collectionArtist == null)
if (collectionArtist == null)
{
BLogger.I("No artist found for: {name}", artist.Name);
continue;
Expand Down
11 changes: 7 additions & 4 deletions BreadPlayer.Views.UWP/ViewModels/NowPlayingViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using IF.Lastfm.Core.Objects;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;

Expand Down Expand Up @@ -168,7 +169,7 @@ private async Task GetLyrics()

timer = new Core.PortableAPIs.DispatcherTimer(new BreadDispatcher())
{
Interval = TimeSpan.FromMilliseconds(10)
Interval = TimeSpan.FromMilliseconds(1)
};
string lyricsText = "";
if (string.IsNullOrEmpty(SharedLogic.Instance.Player.CurrentlyPlayingFile?.SynchronizedLyric))
Expand Down Expand Up @@ -210,13 +211,15 @@ private async Task GetLyrics()
timer.Tick += (s, e) =>
{
var currentPosition = TimeSpan.FromSeconds(SharedLogic.Instance.Player.Position);
if (Lyrics?.Any(t => t.Timestamp.Minutes == currentPosition.Minutes && t.Timestamp.Seconds == currentPosition.Seconds && (t.Timestamp.Milliseconds - currentPosition.Milliseconds) < 50) == true)
if (Lyrics?.Any(t => t.Timestamp.Minutes == currentPosition.Minutes && t.Timestamp.Seconds == currentPosition.Seconds && currentPosition.Milliseconds - t.Timestamp.Milliseconds < 20) == true)
{
var currentLyric = Lyrics.First(t => t.Timestamp.Minutes == currentPosition.Minutes && t.Timestamp.Seconds == currentPosition.Seconds);
var currentLyric = Lyrics.FirstOrDefault(t => t.Timestamp.Minutes == currentPosition.Minutes && t.Timestamp.Seconds == currentPosition.Seconds && currentPosition.Milliseconds - t.Timestamp.Milliseconds < 20);
Debug.WriteLine(currentPosition.Milliseconds % currentLyric.Timestamp.Milliseconds);
if (currentLyric == null)
return;

var previousLyric = Lyrics.FirstOrDefault(t => t.IsActive) ?? null;
if (previousLyric != null && previousLyric.Timestamp == currentLyric.Timestamp)
return;
if (previousLyric != null && previousLyric.IsActive == true)
previousLyric.IsActive = false;
if (!currentLyric.IsActive)
Expand Down
2 changes: 1 addition & 1 deletion BreadPlayer.Views.UWP/ViewModels/ShellViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public ShellViewModel()
DontUpdatePosition = false;
_timer = new DispatcherTimer(new BreadDispatcher())
{
Interval = TimeSpan.FromMilliseconds(500)
Interval = TimeSpan.FromMilliseconds(1)
};
_timer.Tick += Timer_Tick;
_timer.Stop();
Expand Down
31 changes: 30 additions & 1 deletion BreadPlayer.Views.UWP/Views/LibraryView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,36 @@
<GridView.ItemContainerStyle>
<Style TargetType="GridViewItem">
<Setter Property="Margin" Value="20" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="GridViewItem">
<ListViewItemPresenter
ContentTransitions="{TemplateBinding ContentTransitions}"
SelectionCheckMarkVisualEnabled="True"
CheckBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
CheckBoxBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
DragBackground="{ThemeResource ListViewItemDragBackgroundThemeBrush}"
DragForeground="{ThemeResource ListViewItemDragForegroundThemeBrush}"
FocusBorderBrush="{ThemeResource SystemControlForegroundAltHighBrush}"
FocusSecondaryBorderBrush="{ThemeResource SystemControlForegroundBaseHighBrush}"
PlaceholderBackground="Transparent"
PointerOverBackground="Transparent"
PointerOverForeground="{ThemeResource SystemControlHighlightAltBaseHighBrush}"
SelectedBackground="Transparent"
SelectedForeground="{ThemeResource SystemControlHighlightAltBaseHighBrush}"
SelectedPointerOverBackground="Transparent"
PressedBackground="Transparent"
SelectedPressedBackground="Transparent"
DisabledOpacity="{ThemeResource ListViewItemDisabledThemeOpacity}"
DragOpacity="{ThemeResource ListViewItemDragThemeOpacity}"
ReorderHintOffset="{ThemeResource ListViewItemReorderHintThemeOffset}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
ContentMargin="{TemplateBinding Padding}"
CheckMode="Inline"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GridView.ItemContainerStyle>
</GridView>
Expand Down Expand Up @@ -634,7 +664,6 @@
<Setter Target="semanticZoom.(Grid.RowSpan)" Value="2" />
<Setter Target="albumGridView.ItemsPanel" Value="{StaticResource MobileItemsPanelTemplate}" />
<Setter Target="artistGridView.ItemsPanel" Value="{StaticResource MobileItemsPanelTemplate}" />
<Setter Target="albumGridView.ItemTemplate" Value="{StaticResource AlbumMobileTemplate}" />
<Setter Target="artistGridView.ItemTemplate" Value="{StaticResource ArtistMobileTemplate}" />
</VisualState.Setters>
</VisualState>
Expand Down
21 changes: 15 additions & 6 deletions BreadPlayer.Web/Baidu/BaiduClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class BaiduClient : ILyricAPI
public async Task<string> FetchLyrics(Mediafile mediaFile)
{
var results = await Search(WebUtility.UrlEncode(mediaFile.Title + " " + mediaFile.LeadArtist)).ConfigureAwait(false);
if (results.Result.SongInfo?.SongList?.Any() == true
&& results.Result.SongInfo?.SongList?.Any(t => t.Title.Contains(mediaFile.Title)) == true)
if (results?.Result?.SongInfo?.SongList?.Any() == true
&& results?.Result?.SongInfo?.SongList?.Any(t => t.Title.Contains(mediaFile.Title)) == true)
{
var bSong = results.Result.SongInfo.SongList.First(t => t.Title.Contains(mediaFile.Title));
return (await RequestSongLrc(bSong.SongId).ConfigureAwait(false)).LrcContent;
Expand All @@ -28,16 +28,25 @@ public async Task<Lrc> RequestSongLrc(string songId)
{
var url = _helpers.GetCallUrl(Endpoints.MethodSongLrc, _helpers.GetSongsInfoParameterString(songId));
string response = await _helpers.MakeRequest(url).ConfigureAwait(false);
var obj = (Lrc)JsonConvert.DeserializeObject(response, typeof(Lrc));
return obj;
if (response != null)
{
var obj = JsonConvert.DeserializeObject<Lrc>(response);
if (obj != null)
return obj;
}
return null;
}

public async Task<QueryMergeResponse> Search(string query)
{
var url = _helpers.GetCallUrl(Endpoints.MethodQueryMerge, _helpers.GetQueryParameterString(query));
string response = await _helpers.MakeRequest(url).ConfigureAwait(false);
var obj = (QueryMergeResponse)JsonConvert.DeserializeObject(response, typeof(QueryMergeResponse));
return obj;
if (response != null)
{
var obj = JsonConvert.DeserializeObject<QueryMergeResponse>(response);
return obj;
}
return null;
}
}
}
2 changes: 1 addition & 1 deletion BreadPlayer.Web/Netease/NeteaseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task<LyricsResponse> GetLyrics(string id)
public async Task<string> FetchLyrics(Mediafile mediaFile)
{
var results = await SearchSongs(WebUtility.UrlEncode(mediaFile.Title + " " + mediaFile.LeadArtist)).ConfigureAwait(false);
if (results.Result.SongCount > 0)
if (results?.Result?.SongCount > 0)
{
var bSong = results.Result.Songs.FirstOrDefault(t => t.Name.ToLower().Contains(mediaFile.Title.ToLower()));
if (bSong != null)
Expand Down
2 changes: 1 addition & 1 deletion BreadPlayer.Web/Xiami/XiamiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public async Task<string> FetchLyrics(Mediafile mediaFile)
{
XiamiHttpClient.CancelPendingRequests();
var results = await SearchAsync(WebUtility.UrlEncode(mediaFile.Title + " " + mediaFile.LeadArtist));
if (results.Data.Songs.Any(t => t.SongName.ToLower().Contains(mediaFile.Title.ToLower())))
if (results?.Data?.Songs?.Any(t => t.SongName.ToLower().Contains(mediaFile.Title.ToLower())) == true)
{
var xResult = results.Data.Songs.First(t => t.SongName.ToLower().Contains(mediaFile.Title.ToLower()));
var xSong = await GetSongDetailAsync(xResult.SongId.ToString());
Expand Down

0 comments on commit 8c8c4bd

Please sign in to comment.