Example #1
0
        private void GoForward(object sender, EventArgs e)
        {
            var croppedPhotos = new List <Tuple <NSDictionary, UIImage> >();

            var currentPhoto = source.ImageAssets.FirstOrDefault(a => a.Asset.LocalIdentifier == source.CurrentlySelectedItem.Item2.LocalIdentifier);

            if (currentPhoto != null)
            {
                currentPhoto.Offset            = _cropView.ContentOffset;
                currentPhoto.Scale             = _cropView.ZoomScale;
                currentPhoto.OriginalImageSize = _cropView.originalImageSize;
                currentPhoto.Orientation       = _cropView.orientation;
            }

            foreach (var item in source.ImageAssets)
            {
                NSDictionary metadata     = null;
                var          croppedPhoto = _cropView.CropImage(item);
                _m.RequestImageData(item.Asset, new PHImageRequestOptions()
                {
                    Synchronous = true
                }, (data, dataUti, orientation, info) =>
                {
                    var dataSource = CGImageSource.FromData(data);
                    metadata       = dataSource.GetProperties(0).Dictionary;
                });

                croppedPhotos.Add(new Tuple <NSDictionary, UIImage>(metadata, croppedPhoto));
            }

            var descriptionViewController = new DescriptionViewController(croppedPhotos, "jpg");

            NavigationController.PushViewController(descriptionViewController, true);
        }
        private async void OnPostAsync()
        {
            if (!editMode)
            {
                await CheckOnSpam();

                if (_isSpammer)
                {
                    return;
                }
            }

            EnablePostAndEdit(false);

            if (_isFromCamera)
            {
                var croppedPhoto = _cropView.CropImage(new SavedPhoto(null, ImageAssets[0].Item2, _cropView.ContentOffset)
                {
                    OriginalImageSize = _cropView.originalImageSize, Scale = _cropView.ZoomScale
                });
                ImageAssets.RemoveAt(0);
                ImageAssets.Add(new Tuple <NSDictionary, UIImage>(null, croppedPhoto));
            }

            await Task.Run(() =>
            {
                try
                {
                    string title        = null;
                    string description  = null;
                    IList <string> tags = null;

                    InvokeOnMainThread(() =>
                    {
                        title       = titleTextField.Text;
                        description = descriptionTextField.Text;
                        tags        = collectionviewSource.LocalTags;
                    });

                    var mre = new ManualResetEvent(false);

                    if (!editMode)
                    {
                        var shouldReturn     = false;
                        var photoUploadRetry = false;
                        OperationResult <MediaModel>[] photoUploadResponse = new OperationResult <MediaModel> [ImageAssets.Count];
                        do
                        {
                            photoUploadRetry = false;
                            for (int i = 0; i < ImageAssets.Count; i++)
                            {
                                photoUploadResponse[i] = UploadPhoto(ImageAssets[i].Item2, ImageAssets[i].Item1).Result;
                            }

                            if (photoUploadResponse.Any(r => r.IsSuccess == false))
                            {
                                InvokeOnMainThread(() =>
                                {
                                    //Remake this
                                    ShowDialog(photoUploadResponse[0].Error, LocalizationKeys.Cancel, LocalizationKeys.Retry, (arg) =>
                                    {
                                        shouldReturn = true;
                                        mre.Set();
                                    }, (arg) =>
                                    {
                                        photoUploadRetry = true;
                                        mre.Set();
                                    });
                                });

                                mre.Reset();
                                mre.WaitOne();
                            }
                        } while (photoUploadRetry);

                        if (shouldReturn)
                        {
                            return;
                        }

                        model = new PreparePostModel(AppSettings.User.UserInfo, AppSettings.AppInfo.GetModel())
                        {
                            Title       = title,
                            Description = description,
                            Device      = "iOS",

                            Tags  = tags.ToArray(),
                            Media = photoUploadResponse.Select(r => r.Result).ToArray(),
                        };
                    }
                    else
                    {
                        model.Title       = title;
                        model.Description = description;
                        model.Device      = "iOS";
                        model.Tags        = tags.ToArray();
                        model.Media       = post.Media;
                    }

                    var pushToBlockchainRetry = false;
                    do
                    {
                        pushToBlockchainRetry = false;
                        var response          = _presenter.TryCreateOrEditPost(model).Result;
                        if (!(response != null && response.IsSuccess))
                        {
                            InvokeOnMainThread(() =>
                            {
                                ShowDialog(response.Error, LocalizationKeys.Cancel, LocalizationKeys.Retry, (arg) =>
                                {
                                    mre.Set();
                                }, (arg) =>
                                {
                                    pushToBlockchainRetry = true;
                                    mre.Set();
                                });
                            });

                            mre.Reset();
                            mre.WaitOne();
                        }
                        else
                        {
                            InvokeOnMainThread(() =>
                            {
                                ShouldProfileUpdate = true;
                                NavigationController.ViewControllers = new UIViewController[] { NavigationController.ViewControllers[0], this };
                                NavigationController.PopViewController(false);
                            });
                        }
                    } while (pushToBlockchainRetry);
                }
                finally
                {
                    InvokeOnMainThread(() =>
                    {
                        EnablePostAndEdit(true);
                    });
                }
            });
        }
