Ejemplo n.º 1
0
 /// <summary>
 ///     Save state before navigating
 /// </summary>
 /// <param name="suspensionState"></param>
 /// <param name="suspending"></param>
 /// <returns></returns>
 public override async Task OnNavigatedFromAsync(IDictionary <string, object> suspensionState, bool suspending)
 {
     if (suspending)
     {
         suspensionState[nameof(CurrentPokemon)]       = JsonConvert.SerializeObject(CurrentPokemon);
         suspensionState[nameof(CurrentEncounter)]     = CurrentEncounter.ToByteString().ToBase64();
         suspensionState[nameof(CurrentLureEncounter)] = CurrentLureEncounter.ToByteString().ToBase64();
         suspensionState[nameof(CurrentCaptureAward)]  = CurrentCaptureAward.ToByteString().ToBase64();
         suspensionState[nameof(SelectedCaptureItem)]  = SelectedCaptureItem.ToByteString().ToBase64();
     }
     await Task.CompletedTask;
 }
 /// <summary>
 /// </summary>
 /// <param name="parameter">MapPokemonWrapper containing the Pokemon that we're trying to capture</param>
 /// <param name="mode"></param>
 /// <param name="suspensionState"></param>
 /// <returns></returns>
 public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> suspensionState)
 {
     if (suspensionState.Any())
     {
         // Recovering the state
         CurrentPokemon = JsonConvert.DeserializeObject <IMapPokemon>((string)suspensionState[nameof(CurrentPokemon)]);
         CurrentEncounter.MergeFrom(ByteString.FromBase64((string)suspensionState[nameof(CurrentEncounter)]).CreateCodedInput());
         CurrentLureEncounter.MergeFrom(ByteString.FromBase64((string)suspensionState[nameof(CurrentLureEncounter)]).CreateCodedInput());
         CurrentCaptureAward.MergeFrom(ByteString.FromBase64((string)suspensionState[nameof(CurrentCaptureAward)]).CreateCodedInput());
         SelectedCaptureItem.MergeFrom(ByteString.FromBase64((string)suspensionState[nameof(SelectedCaptureItem)]).CreateCodedInput());
     }
     else
     {
         // Navigating from game page, so we need to actually load the encounter
         CurrentPokemon = (IMapPokemon)NavigationHelper.NavigationState[nameof(CurrentPokemon)];
         Busy.SetBusy(true, string.Format(Resources.CodeResources.GetString("LoadingEncounterText"), Resources.Pokemon.GetString(CurrentPokemon.PokemonId.ToString())));
         NavigationHelper.NavigationState.Remove(nameof(CurrentPokemon));
         Logger.Write($"Catching {CurrentPokemon.PokemonId}");
         await HandleEncounter();
     }
 }