Esempio n. 1
0
		public FolderSelectionPage(string path, Action updateAction, Color textColor, Color backgroundColor) : base()
		{
			this.path = path;
			this.updateAction = updateAction;

			Title = path;

			NavigationPage.SetTitleIcon(this, "HomeIcon.png");
			NavigationPage.SetBackButtonTitle(this, string.Empty);

			this.ToolbarItems.Add(new ToolbarItem(Catalog.GetString("New folder"), null, () =>
				{
					App.Click();
					var cfg = new PromptConfig();
					cfg.Message = Catalog.GetString("New folder name");
					cfg.Title = Catalog.GetString("New folder");
					cfg.OnResult = (result) =>
						{
							Device.BeginInvokeOnMainThread(() =>
								{
									App.Click();
									if (result.Ok)
									{
										Directory.CreateDirectory(Path.Combine(path, result.Text));
										this.path = Path.Combine(path, result.Text);
										UpdateDirectories();
									}
								});
						};
					UserDialogs.Instance.Prompt(cfg);
				}, ToolbarItemOrder.Secondary));

			var cell = new DataTemplate(typeof(TextCell));
			cell.SetValue(TextCell.TextColorProperty, textColor);
			cell.SetBinding(TextCell.TextProperty, "Name");

			list = new ListView() {
				BackgroundColor = backgroundColor,
				RowHeight = 50,
				HasUnevenRows = false,
				ItemTemplate = cell,
				ItemsSource = new PathItem[] {},
				HorizontalOptions = LayoutOptions.FillAndExpand,
				VerticalOptions = LayoutOptions.FillAndExpand,
			};

			list.ItemTapped += (object sender, ItemTappedEventArgs e) => {
				var pathItem = ((PathItem)e.Item);
				this.path = pathItem.Path;

				Settings.Current.AddOrUpdateValue<string>(Settings.CartridgePathKey, this.path);

				if(updateAction != null)
				{
					updateAction();
				}

				UpdateDirectories();
			};

//			((StackLayout)ContentLayout).Children.Add(list);
			Content = list;

			UpdateDirectories();
		}
Esempio n. 2
0
		/// <summary>
		/// Handles the menu action.
		/// </summary>
		/// <param name="page">Active page.</param>
		/// <param name="action">Action of menu selected.</param>
		public async void HandleMenuAction(Page page, string action)
		{
			// Notify user
			App.Click();

			if (action == Catalog.GetString("Quit"))
			{
				bool result = await UserDialogs.Instance.ConfirmAsync(Catalog.GetString("Would you like to save the current game?"), Catalog.GetString("Save Game"), Catalog.GetString("Yes"), Catalog.GetString("No"));

				App.Click();

				if (result)
				{
					// Ask for savegame name
					var cfg = new PromptConfig();
					cfg.Message = Catalog.GetString("Provide a comment to identify this savefile");
					cfg.Title = Catalog.GetString("Comment Savefile");
					cfg.OnResult = (savegameResult) =>
					{
						Device.BeginInvokeOnMainThread(() =>
							{
								App.Click();
								if (savegameResult.Ok)
								{
									this.gameModel.Save(savegameResult.Text);

									// Stop engine
									this.gameModel.Stop();

									App.Game = null;

									// Deactivate always on behavior of screen
									DependencyService.Get<IScreen>().AlwaysOn(false);

									// Remove active screen
									App.GameNavigation.CurrentPage.Navigation.PopModalAsync();
									App.GameNavigation = null;
								}
							});
					};
					UserDialogs.Instance.Prompt(cfg);
				}
				else
				{
					// Stop engine
					this.gameModel.Stop();

					App.Game = null;

					// Deactivate always on behavior of screen
					DependencyService.Get<IScreen>().AlwaysOn(false);

					// Remove active screen
					App.GameNavigation.CurrentPage.Navigation.PopModalAsync();
					App.GameNavigation = null;
				}
			}

			if (action == Catalog.GetString("Save"))
			{
				// Ask for savegame name
				var cfg = new PromptConfig();
				cfg.Message = Catalog.GetString("Provide a comment to identify this savefile");
				cfg.Title = Catalog.GetString("Comment Savefile");
				cfg.OnResult = (savegameResult) =>
					{
						Device.BeginInvokeOnMainThread(() =>
							{
								App.Click();
								if (savegameResult.Ok)
								{
									this.gameModel.Save(savegameResult.Text);
								}
							});
					};
				UserDialogs.Instance.Prompt(cfg);
			}
		}
Esempio n. 3
0
		public override void Prompt(PromptConfig config)
		{
			Utils.RequestMainThread(() =>
				{
					var activity = this.getTopActivity();
					var txt = new EditText(activity) {
						Hint = config.Placeholder
					};
					if (config.InputType != InputType.Default)
						txt.SetMaxLines(1);
					this.SetInputType(txt, config.InputType);
					var dialog = new AlertDialog
					.Builder(activity)
					.SetCancelable(false)
					.SetMessage(config.Message)
					.SetTitle(config.Title)
					.SetView(txt)
					.SetPositiveButton(config.OkText, (o, e) =>
						config.OnResult(new PromptResult {
								Ok = true,
								Text = txt.Text
							})
					             )
					.SetNegativeButton(config.CancelText, (o, e) =>
						config.OnResult(new PromptResult {
								Ok = false,
								Text = txt.Text
							})
					             ).Create();
					dialog.Window.SetSoftInputMode(SoftInput.StateVisible);
					dialog.Show();
				});
		}
Esempio n. 4
0
		public override void Prompt(PromptConfig config)
		{
			UIApplication.SharedApplication.InvokeOnMainThread(() =>
				{
					var result = new PromptResult();
					if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
					{
						var dlg = UIAlertController.Create(config.Title ?? String.Empty, config.Message, UIAlertControllerStyle.Alert);
						UITextField txt = null;
						dlg.AddAction(UIAlertAction.Create(config.OkText, UIAlertActionStyle.Default, x =>
								{
									result.Ok = true;
									result.Text = txt.Text.Trim();
									config.OnResult(result);
								}));
						dlg.AddAction(UIAlertAction.Create(config.CancelText, UIAlertActionStyle.Default, x =>
								{
									result.Ok = false;
									result.Text = txt.Text.Trim();
									config.OnResult(result);
								}));
						dlg.AddTextField(x =>
							{
								this.SetInputType(x, config.InputType);
								x.Placeholder = config.Placeholder ?? String.Empty;
								txt = x;
							});
						this.Present(dlg);
					}
					else
					{
						var isPassword = config.InputType == InputType.Password;
						var dlg = new UIAlertView(config.Title ?? String.Empty, config.Message, null, config.CancelText, config.OkText) {
							AlertViewStyle = isPassword
								? UIAlertViewStyle.SecureTextInput
								: UIAlertViewStyle.PlainTextInput
						};
						var txt = dlg.GetTextField(0);
						this.SetInputType(txt, config.InputType);
						txt.Placeholder = config.Placeholder;
						dlg.Clicked += (s, e) =>
						{
							result.Ok = ((int)dlg.CancelButtonIndex != (int)e.ButtonIndex);
							result.Text = txt.Text.Trim();
							config.OnResult(result);
						};
						dlg.Show();
					}
				});
		}
Esempio n. 5
0
		public abstract void Prompt(PromptConfig config);
Esempio n. 6
0
		public virtual Task<PromptResult> PromptAsync(PromptConfig config)
		{
			var tcs = new TaskCompletionSource<PromptResult>();
			config.OnResult = x => tcs.TrySetResult(x);
			this.Prompt(config);
			return tcs.Task;
		}