Example #3
0
        protected virtual async void OnPostAsync(bool skipPreparationSteps)
        {
            if (!skipPreparationSteps)
            {
                await CheckOnSpam(true);

                if (_isSpammer)
                {
                    return;
                }
            }

            EnablePostAndEdit(false);

            if (_isFromCamera && !skipPreparationSteps)
            {
                var croppedPhoto = _cropView.CropImage(new SavedPhoto(null, ImageAssets[0].Item2, _cropView.ContentOffset)
                {
                    OriginalImageSize = _cropView.originalImageSize, Scale = _cropView.ZoomScale
                });
                ImageAssets.RemoveAt(0);
                ImageAssets.Add(new Tuple <NSDictionary, UIImage>(null, croppedPhoto));
            }

            await Task.Run(() =>
            {
                try
                {
                    var shouldReturn    = false;
                    string title        = null;
                    string description  = null;
                    IList <string> tags = null;

                    InvokeOnMainThread(() =>
                    {
                        title       = titleTextField.Text;
                        description = descriptionTextField.Text;
                        tags        = collectionviewSource.LocalTags;
                    });

                    mre = new ManualResetEvent(false);

                    if (!skipPreparationSteps)
                    {
                        var photoUploadRetry = false;
                        OperationResult <MediaModel>[] photoUploadResponse = new OperationResult <MediaModel> [ImageAssets.Count];
                        do
                        {
                            photoUploadRetry = false;
                            for (int i = 0; i < ImageAssets.Count; i++)
                            {
                                photoUploadResponse[i] = UploadPhoto(ImageAssets[i].Item2, ImageAssets[i].Item1).Result;
                            }

                            if (photoUploadResponse.Any(r => r.IsSuccess == false))
                            {
                                InvokeOnMainThread(() =>
                                {
                                    //Remake this
                                    ShowDialog(photoUploadResponse[0].Exception, LocalizationKeys.Cancel,
                                               LocalizationKeys.Retry, (arg) =>
                                    {
                                        shouldReturn = true;
                                        mre.Set();
                                    }, (arg) =>
                                    {
                                        photoUploadRetry = true;
                                        mre.Set();
                                    });
                                });

                                mre.Reset();
                                mre.WaitOne();
                            }
                        } while (photoUploadRetry);

                        if (shouldReturn)
                        {
                            return;
                        }

                        model = new PreparePostModel(AppSettings.User.UserInfo, AppSettings.AppInfo.GetModel())
                        {
                            Title       = title,
                            Description = description,
                            Device      = "iOS",

                            Tags  = tags.ToArray(),
                            Media = photoUploadResponse.Select(r => r.Result).ToArray(),
                        };
                    }

                    CreateOrEditPost(skipPreparationSteps);
                }
                catch (Exception ex)
                {
                    AppSettings.Logger.Warning(ex);
                }
                finally
                {
                    InvokeOnMainThread(() => { EnablePostAndEdit(true); });
                }
            });
        }