/// <summary> /// </summary> /// <param name="parameter"></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 PokemonInventory = JsonConvert.DeserializeObject <ObservableCollection <PokemonDataWrapper> >((string)suspensionState[nameof(PokemonInventory)]); EggsInventory = JsonConvert.DeserializeObject <ObservableCollection <PokemonDataWrapper> >((string)suspensionState[nameof(EggsInventory)]); CurrentPokemonSortingMode = (PokemonSortingModes)suspensionState[nameof(CurrentPokemonSortingMode)]; PlayerProfile = GameClient.PlayerData; } else { // Navigating from game page, so we need to actually load the inventory // The sorting mode is directly bound to the settings PokemonInventory = new ObservableCollection <PokemonDataWrapper>(GameClient.PokemonsInventory .Select(pokemonData => new PokemonDataWrapper(pokemonData)) .SortBySortingmode(CurrentPokemonSortingMode)); RaisePropertyChanged(() => PokemonInventory); var unincubatedEggs = GameClient.EggsInventory.Where(o => string.IsNullOrEmpty(o.EggIncubatorId)) .OrderBy(c => c.EggKmWalkedTarget); var incubatedEggs = GameClient.EggsInventory.Where(o => !string.IsNullOrEmpty(o.EggIncubatorId)) .OrderBy(c => c.EggKmWalkedTarget); EggsInventory.Clear(); // advancedrei: I have verified this is the sort order in the game. foreach (var incubatedEgg in incubatedEggs) { EggsInventory.Add(new IncubatedEggDataWrapper(GameClient.GetIncubatorFromEgg(incubatedEgg), GameClient.PlayerStats.KmWalked, incubatedEgg)); } foreach (var pokemonData in unincubatedEggs) { EggsInventory.Add(new PokemonDataWrapper(pokemonData)); } RaisePropertyChanged(() => TotalPokemonCount); PlayerProfile = GameClient.PlayerData; } // try restoring scrolling position if (NavigationHelper.NavigationState.ContainsKey("LastViewedPokemonDetailID")) { ulong pokemonId = (ulong)NavigationHelper.NavigationState["LastViewedPokemonDetailID"]; NavigationHelper.NavigationState.Remove("LastViewedPokemonDetailID"); var pokemon = PokemonInventory.Where(p => p.Id == pokemonId).FirstOrDefault(); if (pokemon != null) { ScrollPokemonToVisibleRequired?.Invoke(pokemon); } } // set the selectioMode to GoToDetail currentSelectionMode = SelectionMode.GoToDetail; await Task.CompletedTask; }
/// <summary> /// </summary> /// <param name="parameter"></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 PokemonInventory = JsonConvert.DeserializeObject <ObservableCollection <PokemonDataWrapper> >((string)suspensionState[nameof(PokemonInventory)]); EggsInventory = JsonConvert.DeserializeObject <ObservableCollection <PokemonDataWrapper> >((string)suspensionState[nameof(EggsInventory)]); PlayerProfile = new PlayerData(); PlayerProfile.MergeFrom(ByteString.FromBase64((string)suspensionState[nameof(PlayerProfile)]).CreateCodedInput()); RaisePropertyChanged(() => PlayerProfile); } else { // Navigating from game page, so we need to actually load the inventory // The sorting mode is directly bound to the settings PokemonInventory = new ObservableCollection <PokemonDataWrapper>(GetSortedPokemonCollection( GameClient.PokemonsInventory.Select(pokemonData => new PokemonDataWrapper(pokemonData)), CurrentPokemonSortingMode)); RaisePropertyChanged(() => PokemonInventory); var unincubatedEggs = GameClient.EggsInventory.Where(o => string.IsNullOrEmpty(o.EggIncubatorId)) .OrderBy(c => c.EggKmWalkedTarget); var incubatedEggs = GameClient.EggsInventory.Where(o => !string.IsNullOrEmpty(o.EggIncubatorId)) .OrderBy(c => c.EggKmWalkedTarget); EggsInventory.Clear(); // advancedrei: I have verified this is the sort order in the game. foreach (var incubatedEgg in incubatedEggs) { var incubatorData = GameClient.UsedIncubatorsInventory.FirstOrDefault(incubator => incubator.Id == incubatedEgg.EggIncubatorId); EggsInventory.Add(new IncubatedEggDataWrapper(incubatorData, GameClient.PlayerStats.KmWalked, incubatedEgg)); } foreach (var pokemonData in unincubatedEggs) { EggsInventory.Add(new PokemonDataWrapper(pokemonData)); } if (mode == NavigationMode.Back) { ResetView?.Invoke(); } PlayerProfile = GameClient.PlayerProfile; } await Task.CompletedTask; }
/// <summary> /// Updates inventory data /// </summary> public static async Task UpdateInventory() { // Get ALL the items var fullInventory = (await GetInventory()).InventoryDelta.InventoryItems; // Update items var tmpItemsInventory = fullInventory.Where(item => item.InventoryItemData.Item != null).GroupBy(item => item.InventoryItemData.Item); ItemsInventory.Clear(); foreach (var item in tmpItemsInventory) { ItemsInventory.Add(item.First().InventoryItemData.Item); } // Update incbuators //var tmpIncubatorsInventory = fullInventory.Where(item => item.InventoryItemData.EggIncubators != null).GroupBy(item => item.InventoryItemData.EggIncubators); //IncubatorsInventory.Clear(); //foreach (var item in tmpIncubatorsInventory) //{ // IncubatorsInventory.Add(item.First().InventoryItemData.Item); //} // Update Pokemons var tmpPokemonsInventory = fullInventory.Where(item => item.InventoryItemData.PokemonData != null).Select(itemt => itemt.InventoryItemData.PokemonData); PokemonsInventory.Clear(); EggsInventory.Clear(); foreach (var pokemon in tmpPokemonsInventory) { if (pokemon.IsEgg) { EggsInventory.Add(pokemon); } else { PokemonsInventory.Add(pokemon); } } }