Beispiel #1
0
            // This method fetches the whole ImageRecord that a user taps on and then passes it to the delegate
            public override void ItemSelected(UICollectionView collectionView, NSIndexPath indexPath)
            {
                // If the user has already tapped on a thumbnail, prevent them from tapping any others
                if (controller.lockSelectThumbnail)
                {
                    return;
                }
                else
                {
                    controller.lockSelectThumbnail = true;
                }

                // Starts animating the thumbnail to indicate it is loading
                controller.ImageCollection.SetLoadingFlag(indexPath, true);

                // Uses convenience API to fetch the whole image record associated with the thumbnail that was tapped
                CKRecordID userSelectedRecordID = controller.ImageCollection.GetRecordId(indexPath);

                controller.PublicCloudDatabase.FetchRecord(userSelectedRecordID, (record, error) => {
                    // If we get a partial failure, we should unwrap it
                    if (error != null && error.Code == (long)CKErrorCode.PartialFailure)
                    {
                        CKErrorInfo info = new CKErrorInfo(error);
                        error            = info[userSelectedRecordID];
                    }

                    Error errorResponse = controller.HandleError(error);

                    switch (errorResponse)
                    {
                    case Error.Success:
                        controller.ImageCollection.SetLoadingFlag(indexPath, false);
                        Image selectedImage = new Image(record);
                        InvokeOnMainThread(() => {
                            controller.MasterController.GoTo(controller, selectedImage);
                        });
                        break;

                    case Error.Retry:
                        Utils.Retry(() => {
                            controller.lockSelectThumbnail = false;
                            ItemSelected(collectionView, indexPath);
                        }, error);
                        break;

                    case Error.Ignore:
                        Console.WriteLine("Error: {0}", error.Description);
                        string errorTitle       = "Error";
                        string errorMessage     = "We couldn't fetch the full size thumbnail you tried to select, try again";
                        string dismissButton    = "Okay";
                        UIAlertController alert = UIAlertController.Create(errorTitle, errorMessage, UIAlertControllerStyle.Alert);
                        alert.AddAction(UIAlertAction.Create(dismissButton, UIAlertActionStyle.Cancel, null));
                        InvokeOnMainThread(() => controller.PresentViewController(alert, true, null));
                        controller.ImageCollection.SetLoadingFlag(indexPath, false);
                        controller.lockSelectThumbnail = false;
                        break;

                    default:
                        throw new NotImplementedException();
                    }
                });
            }