From c9ce758cc6a621a49f27831e0609ef78b464c86b Mon Sep 17 00:00:00 2001 From: Me on Windows Date: Fri, 18 Jun 2021 16:16:36 +0000 Subject: [PATCH] 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. --- QuickPlay/Configuration.cs | 35 ++++++++++++++++++++++++-- QuickPlay/MainActivity.cs | 32 +++++++++++++----------- QuickPlay/QuickPlay.csproj | 1 + QuickPlay/SongRecycler.cs | 50 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 16 deletions(-) create mode 100644 QuickPlay/SongRecycler.cs diff --git a/QuickPlay/Configuration.cs b/QuickPlay/Configuration.cs index 16771e0..610f528 100644 --- a/QuickPlay/Configuration.cs +++ b/QuickPlay/Configuration.cs @@ -3,12 +3,14 @@ using System.IO; namespace QuickPlay { +#pragma warning disable CS0659 // This is basically an almost-singleton, which will never be put in any hash table. /// /// Application (global) configuration data class /// [Serializable] sealed class AppConfiguration { + // XXX: All the fields need to be checked in overriden Equals method public readonly string playerConfigUrl; public static AppConfiguration loadSavedConfiguration() @@ -25,7 +27,26 @@ namespace QuickPlay var newConfig = AppConfiguration.loadSavedConfiguration(); 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 /// /// Configuration of the player. @@ -38,6 +59,11 @@ namespace QuickPlay { return null; // FIXME: Implement } + + public IPlayer GetPlayer() + { + throw new NotImplementedException(); + } } interface IPlayerConfigurationProvider @@ -45,9 +71,14 @@ namespace QuickPlay 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(); } diff --git a/QuickPlay/MainActivity.cs b/QuickPlay/MainActivity.cs index 7e8ac12..406d40d 100644 --- a/QuickPlay/MainActivity.cs +++ b/QuickPlay/MainActivity.cs @@ -10,6 +10,7 @@ using Android.Widget; //using Google.Android.Material.Snackbar; using Android.Support.V7.App; using Toolbar = Android.Support.V7.Widget.Toolbar; +using GridLayoutManager = Android.Support.V7.Widget.GridLayoutManager; using System.Net; //using MpcNET; @@ -25,7 +26,8 @@ namespace QuickPlay public class MainActivity : AppCompatActivity { private AppConfiguration appConfig; - private List playerConfigs; + private Android.Support.V7.Widget.RecyclerView recyclerView; + private IPlayer currentPlayer; protected override void OnCreate(Bundle savedInstanceState) { @@ -33,8 +35,8 @@ namespace QuickPlay // App initialization - //appConfig = AppConfiguration.loadSavedConfiguration(); - //playerConfigs = acquirePlayerConfigs(); + appConfig = AppConfiguration.loadSavedConfiguration(); + currentPlayer = appConfig.GetPlayerConfig().GetPlayer(); // UI initialization SetContentView(Resource.Layout.activity_main); @@ -47,6 +49,19 @@ namespace QuickPlay // Hide the play bar by default var bar = FindViewById(Resource.Id.currentSongBar); bar.Visibility = ViewStates.Invisible; + + // Initialize the RecyclerView + // Since this is rather complicated, it is in a separate method + InitializeRecyclerView(); + } + + private void InitializeRecyclerView() + { + recyclerView = FindViewById(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) @@ -72,16 +87,5 @@ namespace QuickPlay } return base.OnOptionsItemSelected(item); } - - List acquirePlayerConfigs() - { - // FIXME: Bad! We have IPlayerConfigurationProviders - ///var url = appConfig.playerConfigUrl; - // TODO: Learn cURL and get configs :-) - - return null; - throw new NotImplementedException(); - } - } } diff --git a/QuickPlay/QuickPlay.csproj b/QuickPlay/QuickPlay.csproj index 0894629..cca639b 100644 --- a/QuickPlay/QuickPlay.csproj +++ b/QuickPlay/QuickPlay.csproj @@ -72,6 +72,7 @@ + diff --git a/QuickPlay/SongRecycler.cs b/QuickPlay/SongRecycler.cs new file mode 100644 index 0000000..334e791 --- /dev/null +++ b/QuickPlay/SongRecycler.cs @@ -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(); + } + } +} \ No newline at end of file