<commit_before>﻿using System;

using UIKit;
using Foundation;
using Photos;
using GMImagePicker;
using System.Threading.Tasks;
using CoreGraphics;
using MobileCoreServices;

namespace GMPhotoPicker.Xamarin
{
	public partial class ViewController : UIViewController
	{
		public ViewController (IntPtr handle) : base (handle)
		{
		}

		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			// Perform any additional setup after loading the view, typically from a nib.
		}

		public override void DidReceiveMemoryWarning ()
		{
			base.DidReceiveMemoryWarning ();
			// Release any cached data, images, etc that aren't in use.
		}

		async partial void ShowGMImagePicker (NSObject sender)
		{
			var picker = new GMImagePickerController {
				Title = "Custom Title",
				CustomDoneButtonTitle = "Finished",
				CustomCancelButtonTitle = "Nope",
				CustomNavigationBarPrompt = "Take a new photo or select an existing one!",
				ColsInPortrait = 3,
				ColsInLandscape = 5,
				MinimumInteritemSpacing = 2.0f,
				DisplaySelectionInfoToolbar = true,
				AllowsMultipleSelection = true,
				ShowCameraButton = true,
				AutoSelectCameraImages = true,
				ModalPresentationStyle = UIModalPresentationStyle.Popover,
				MediaTypes = new [] { PHAssetMediaType.Image },

				// Other customizations to play with:
				//ConfirmSingleSelection = true,
				//ConfirmSingleSelectionPrompt = "Do you want to select the image you have chosen?",
				//PickerBackgroundColor = UIColor.Black,
				//PickerTextColor = UIColor.White,
				//ToolbarBarTintColor = UIColor.DarkGray,
				//ToolbarTextColor = UIColor.White,
				//ToolbarTintColor = UIColor.Red,
				//NavigationBarBackgroundColor = UIColor.Black,
				//NavigationBarTextColor = UIColor.White,
				//NavigationBarTintColor = UIColor.Red,
				//PickerFontName = "Verdana",
				//PickefrBoldFontName = "Verdana-Bold",
				// PickerFontNormalSize = 14.0f,
				//PickerFontHeaderSize = 17.0f,
				//PickerStatusBarStyle = UIStatusBarStyle.LightContent,
				//UseCustomFontForNavigationBar = true,
			};

			picker.CustomSmartCollections = new [] { 
				PHAssetCollectionSubtype.SmartAlbumUserLibrary, 
				PHAssetCollectionSubtype.AlbumRegular 
			};

			// Event handling
			picker.FinishedPickingAssets += Picker_FinishedPickingAssets;
			picker.Canceled += Picker_Canceled;

            // Other events to implement in order to influence selection behavior:
            // Set EventArgs::Cancel flag to true in order to prevent the action from happening
            picker.ShouldDeselectAsset += (s, e) => { /* allow deselection of (mandatory) assets */ };
            picker.ShouldEnableAsset += (s, e) => { /* determine if a specific asset should be enabled */ };
            picker.ShouldHighlightAsset += (s, e) => { /* determine if a specific asset should be highlighted */ };
            picker.ShouldShowAsset += (s, e) => { /* determine if a specific asset should be displayed */ };
            picker.ShouldSelectAsset += (s, e) => { /* determine if a specific asset can be selected */ };

			var popPC = picker.PopoverPresentationController;
			popPC.PermittedArrowDirections = UIPopoverArrowDirection.Any;
			popPC.SourceView = gmImagePickerButton;
			popPC.SourceRect = gmImagePickerButton.Bounds;
//			popPC.BackgroundColor = UIColor.Black;

			await PresentViewControllerAsync(picker, true);
		}

		void Picker_Canceled (object sender, EventArgs e)
		{
			if (sender is UIImagePickerController) {
				((UIImagePickerController)sender).DismissViewController (true, null);
			}
			Console.WriteLine ("User canceled picking image.");
		}

