private void OnSingleButtonFragmentClick(Object sender, EventArgs e) { SingleButtonFragment singleButtonFragment = this.FragmentManager.FindFragmentByTag("button_fragment") as SingleButtonFragment; SudokuView sudokuView = this.View.FindViewById <SudokuView>(Resource.Id.sudoku_view); String addText = this.Resources.GetString(Resource.String.add_button_text); String removeText = this.Resources.GetString(Resource.String.remove_button_text); String playText = this.Resources.GetString(Resource.String.play_button_text); if (singleButtonFragment.Text == addText) { SudokuGenerator.AddNumbers(this.ViewModel.Sudoku); sudokuView.Update(); this.ViewModel.ButtonText = singleButtonFragment.Text = removeText; } else if (singleButtonFragment.Text == removeText) { SudokuGenerator.RemoveNumbers(this.ViewModel.Sudoku); sudokuView.Update(); this.ViewModel.ButtonText = singleButtonFragment.Text = playText; } else if (singleButtonFragment.Text == playText) { this.Stop(); FragmentTransaction ft = this.FragmentManager.BeginTransaction(); ft.Remove(singleButtonFragment); ft.Commit(); this.Activity.Intent.PutExtra("action", (int)ActionType.Play); this.Activity.Intent.Extras.PutInt("action", (int)ActionType.Play); ActionType action = (ActionType)this.Activity.Intent.Extras.GetInt("action", (int)ActionType.None); this.ViewModel.ButtonText = null; this.Start(); } }
/*public override void OnActivityCreated(Bundle savedInstanceState) * { * base.OnActivityCreated(savedInstanceState);*/ private void Start() { this.ViewModel = (SudokuViewModel) new ViewModelProvider(this).Get(Java.Lang.Class.FromType(typeof(SudokuViewModel))); ActionType action = this.ViewModel.Action = (ActionType)this.Activity.Intent.Extras.GetInt("action", 1); switch (action) { case ActionType.Continue: this.ViewModel.OpenAsync(this.Context.FilesDir, SudokuDifficulty.None); break; case ActionType.Generate: case ActionType.New: SudokuDifficulty difficulty = (SudokuDifficulty)this.Activity.Intent.Extras.GetInt("difficulty", 1); this.ViewModel.OpenAsync(this.Context.FilesDir, difficulty); break; case ActionType.Play: break; default: throw new NotSupportedException(); } SudokuView sudokuView = this.View.FindViewById <SudokuView>(Resource.Id.sudoku_view); ControlFragment controlFragment; SingleButtonFragment singleButtonFragment; this.SudokuViewChanged = new EventHandler <SudokuViewEventArgs>((sender, e) => this.ViewModel.SetRowAndColumn(e.Row, e.Column)); this.ViewModelCompleted = new EventHandler(this.OnCompletion); this.ViewModelStateChangedSudokuViewUpdate = new EventHandler <ControlEventArgs>((sender, e) => { sudokuView.SelectedNumber = e.Number; sudokuView.SetRowAndColumn(this.ViewModel.Row, this.ViewModel.Column); }); this.ViewModelSudokuChanged = new EventHandler((sender, e) => { sudokuView.Sudoku = this.ViewModel.Sudoku; sudokuView.Update(); }); sudokuView.Changed += this.SudokuViewChanged; this.ViewModel.StateChanged += this.ViewModelStateChangedControlFragmentUpdate; this.ViewModel.StateChanged += this.ViewModelStateChangedSudokuViewUpdate; this.ViewModel.Completed += this.ViewModelCompleted; this.ViewModel.SudokuChanged += this.ViewModelSudokuChanged; sudokuView.Sudoku = this.ViewModel.Sudoku; sudokuView.SetRowAndColumn(this.ViewModel.Row, this.ViewModel.Column); sudokuView.SelectedNumber = this.ViewModel.State.Number; FragmentTransaction ft = this.Activity.SupportFragmentManager.BeginTransaction();; switch (action) { case ActionType.Continue: case ActionType.New: case ActionType.Play: //controlFragment = this.ChildFragmentManager.FindFragmentById(Resource.Id.control_fragment) as ControlFragment; controlFragment = new ControlFragment(); this.ControlFragmentChanged = new EventHandler <ControlEventArgs>((sender, e) => this.ViewModel.State = e); this.ViewModelStateChangedControlFragmentUpdate = new EventHandler <ControlEventArgs>((sender, e) => controlFragment.State = e); controlFragment.Changed += this.ControlFragmentChanged; controlFragment.State = this.ViewModel.State; this.ViewModel.StateChanged += this.ViewModelStateChangedControlFragmentUpdate; ft.Add(Resource.Id.fragment_frame_layout, controlFragment, "control_fragment"); ft.Commit(); break; case ActionType.Generate: if (this.ViewModel.ButtonText is null) { this.ViewModel.ButtonText = this.Resources.GetString(Resource.String.add_button_text); } singleButtonFragment = new SingleButtonFragment(this.ViewModel.ButtonText); this.SingleButtonFragmentClicked = new EventHandler(this.OnSingleButtonFragmentClick); singleButtonFragment.Click += this.SingleButtonFragmentClicked; ft.Add(Resource.Id.fragment_frame_layout, singleButtonFragment, "button_fragment"); ft.Commit(); break; } }