Skip to content

Commit

Permalink
Added adapter to IBluetoothLE
Browse files Browse the repository at this point in the history
  • Loading branch information
smstuebe committed May 12, 2016
1 parent b00675a commit d5d9cac
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .build/Plugin.BLE.nuspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Xam.Plugin.BLE</id>
<id>Plugin.BLE</id>
<version>0.9.4</version>
<title>BLE Plugin for Xamarin</title>
<authors>xabre, smstube</authors>
Expand Down
5 changes: 3 additions & 2 deletions Source/MvvmCross.Plugins.BLE.Droid/Plugin.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -15,7 +15,8 @@ public Plugin()
}
public void Load()
{
Mvx.LazyConstructAndRegisterSingleton<IAdapter>(() => new Adapter());
Mvx.LazyConstructAndRegisterSingleton<IBluetoothLE>(() => CrossBle.Current);
Mvx.LazyConstructAndRegisterSingleton<IAdapter>(() => Mvx.Resolve<IBluetoothLE>().Adapter);
}
}
}
5 changes: 3 additions & 2 deletions Source/MvvmCross.Plugins.BLE.iOS/Plugin.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -18,7 +18,8 @@ public Plugin()
public void Load()
{
Mvx.Trace("Loading BT plugin");
Mvx.RegisterSingleton<IAdapter>(new Adapter());
Mvx.LazyConstructAndRegisterSingleton<IBluetoothLE>(() => CrossBle.Current);
Mvx.LazyConstructAndRegisterSingleton<IAdapter>(() => Mvx.Resolve<IBluetoothLE>().Adapter);
}
}
}
2 changes: 1 addition & 1 deletion Source/Plugin.BLE.Abstractions/Contracts/IBluetoothLE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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), ...
}
Expand Down
4 changes: 4 additions & 0 deletions Source/Plugin.BLE.Android/BleImplementation.cs
Original file line number Diff line number Diff line change
@@ -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<IAdapter> _adapter = new Lazy<IAdapter>(() => new Adapter(), System.Threading.LazyThreadSafetyMode.PublicationOnly);
public IAdapter Adapter => _adapter.Value;

public BleImplementation()
{
Trace.TraceImplementation = Console.WriteLine;
Expand Down
4 changes: 4 additions & 0 deletions Source/Plugin.BLE.iOS/BleImplementation.cs
Original file line number Diff line number Diff line change
@@ -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<IAdapter> _adapter = new Lazy<IAdapter>(() => new Adapter(), System.Threading.LazyThreadSafetyMode.PublicationOnly);
public IAdapter Adapter => _adapter.Value;

public BleImplementation()
{
Trace.TraceImplementation = Console.WriteLine;
Expand Down
4 changes: 2 additions & 2 deletions Source/Plugin.BLE/CrossBle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Plugin.BLE
{
public static class CrossBle
{
static readonly Lazy<IBluetoothLE> Implementation = new Lazy<IBluetoothLE>(CreatePermissions, System.Threading.LazyThreadSafetyMode.PublicationOnly);
static readonly Lazy<IBluetoothLE> Implementation = new Lazy<IBluetoothLE>(CreateImplementation, System.Threading.LazyThreadSafetyMode.PublicationOnly);

public static IBluetoothLE Current
{
Expand All @@ -20,7 +20,7 @@ public static IBluetoothLE Current
}
}

static IBluetoothLE CreatePermissions()
static IBluetoothLE CreateImplementation()
{
#if PORTABLE
return null;
Expand Down

0 comments on commit d5d9cac

Please sign in to comment.