Added option menu for the music library, skeleton Album view, added album repository
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Mear.Models
|
||||||
|
{
|
||||||
|
public class Album
|
||||||
|
{
|
||||||
|
[JsonProperty("id")]
|
||||||
|
public int Id { get; set; }
|
||||||
|
[JsonProperty("title")]
|
||||||
|
public string Title { get; set; }
|
||||||
|
[JsonProperty("album_artist")]
|
||||||
|
public string AlbumArtist { get; set; }
|
||||||
|
[JsonProperty("song_count")]
|
||||||
|
public int SongCount { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using RestSharp;
|
||||||
|
|
||||||
|
using Mear.Constants.API;
|
||||||
|
using Mear.Models;
|
||||||
|
using Mear.Repositories.Database;
|
||||||
|
|
||||||
|
namespace Mear.Repositories.Remote
|
||||||
|
{
|
||||||
|
public class RemoteAlbumRepository
|
||||||
|
{
|
||||||
|
#region Fields
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Properties
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
public List<Album> RetrieveAlbums()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var client = new RestClient(API.ApiUrl);
|
||||||
|
var apiEndpoint = $@"api/{API.APIVersion}/album";
|
||||||
|
var request = new RestRequest(apiEndpoint, Method.GET);
|
||||||
|
|
||||||
|
var tkRepo = new DBTokenRepository();
|
||||||
|
var token = tkRepo.RetrieveToken();
|
||||||
|
request.AddHeader("Authorization", $"Bearer {token.AccessToken}");
|
||||||
|
|
||||||
|
var reponse = client.Execute(request);
|
||||||
|
|
||||||
|
var albums = JsonConvert.DeserializeObject<List<Album>>(reponse.Content);
|
||||||
|
|
||||||
|
return albums;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
var msg = ex.Message;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using Xamarin.Forms;
|
||||||
|
|
||||||
|
using Mear.Models;
|
||||||
|
using Mear.Repositories.Remote;
|
||||||
|
|
||||||
|
namespace Mear.ViewModels
|
||||||
|
{
|
||||||
|
public class AlbumViewModel : BaseViewModel
|
||||||
|
{
|
||||||
|
#region Fields
|
||||||
|
private ObservableCollection<Album> _albumItems;
|
||||||
|
private Command _refreshAlbums;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Properties
|
||||||
|
public ObservableCollection<Album> AlbumItems
|
||||||
|
{
|
||||||
|
get => _albumItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Command RefreshAlbums
|
||||||
|
{
|
||||||
|
get => _refreshAlbums;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
public AlbumViewModel()
|
||||||
|
{
|
||||||
|
_albumItems = new ObservableCollection<Album>();
|
||||||
|
_refreshAlbums = new Command(async () => await PopulateAlbumsAsync());
|
||||||
|
|
||||||
|
PopulateAlbumsAsync();
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
private async Task PopulateAlbumsAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var albumRepo = new RemoteAlbumRepository();
|
||||||
|
var albums = albumRepo.RetrieveAlbums().OrderBy(a => a.Title).ToList();
|
||||||
|
|
||||||
|
_albumItems.Clear();
|
||||||
|
|
||||||
|
foreach (var album in albums)
|
||||||
|
{
|
||||||
|
_albumItems.Add(album);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
var msg = ex.Message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Mear.ViewModels
|
||||||
|
{
|
||||||
|
public class ArtistViewModel : BaseViewModel
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,10 +4,48 @@
|
|||||||
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
|
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
x:Class="Mear.Views.AlbumView">
|
x:Class="Mear.Views.AlbumView"
|
||||||
<ContentPage.Content>
|
xmlns:vm="clr-namespace:Mear.ViewModels"
|
||||||
|
Title="{Binding Title}">
|
||||||
|
|
||||||
|
<ContentPage.BindingContext>
|
||||||
|
<vm:AlbumViewModel />
|
||||||
|
</ContentPage.BindingContext>
|
||||||
<StackLayout>
|
<StackLayout>
|
||||||
<Label Text="Album view!" />
|
<ListView x:Name="AlbumListView"
|
||||||
|
ItemsSource="{Binding AlbumItems}"
|
||||||
|
VerticalOptions="FillAndExpand"
|
||||||
|
HasUnevenRows="False"
|
||||||
|
IsPullToRefreshEnabled="True"
|
||||||
|
RowHeight="80"
|
||||||
|
RefreshCommand="{Binding RefreshAlbums}"
|
||||||
|
ItemSelected="AlbumListView_ItemSelected" >
|
||||||
|
<ListView.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<ViewCell>
|
||||||
|
<Grid Padding="5">
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="Auto" />
|
||||||
|
<ColumnDefinition Width="Auto" />
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
|
<StackLayout Grid.Row="0" Grid.Column="0">
|
||||||
|
<Label Text="{Binding Title}"
|
||||||
|
d:Text="{Binding .}"
|
||||||
|
LineBreakMode="NoWrap"
|
||||||
|
FontSize="16" />
|
||||||
|
<Label Text="{Binding AlbumArtist}"
|
||||||
|
d:Text="{Binding .}"
|
||||||
|
LineBreakMode="NoWrap"
|
||||||
|
FontSize="14" />
|
||||||
|
</StackLayout>
|
||||||
|
</Grid>
|
||||||
|
</ViewCell>
|
||||||
|
</DataTemplate>
|
||||||
|
</ListView.ItemTemplate>
|
||||||
|
</ListView>
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
</ContentPage.Content>
|
|
||||||
</ContentPage>
|
</ContentPage>
|
||||||
@@ -7,14 +7,38 @@ using System.Threading.Tasks;
|
|||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
using Xamarin.Forms.Xaml;
|
using Xamarin.Forms.Xaml;
|
||||||
|
|
||||||
|
using Mear.ViewModels;
|
||||||
|
|
||||||
namespace Mear.Views
|
namespace Mear.Views
|
||||||
{
|
{
|
||||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||||
public partial class AlbumView : ContentPage
|
public partial class AlbumView : ContentPage
|
||||||
{
|
{
|
||||||
|
#region Fields
|
||||||
|
private AlbumViewModel _viewModel;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Properties
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
public AlbumView()
|
public AlbumView()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
BindingContext = _viewModel = new AlbumViewModel();
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
#region Events
|
||||||
|
private void AlbumListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,11 @@
|
|||||||
xmlns:views="clr-namespace:Mear.Views"
|
xmlns:views="clr-namespace:Mear.Views"
|
||||||
x:Class="Mear.Views.MusicLibrary">
|
x:Class="Mear.Views.MusicLibrary">
|
||||||
|
|
||||||
|
<TabbedPage.ToolbarItems>
|
||||||
|
<ToolbarItem Name="Options" Order="Secondary" Priority="1" Clicked="Options_Clicked" />
|
||||||
|
<ToolbarItem Name="Settings" Order="Secondary" Priority="2" Clicked="Settings_Clicked" />
|
||||||
|
</TabbedPage.ToolbarItems>
|
||||||
|
|
||||||
<TabbedPage.Children>
|
<TabbedPage.Children>
|
||||||
<NavigationPage Title="Songs">
|
<NavigationPage Title="Songs">
|
||||||
<NavigationPage.Icon>
|
<NavigationPage.Icon>
|
||||||
|
|||||||
@@ -32,6 +32,16 @@ namespace Mear.Views
|
|||||||
|
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
#region Events
|
||||||
|
private void Options_Clicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var i = 0;
|
||||||
|
}
|
||||||
|
private void Settings_Clicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Test
|
#region Test
|
||||||
public void TokenTest()
|
public void TokenTest()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,11 +18,12 @@
|
|||||||
VerticalOptions="FillAndExpand"
|
VerticalOptions="FillAndExpand"
|
||||||
HasUnevenRows="False"
|
HasUnevenRows="False"
|
||||||
IsPullToRefreshEnabled="True"
|
IsPullToRefreshEnabled="True"
|
||||||
|
RowHeight="75"
|
||||||
RefreshCommand="{Binding RefreshSongs}"
|
RefreshCommand="{Binding RefreshSongs}"
|
||||||
ItemSelected="SongListView_ItemSelected" >
|
ItemSelected="SongListView_ItemSelected" >
|
||||||
<ListView.ItemTemplate>
|
<ListView.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<ViewCell Height="150">
|
<ViewCell>
|
||||||
<Grid MinimumHeightRequest="100" Padding="5">
|
<Grid MinimumHeightRequest="100" Padding="5">
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
@@ -36,20 +37,21 @@
|
|||||||
<Label Text="{Binding Title}"
|
<Label Text="{Binding Title}"
|
||||||
d:Text="{Binding .}"
|
d:Text="{Binding .}"
|
||||||
LineBreakMode="NoWrap"
|
LineBreakMode="NoWrap"
|
||||||
FontSize="15" />
|
FontSize="16" />
|
||||||
<Label Text="{Binding Artist}"
|
<Label Text="{Binding Artist}"
|
||||||
d:Text="{Binding .}"
|
d:Text="{Binding .}"
|
||||||
LineBreakMode="NoWrap"
|
LineBreakMode="NoWrap"
|
||||||
FontSize="15" />
|
FontSize="14" />
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
<ImageButton x:Name="SongOptions"
|
<ImageButton x:Name="SongOptions"
|
||||||
Grid.Row="0"
|
Grid.Row="0"
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
HorizontalOptions="End"
|
HorizontalOptions="End"
|
||||||
VerticalOptions="Center"
|
VerticalOptions="Center"
|
||||||
HeightRequest="10"
|
HeightRequest="50"
|
||||||
WidthRequest="80"
|
WidthRequest="80"
|
||||||
Source="Search.png"
|
BackgroundColor="Transparent"
|
||||||
|
Source="XamarinLogo.png"
|
||||||
CommandParameter="{Binding Id}"
|
CommandParameter="{Binding Id}"
|
||||||
Clicked="SongOptions_Clicked" />
|
Clicked="SongOptions_Clicked" />
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
Reference in New Issue
Block a user