Attempt 2

This commit is contained in:
Anuken
2019-11-10 21:16:51 -05:00
parent f2f5fde3a5
commit b8aa3c8b21

View File

@@ -39,7 +39,8 @@ public class IOSLauncher extends IOSApplication.Delegate{
@Override @Override
public void showFileChooser(boolean open, String extension, Cons<FileHandle> cons){ public void showFileChooser(boolean open, String extension, Cons<FileHandle> cons){
UIDocumentBrowserViewController cont = new UIDocumentBrowserViewController((NSArray)null); UIDocumentBrowserViewController cont = new UIDocumentBrowserViewController((NSArray<NSString>)null);
NSArray<UIBarButtonItem> arr = new NSArray<>(new UIBarButtonItem(Core.bundle.get("cancel"), UIBarButtonItemStyle.Plain, NSArray<UIBarButtonItem> arr = new NSArray<>(new UIBarButtonItem(Core.bundle.get("cancel"), UIBarButtonItemStyle.Plain,
uiBarButtonItem -> cont.dismissViewController(true, () -> {}))); uiBarButtonItem -> cont.dismissViewController(true, () -> {})));
@@ -63,6 +64,11 @@ public class IOSLauncher extends IOSApplication.Delegate{
coord.coordinateReadingItem(documentURLs.get(0), NSFileCoordinatorReadingOptions.None, url -> { coord.coordinateReadingItem(documentURLs.get(0), NSFileCoordinatorReadingOptions.None, url -> {
NSInputStream stream = new NSInputStream(NSData.read(url)); NSInputStream stream = new NSInputStream(NSData.read(url));
try{
cons.get(new FileHandle(url.getAbsoluteURL().getPath()));
/*
cons.get(new FileHandle(url.getPath()){ cons.get(new FileHandle(url.getPath()){
@Override @Override
public InputStream read(){ public InputStream read(){
@@ -79,14 +85,12 @@ public class IOSLauncher extends IOSApplication.Delegate{
public int read(byte[] bytes, int offset, int length){ public int read(byte[] bytes, int offset, int length){
return (int)stream.read(bytes, offset, length); return (int)stream.read(bytes, offset, length);
} }
@Override
public void close() throws IOException{
stream.close();
}
}; };
} }
}); });*/
}catch(Throwable t){
ui.showException(t);
}
}); });
}catch(Throwable t){ }catch(Throwable t){
ui.showException(t); ui.showException(t);
@@ -138,24 +142,22 @@ public class IOSLauncher extends IOSApplication.Delegate{
cont.setDelegate(new ChooserDelegate()); cont.setDelegate(new ChooserDelegate());
// DispatchQueue.getMainQueue().sync(() -> {
UIApplication.getSharedApplication().getKeyWindow().getRootViewController().presentViewController(cont, true, () -> {}); UIApplication.getSharedApplication().getKeyWindow().getRootViewController().presentViewController(cont, true, () -> {});
// });
} }
@Override @Override
public void shareFile(FileHandle file){ public void shareFile(FileHandle file){
try{
Log.info("Attempting to share file " + file); Log.info("Attempting to share file " + file);
FileHandle to = Core.files.absolute(getDocumentsDirectory()).child(file.name()); FileHandle to = Core.files.absolute(getDocumentsDirectory()).child(file.name());
file.copyTo(to); file.copyTo(to);
NSURL url = new NSURL(to.file()); NSURL url = new NSURL(to.file());
UIActivityViewController p = new UIActivityViewController(Collections.singletonList(url), null); UIActivityViewController p = new UIActivityViewController(Collections.singletonList(url), null);
UIApplication.getSharedApplication().getKeyWindow().getRootViewController().presentViewController(p, true, () -> Log.info("Success! Presented {0}", to));
//DispatchQueue.getMainQueue().sync(() -> { }catch(Throwable t){
UIApplication.getSharedApplication().getKeyWindow().getRootViewController() ui.showException(t);
.presentViewController(p, true, () -> Log.info("Success! Presented {0}", to)); }
//});
} }
@Override @Override