LastClipboardValue using static store rather than state

This commit is contained in:
Kyle Spearrin 2019-07-31 11:21:07 -04:00
parent 431804ea80
commit d91d71333b
5 changed files with 25 additions and 7 deletions

View file

@ -145,6 +145,7 @@
<Compile Include="Utilities\AndroidHelpers.cs" /> <Compile Include="Utilities\AndroidHelpers.cs" />
<Compile Include="Utilities\CustomFingerprintDialogFragment.cs" /> <Compile Include="Utilities\CustomFingerprintDialogFragment.cs" />
<Compile Include="Utilities\HockeyAppCrashManagerListener.cs" /> <Compile Include="Utilities\HockeyAppCrashManagerListener.cs" />
<Compile Include="Utilities\StaticStore.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<AndroidAsset Include="Assets\FontAwesome.ttf" /> <AndroidAsset Include="Assets\FontAwesome.ttf" />

View file

@ -378,7 +378,7 @@ namespace Bit.Droid
{ {
return; return;
} }
await _stateService.SaveAsync(Constants.LastClipboardValueKey, data.Item1); StaticStore.LastClipboardValue = data.Item1;
var triggerMs = Java.Lang.JavaSystem.CurrentTimeMillis() + clearMs.Value; var triggerMs = Java.Lang.JavaSystem.CurrentTimeMillis() + clearMs.Value;
var alarmManager = GetSystemService(AlarmService) as AlarmManager; var alarmManager = GetSystemService(AlarmService) as AlarmManager;
alarmManager.Set(AlarmType.Rtc, triggerMs, _clearClipboardPendingIntent); alarmManager.Set(AlarmType.Rtc, triggerMs, _clearClipboardPendingIntent);

View file

@ -2,22 +2,21 @@
using Bit.Core; using Bit.Core;
using Bit.Core.Abstractions; using Bit.Core.Abstractions;
using Bit.Core.Utilities; using Bit.Core.Utilities;
using Bit.Droid.Utilities;
namespace Bit.Droid.Receivers namespace Bit.Droid.Receivers
{ {
[BroadcastReceiver(Name = "com.x8bit.bitwarden.ClearClipboardAlarmReceiver", Exported = false)] [BroadcastReceiver(Name = "com.x8bit.bitwarden.ClearClipboardAlarmReceiver", Exported = false)]
public class ClearClipboardAlarmReceiver : BroadcastReceiver public class ClearClipboardAlarmReceiver : BroadcastReceiver
{ {
public async override void OnReceive(Context context, Intent intent) public override void OnReceive(Context context, Intent intent)
{ {
var stateService = ServiceContainer.Resolve<IStateService>("stateService");
var clipboardManager = context.GetSystemService(Context.ClipboardService) as ClipboardManager; var clipboardManager = context.GetSystemService(Context.ClipboardService) as ClipboardManager;
var lastClipboardValue = await stateService.GetAsync<string>(Constants.LastClipboardValueKey); if(StaticStore.LastClipboardValue != null && StaticStore.LastClipboardValue == clipboardManager.Text)
await stateService.RemoveAsync(Constants.LastClipboardValueKey);
if(lastClipboardValue == clipboardManager.Text)
{ {
clipboardManager.Text = string.Empty; clipboardManager.Text = string.Empty;
} }
StaticStore.LastClipboardValue = null;
} }
} }
} }

View file

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
namespace Bit.Droid.Utilities
{
public static class StaticStore
{
public static string LastClipboardValue { get; set; }
}
}

View file

@ -24,7 +24,6 @@
public static string PushInitialPromptShownKey = "pushInitialPromptShown"; public static string PushInitialPromptShownKey = "pushInitialPromptShown";
public static string ThemeKey = "theme"; public static string ThemeKey = "theme";
public static string ClearClipboardKey = "clearClipboard"; public static string ClearClipboardKey = "clearClipboard";
public static string LastClipboardValueKey = "lastClipboardValue";
public static string LastBuildKey = "lastBuild"; public static string LastBuildKey = "lastBuild";
public static string OldUserIdKey = "userId"; public static string OldUserIdKey = "userId";
public static string AddSitePromptShownKey = "addSitePromptShown"; public static string AddSitePromptShownKey = "addSitePromptShown";