From 4cc7fb8eed2cfee46ab604e9a046d4afde3295a6 Mon Sep 17 00:00:00 2001 From: amazing-username Date: Mon, 10 Jun 2019 17:28:42 -0700 Subject: [PATCH] Started working on the Searching functionality for the Song view. #44 --- Mear/Mear.Android/Mear.Android.csproj | 3 + .../Resources/Resource.designer.cs | 91 +++---- Mear/Mear.Android/Resources/values/styles.xml | 5 +- Mear/Mear.iOS/Mear.iOS.csproj | 3 + Mear/Mear/App.xaml | 22 +- Mear/Mear/App.xaml.cs | 1 - Mear/Mear/Mear.csproj | 1 + Mear/Mear/ViewModels/BaseViewModel.cs | 2 +- Mear/Mear/ViewModels/SongViewModel.cs | 228 ++++++++++-------- Mear/Mear/Views/SongView.xaml | 8 +- 10 files changed, 218 insertions(+), 146 deletions(-) diff --git a/Mear/Mear.Android/Mear.Android.csproj b/Mear/Mear.Android/Mear.Android.csproj index 256ecb1..a157e0c 100644 --- a/Mear/Mear.Android/Mear.Android.csproj +++ b/Mear/Mear.Android/Mear.Android.csproj @@ -64,6 +64,9 @@ 1.5.231 + + 1.5.2 + diff --git a/Mear/Mear.Android/Resources/Resource.designer.cs b/Mear/Mear.Android/Resources/Resource.designer.cs index 7eb0ac5..ef4123b 100644 --- a/Mear/Mear.Android/Resources/Resource.designer.cs +++ b/Mear/Mear.Android/Resources/Resource.designer.cs @@ -9771,113 +9771,113 @@ namespace Mear.Droid // aapt resource value: 0x7f0b0043 public const int character_counter_pattern = 2131427395; - // aapt resource value: 0x7f0b004e - public const int download_notification_channel_name = 2131427406; - // aapt resource value: 0x7f0b004f - public const int exo_controls_fastforward_description = 2131427407; + public const int download_notification_channel_name = 2131427407; // aapt resource value: 0x7f0b0050 - public const int exo_controls_fullscreen_description = 2131427408; + public const int exo_controls_fastforward_description = 2131427408; // aapt resource value: 0x7f0b0051 - public const int exo_controls_next_description = 2131427409; + public const int exo_controls_fullscreen_description = 2131427409; // aapt resource value: 0x7f0b0052 - public const int exo_controls_pause_description = 2131427410; + public const int exo_controls_next_description = 2131427410; // aapt resource value: 0x7f0b0053 - public const int exo_controls_play_description = 2131427411; + public const int exo_controls_pause_description = 2131427411; // aapt resource value: 0x7f0b0054 - public const int exo_controls_previous_description = 2131427412; + public const int exo_controls_play_description = 2131427412; // aapt resource value: 0x7f0b0055 - public const int exo_controls_repeat_all_description = 2131427413; + public const int exo_controls_previous_description = 2131427413; // aapt resource value: 0x7f0b0056 - public const int exo_controls_repeat_off_description = 2131427414; + public const int exo_controls_repeat_all_description = 2131427414; // aapt resource value: 0x7f0b0057 - public const int exo_controls_repeat_one_description = 2131427415; + public const int exo_controls_repeat_off_description = 2131427415; // aapt resource value: 0x7f0b0058 - public const int exo_controls_rewind_description = 2131427416; + public const int exo_controls_repeat_one_description = 2131427416; // aapt resource value: 0x7f0b0059 - public const int exo_controls_shuffle_description = 2131427417; + public const int exo_controls_rewind_description = 2131427417; // aapt resource value: 0x7f0b005a - public const int exo_controls_stop_description = 2131427418; + public const int exo_controls_shuffle_description = 2131427418; // aapt resource value: 0x7f0b005b - public const int exo_download_completed = 2131427419; + public const int exo_controls_stop_description = 2131427419; // aapt resource value: 0x7f0b005c - public const int exo_download_description = 2131427420; + public const int exo_download_completed = 2131427420; // aapt resource value: 0x7f0b005d - public const int exo_download_downloading = 2131427421; + public const int exo_download_description = 2131427421; // aapt resource value: 0x7f0b005e - public const int exo_download_failed = 2131427422; + public const int exo_download_downloading = 2131427422; // aapt resource value: 0x7f0b005f - public const int exo_download_notification_channel_name = 2131427423; + public const int exo_download_failed = 2131427423; // aapt resource value: 0x7f0b0060 - public const int exo_download_removing = 2131427424; + public const int exo_download_notification_channel_name = 2131427424; // aapt resource value: 0x7f0b0061 - public const int exo_item_list = 2131427425; - - // aapt resource value: 0x7f0b006f - public const int exo_media_action_repeat_all_description = 2131427439; - - // aapt resource value: 0x7f0b0070 - public const int exo_media_action_repeat_off_description = 2131427440; - - // aapt resource value: 0x7f0b0071 - public const int exo_media_action_repeat_one_description = 2131427441; + public const int exo_download_removing = 2131427425; // aapt resource value: 0x7f0b0062 - public const int exo_track_bitrate = 2131427426; + public const int exo_item_list = 2131427426; + + // aapt resource value: 0x7f0b0070 + public const int exo_media_action_repeat_all_description = 2131427440; + + // aapt resource value: 0x7f0b0071 + public const int exo_media_action_repeat_off_description = 2131427441; + + // aapt resource value: 0x7f0b0072 + public const int exo_media_action_repeat_one_description = 2131427442; // aapt resource value: 0x7f0b0063 - public const int exo_track_mono = 2131427427; + public const int exo_track_bitrate = 2131427427; // aapt resource value: 0x7f0b0064 - public const int exo_track_resolution = 2131427428; + public const int exo_track_mono = 2131427428; // aapt resource value: 0x7f0b0065 - public const int exo_track_selection_auto = 2131427429; + public const int exo_track_resolution = 2131427429; // aapt resource value: 0x7f0b0066 - public const int exo_track_selection_none = 2131427430; + public const int exo_track_selection_auto = 2131427430; // aapt resource value: 0x7f0b0067 - public const int exo_track_selection_title_audio = 2131427431; + public const int exo_track_selection_none = 2131427431; // aapt resource value: 0x7f0b0068 - public const int exo_track_selection_title_text = 2131427432; + public const int exo_track_selection_title_audio = 2131427432; // aapt resource value: 0x7f0b0069 - public const int exo_track_selection_title_video = 2131427433; + public const int exo_track_selection_title_text = 2131427433; // aapt resource value: 0x7f0b006a - public const int exo_track_stereo = 2131427434; + public const int exo_track_selection_title_video = 2131427434; // aapt resource value: 0x7f0b006b - public const int exo_track_surround = 2131427435; + public const int exo_track_stereo = 2131427435; // aapt resource value: 0x7f0b006c - public const int exo_track_surround_5_point_1 = 2131427436; + public const int exo_track_surround = 2131427436; // aapt resource value: 0x7f0b006d - public const int exo_track_surround_7_point_1 = 2131427437; + public const int exo_track_surround_5_point_1 = 2131427437; // aapt resource value: 0x7f0b006e - public const int exo_track_unknown = 2131427438; + public const int exo_track_surround_7_point_1 = 2131427438; + + // aapt resource value: 0x7f0b006f + public const int exo_track_unknown = 2131427439; // aapt resource value: 0x7f0b0044 public const int fab_transformation_scrim_behavior = 2131427396; @@ -9888,6 +9888,9 @@ namespace Mear.Droid // aapt resource value: 0x7f0b0046 public const int hide_bottom_view_on_scroll_behavior = 2131427398; + // aapt resource value: 0x7f0b004e + public const int library_name = 2131427406; + // aapt resource value: 0x7f0b0000 public const int mr_button_content_description = 2131427328; diff --git a/Mear/Mear.Android/Resources/values/styles.xml b/Mear/Mear.Android/Resources/values/styles.xml index 43b0a58..9e6b4ee 100644 --- a/Mear/Mear.Android/Resources/values/styles.xml +++ b/Mear/Mear.Android/Resources/values/styles.xml @@ -11,9 +11,12 @@ false + + #222222 - #1976D2 + #000000 #FF4081 diff --git a/Mear/Mear.iOS/Mear.iOS.csproj b/Mear/Mear.iOS/Mear.iOS.csproj index 050047e..8ffd5ad 100644 --- a/Mear/Mear.iOS/Mear.iOS.csproj +++ b/Mear/Mear.iOS/Mear.iOS.csproj @@ -130,6 +130,9 @@ 1.5.231 + + 1.5.2 + diff --git a/Mear/Mear/App.xaml b/Mear/Mear/App.xaml index 61c53ec..012cfa8 100644 --- a/Mear/Mear/App.xaml +++ b/Mear/Mear/App.xaml @@ -20,6 +20,13 @@ #ffffee + + #ffffff + + \ No newline at end of file diff --git a/Mear/Mear/App.xaml.cs b/Mear/Mear/App.xaml.cs index 44e29fa..ad38c1c 100644 --- a/Mear/Mear/App.xaml.cs +++ b/Mear/Mear/App.xaml.cs @@ -13,7 +13,6 @@ namespace Mear InitializeComponent(); MainPage = new Landing(); - MainPage.SetValue(NavigationPage.BarBackgroundColorProperty, Color.Black); MainPage.SetValue(NavigationPage.BarTextColorProperty, Color.White); } diff --git a/Mear/Mear/Mear.csproj b/Mear/Mear/Mear.csproj index aa062d5..34b6ada 100644 --- a/Mear/Mear/Mear.csproj +++ b/Mear/Mear/Mear.csproj @@ -15,6 +15,7 @@ + diff --git a/Mear/Mear/ViewModels/BaseViewModel.cs b/Mear/Mear/ViewModels/BaseViewModel.cs index 80d7913..2f8b671 100644 --- a/Mear/Mear/ViewModels/BaseViewModel.cs +++ b/Mear/Mear/ViewModels/BaseViewModel.cs @@ -31,7 +31,7 @@ namespace Mear.ViewModels #region Methods - private void NotifyPropertyChanged(string propertyName) + protected void NotifyPropertyChanged(string propertyName) { if (PropertyChanged != null) { diff --git a/Mear/Mear/ViewModels/SongViewModel.cs b/Mear/Mear/ViewModels/SongViewModel.cs index e7a4872..8f363a0 100644 --- a/Mear/Mear/ViewModels/SongViewModel.cs +++ b/Mear/Mear/ViewModels/SongViewModel.cs @@ -13,117 +13,151 @@ using Mear.Repositories.Remote; namespace Mear.ViewModels { - public class SongViewModel : BaseViewModel - { - #region Fields - private ObservableCollection _songItems; - private Command _refreshSongs; - #endregion + public class SongViewModel : BaseViewModel + { + #region Fields + private ObservableCollection _songItems; + private Command _refreshSongs; + private Command _searchSongsCommand; + private string _searchedText; + #endregion - #region Properties - public ObservableCollection SongItems - { - get => _songItems; - set => _songItems = value; - } + #region Properties + public ObservableCollection SongItems + { + get => _songItems; + set => _songItems = value; + } - public Command RefreshSongs - { - get => _refreshSongs; - set => _refreshSongs = value; - } - #endregion + public Command RefreshSongs + { + get => _refreshSongs; + set => _refreshSongs = value; + } + public Command SearchSongsCommand + { + get => _searchSongsCommand; + set => _searchSongsCommand = value; + } + + public string SearchedText + { + get => _searchedText; + set + { + _searchedText = value; + NotifyPropertyChanged("SearchSong"); + //SearchSongText(_searchedText); + } + } + #endregion - #region Constructors - public SongViewModel() - { - _songItems = new ObservableCollection(); - _refreshSongs = new Command(async () => await PopulateSongsAsync()); + #region Constructors + public SongViewModel() + { + _songItems = new ObservableCollection(); + _refreshSongs = new Command(async () => await PopulateSongsAsync()); + _searchSongsCommand = new Command(async () => await SearchSongText()); - PopulateSongs(); - } - #endregion + PopulateSongs(); + } + #endregion - #region Methods - public void PopulateSongs() - { - var songRepo = new RemoteSongRepository(); - var localSongRepo = new LocalSongRepository(); - var lclSongs = localSongRepo.RetrieveSongs(); - var rmtSongs = songRepo.RetrieveSongs().OrderBy(s => s.Title).ToList(); - var songs = new List(); - if (lclSongs != null) - { - lclSongs = lclSongs.OrderBy(s => s.Title).ToList(); - songs = MergeSongs(lclSongs, rmtSongs); - } - else - { - songs = rmtSongs; - } + #region Methods + public void PopulateSongs() + { + var songRepo = new RemoteSongRepository(); + var localSongRepo = new LocalSongRepository(); + var lclSongs = localSongRepo.RetrieveSongs(); + var rmtSongs = songRepo.RetrieveSongs().OrderBy(s => s.Title).ToList(); + var songs = new List(); + if (lclSongs != null) + { + lclSongs = lclSongs.OrderBy(s => s.Title).ToList(); + songs = MergeSongs(lclSongs, rmtSongs); + } + else + { + songs = rmtSongs; + } - foreach (var song in songs) - { - _songItems.Add(song); - } - } + foreach (var song in songs) + { + _songItems.Add(song); + } + } - private List MergeSongs(List local, List remote) - { - try - { - foreach (Song lclSong in local) - { - Song song = remote.Find(s => (s.Title.Equals(lclSong.Title))); - remote.Remove(song); - remote.Add(lclSong); - } + private List MergeSongs(List local, List remote) + { + try + { + foreach (Song lclSong in local) + { + Song song = remote.Find(s => (s.Title.Equals(lclSong.Title))); + remote.Remove(song); + remote.Add(lclSong); + } - return remote; - } - catch (Exception ex) - { - var msg = ex.Message; - } + return remote; + } + catch (Exception ex) + { + var msg = ex.Message; + } - return null; - } - private async Task PopulateSongsAsync() - { - try - { - var songRepo = new RemoteSongRepository(); - var localSongRepo = new LocalSongRepository(); - var lclSongs = localSongRepo.RetrieveSongs(); - var rmtSongs = songRepo.RetrieveSongs().OrderBy(s => s.Title).ToList(); - var songs = new List(); - if (lclSongs != null) - { - lclSongs = lclSongs.OrderBy(s => s.Title).ToList(); - songs = MergeSongs(lclSongs, rmtSongs); - } - else - { - songs = rmtSongs; - } + return null; + } + private async Task PopulateSongsAsync() + { + try + { + var songRepo = new RemoteSongRepository(); + var localSongRepo = new LocalSongRepository(); + var lclSongs = localSongRepo.RetrieveSongs(); + var rmtSongs = songRepo.RetrieveSongs().OrderBy(s => s.Title).ToList(); + var songs = new List(); + if (lclSongs != null) + { + lclSongs = lclSongs.OrderBy(s => s.Title).ToList(); + songs = MergeSongs(lclSongs, rmtSongs); + } + else + { + songs = rmtSongs; + } _songItems.Clear(); - foreach (var song in songs) - { - _songItems.Add(song); - } - } - catch (Exception ex) - { - var msg = ex.Message; - } + foreach (var song in songs) + { + _songItems.Add(song); + } + } + catch (Exception ex) + { + var msg = ex.Message; + } IsRefreshing = false; - } - #endregion - } -} + } + + private async Task SearchSongText() + { + if (_searchedText == null) + { + return; + } + var searchPhrase = _searchedText.Trim(); + + const int SEARCH_PHRASE_MIN_LENGTH = 3; + if (searchPhrase.Length < SEARCH_PHRASE_MIN_LENGTH) return; // SEARCH_PHRASE_MIN_LENGTH = 3 + + _songItems.Where(sng => sng.Title.Contains(_searchedText) || sng.Artist.Contains(_searchedText)); + + } + #endregion + } + } diff --git a/Mear/Mear/Views/SongView.xaml b/Mear/Mear/Views/SongView.xaml index 46f398d..2d7a807 100644 --- a/Mear/Mear/Views/SongView.xaml +++ b/Mear/Mear/Views/SongView.xaml @@ -13,7 +13,13 @@ - + +