Implement a PoC of the recycler view

develop
LEdoian 3 years ago
parent 35c4937632
commit cda69227eb

@ -49,13 +49,9 @@ namespace QuickPlay
string Identifier { get; } string Identifier { get; }
PlayableMetadata Metadata { get; } PlayableMetadata Metadata { get; }
} }
interface ILayout
{
// TODO
}
interface ILayoutStrategy interface ILayoutStrategy
{ {
ILayout LayOut(ICollection<IPlayable> playables); List<IPlayable> LayOut(ICollection<IPlayable> playables);
} }
public class CannotConnectException: Exception public class CannotConnectException: Exception

@ -0,0 +1,21 @@
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using System;
using System.Collections.Generic;
namespace QuickPlay
{
class LexicographicLayoutStrategy : ILayoutStrategy
{
public List<IPlayable> LayOut(ICollection<IPlayable> playables)
{
List<IPlayable> list = new List<IPlayable>(playables);
list.Sort((IPlayable x, IPlayable y) => x.Identifier.CompareTo(y.Identifier));
return list;
}
}
}

@ -44,7 +44,6 @@ namespace QuickPlay
} catch (CannotConnectException e) } catch (CannotConnectException e)
{ {
//TODO: View a toast with details and change some colors? //TODO: View a toast with details and change some colors?
Console.WriteLine("This is bad.");
var t = Toast.MakeText(this, e.Message + ": " + e.InnerException.Message ?? "", ToastLength.Long); var t = Toast.MakeText(this, e.Message + ": " + e.InnerException.Message ?? "", ToastLength.Long);
t.Show(); t.Show();
} }
@ -69,7 +68,8 @@ namespace QuickPlay
private void InitializeRecyclerView() private void InitializeRecyclerView()
{ {
recyclerView = FindViewById<Android.Support.V7.Widget.RecyclerView>(Resource.Id.recyclerView1); recyclerView = FindViewById<Android.Support.V7.Widget.RecyclerView>(Resource.Id.recyclerView1);
var adapter = new SongRecyclerAdapter(currentPlayer); var layoutStrategy = new LexicographicLayoutStrategy();
var adapter = new SongRecyclerAdapter(currentPlayer, layoutStrategy);
recyclerView.SetAdapter(adapter); recyclerView.SetAdapter(adapter);
var layoutManager = new GridLayoutManager(this, 2, GridLayoutManager.Vertical, false); var layoutManager = new GridLayoutManager(this, 2, GridLayoutManager.Vertical, false);
recyclerView.SetLayoutManager(layoutManager); recyclerView.SetLayoutManager(layoutManager);

@ -71,6 +71,7 @@
<Compile Include="Configuration.cs" /> <Compile Include="Configuration.cs" />
<Compile Include="IniParser.cs" /> <Compile Include="IniParser.cs" />
<Compile Include="Interfaces.cs" /> <Compile Include="Interfaces.cs" />
<Compile Include="LayoutStrategies.cs" />
<Compile Include="MpdMonitorService.cs" /> <Compile Include="MpdMonitorService.cs" />
<Compile Include="MainActivity.cs" /> <Compile Include="MainActivity.cs" />
<Compile Include="MpdPlayer.cs" /> <Compile Include="MpdPlayer.cs" />
@ -221,6 +222,11 @@
<ItemGroup> <ItemGroup>
<AndroidResource Include="Resources\layout\commonTopBar.axml" /> <AndroidResource Include="Resources\layout\commonTopBar.axml" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\layout\songLayout.xml">
<SubType>Designer</SubType>
</AndroidResource>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" /> <Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

@ -3091,8 +3091,8 @@ namespace QuickPlay
// aapt resource value: 0x7f0900be // aapt resource value: 0x7f0900be
public const int action_divider = 2131296446; public const int action_divider = 2131296446;
// aapt resource value: 0x7f0900c4 // aapt resource value: 0x7f0900c5
public const int action_edit = 2131296452; public const int action_edit = 2131296453;
// aapt resource value: 0x7f0900b4 // aapt resource value: 0x7f0900b4
public const int action_image = 2131296436; public const int action_image = 2131296436;
@ -3112,8 +3112,8 @@ namespace QuickPlay
// aapt resource value: 0x7f09006b // aapt resource value: 0x7f09006b
public const int action_mode_close_button = 2131296363; public const int action_mode_close_button = 2131296363;
// aapt resource value: 0x7f0900c3 // aapt resource value: 0x7f0900c4
public const int action_settings = 2131296451; public const int action_settings = 2131296452;
// aapt resource value: 0x7f0900b5 // aapt resource value: 0x7f0900b5
public const int action_text = 2131296437; public const int action_text = 2131296437;
@ -3331,8 +3331,8 @@ namespace QuickPlay
// aapt resource value: 0x7f090070 // aapt resource value: 0x7f090070
public const int list_item = 2131296368; public const int list_item = 2131296368;
// aapt resource value: 0x7f0900c2 // aapt resource value: 0x7f0900c3
public const int masked = 2131296450; public const int masked = 2131296451;
// aapt resource value: 0x7f09009c // aapt resource value: 0x7f09009c
public const int message = 2131296412; public const int message = 2131296412;
@ -3502,6 +3502,9 @@ namespace QuickPlay
// aapt resource value: 0x7f09004b // aapt resource value: 0x7f09004b
public const int snapMargins = 2131296331; public const int snapMargins = 2131296331;
// aapt resource value: 0x7f0900c1
public const int songName = 2131296449;
// aapt resource value: 0x7f090073 // aapt resource value: 0x7f090073
public const int spacer = 2131296371; public const int spacer = 2131296371;
@ -3625,8 +3628,8 @@ namespace QuickPlay
// aapt resource value: 0x7f09001b // aapt resource value: 0x7f09001b
public const int view_offset_helper = 2131296283; public const int view_offset_helper = 2131296283;
// aapt resource value: 0x7f0900c1 // aapt resource value: 0x7f0900c2
public const int visible = 2131296449; public const int visible = 2131296450;
// aapt resource value: 0x7f090043 // aapt resource value: 0x7f090043
public const int withText = 2131296323; public const int withText = 2131296323;
@ -3896,7 +3899,10 @@ namespace QuickPlay
public const int select_dialog_singlechoice_material = 2130968630; public const int select_dialog_singlechoice_material = 2130968630;
// aapt resource value: 0x7f040037 // aapt resource value: 0x7f040037
public const int support_simple_spinner_dropdown_item = 2130968631; public const int songLayout = 2130968631;
// aapt resource value: 0x7f040038
public const int support_simple_spinner_dropdown_item = 2130968632;
static Layout() static Layout()
{ {

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- I am going to assume that the match_parent width respects the two-column layout. -->
<!-- The CardView just adds some beauty -->
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardElevation="4dp"
app:cardUseCompatPadding="true"
app:cardCornerRadius="5dp"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:text="Song Name"
android:id="@+id/songName"
/>
</android.support.v7.widget.CardView>
</FrameLayout>

@ -14,9 +14,11 @@ namespace QuickPlay
class SongRecyclerAdapter : Android.Support.V7.Widget.RecyclerView.Adapter class SongRecyclerAdapter : Android.Support.V7.Widget.RecyclerView.Adapter
{ {
IPlayer player; IPlayer player;
public SongRecyclerAdapter(IPlayer player) ILayoutStrategy layoutStrategy;
public SongRecyclerAdapter(IPlayer player, ILayoutStrategy layoutStrategy)
{ {
this.player = player; this.player = player;
this.layoutStrategy = layoutStrategy;
} }
public override int ItemCount public override int ItemCount
{ {
@ -27,18 +29,23 @@ namespace QuickPlay
} }
public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
{ {
throw new NotImplementedException(); // I admit I have little idea what I am doing.
View itemView = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.songLayout, parent, false);
return new SongRecyclerViewHolder(itemView);
} }
public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position) public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{ {
throw new NotImplementedException(); SongRecyclerViewHolder vh = (SongRecyclerViewHolder)holder;
List<IPlayable> layout = layoutStrategy.LayOut(player.Songs.Values);
vh.SongName.Text = layout[position].Identifier;
} }
} }
class SongRecyclerViewHolder : Android.Support.V7.Widget.RecyclerView.ViewHolder class SongRecyclerViewHolder : Android.Support.V7.Widget.RecyclerView.ViewHolder
{ {
public TextView SongName { get; private set; }
public SongRecyclerViewHolder(View itemView) : base(itemView) public SongRecyclerViewHolder(View itemView) : base(itemView)
{ {
throw new NotImplementedException(); SongName = itemView.FindViewById<TextView>(Resource.Id.songName);
} }
} }
} }
Loading…
Cancel
Save