Added more new API Class

This commit is contained in:
TheJoKlLa
2022-05-16 22:41:29 +02:00
parent 4f3521eec3
commit 0ee3dc8497
29 changed files with 468 additions and 370 deletions

View File

@ -76,6 +76,10 @@
<Compile Include="PlatformInitializer.cs" />
<Compile Include="Resources\Resource.designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\APIBinder.cs" />
<Compile Include="Services\APIBindedService.cs" />
<Compile Include="Services\APIService.cs" />
<Compile Include="Services\APIServiceConnection.cs" />
<Compile Include="Services\PreferenceStorageService.cs" />
<Compile Include="Services\SecretStorage.cs" />
<Compile Include="Services\VersioningService.cs" />

View File

@ -1,7 +1,7 @@
using Borepin.Droid.Services;
using Borepin.Service;
using Borepin.Service.Storage;
using Borepin.Service.Versioning;
using FabAccessAPI;
using Prism;
using Prism.Ioc;
@ -15,7 +15,7 @@ namespace Borepin.Droid
containerRegistry.Register<ISecretStorageService, SecretStorage>();
containerRegistry.Register<IVersioningService, VersioningService>();
containerRegistry.RegisterSingleton<IAPI, API>();
containerRegistry.RegisterSingleton<IAPIService, APIService>();
}
}
}

View File

@ -0,0 +1,50 @@
using Android.App;
using Android.Content;
using Android.OS;
using FabAccessAPI;
namespace Borepin.Droid.Services
{
[Service(Name= "org.fab_infra.fabaccess.APIService")]
public class APIBindedService : Android.App.Service
{
#region Private Members
private IAPI _API;
#endregion
#region Members
public IBinder Binder { get; private set; }
#endregion
#region Methods
public IAPI GetAPI()
{
return _API;
}
public override void OnCreate()
{
base.OnCreate();
_API = new API();
}
public override IBinder OnBind(Intent intent)
{
Binder = new APIBinder(this);
return Binder;
}
public override bool OnUnbind(Intent intent)
{
return base.OnUnbind(intent);
}
public override void OnDestroy()
{
Binder = null;
_API = null;
base.OnDestroy();
}
#endregion
}
}

View File

@ -0,0 +1,18 @@
using Android.OS;
namespace Borepin.Droid.Services
{
public class APIBinder : Binder
{
#region Constructors
public APIBinder(APIBindedService service)
{
Service = service;
}
#endregion
#region Members
public APIBindedService Service { get; private set; }
#endregion
}
}

View File

@ -0,0 +1,28 @@
using Android.App;
using Android.Content;
using Borepin.Service;
using FabAccessAPI;
namespace Borepin.Droid.Services
{
public class APIService : IAPIService
{
#region Private Members
private readonly APIServiceConnection _APIServiceConnection;
#endregion
#region Constructors
public APIService()
{
Context context = Application.Context;
Intent service = new Intent(context, typeof(APIBindedService));
context.BindService(service, _APIServiceConnection, Bind.AutoCreate);
}
#endregion
public IAPI GetAPI()
{
return _APIServiceConnection?.Binder?.Service?.GetAPI();
}
}
}

View File

@ -0,0 +1,32 @@
using Android.Content;
using Android.OS;
using FabAccessAPI;
namespace Borepin.Droid.Services
{
class APIServiceConnection : Java.Lang.Object, IServiceConnection
{
#region Members
public bool IsConnected
{
get
{
return Binder != null;
}
}
public APIBinder Binder { get; private set; } = null;
#endregion
#region Methods
public void OnServiceConnected(ComponentName name, IBinder service)
{
Binder = service as APIBinder;
}
public void OnServiceDisconnected(ComponentName name)
{
Binder = null;
}
#endregion
}
}