Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a68f4cb
commit cb0a2c9
Showing
4 changed files
with
164 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Collections.Generic; | ||
using System.Reactive; | ||
using System.Reactive.Concurrency; | ||
using System.Reactive.Disposables; | ||
using ReactiveUI; | ||
using Android.App; | ||
|
||
namespace ReactiveUI.Android | ||
{ | ||
public class AndroidUIScheduler : IScheduler, IEnableLogger | ||
{ | ||
Activity activity; | ||
|
||
public AndroidUIScheduler(Activity activity) | ||
{ | ||
this.activity = activity; | ||
} | ||
|
||
public DateTimeOffset Now { | ||
get { return DateTimeOffset.Now; } | ||
} | ||
|
||
public IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action) | ||
{ | ||
IDisposable innerDisp = Disposable.Empty; | ||
activity.RunOnUiThread(new Action(() => innerDisp = action(this, state))); | ||
|
||
return innerDisp; | ||
} | ||
|
||
public IDisposable Schedule<TState>(TState state, DateTimeOffset dueTime, Func<IScheduler, TState, IDisposable> action) | ||
{ | ||
if (dueTime <= Now) { | ||
return Schedule(state, action); | ||
} | ||
|
||
return Schedule(state, dueTime - Now, action); | ||
} | ||
|
||
public IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action) | ||
{ | ||
bool isCancelled = false; | ||
|
||
var disp = Scheduler.TaskPool.Schedule(state, dueTime, (sched, st) => { | ||
IDisposable innerDisp = Disposable.Empty; | ||
if (!isCancelled) { | ||
activity.RunOnUiThread(() => { | ||
if (!isCancelled) innerDisp = action(this, state); | ||
}); | ||
} | ||
return Disposable.Create(() => { | ||
isCancelled = true; | ||
innerDisp.Dispose(); | ||
}); | ||
}); | ||
|
||
return Disposable.Create(() => { | ||
isCancelled = true; | ||
disp.Dispose(); | ||
}); | ||
} | ||
} | ||
} | ||
|
||
// vim: tw=120 ts=4 sw=4 et : |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProductVersion>10.0.0</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{55A6E11B-B074-4A0B-B937-267D840E31DF}</ProjectGuid> | ||
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | ||
<OutputType>Library</OutputType> | ||
<RootNamespace>ReactiveUI.Android</RootNamespace> | ||
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix> | ||
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix> | ||
<AssemblyName>ReactiveUI.Android</AssemblyName> | ||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>True</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>False</Optimize> | ||
<OutputPath>bin\Debug</OutputPath> | ||
<DefineConstants>DEBUG;</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<AndroidLinkMode>None</AndroidLinkMode> | ||
<ConsolePause>False</ConsolePause> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>none</DebugType> | ||
<Optimize>True</Optimize> | ||
<OutputPath>bin\Release</OutputPath> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<ConsolePause>False</ConsolePause> | ||
<AndroidLinkMode>SdkOnly</AndroidLinkMode> | ||
<AndroidUseSharedRuntime>False</AndroidUseSharedRuntime> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="Mono.Android" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" /> | ||
<ItemGroup> | ||
<ProjectReference Include="..\ext\mono.reactive\System.Reactive.Core\System.Reactive.Core.csproj"> | ||
<Project>{AD27C5E8-8A0C-454D-B7AA-76A54793B81F}</Project> | ||
<Name>System.Reactive.Core</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\ext\mono.reactive\System.Reactive.Interfaces\System.Reactive.Interfaces.csproj"> | ||
<Project>{755E549E-1BDE-4153-A58B-7C969C902CAD}</Project> | ||
<Name>System.Reactive.Interfaces</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\ext\mono.reactive\System.Reactive.Linq\System.Reactive.Linq.csproj"> | ||
<Project>{F0395470-330B-4DBF-B1A5-D873E597DD05}</Project> | ||
<Name>System.Reactive.Linq</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\ext\mono.reactive\System.Reactive.PlatformServices\System.Reactive.PlatformServices.csproj"> | ||
<Project>{AEEBFC85-91B8-410F-BBB7-BD12BBC61BE6}</Project> | ||
<Name>System.Reactive.PlatformServices</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\ext\mono.reactive\System.Reactive.Providers2\System.Reactive.Providers2.csproj"> | ||
<Project>{9652D18A-CF8D-40D7-BC1D-2090E58EC1FF}</Project> | ||
<Name>System.Reactive.Providers2</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\ReactiveUI\ReactiveUI_Android.csproj"> | ||
<Project>{292A477B-BB94-43C1-984E-E177EF9FEDB7}</Project> | ||
<Name>ReactiveUI_Android</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\ReactiveUI.Xaml\ReactiveUI.Xaml_Android.csproj"> | ||
<Project>{761AC9BA-4A9C-440C-9B6C-2569978F0610}</Project> | ||
<Name>ReactiveUI.Xaml_Android</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="AndroidUIScheduler.cs" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters