Example #1
0
        async Task <IList <MediaFile> > PickMediaAsync(string title, PHAssetMediaType type)
        {
            mediaPickTcs  = new TaskCompletionSource <IList <MediaFile> >();
            currentPicker = new GMImagePickerController()
            {
                Title      = title,
                MediaTypes = new[] { type }
            };

            currentPicker.FinishedPickingAssets += FinishedPickingAssets;

            var window = UIApplication.SharedApplication.KeyWindow;
            var vc     = window.RootViewController;

            while (vc.PresentedViewController != null)
            {
                vc = vc.PresentedViewController;
            }

            await vc.PresentViewControllerAsync(currentPicker, true);

            var results = await mediaPickTcs.Task;

            currentPicker.FinishedPickingAssets -= FinishedPickingAssets;
            OnMediaPickedCompleted?.Invoke(this, results);
            return(results);
        }
Example #2
0
        async Task <IList <MediaModel> > PickMediaAsync(string sTitle, PHAssetMediaType oType)
        {
            _taskCompletionSource = new TaskCompletionSource <IList <MediaModel> >();

            GMPicker = new GMImagePickerController()
            {
                Title      = sTitle,
                MediaTypes = new[] { oType }
            };

            GMPicker.FinishedPickingAssets += FinishedPickingAsync;
            var window = UIApplication.SharedApplication.KeyWindow;
            var vc     = window.RootViewController;

            while (vc.PresentedViewController != null)
            {
                vc = vc.PresentedViewController;
            }
            await vc.PresentViewControllerAsync(GMPicker, true);

            var results = await _taskCompletionSource.Task;

            GMPicker.FinishedPickingAssets -= FinishedPickingAsync;
            OnMediaPickedCompleted?.Invoke(this, results);
            return(results);
        }
        public async Task OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            var mediaPicked = new ObservableCollection <MediaFile>();
            var tasks       = new List <Task>();

            if (requestCode == MultiPickerResultCode)
            {
                if (resultCode == Result.Ok)
                {
                    if (data != null)
                    {
                        ClipData clipData = data.ClipData;
                        if (clipData != null)
                        {
                            for (int i = 0; i < clipData.ItemCount; i++)
                            {
                                ClipData.Item   item = clipData.GetItemAt(i);
                                Android.Net.Uri uri  = item.Uri;

                                tasks.Add(Task.Run(
                                              () =>
                                {
                                    var media = CreateMediaFileFromUri(uri);

                                    if (media != null)
                                    {
                                        lock (Obj)
                                        {
                                            mediaPicked.Add(media);
                                        }
                                        OnMediaPicked?.Invoke(this, media);
                                    }
                                }));
                            }
                        }
                        else
                        {
                            Android.Net.Uri uri   = data.Data;
                            var             media = CreateMediaFileFromUri(uri);
                            if (media != null)
                            {
                                mediaPicked.Add(media);
                                OnMediaPicked?.Invoke(this, media);
                            }
                        }
                    }
                }
                await Task.WhenAll(tasks);

                OnMediaPickedCompleted?.Invoke(this, mediaPicked);
                _mediaPickedTcs?.TrySetResult(mediaPicked);
            }
        }
        public void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            ObservableCollection <MediaModel> oCollection = null;

            if (requestCode == SOURCE_PICK_CODE)
            {
                if (resultCode == Result.Ok)
                {
                    oCollection = new ObservableCollection <MediaModel>();

                    if (data != null)
                    {
                        ClipData oData = data.ClipData;

                        if (oData != null)
                        {
                            for (int i = 0; i < oData.ItemCount; i++)
                            {
                                ClipData.Item   oItem  = oData.GetItemAt(i);
                                Android.Net.Uri oUri   = oItem.Uri;
                                var             oModel = CreateMediaModel(oUri);
                                if (oModel != null)
                                {
                                    oCollection.Add(oModel);
                                    OnMediaPicked?.Invoke(this, oModel);
                                }
                            }
                        }
                        else
                        {
                            Android.Net.Uri oUri   = data.Data;
                            var             oModel = CreateMediaModel(oUri);

                            if (oModel != null)
                            {
                                oCollection.Add(oModel);
                                OnMediaPicked?.Invoke(this, oModel);
                            }
                        }

                        OnMediaPickedCompleted?.Invoke(this, oCollection);
                    }
                }

                _taskCompletionSource?.TrySetResult(oCollection);
            }
        }
Example #5
0
        public void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            ObservableCollection <MediaFile> mediaPicked = null;

            if (requestCode == MultiPickerResultCode)
            {
                if (resultCode == Result.Ok)
                {
                    mediaPicked = new ObservableCollection <MediaFile>();
                    if (data != null)
                    {
                        ClipData clipData = data.ClipData;
                        if (clipData != null)
                        {
                            for (int i = 0; i < clipData.ItemCount; i++)
                            {
                                ClipData.Item   item  = clipData.GetItemAt(i);
                                Android.Net.Uri uri   = item.Uri;
                                var             media = CreateMediaFileFromUri(uri);
                                if (media != null)
                                {
                                    mediaPicked.Add(media);
                                    OnMediaPicked?.Invoke(this, media);
                                }
                            }
                        }
                        else
                        {
                            Android.Net.Uri uri   = data.Data;
                            var             media = CreateMediaFileFromUri(uri);
                            if (media != null)
                            {
                                mediaPicked.Add(media);
                                OnMediaPicked?.Invoke(this, media);
                            }
                        }

                        OnMediaPickedCompleted?.Invoke(this, mediaPicked);
                    }
                }

                mediaPickedTcs?.TrySetResult(mediaPicked);
            }
        }