public void ShowPreviousStep() { //if there are still steps/questions if (StepList.Any()) { //get the last step in the list var lastStep = StepList.Last(); //display it ShowStep(lastStep); } else { //if there are no steps remaining, call OnBackPressed base.OnBackPressed(); } }
public async void ShowStep(Step processFlowStep) { //either display the step or remove it from the persisted step list if (processFlowStep != null) { var stepToAddRemove = processFlowStep; if (StepList.Contains(stepToAddRemove)) { //text/numeric/date input answers to be removed from state if (stepToAddRemove.Type != (int)StepInputTypeEnum.Options) { //remove the saved answer from persisted state StepAnswersDictionary.Remove(stepToAddRemove.Id); } //if it already exists in the persisted step list, remove it StepList.Remove(stepToAddRemove); if (StepList.Any()) { //and get the step before it stepToAddRemove = StepList.Last(); } else { //if after removing and there are no more steps, go back to the previous activity base.OnBackPressed(); } } else { //if it doesnt exist in the persisted step list, add it StepList.Add(stepToAddRemove); } //instantiate a new Step Fragment var processFlowFragment = new ProcessFlowFragment(); Bundle args = new Bundle(); //serialize the object to a step definition string var processFlowString = JsonConvert.SerializeObject(stepToAddRemove); //pass the step string definition to the fragment in the bundle args.PutString(ProcessFlowStep, processFlowString); // if the step to be shown is a text/numeric/date input, check the dictionary for a saved answer entered previously and pass it to the fragment if (stepToAddRemove.Type != (int)StepInputTypeEnum.Options) { string stepAnwer = null; if (StepAnswersDictionary.TryGetValue(stepToAddRemove.Id, out stepAnwer)) { Logger.Verbose(stepToAddRemove.HeaderText + " : Answer found in Dictionary to be shown in Fragment : " + stepAnwer); } args.PutString(ProcessFlowStepAnswer, stepAnwer); } processFlowFragment.Arguments = args; //display the fragment ReplaceFragment(processFlowFragment, Resource.Id.ticket_placeholder, TicketFragmentTag); } }