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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d"
|
||||
x:Class="Mear.Views.AlbumView">
|
||||
<ContentPage.Content>
|
||||
<StackLayout>
|
||||
<Label Text="Album view!" />
|
||||
</StackLayout>
|
||||
</ContentPage.Content>
|
||||
x:Class="Mear.Views.AlbumView"
|
||||
xmlns:vm="clr-namespace:Mear.ViewModels"
|
||||
Title="{Binding Title}">
|
||||
|
||||
<ContentPage.BindingContext>
|
||||
<vm:AlbumViewModel />
|
||||
</ContentPage.BindingContext>
|
||||
<StackLayout>
|
||||
<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>
|
||||
</ContentPage>
|
||||
@@ -7,14 +7,38 @@ using System.Threading.Tasks;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
using Mear.ViewModels;
|
||||
|
||||
namespace Mear.Views
|
||||
{
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class AlbumView : ContentPage
|
||||
{
|
||||
#region Fields
|
||||
private AlbumViewModel _viewModel;
|
||||
#endregion
|
||||
|
||||
|
||||
#region Properties
|
||||
#endregion
|
||||
|
||||
|
||||
#region Constructors
|
||||
public AlbumView()
|
||||
{
|
||||
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"
|
||||
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>
|
||||
<NavigationPage Title="Songs">
|
||||
<NavigationPage.Icon>
|
||||
|
||||
@@ -32,6 +32,16 @@ namespace Mear.Views
|
||||
|
||||
|
||||
#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
|
||||
public void TokenTest()
|
||||
{
|
||||
|
||||
@@ -18,11 +18,12 @@
|
||||
VerticalOptions="FillAndExpand"
|
||||
HasUnevenRows="False"
|
||||
IsPullToRefreshEnabled="True"
|
||||
RowHeight="75"
|
||||
RefreshCommand="{Binding RefreshSongs}"
|
||||
ItemSelected="SongListView_ItemSelected" >
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ViewCell Height="150">
|
||||
<ViewCell>
|
||||
<Grid MinimumHeightRequest="100" Padding="5">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
@@ -36,20 +37,21 @@
|
||||
<Label Text="{Binding Title}"
|
||||
d:Text="{Binding .}"
|
||||
LineBreakMode="NoWrap"
|
||||
FontSize="15" />
|
||||
FontSize="16" />
|
||||
<Label Text="{Binding Artist}"
|
||||
d:Text="{Binding .}"
|
||||
LineBreakMode="NoWrap"
|
||||
FontSize="15" />
|
||||
FontSize="14" />
|
||||
</StackLayout>
|
||||
<ImageButton x:Name="SongOptions"
|
||||
Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
HorizontalOptions="End"
|
||||
VerticalOptions="Center"
|
||||
HeightRequest="10"
|
||||
HeightRequest="50"
|
||||
WidthRequest="80"
|
||||
Source="Search.png"
|
||||
BackgroundColor="Transparent"
|
||||
Source="XamarinLogo.png"
|
||||
CommandParameter="{Binding Id}"
|
||||
Clicked="SongOptions_Clicked" />
|
||||
</Grid>
|
||||
|
||||
Reference in New Issue
Block a user