mirror of
https://github.com/bitwarden/android.git
synced 2024-12-24 18:08:26 +03:00
get file data from document picker
This commit is contained in:
parent
d0b616ba24
commit
98e429505c
7 changed files with 116 additions and 51 deletions
|
@ -215,6 +215,11 @@
|
|||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>AppResources.hi.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Resources\AppResources.hr.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>AppResources.hr.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Resources\AppResources.id.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
|
@ -240,6 +245,11 @@
|
|||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>AppResources.pt-PT.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Resources\AppResources.ro.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>AppResources.ro.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Resources\AppResources.ru.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
|
@ -329,6 +339,10 @@
|
|||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>AppResources.hi.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Resources\AppResources.hr.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>AppResources.hr.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Resources\AppResources.id.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>AppResources.id.Designer.cs</LastGenOutput>
|
||||
|
@ -349,6 +363,10 @@
|
|||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>AppResources.pt-PT.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Resources\AppResources.ro.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>AppResources.ro.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Resources\AppResources.ru.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>AppResources.ru.Designer.cs</LastGenOutput>
|
||||
|
|
18
src/App/Resources/AppResources.Designer.cs
generated
18
src/App/Resources/AppResources.Designer.cs
generated
|
@ -448,6 +448,15 @@ namespace Bit.App.Resources {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Camera.
|
||||
/// </summary>
|
||||
public static string Camera {
|
||||
get {
|
||||
return ResourceManager.GetString("Camera", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Scanning will happen automatically..
|
||||
/// </summary>
|
||||
|
@ -1708,6 +1717,15 @@ namespace Bit.App.Resources {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Photos.
|
||||
/// </summary>
|
||||
public static string Photos {
|
||||
get {
|
||||
return ResourceManager.GetString("Photos", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Possible Matching Logins.
|
||||
/// </summary>
|
||||
|
|
0
src/App/Resources/AppResources.hr.Designer.cs
generated
Normal file
0
src/App/Resources/AppResources.hr.Designer.cs
generated
Normal file
|
@ -944,4 +944,10 @@
|
|||
<data name="ScanQrTitle" xml:space="preserve">
|
||||
<value>Scan QR Code</value>
|
||||
</data>
|
||||
<data name="Camera" xml:space="preserve">
|
||||
<value>Camera</value>
|
||||
</data>
|
||||
<data name="Photos" xml:space="preserve">
|
||||
<value>Photos</value>
|
||||
</data>
|
||||
</root>
|
0
src/App/Resources/AppResources.ro.Designer.cs
generated
Normal file
0
src/App/Resources/AppResources.ro.Designer.cs
generated
Normal file
|
@ -12,7 +12,7 @@
|
|||
</array>
|
||||
<key>com.apple.developer.ubiquity-container-identifiers</key>
|
||||
<array>
|
||||
<string>$(TeamIdentifierPrefix)com.8bit.bitwarden</string>
|
||||
<string>iCloud.$(CFBundleIdentifier)</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
|
@ -4,6 +4,7 @@ using UIKit;
|
|||
using Foundation;
|
||||
using System.IO;
|
||||
using MobileCoreServices;
|
||||
using Bit.App.Resources;
|
||||
|
||||
namespace Bit.iOS.Services
|
||||
{
|
||||
|
@ -88,65 +89,87 @@ namespace Bit.iOS.Services
|
|||
public byte[] SelectFile()
|
||||
{
|
||||
var controller = GetVisibleViewController();
|
||||
var picker = new UIDocumentMenuViewController(new string[] { UTType.Data }, UIDocumentPickerMode.Import);
|
||||
|
||||
var allowedUTIs = new string[]
|
||||
{
|
||||
UTType.AliasFile,
|
||||
UTType.AliasRecord,
|
||||
UTType.AppleICNS,
|
||||
UTType.Image,
|
||||
UTType.Movie,
|
||||
UTType.GIF,
|
||||
UTType.Video,
|
||||
UTType.Folder,
|
||||
UTType.ApplicationFile,
|
||||
UTType.JPEG,
|
||||
UTType.PNG,
|
||||
UTType.BMP,
|
||||
UTType.Spreadsheet
|
||||
};
|
||||
|
||||
var picker = new UIDocumentMenuViewController(allowedUTIs, UIDocumentPickerMode.Open);
|
||||
picker.AddOption("Camera", null, UIDocumentMenuOrder.First, () =>
|
||||
picker.AddOption(AppResources.Camera, null, UIDocumentMenuOrder.First, () =>
|
||||
{
|
||||
var imagePicker = new UIImagePickerController { SourceType = UIImagePickerControllerSourceType.Camera };
|
||||
|
||||
imagePicker.FinishedPickingMedia += (sender, ev) =>
|
||||
{
|
||||
//var filepath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "tmp.png");
|
||||
//var image = (UIImage)ev.Info.ObjectForKey(new NSString("UIImagePickerControllerOriginalImage"));
|
||||
//DismissViewController(true, null)
|
||||
};
|
||||
|
||||
imagePicker.Canceled += (sender, ev2) =>
|
||||
{
|
||||
//DismissViewController(true, null)
|
||||
};
|
||||
|
||||
imagePicker.FinishedPickingMedia += ImagePicker_FinishedPickingMedia;
|
||||
imagePicker.Canceled += ImagePicker_Canceled;
|
||||
controller.PresentModalViewController(imagePicker, true);
|
||||
});
|
||||
picker.AddOption("Photo Library", null, UIDocumentMenuOrder.First, () =>
|
||||
|
||||
picker.AddOption(AppResources.Photos, null, UIDocumentMenuOrder.First, () =>
|
||||
{
|
||||
var imagePicker = new UIImagePickerController { SourceType = UIImagePickerControllerSourceType.PhotoLibrary };
|
||||
|
||||
imagePicker.FinishedPickingMedia += (sender, ev) =>
|
||||
{
|
||||
//var filepath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "tmp.png");
|
||||
//var image = (UIImage)ev.Info.ObjectForKey(new NSString("UIImagePickerControllerOriginalImage"));
|
||||
//DismissViewController(true, null)
|
||||
};
|
||||
|
||||
imagePicker.Canceled += (sender, ev2) =>
|
||||
{
|
||||
//DismissViewController(true, null)
|
||||
};
|
||||
|
||||
imagePicker.FinishedPickingMedia += ImagePicker_FinishedPickingMedia;
|
||||
imagePicker.Canceled += ImagePicker_Canceled;
|
||||
controller.PresentModalViewController(imagePicker, true);
|
||||
});
|
||||
|
||||
controller.PresentViewController(picker, true, null);
|
||||
picker.DidPickDocumentPicker += (sender, e) =>
|
||||
{
|
||||
controller.PresentViewController(e.DocumentPicker, true, null);
|
||||
e.DocumentPicker.DidPickDocument += DocumentPicker_DidPickDocument;
|
||||
};
|
||||
|
||||
controller.PresentViewController(picker, true, null);
|
||||
return null;
|
||||
}
|
||||
|
||||
private void ImagePicker_FinishedPickingMedia(object sender, UIImagePickerMediaPickedEventArgs e)
|
||||
{
|
||||
if(sender is UIImagePickerController picker)
|
||||
{
|
||||
//var image = (UIImage)e.Info.ObjectForKey(new NSString("UIImagePickerControllerOriginalImage"));
|
||||
|
||||
// TODO: determine if JPG or PNG from extension. Get filename somehow?
|
||||
byte[] data;
|
||||
if(false)
|
||||
{
|
||||
using(var imageData = e.OriginalImage.AsJPEG())
|
||||
{
|
||||
data = new byte[imageData.Length];
|
||||
System.Runtime.InteropServices.Marshal.Copy(imageData.Bytes, data, 0,
|
||||
Convert.ToInt32(imageData.Length));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
using(var imageData = e.OriginalImage.AsPNG())
|
||||
{
|
||||
data = new byte[imageData.Length];
|
||||
System.Runtime.InteropServices.Marshal.Copy(imageData.Bytes, data, 0,
|
||||
Convert.ToInt32(imageData.Length));
|
||||
}
|
||||
}
|
||||
|
||||
picker.DismissViewController(true, null);
|
||||
}
|
||||
}
|
||||
|
||||
private void ImagePicker_Canceled(object sender, EventArgs e)
|
||||
{
|
||||
if(sender is UIImagePickerController picker)
|
||||
{
|
||||
picker.DismissViewController(true, null);
|
||||
}
|
||||
}
|
||||
|
||||
private void DocumentPicker_DidPickDocument(object sender, UIDocumentPickedEventArgs e)
|
||||
{
|
||||
e.Url.StartAccessingSecurityScopedResource();
|
||||
var fileCoordinator = new NSFileCoordinator();
|
||||
|
||||
// TODO: get filename?
|
||||
|
||||
NSError error;
|
||||
fileCoordinator.CoordinateRead(e.Url, NSFileCoordinatorReadingOptions.WithoutChanges, out error, (url) =>
|
||||
{
|
||||
var data = NSData.FromUrl(url).ToArray();
|
||||
});
|
||||
|
||||
e.Url.StopAccessingSecurityScopedResource();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue