2017-12-23 08:04:52 +03:00
|
|
|
|
using Acr.UserDialogs;
|
|
|
|
|
using Bit.App.Abstractions;
|
2017-11-29 05:08:45 +03:00
|
|
|
|
using Bit.App.Models.Page;
|
2017-12-22 23:00:11 +03:00
|
|
|
|
using Coding4Fun.Toolkit.Controls;
|
2017-10-03 05:15:13 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.InteropServices.WindowsRuntime;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Windows.ApplicationModel.Core;
|
|
|
|
|
using Windows.ApplicationModel.DataTransfer;
|
|
|
|
|
using Windows.Storage;
|
|
|
|
|
using Windows.System;
|
2017-12-22 23:00:11 +03:00
|
|
|
|
using Windows.UI;
|
2017-10-03 05:15:13 +03:00
|
|
|
|
using Windows.UI.Core;
|
2017-12-22 23:00:11 +03:00
|
|
|
|
using Windows.UI.Xaml;
|
|
|
|
|
using Windows.UI.Xaml.Media;
|
2017-10-03 05:15:13 +03:00
|
|
|
|
|
|
|
|
|
namespace Bit.UWP.Services
|
|
|
|
|
{
|
|
|
|
|
public class DeviceActionService : IDeviceActionService
|
|
|
|
|
{
|
2017-12-23 08:04:52 +03:00
|
|
|
|
private readonly IUserDialogs _userDialogs;
|
|
|
|
|
|
|
|
|
|
public DeviceActionService(IUserDialogs userDialogs)
|
|
|
|
|
{
|
|
|
|
|
_userDialogs = userDialogs;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-03 05:38:56 +03:00
|
|
|
|
public bool CanOpenFile(string fileName) => true;
|
2017-10-03 05:15:13 +03:00
|
|
|
|
|
|
|
|
|
public void ClearCache()
|
|
|
|
|
{
|
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
{
|
2017-10-03 05:38:10 +03:00
|
|
|
|
foreach(var item in await ApplicationData.Current.LocalCacheFolder.GetItemsAsync())
|
2017-10-03 05:15:13 +03:00
|
|
|
|
{
|
|
|
|
|
await item.DeleteAsync();
|
|
|
|
|
}
|
|
|
|
|
}).Wait();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CopyToClipboard(string text)
|
|
|
|
|
{
|
2017-10-03 05:38:10 +03:00
|
|
|
|
var dataPackage = new DataPackage
|
|
|
|
|
{
|
|
|
|
|
RequestedOperation = DataPackageOperation.Copy
|
|
|
|
|
};
|
2017-10-03 05:15:13 +03:00
|
|
|
|
dataPackage.SetText(text);
|
|
|
|
|
Clipboard.SetContent(dataPackage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool OpenFile(byte[] fileData, string id, string fileName)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//the method is synchronous in the interface, so the async method are run synchronously here
|
|
|
|
|
var storageFolder = ApplicationData.Current.LocalCacheFolder;
|
|
|
|
|
var file = storageFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting).AsTask().Result;
|
|
|
|
|
FileIO.WriteBytesAsync(file, fileData).AsTask().Wait();
|
|
|
|
|
Launcher.LaunchFileAsync(file, new LauncherOptions { DisplayApplicationPicker = true }).AsTask().Wait();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task SelectFileAsync()
|
|
|
|
|
{
|
|
|
|
|
var picker = new Windows.Storage.Pickers.FileOpenPicker
|
|
|
|
|
{
|
|
|
|
|
ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail,
|
|
|
|
|
SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary,
|
|
|
|
|
FileTypeFilter = { "*" }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
|
|
|
|
|
{
|
|
|
|
|
var file = await picker.PickSingleFileAsync();
|
2017-10-03 05:38:10 +03:00
|
|
|
|
if(file != null)
|
|
|
|
|
{
|
2017-10-03 05:15:13 +03:00
|
|
|
|
await SelectFileResult(file);
|
2017-10-03 05:38:10 +03:00
|
|
|
|
}
|
2017-10-03 05:15:13 +03:00
|
|
|
|
}).AsTask();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task SelectFileResult(StorageFile file)
|
|
|
|
|
{
|
|
|
|
|
var buffer = await FileIO.ReadBufferAsync(file);
|
2017-12-22 23:00:11 +03:00
|
|
|
|
Xamarin.Forms.MessagingCenter.Send(Xamarin.Forms.Application.Current, "SelectFileResult",
|
2017-10-03 05:15:13 +03:00
|
|
|
|
new Tuple<byte[], string>(buffer.ToArray(), file.Name));
|
|
|
|
|
}
|
2017-11-29 05:08:45 +03:00
|
|
|
|
|
|
|
|
|
public void Autofill(VaultListPageModel.Cipher cipher)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CloseAutofill()
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Background()
|
|
|
|
|
{
|
|
|
|
|
// do nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RateApp()
|
|
|
|
|
{
|
|
|
|
|
// do nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DismissKeyboard()
|
|
|
|
|
{
|
|
|
|
|
// do nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LaunchApp(string appName)
|
|
|
|
|
{
|
|
|
|
|
// do nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OpenAccessibilitySettings()
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OpenAutofillSettings()
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
2017-12-22 23:00:11 +03:00
|
|
|
|
|
|
|
|
|
public void Toast(string text, bool longDuration = false)
|
|
|
|
|
{
|
|
|
|
|
new ToastPrompt
|
|
|
|
|
{
|
|
|
|
|
Message = text,
|
|
|
|
|
TextWrapping = TextWrapping.Wrap,
|
|
|
|
|
MillisecondsUntilHidden = Convert.ToInt32(longDuration ? 5 : 2) * 1000,
|
|
|
|
|
Background = new SolidColorBrush(Color.FromArgb(255, 73, 73, 73)),
|
|
|
|
|
Foreground = new SolidColorBrush(Colors.White),
|
|
|
|
|
Margin = new Thickness(0, 0, 0, 100),
|
|
|
|
|
HorizontalAlignment = HorizontalAlignment.Center,
|
|
|
|
|
VerticalAlignment = VerticalAlignment.Bottom,
|
|
|
|
|
HorizontalContentAlignment = HorizontalAlignment.Center,
|
|
|
|
|
VerticalContentAlignment = VerticalAlignment.Center,
|
|
|
|
|
Stretch = Stretch.Uniform,
|
|
|
|
|
IsHitTestVisible = false
|
|
|
|
|
}.Show();
|
|
|
|
|
}
|
2017-12-23 08:04:52 +03:00
|
|
|
|
|
|
|
|
|
public void ShowLoading(string text)
|
|
|
|
|
{
|
|
|
|
|
_userDialogs.ShowLoading(text, MaskType.Black);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void HideLoading()
|
|
|
|
|
{
|
|
|
|
|
_userDialogs.HideLoading();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task LaunchAppAsync(string appName, Xamarin.Forms.Page page)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
2017-10-03 05:15:13 +03:00
|
|
|
|
}
|
|
|
|
|
}
|