From 71abb3fcd8ad5348e9477aea7d7b33fa46a23703 Mon Sep 17 00:00:00 2001 From: Me on Windows Date: Sun, 4 Jul 2021 00:49:36 +0000 Subject: [PATCH] Hide context to the environment --- QuickPlay/Interfaces.cs | 5 +---- QuickPlay/MainActivity.cs | 2 +- QuickPlay/MpdMonitorService.cs | 1 + QuickPlay/MpdPlayer.cs | 11 +++-------- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/QuickPlay/Interfaces.cs b/QuickPlay/Interfaces.cs index 6c25806..1d0e079 100644 --- a/QuickPlay/Interfaces.cs +++ b/QuickPlay/Interfaces.cs @@ -25,11 +25,8 @@ namespace QuickPlay /// Since this operation can be asynchronous, we cannot put it in th /// constructor. And this allows for some tweaks before connecting. /// - /// - /// Context to run possible services from. - /// /// - Task ConnectAsync(Context context); + Task ConnectAsync(); } /// /// A simple dataclass to hold auxiliary data of the Playable objects. diff --git a/QuickPlay/MainActivity.cs b/QuickPlay/MainActivity.cs index 4420148..40d146c 100644 --- a/QuickPlay/MainActivity.cs +++ b/QuickPlay/MainActivity.cs @@ -40,7 +40,7 @@ namespace QuickPlay currentPlayer = playerConfig.GetPlayer(); try { - await currentPlayer.ConnectAsync(this); + await currentPlayer.ConnectAsync(); } catch (CannotConnectException e) { //TODO: View a toast with details and change some colors? diff --git a/QuickPlay/MpdMonitorService.cs b/QuickPlay/MpdMonitorService.cs index 6de4936..3075524 100644 --- a/QuickPlay/MpdMonitorService.cs +++ b/QuickPlay/MpdMonitorService.cs @@ -17,6 +17,7 @@ namespace QuickPlay public override void OnCreate() { base.OnCreate(); + // TODO: Create the watching thread } public override IBinder OnBind(Intent intent) { diff --git a/QuickPlay/MpdPlayer.cs b/QuickPlay/MpdPlayer.cs index b83bcb1..228710f 100644 --- a/QuickPlay/MpdPlayer.cs +++ b/QuickPlay/MpdPlayer.cs @@ -16,7 +16,6 @@ namespace QuickPlay class MpdPlayer: IPlayer { MpcCoreClient mpd; - Thread serviceThread; // MpcCore uses strings, so be it string mpdIP, mpdPort; @@ -49,7 +48,7 @@ namespace QuickPlay mpdPort = connDetails.Length >=2 ? connDetails[1] : "6600"; // XXX: Unneccessary default here... // Connecting and monitoring remote player is done in ConnectAsync. } - public async Task ConnectAsync(Context ctx) + public async Task ConnectAsync() { // Create a persistent connection var conn = new MpcCoreConnection(mpdIP, mpdPort); @@ -62,12 +61,8 @@ namespace QuickPlay throw new CannotConnectException("MPD connect failed", e); } // Start the monitoring service - Console.WriteLine("Hello! Will run thr."); - serviceThread = new Thread(() => - { - var intent = new Intent(ctx, typeof(MpdMonitorService)); - }); - Console.WriteLine("Thread possibly started"); + var ctx = Android.App.Application.Context; + var intent = new Intent(ctx, typeof(MpdMonitorService)); } } } \ No newline at end of file