Started working on the Searching functionality for the Song view. #44

This commit is contained in:
amazing-username
2019-06-10 17:28:42 -07:00
parent ca1d79137b
commit 4cc7fb8eed
10 changed files with 218 additions and 146 deletions
+3
View File
@@ -64,6 +64,9 @@
<PackageReference Include="sqlite-net-pcl">
<Version>1.5.231</Version>
</PackageReference>
<PackageReference Include="UXDivers.GorillaPlayer.SDK">
<Version>1.5.2</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms" Version="4.0.0.482894" />
<PackageReference Include="Xamarin.Android.Support.Design" Version="28.0.0.1" />
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="28.0.0.1" />
+47 -44
View File
@@ -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;
@@ -11,9 +11,12 @@
<item name="windowActionBar">false</item>
<!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette -->
<!-- colorPrimary is used for the default action bar background -->
<!--
<item name="colorPrimary">#2196F3</item>
-->
<item name="colorPrimary">#222222</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#1976D2</item>
<item name="colorPrimaryDark">#000000</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">#FF4081</item>
+3
View File
@@ -130,6 +130,9 @@
<PackageReference Include="sqlite-net-pcl">
<Version>1.5.231</Version>
</PackageReference>
<PackageReference Include="UXDivers.GorillaPlayer.SDK">
<Version>1.5.2</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms" Version="4.0.0.482894" />
<PackageReference Include="Xamarin.Essentials" Version="1.1.0" />
</ItemGroup>
+21 -1
View File
@@ -20,6 +20,13 @@
<Color x:Key="EntryTextColor">#ffffee</Color>
<!--
<Color x:Key="SearchBarBackgroundColor">#ffffee</Color>
<Color x:Key="SearchBarCancelButtonColor">#999999</Color>
<Color x:Key="StaticResource SearchBarPlaceholderColor">#ffeeff</Color>
-->
<Color x:Key="StaticResource SearchBarTextColor">#ffffff</Color>
<Style TargetType="NavigationPage">
<Setter Property="BackgroundColor" Value="{StaticResource NavigationPageBackgroundColor}" />
<Setter Property="BarBackgroundColor" Value="{StaticResource NavigationPageColor}" />
@@ -30,9 +37,14 @@
</Style>
<Style TargetType="TabbedPage">
<Setter Property="BarTextColor" Value="{StaticResource TabbedBarTextColor}" />
<!--
<Setter Property="UnselectedTabColor" Value="{StaticResource TabbedUnselectedColor}" />
-->
<Setter Property="UnselectedTabColor" Value="Green" />
<!--
<Setter Property="SelectedTabColor" Value="{StaticResource TabbedSelectedColor}" />
<Setter Property="BarBackgroundColor" Value="Green" />
-->
<Setter Property="SelectedTabColor" Value="Yellow" />
</Style>
<Style TargetType="StackLayout">
<Setter Property="BackgroundColor" Value="{StaticResource NavigationPageColor}" />
@@ -49,6 +61,14 @@
<Style TargetType="Entry">
<Setter Property="TextColor" Value="{StaticResource EntryTextColor}" />
</Style>
<!--
<Style TargetType="SearchBar">
<Setter Property="BackgroundColor" Value="{StaticResource SearchBarBackgroundColor}" />
<Setter Property="CancelButtonColor" Value="{StaticResource SearchBarCancelButtonColor}" />
<Setter Property="PlaceholderColor" Value="{StaticResource SearchBarPlaceholderColor}" />
<Setter Property="TextColor" Value="{StaticResource SearchBarTextColor}" />
</Style>
-->
</Application.Resources>
</Application>
-1
View File
@@ -13,7 +13,6 @@ namespace Mear
InitializeComponent();
MainPage = new Landing();
MainPage.SetValue(NavigationPage.BarBackgroundColorProperty, Color.Black);
MainPage.SetValue(NavigationPage.BarTextColorProperty, Color.White);
}
+1
View File
@@ -15,6 +15,7 @@
<PackageReference Include="Plugin.MediaManager" Version="0.6.7" />
<PackageReference Include="RestSharp" Version="106.6.9" />
<PackageReference Include="sqlite-net-pcl" Version="1.5.231" />
<PackageReference Include="UXDivers.GorillaPlayer.SDK" Version="1.5.2" />
<PackageReference Include="Xamarin.Forms" Version="4.0.0.482894" />
<PackageReference Include="Xamarin.Essentials" Version="1.1.0" />
</ItemGroup>
+1 -1
View File
@@ -31,7 +31,7 @@ namespace Mear.ViewModels
#region Methods
private void NotifyPropertyChanged(string propertyName)
protected void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
+131 -97
View File
@@ -13,117 +13,151 @@ using Mear.Repositories.Remote;
namespace Mear.ViewModels
{
public class SongViewModel : BaseViewModel
{
#region Fields
private ObservableCollection<Song> _songItems;
private Command _refreshSongs;
#endregion
public class SongViewModel : BaseViewModel
{
#region Fields
private ObservableCollection<Song> _songItems;
private Command _refreshSongs;
private Command _searchSongsCommand;
private string _searchedText;
#endregion
#region Properties
public ObservableCollection<Song> SongItems
{
get => _songItems;
set => _songItems = value;
}
#region Properties
public ObservableCollection<Song> 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<Song>();
_refreshSongs = new Command(async () => await PopulateSongsAsync());
#region Constructors
public SongViewModel()
{
_songItems = new ObservableCollection<Song>();
_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<Song>();
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<Song>();
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<Song> MergeSongs(List<Song> local, List<Song> 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<Song> MergeSongs(List<Song> local, List<Song> 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<Song>();
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<Song>();
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
}
}
+7 -1
View File
@@ -13,7 +13,13 @@
</ContentPage.BindingContext>
<StackLayout>
<ListView x:Name="SongListView"
<SearchBar x:Name="SearchSong"
Placeholder="Title, Artist"
SearchCommand="{Binding SearchSongsCommand}"
SearchCommandParameter="{Binding SearchedText, Source=x:Reference Search}"
Text="{Binding SerachedText, Mode=TwoWay}">
</SearchBar>
<ListView x:Name="SongListView"
ItemsSource="{Binding SongItems}"
VerticalOptions="FillAndExpand"
HasUnevenRows="False"