mirror of
https://github.com/bitwarden/android.git
synced 2024-12-25 02:18:27 +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>
|
<DesignTime>True</DesignTime>
|
||||||
<DependentUpon>AppResources.hi.resx</DependentUpon>
|
<DependentUpon>AppResources.hi.resx</DependentUpon>
|
||||||
</Compile>
|
</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">
|
<Compile Include="Resources\AppResources.id.Designer.cs">
|
||||||
<AutoGen>True</AutoGen>
|
<AutoGen>True</AutoGen>
|
||||||
<DesignTime>True</DesignTime>
|
<DesignTime>True</DesignTime>
|
||||||
|
@ -240,6 +245,11 @@
|
||||||
<DesignTime>True</DesignTime>
|
<DesignTime>True</DesignTime>
|
||||||
<DependentUpon>AppResources.pt-PT.resx</DependentUpon>
|
<DependentUpon>AppResources.pt-PT.resx</DependentUpon>
|
||||||
</Compile>
|
</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">
|
<Compile Include="Resources\AppResources.ru.Designer.cs">
|
||||||
<AutoGen>True</AutoGen>
|
<AutoGen>True</AutoGen>
|
||||||
<DesignTime>True</DesignTime>
|
<DesignTime>True</DesignTime>
|
||||||
|
@ -329,6 +339,10 @@
|
||||||
<Generator>ResXFileCodeGenerator</Generator>
|
<Generator>ResXFileCodeGenerator</Generator>
|
||||||
<LastGenOutput>AppResources.hi.Designer.cs</LastGenOutput>
|
<LastGenOutput>AppResources.hi.Designer.cs</LastGenOutput>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
|
<EmbeddedResource Include="Resources\AppResources.hr.resx">
|
||||||
|
<Generator>ResXFileCodeGenerator</Generator>
|
||||||
|
<LastGenOutput>AppResources.hr.Designer.cs</LastGenOutput>
|
||||||
|
</EmbeddedResource>
|
||||||
<EmbeddedResource Include="Resources\AppResources.id.resx">
|
<EmbeddedResource Include="Resources\AppResources.id.resx">
|
||||||
<Generator>ResXFileCodeGenerator</Generator>
|
<Generator>ResXFileCodeGenerator</Generator>
|
||||||
<LastGenOutput>AppResources.id.Designer.cs</LastGenOutput>
|
<LastGenOutput>AppResources.id.Designer.cs</LastGenOutput>
|
||||||
|
@ -349,6 +363,10 @@
|
||||||
<Generator>ResXFileCodeGenerator</Generator>
|
<Generator>ResXFileCodeGenerator</Generator>
|
||||||
<LastGenOutput>AppResources.pt-PT.Designer.cs</LastGenOutput>
|
<LastGenOutput>AppResources.pt-PT.Designer.cs</LastGenOutput>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
|
<EmbeddedResource Include="Resources\AppResources.ro.resx">
|
||||||
|
<Generator>ResXFileCodeGenerator</Generator>
|
||||||
|
<LastGenOutput>AppResources.ro.Designer.cs</LastGenOutput>
|
||||||
|
</EmbeddedResource>
|
||||||
<EmbeddedResource Include="Resources\AppResources.ru.resx">
|
<EmbeddedResource Include="Resources\AppResources.ru.resx">
|
||||||
<Generator>ResXFileCodeGenerator</Generator>
|
<Generator>ResXFileCodeGenerator</Generator>
|
||||||
<LastGenOutput>AppResources.ru.Designer.cs</LastGenOutput>
|
<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>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Scanning will happen automatically..
|
/// Looks up a localized string similar to Scanning will happen automatically..
|
||||||
/// </summary>
|
/// </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>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Possible Matching Logins.
|
/// Looks up a localized string similar to Possible Matching Logins.
|
||||||
/// </summary>
|
/// </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">
|
<data name="ScanQrTitle" xml:space="preserve">
|
||||||
<value>Scan QR Code</value>
|
<value>Scan QR Code</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Camera" xml:space="preserve">
|
||||||
|
<value>Camera</value>
|
||||||
|
</data>
|
||||||
|
<data name="Photos" xml:space="preserve">
|
||||||
|
<value>Photos</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
0
src/App/Resources/AppResources.ro.Designer.cs
generated
Normal file
0
src/App/Resources/AppResources.ro.Designer.cs
generated
Normal file
|
@ -10,9 +10,9 @@
|
||||||
<array>
|
<array>
|
||||||
<string>$(AppIdentifierPrefix)com.8bit.bitwarden</string>
|
<string>$(AppIdentifierPrefix)com.8bit.bitwarden</string>
|
||||||
</array>
|
</array>
|
||||||
<key>com.apple.developer.ubiquity-container-identifiers</key>
|
<key>com.apple.developer.ubiquity-container-identifiers</key>
|
||||||
<array>
|
<array>
|
||||||
<string>$(TeamIdentifierPrefix)com.8bit.bitwarden</string>
|
<string>iCloud.$(CFBundleIdentifier)</string>
|
||||||
</array>
|
</array>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
|
|
@ -4,6 +4,7 @@ using UIKit;
|
||||||
using Foundation;
|
using Foundation;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using MobileCoreServices;
|
using MobileCoreServices;
|
||||||
|
using Bit.App.Resources;
|
||||||
|
|
||||||
namespace Bit.iOS.Services
|
namespace Bit.iOS.Services
|
||||||
{
|
{
|
||||||
|
@ -88,65 +89,87 @@ namespace Bit.iOS.Services
|
||||||
public byte[] SelectFile()
|
public byte[] SelectFile()
|
||||||
{
|
{
|
||||||
var controller = GetVisibleViewController();
|
var controller = GetVisibleViewController();
|
||||||
|
var picker = new UIDocumentMenuViewController(new string[] { UTType.Data }, UIDocumentPickerMode.Import);
|
||||||
|
|
||||||
var allowedUTIs = new string[]
|
picker.AddOption(AppResources.Camera, null, UIDocumentMenuOrder.First, () =>
|
||||||
{
|
|
||||||
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, () =>
|
|
||||||
{
|
{
|
||||||
var imagePicker = new UIImagePickerController { SourceType = UIImagePickerControllerSourceType.Camera };
|
var imagePicker = new UIImagePickerController { SourceType = UIImagePickerControllerSourceType.Camera };
|
||||||
|
imagePicker.FinishedPickingMedia += ImagePicker_FinishedPickingMedia;
|
||||||
imagePicker.FinishedPickingMedia += (sender, ev) =>
|
imagePicker.Canceled += ImagePicker_Canceled;
|
||||||
{
|
|
||||||
//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)
|
|
||||||
};
|
|
||||||
|
|
||||||
controller.PresentModalViewController(imagePicker, true);
|
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 };
|
var imagePicker = new UIImagePickerController { SourceType = UIImagePickerControllerSourceType.PhotoLibrary };
|
||||||
|
imagePicker.FinishedPickingMedia += ImagePicker_FinishedPickingMedia;
|
||||||
imagePicker.FinishedPickingMedia += (sender, ev) =>
|
imagePicker.Canceled += ImagePicker_Canceled;
|
||||||
{
|
|
||||||
//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)
|
|
||||||
};
|
|
||||||
|
|
||||||
controller.PresentModalViewController(imagePicker, true);
|
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;
|
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