/// <summary> /// </summary> /// <param name="parameter">FortData containing the Pokestop that we're visiting</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 CurrentPokestop = JsonConvert.DeserializeObject <FortDataWrapper>((string)suspensionState[nameof(CurrentPokestop)]); CurrentPokestopInfo.MergeFrom(ByteString.FromBase64((string)suspensionState[nameof(CurrentPokestop)]).CreateCodedInput()); CurrentSearchResponse.MergeFrom(ByteString.FromBase64((string)suspensionState[nameof(CurrentSearchResponse)]).CreateCodedInput()); } else { // Navigating from game page, so we need to actually load the Pokestop Busy.SetBusy(true, "Loading Pokestop"); CurrentPokestop = (FortDataWrapper)NavigationHelper.NavigationState[nameof(CurrentPokestop)]; NavigationHelper.NavigationState.Remove(nameof(CurrentPokestop)); Logger.Write($"Searching {CurrentPokestop.Id}"); CurrentPokestopInfo = await GameClient.GetFort(CurrentPokestop.Id, CurrentPokestop.Latitude, CurrentPokestop.Longitude); Busy.SetBusy(false); // If timeout is expired we can go to to pokestop page if (CurrentPokestop.CooldownCompleteTimestampMs >= DateTime.UtcNow.ToUnixTime()) { // Timeout is not expired yet, player can't get items from the fort SearchInCooldown?.Invoke(null, null); } } }
/// <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(CurrentPokestop)] = JsonConvert.SerializeObject(CurrentPokestop); suspensionState[nameof(CurrentPokestopInfo)] = CurrentPokestopInfo.ToByteString().ToBase64(); suspensionState[nameof(CurrentSearchResponse)] = CurrentSearchResponse.ToByteString().ToBase64(); } await Task.CompletedTask; }