Ejemplo n.º 1
0
        public void IF_OpenGallery(ISupportMediaResultListener _supportMediaResultListener, SyncPhotoOptions options, int _CodeRequest)
        {
            CodeRequest = _CodeRequest;
            supportMediaResultListener = _supportMediaResultListener;

            UIStoryboard storyboard = UIStoryboard.FromName("SupportMediaStoryboard", null);
            SupportGalleryPickerController controller = (SupportGalleryPickerController)storyboard.InstantiateViewController("SupportGalleryPickerController");

            controller.syncPhotoOptions = options;
            NaviExtensions.OpenController(controller);
        }
        public Task <List <SupportImageXF> > IF_OpenGallery(SyncPhotoOptions options)
        {
            ManualResetEvent manualResetEvent = new ManualResetEvent(false);

            List <SupportImageXF> result = new List <SupportImageXF>();

            var currentPresent = NaviExtensions.GetTopController();

            if (currentPresent == null)
            {
                return(Task.FromResult(new List <SupportImageXF>()));
            }

            return(Task.Factory.StartNew(() => {
                try
                {
                    manualResetEvent.Reset();

                    SupportGalleryPickerController supportGalleryPickerController = null;

                    currentPresent.InvokeOnMainThread(() => {
                        var storyboard = UIStoryboard.FromName("SupportMediaStoryboard", null);
                        supportGalleryPickerController = (SupportGalleryPickerController)storyboard.InstantiateViewController("SupportGalleryPickerController");
                        supportGalleryPickerController.syncPhotoOptions = options;

                        supportGalleryPickerController.OnPicked += (obj) =>
                        {
                            supportGalleryPickerController.InvokeOnMainThread(() =>
                            {
                                try
                                {
                                    supportGalleryPickerController.DismissViewController(true, () =>
                                    {
                                        if (obj != null)
                                        {
                                            foreach (var item in obj)
                                            {
                                                result.Add(item.galleryImageXF);
                                            }
                                        }
                                        manualResetEvent.Set();
                                    });
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine(ex.StackTrace);
                                    manualResetEvent.Set();
                                }
                            });
                        };
                        currentPresent.PresentViewController(supportGalleryPickerController, true, null);
                    });

                    manualResetEvent.WaitOne();

                    if (supportGalleryPickerController != null)
                    {
                        supportGalleryPickerController.Dispose();
                    }

                    return result;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    return result;
                }
            }));
        }