From e0de184cc85413815af261dfdaac971b7b120f75 Mon Sep 17 00:00:00 2001 From: amazing-username Date: Fri, 31 May 2019 20:33:14 -0400 Subject: [PATCH] Added Song DB repository but functionality is not fully implemented. Working on the song player view. --- Mear/Mear/Mear.csproj | 3 + Mear/Mear/Models/Song.cs | 7 +- Mear/Mear/Playback/MearPlayer.cs | 3 +- .../Repositories/Database/DBSongRepository.cs | 84 +++++++++++++++++++ Mear/Mear/Views/MearPlayerView.xaml | 51 +++++++++++ Mear/Mear/Views/MearPlayerView.xaml.cs | 35 ++++++++ Mear/Mear/Views/SongView.xaml.cs | 1 + 7 files changed, 182 insertions(+), 2 deletions(-) create mode 100644 Mear/Mear/Repositories/Database/DBSongRepository.cs create mode 100644 Mear/Mear/Views/MearPlayerView.xaml create mode 100644 Mear/Mear/Views/MearPlayerView.xaml.cs diff --git a/Mear/Mear/Mear.csproj b/Mear/Mear/Mear.csproj index 2bddbb3..0bd109c 100644 --- a/Mear/Mear/Mear.csproj +++ b/Mear/Mear/Mear.csproj @@ -38,6 +38,9 @@ MSBuild:UpdateDesignTimeXaml + + MSBuild:UpdateDesignTimeXaml + MSBuild:UpdateDesignTimeXaml diff --git a/Mear/Mear/Models/Song.cs b/Mear/Mear/Models/Song.cs index f96ea4c..2b6c2cc 100644 --- a/Mear/Mear/Models/Song.cs +++ b/Mear/Mear/Models/Song.cs @@ -1,13 +1,18 @@ using System; using System.Collections.Generic; +using System.Runtime.Serialization; using System.Text; using Newtonsoft.Json; +using SQLite; namespace Mear.Models { + [DataContract] + [Table("Song")] public class Song { + [PrimaryKey, Column("Id"), AutoIncrement] [JsonProperty("id")] public int Id { get; set; } [JsonProperty("title")] @@ -24,7 +29,7 @@ namespace Mear.Models public int? Duration { get; set; } [JsonProperty("filename")] public string Filename { get; set; } - [JsonProperty("song_path")] + [JsonIgnore] public string SongPath { set; get; } } } diff --git a/Mear/Mear/Playback/MearPlayer.cs b/Mear/Mear/Playback/MearPlayer.cs index 6507ca3..be40a58 100644 --- a/Mear/Mear/Playback/MearPlayer.cs +++ b/Mear/Mear/Playback/MearPlayer.cs @@ -55,7 +55,8 @@ namespace Mear.Playback var response = client.DownloadData(request); await CrossMediaManager.Current.Play(tmpFile); - var title = CrossMediaManager.Current.MediaQueue.Title; + var title = CrossMediaManager.Current.MediaQueue.Current.Title; + var ttl = CrossMediaManager.Current.MediaQueue.Title; } } catch (Exception ex) diff --git a/Mear/Mear/Repositories/Database/DBSongRepository.cs b/Mear/Mear/Repositories/Database/DBSongRepository.cs new file mode 100644 index 0000000..088ce53 --- /dev/null +++ b/Mear/Mear/Repositories/Database/DBSongRepository.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using SQLite; + +using Mear.Constants.App; +using Mear.Models; + +namespace Mear.Repositories.Database +{ + public class DBSongRepository : DBRepository + { + #region Fields + #endregion + + + #region Properties + #endregion + + + #region Constructors + public DBSongRepository() + { + Initialize(); + } + #endregion + + + #region Methods + public Song RetrieveSong(int id) + { + try + { + var song = _Db.Table().Where(s => s.Id == id).First(); + + return song; + } + catch (Exception ex) + { + var msg = ex.Message; + } + + return null; + } + public Song RetrieveSong(string artist, string title) + { + try + { + var song = _Db.Table().Where(s => + (s.Artist.Equals(artist) && s.Title.Equals(title))).First(); + + return song; + } + catch (Exception ex) + { + var msg = ex.Message; + } + + return null; + } + + public void SaveSong(Song song) + { + if (!DoesTableExist("Song")) + { + _Db.CreateTable(); + } + + _Db.Insert(song); + } + public void UpdateSong(Song song) + { + if (!DoesTableExist("Song")) + { + return; + } + + // TODO: Implement functionality for udpating song + } + #endregion + } +} diff --git a/Mear/Mear/Views/MearPlayerView.xaml b/Mear/Mear/Views/MearPlayerView.xaml new file mode 100644 index 0000000..58b9394 --- /dev/null +++ b/Mear/Mear/Views/MearPlayerView.xaml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + +