Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
57 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,8 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace MusicBeePlugin.Models | ||
namespace MusicBeePlugin.Models | ||
{ | ||
public class Song : Plugin | ||
public class Song | ||
{ | ||
private MusicBeeApiInterface mbApiInterface | ||
{ | ||
get { return ApiInterface.mbApiInterface; } | ||
} | ||
|
||
public Song(string sourceFileUrl) | ||
{ | ||
Url = sourceFileUrl; | ||
TrackTitle = mbApiInterface.Library_GetFileTag(Url, MetaDataType.TrackTitle); | ||
} | ||
|
||
public string Url { get; } | ||
public string TrackTitle { get; } | ||
public string Url { get; set; } | ||
public string Name { get; set; } | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,134 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Runtime.CompilerServices; | ||
using MusicBeePlugin; | ||
using System.Collections.ObjectModel; | ||
using System.Collections.ObjectModel; | ||
using MusicBeePlugin.Models; | ||
|
||
namespace MusicBeePlugin.ViewModels | ||
{ | ||
public class SearchWindowViewModel : Plugin, INotifyPropertyChanged | ||
public class SearchWindowViewModel | ||
{ | ||
#region Properties | ||
private MusicBeeApiInterface mbApiInterface | ||
{ | ||
get { return ApiInterface.mbApiInterface; } | ||
} | ||
public ObservableCollection<Song> NowPlayingList { get; set; } | ||
|
||
public ObservableCollection<Song> SearchList | ||
{ | ||
get | ||
{ | ||
return GetSongsMatchingKey(); | ||
} | ||
} | ||
|
||
public Song SelectedSong | ||
{ | ||
get; set; | ||
} | ||
|
||
private string _TextBoxSearch; | ||
public string TextBoxSearch | ||
{ | ||
get { return _TextBoxSearch; } | ||
set | ||
{ | ||
_TextBoxSearch = value; | ||
OnPropertyChanged(); | ||
OnPropertyChanged("SearchList"); | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
#region INotifyPropertyChanged implementation | ||
public event PropertyChangedEventHandler PropertyChanged; | ||
protected void OnPropertyChanged([CallerMemberName] string propertyName = null) | ||
{ | ||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | ||
} | ||
|
||
#endregion | ||
|
||
#region Commands | ||
public RelayCommand PlaySelectedSongCommand { get; } | ||
public RelayCommand GetNextSearchResult { get; } | ||
#endregion | ||
|
||
|
||
public SearchWindowViewModel() | ||
{ | ||
NowPlayingList = LoadNowPlayingQueue(); | ||
|
||
PlaySelectedSongCommand = new RelayCommand(x => | ||
{ | ||
PlayNow(SelectedSong); | ||
}, x => this.SelectedSong != null); | ||
|
||
GetNextSearchResult = new RelayCommand(x => | ||
{ | ||
SearchList.GetEnumerator().MoveNext(); | ||
}, x => SearchList.Count() != 0); | ||
} | ||
|
||
#region Methods | ||
private void PlayNow(Song target) | ||
{ | ||
NowPlayingList_FileActionDelegate FileAction = mbApiInterface.NowPlayingList_PlayNow; | ||
FileAction(target.Url); | ||
} | ||
|
||
private ObservableCollection<Song> LoadNowPlayingQueue() | ||
{ | ||
ObservableCollection<Song> instance = new ObservableCollection<Song>(); | ||
|
||
string[] fileUrls = new string[0]; | ||
mbApiInterface.NowPlayingList_QueryFilesEx(null, ref fileUrls); | ||
|
||
foreach (var url in fileUrls) | ||
{ | ||
instance.Add(new Song(url)); | ||
} | ||
|
||
return instance; | ||
} | ||
|
||
|
||
private ObservableCollection<Song> GetSongsMatchingKey() | ||
{ | ||
ObservableCollection<Song> instance = new ObservableCollection<Song>(); | ||
var query = TextBoxSearch; | ||
|
||
if (NowPlayingList.Count() == 0 || string.IsNullOrEmpty(query)) | ||
{ | ||
return instance; | ||
} | ||
|
||
try | ||
{ | ||
NowPlayingList.Any(x => x.TrackTitle.StartsWith(query, StringComparison.CurrentCultureIgnoreCase)); | ||
} | ||
catch(ArgumentNullException) | ||
{ | ||
return instance; | ||
} | ||
|
||
foreach(Song song in NowPlayingList) | ||
{ | ||
if (song.TrackTitle.StartsWith(query, StringComparison.CurrentCultureIgnoreCase)) | ||
instance.Add(song); | ||
|
||
} | ||
|
||
return instance; | ||
} | ||
|
||
#endregion | ||
|
||
public Song SelectedSong { get; set; } | ||
public RelayCommand PlaySelectedSong { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters