WIP: Tweak configuration code to be more coherent and usable

It would still love to use reflection, but I am not learning that, at
least now.
develop
LEdoian 3 years ago
parent ed42e693a9
commit c9ce758cc6

@ -3,12 +3,14 @@ using System.IO;
namespace QuickPlay namespace QuickPlay
{ {
#pragma warning disable CS0659 // This is basically an almost-singleton, which will never be put in any hash table.
/// <summary> /// <summary>
/// Application (global) configuration data class /// Application (global) configuration data class
/// </summary> /// </summary>
[Serializable] [Serializable]
sealed class AppConfiguration sealed class AppConfiguration
{ {
// XXX: All the fields need to be checked in overriden Equals method
public readonly string playerConfigUrl; public readonly string playerConfigUrl;
public static AppConfiguration loadSavedConfiguration() public static AppConfiguration loadSavedConfiguration()
@ -25,7 +27,26 @@ namespace QuickPlay
var newConfig = AppConfiguration.loadSavedConfiguration(); var newConfig = AppConfiguration.loadSavedConfiguration();
if (this != newConfig) throw new InvalidDataException("Saved configuration is different from the supplied one."); if (this != newConfig) throw new InvalidDataException("Saved configuration is different from the supplied one.");
} }
public PlayerConfiguration GetPlayerConfig()
{
// TODO: decide sensibly
var cfgProvider = new CurlConfigurationProvider(playerConfigUrl);
return cfgProvider.GetConfiguration();
}
// We want to compare by values.
// It might actually be a bit more sensible to compare serialized
// versions of the objects, but that seems unneccessarily hard.
public override bool Equals(object obj)
{
var other = (AppConfiguration)obj;
// These fields have to match...
if (this.playerConfigUrl != other.playerConfigUrl) return false;
return true;
}
} }
#pragma warning restore CS0659
/// <summary> /// <summary>
/// Configuration of the player. /// Configuration of the player.
@ -38,6 +59,11 @@ namespace QuickPlay
{ {
return null; // FIXME: Implement return null; // FIXME: Implement
} }
public IPlayer GetPlayer()
{
throw new NotImplementedException();
}
} }
interface IPlayerConfigurationProvider interface IPlayerConfigurationProvider
@ -45,9 +71,14 @@ namespace QuickPlay
PlayerConfiguration GetConfiguration(); PlayerConfiguration GetConfiguration();
} }
sealed class NetworkConfigurationProvider : IPlayerConfigurationProvider sealed class CurlConfigurationProvider : IPlayerConfigurationProvider
{ {
PlayerConfiguration IPlayerConfigurationProvider.GetConfiguration() readonly string configUrl;
public CurlConfigurationProvider(string url)
{
configUrl = url;
}
public PlayerConfiguration GetConfiguration()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

@ -10,6 +10,7 @@ using Android.Widget;
//using Google.Android.Material.Snackbar; //using Google.Android.Material.Snackbar;
using Android.Support.V7.App; using Android.Support.V7.App;
using Toolbar = Android.Support.V7.Widget.Toolbar; using Toolbar = Android.Support.V7.Widget.Toolbar;
using GridLayoutManager = Android.Support.V7.Widget.GridLayoutManager;
using System.Net; using System.Net;
//using MpcNET; //using MpcNET;
@ -25,7 +26,8 @@ namespace QuickPlay
public class MainActivity : AppCompatActivity public class MainActivity : AppCompatActivity
{ {
private AppConfiguration appConfig; private AppConfiguration appConfig;
private List<PlayerConfiguration> playerConfigs; private Android.Support.V7.Widget.RecyclerView recyclerView;
private IPlayer currentPlayer;
protected override void OnCreate(Bundle savedInstanceState) protected override void OnCreate(Bundle savedInstanceState)
{ {
@ -33,8 +35,8 @@ namespace QuickPlay
// App initialization // App initialization
//appConfig = AppConfiguration.loadSavedConfiguration(); appConfig = AppConfiguration.loadSavedConfiguration();
//playerConfigs = acquirePlayerConfigs(); currentPlayer = appConfig.GetPlayerConfig().GetPlayer();
// UI initialization // UI initialization
SetContentView(Resource.Layout.activity_main); SetContentView(Resource.Layout.activity_main);
@ -47,6 +49,19 @@ namespace QuickPlay
// Hide the play bar by default // Hide the play bar by default
var bar = FindViewById(Resource.Id.currentSongBar); var bar = FindViewById(Resource.Id.currentSongBar);
bar.Visibility = ViewStates.Invisible; bar.Visibility = ViewStates.Invisible;
// Initialize the RecyclerView
// Since this is rather complicated, it is in a separate method
InitializeRecyclerView();
}
private void InitializeRecyclerView()
{
recyclerView = FindViewById<Android.Support.V7.Widget.RecyclerView>(Resource.Id.recyclerView1);
var adapter = new SongRecyclerAdapter(currentPlayer);
recyclerView.SetAdapter(adapter);
var layoutManager = new GridLayoutManager(this, 2, GridLayoutManager.Vertical, false);
recyclerView.SetLayoutManager(layoutManager);
} }
public override bool OnCreateOptionsMenu(IMenu menu) public override bool OnCreateOptionsMenu(IMenu menu)
@ -72,16 +87,5 @@ namespace QuickPlay
} }
return base.OnOptionsItemSelected(item); return base.OnOptionsItemSelected(item);
} }
List<PlayerConfiguration> acquirePlayerConfigs()
{
// FIXME: Bad! We have IPlayerConfigurationProviders
///var url = appConfig.playerConfigUrl;
// TODO: Learn cURL and get configs :-)
return null;
throw new NotImplementedException();
}
} }
} }

@ -72,6 +72,7 @@
<Compile Include="MainActivity.cs" /> <Compile Include="MainActivity.cs" />
<Compile Include="Resources\Resource.designer.cs" /> <Compile Include="Resources\Resource.designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SongRecycler.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="Resources\AboutResources.txt" /> <None Include="Resources\AboutResources.txt" />

@ -0,0 +1,50 @@
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Support.V7.Widget;
using Android.Views;
using Android.Widget;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace QuickPlay
{
class SongRecyclerAdapter : Android.Support.V7.Widget.RecyclerView.Adapter
{
public SongRecyclerAdapter(IPlayer player)
{
throw new NotImplementedException();
}
public override int ItemCount
{
get
{
throw new NotImplementedException();
}
}
public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
{
throw new NotImplementedException();
}
public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
throw new NotImplementedException();
}
public SongRecyclerAdapter(int TODO)
{
}
}
class SongRecyclerViewHolder : Android.Support.V7.Widget.RecyclerView.ViewHolder
{
public SongRecyclerViewHolder(View itemView) : base(itemView)
{
throw new NotImplementedException();
}
}
}
Loading…
Cancel
Save