From d5d9caca7a260b576733347c93b7f5d369a7e31b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sven-Michael=20St=C3=BCbe?= Date: Thu, 12 May 2016 15:38:45 +0200 Subject: [PATCH] Added adapter to IBluetoothLE --- .build/Plugin.BLE.nuspec | 2 +- Source/MvvmCross.Plugins.BLE.Droid/Plugin.cs | 5 +++-- Source/MvvmCross.Plugins.BLE.iOS/Plugin.cs | 5 +++-- Source/Plugin.BLE.Abstractions/Contracts/IBluetoothLE.cs | 2 +- Source/Plugin.BLE.Android/BleImplementation.cs | 4 ++++ Source/Plugin.BLE.iOS/BleImplementation.cs | 4 ++++ Source/Plugin.BLE/CrossBle.cs | 4 ++-- 7 files changed, 18 insertions(+), 8 deletions(-) diff --git a/.build/Plugin.BLE.nuspec b/.build/Plugin.BLE.nuspec index 07e59f1e..19a376b7 100644 --- a/.build/Plugin.BLE.nuspec +++ b/.build/Plugin.BLE.nuspec @@ -1,6 +1,6 @@ - Xam.Plugin.BLE + Plugin.BLE 0.9.4 BLE Plugin for Xamarin xabre, smstube diff --git a/Source/MvvmCross.Plugins.BLE.Droid/Plugin.cs b/Source/MvvmCross.Plugins.BLE.Droid/Plugin.cs index 35755975..119ad9ee 100644 --- a/Source/MvvmCross.Plugins.BLE.Droid/Plugin.cs +++ b/Source/MvvmCross.Plugins.BLE.Droid/Plugin.cs @@ -1,8 +1,8 @@ using MvvmCross.Platform; using MvvmCross.Platform.Plugins; +using Plugin.BLE; using Plugin.BLE.Abstractions; using Plugin.BLE.Abstractions.Contracts; -using Plugin.BLE.Android; namespace MvvmCross.Plugins.BLE.Droid { @@ -15,7 +15,8 @@ public Plugin() } public void Load() { - Mvx.LazyConstructAndRegisterSingleton(() => new Adapter()); + Mvx.LazyConstructAndRegisterSingleton(() => CrossBle.Current); + Mvx.LazyConstructAndRegisterSingleton(() => Mvx.Resolve().Adapter); } } } \ No newline at end of file diff --git a/Source/MvvmCross.Plugins.BLE.iOS/Plugin.cs b/Source/MvvmCross.Plugins.BLE.iOS/Plugin.cs index 474586f3..443b68e8 100644 --- a/Source/MvvmCross.Plugins.BLE.iOS/Plugin.cs +++ b/Source/MvvmCross.Plugins.BLE.iOS/Plugin.cs @@ -1,8 +1,8 @@ using MvvmCross.Platform; using MvvmCross.Platform.Plugins; +using Plugin.BLE; using Plugin.BLE.Abstractions; using Plugin.BLE.Abstractions.Contracts; -using Plugin.BLE.iOS; namespace MvvmCross.Plugins.BLE.iOS { @@ -18,7 +18,8 @@ public Plugin() public void Load() { Mvx.Trace("Loading BT plugin"); - Mvx.RegisterSingleton(new Adapter()); + Mvx.LazyConstructAndRegisterSingleton(() => CrossBle.Current); + Mvx.LazyConstructAndRegisterSingleton(() => Mvx.Resolve().Adapter); } } } \ No newline at end of file diff --git a/Source/Plugin.BLE.Abstractions/Contracts/IBluetoothLE.cs b/Source/Plugin.BLE.Abstractions/Contracts/IBluetoothLE.cs index f14c1aa0..2f97b4bb 100644 --- a/Source/Plugin.BLE.Abstractions/Contracts/IBluetoothLE.cs +++ b/Source/Plugin.BLE.Abstractions/Contracts/IBluetoothLE.cs @@ -2,7 +2,7 @@ namespace Plugin.BLE.Abstractions.Contracts { public interface IBluetoothLE { - // TODO: IAdapter + IAdapter Adapter { get; } // TODO: Activate // TODO: Get some information like version (if possible), ... } diff --git a/Source/Plugin.BLE.Android/BleImplementation.cs b/Source/Plugin.BLE.Android/BleImplementation.cs index 30f2a0fb..7800df7b 100644 --- a/Source/Plugin.BLE.Android/BleImplementation.cs +++ b/Source/Plugin.BLE.Android/BleImplementation.cs @@ -1,12 +1,16 @@ using System; using Plugin.BLE.Abstractions; using Plugin.BLE.Abstractions.Contracts; +using Plugin.BLE.Android; // ReSharper disable once CheckNamespace namespace Plugin.BLE { internal class BleImplementation : IBluetoothLE { + private readonly Lazy _adapter = new Lazy(() => new Adapter(), System.Threading.LazyThreadSafetyMode.PublicationOnly); + public IAdapter Adapter => _adapter.Value; + public BleImplementation() { Trace.TraceImplementation = Console.WriteLine; diff --git a/Source/Plugin.BLE.iOS/BleImplementation.cs b/Source/Plugin.BLE.iOS/BleImplementation.cs index 823b59e1..9ea0e337 100644 --- a/Source/Plugin.BLE.iOS/BleImplementation.cs +++ b/Source/Plugin.BLE.iOS/BleImplementation.cs @@ -1,11 +1,15 @@ using System; using Plugin.BLE.Abstractions; using Plugin.BLE.Abstractions.Contracts; +using Plugin.BLE.iOS; namespace Plugin.BLE { internal class BleImplementation : IBluetoothLE { + private readonly Lazy _adapter = new Lazy(() => new Adapter(), System.Threading.LazyThreadSafetyMode.PublicationOnly); + public IAdapter Adapter => _adapter.Value; + public BleImplementation() { Trace.TraceImplementation = Console.WriteLine; diff --git a/Source/Plugin.BLE/CrossBle.cs b/Source/Plugin.BLE/CrossBle.cs index 59bee020..3b5cfe13 100644 --- a/Source/Plugin.BLE/CrossBle.cs +++ b/Source/Plugin.BLE/CrossBle.cs @@ -5,7 +5,7 @@ namespace Plugin.BLE { public static class CrossBle { - static readonly Lazy Implementation = new Lazy(CreatePermissions, System.Threading.LazyThreadSafetyMode.PublicationOnly); + static readonly Lazy Implementation = new Lazy(CreateImplementation, System.Threading.LazyThreadSafetyMode.PublicationOnly); public static IBluetoothLE Current { @@ -20,7 +20,7 @@ public static IBluetoothLE Current } } - static IBluetoothLE CreatePermissions() + static IBluetoothLE CreateImplementation() { #if PORTABLE return null;