		async void Picker_FinishedPickingAssets (object sender, MultiAssetEventArgs args)
		{
			PHImageManager imageManager = new PHImageManager();

			Console.WriteLine ("User finished picking assets. {0} items selected.", args.Assets.Length);

			// For demo purposes: just show all chosen pictures in order every second
			foreach (var asset in args.Assets) {<commit_msg>Cleanup and fixes for sample code<commit_after>﻿using System;

using UIKit;
using Foundation;
using Photos;
using GMImagePicker;
using System.Threading.Tasks;
using CoreGraphics;
using MobileCoreServices;

namespace GMPhotoPicker.Xamarin
{
	public partial class ViewController : UIViewController
	{
		public ViewController (IntPtr handle) : base (handle)
		{
		}

		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			// Perform any additional setup after loading the view, typically from a nib.
		}

		public override void DidReceiveMemoryWarning ()
		{
			base.DidReceiveMemoryWarning ();
			// Release any cached data, images, etc that aren't in use.
		}

		async partial void ShowGMImagePicker (NSObject sender)
		{
			var picker = new GMImagePickerController {
				Title = "Custom Title",
				CustomDoneButtonTitle = "Finished",
				CustomCancelButtonTitle = "Nope",
				CustomNavigationBarPrompt = "Take a new photo or select an existing one!",
				ColsInPortrait = 3,
				ColsInLandscape = 5,
				MinimumInteritemSpacing = 2.0f,
				DisplaySelectionInfoToolbar = true,
				AllowsMultipleSelection = true,
				ShowCameraButton = true,
				AutoSelectCameraImages = true,
				ModalPresentationStyle = UIModalPresentationStyle.Popover,
				MediaTypes = new [] { PHAssetMediaType.Image },

				// Other customizations to play with:
				//ConfirmSingleSelection = true,
				//ConfirmSingleSelectionPrompt = "Do you want to select the image you have chosen?",
				//PickerBackgroundColor = UIColor.Black,
				//PickerTextColor = UIColor.White,
				//ToolbarBarTintColor = UIColor.DarkGray,
				//ToolbarTextColor = UIColor.White,
				//ToolbarTintColor = UIColor.Red,
				//NavigationBarBackgroundColor = UIColor.Black,
				//NavigationBarTextColor = UIColor.White,
				//NavigationBarTintColor = UIColor.Red,
				//PickerFontName = "Verdana",
				//PickerBoldFontName = "Verdana-Bold",
				//PickerFontNormalSize = 14.0f,
				//PickerFontHeaderSize = 17.0f,
				//PickerStatusBarStyle = UIStatusBarStyle.LightContent,
				//UseCustomFontForNavigationBar = true,
			};

			// You can limit which galleries are available to browse through
			picker.CustomSmartCollections = new [] { 
				PHAssetCollectionSubtype.SmartAlbumUserLibrary, 
				PHAssetCollectionSubtype.AlbumRegular 
			};

			// Event handling
			picker.FinishedPickingAssets += Picker_FinishedPickingAssets;
			picker.Canceled += Picker_Canceled;

            // Other events to implement in order to influence selection behavior:
            // Set EventArgs::Cancel flag to true in order to prevent the action from happening
            picker.ShouldDeselectAsset += (s, e) => { /* allow deselection of (mandatory) assets */ };
            picker.ShouldEnableAsset += (s, e) => { /* determine if a specific asset should be enabled */ };
            picker.ShouldHighlightAsset += (s, e) => { /* determine if a specific asset should be highlighted */ };
            picker.ShouldShowAsset += (s, e) => { /* determine if a specific asset should be displayed */ };
            picker.ShouldSelectAsset += (s, e) => { /* determine if a specific asset can be selected */ };

			picker.AssetSelected += (s, e) => { /* keep track of individual asset selection */ };
			picker.AssetDeselected += (s, e) => { /* keep track of individual asset de-selection */ };

			// GMImagePicker can be treated as a PopOver as well:
			var popPC = picker.PopoverPresentationController;
			popPC.PermittedArrowDirections = UIPopoverArrowDirection.Any;
			popPC.SourceView = gmImagePickerButton;
			popPC.SourceRect = gmImagePickerButton.Bounds;
			//popPC.BackgroundColor = UIColor.Black;

			await PresentViewControllerAsync(picker, true);
		}

		void Picker_Canceled (object sender, EventArgs e)
		{
			if (sender is UIImagePickerController) {
				((UIImagePickerController)sender).DismissViewController (true, null);
			}
			Console.WriteLine ("User canceled picking image.");
		}

		async void Picker_FinishedPickingAssets (object sender, MultiAssetEventArgs args)
		{
			PHImageManager imageManager = new PHImageManager();

			Console.WriteLine ("User finished picking assets. {0} items selected.", args.Assets.Length);

			// For demo purposes: just show all chosen pictures in order every second
			foreach (var asset in args.Assets) {
{'fraction_non_alphanumeric': 0.0933156049800556, 'fraction_numerical': 0.0026592529916596155, 'mean_word_length': 3.5864745011086474, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6533021', 'n_tokens_mistral': 2683, 'n_tokens_neox': 2297, 'n_words': 656}