/// <summary> /// When new items are added to the Pokedex, reset the Nearby Pokemon so their state can be re-run. /// </summary> /// <remarks> /// This exists because the Nearby Pokemon are Map objects, and are loaded before Inventory. If you don't do this, /// the first Nearby items are always shown as "new to the Pokedex" until they disappear, regardless of if they are /// ACTUALLY new. /// </remarks> private static void PokedexInventory_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Add) { // advancedrei: This is a total order-of-operations hack. var nearby = NearbyPokemons.ToList(); NearbyPokemons.Clear(); NearbyPokemons.AddRange(nearby); } }
/// <summary> /// Logs the user out by clearing data and timers /// </summary> public static void DoLogout() { // Clear stored token SettingsService.Instance.PtcAuthToken = null; SettingsService.Instance.GoogleAuthToken = null; _mapUpdateTimer?.Stop(); _mapUpdateTimer = null; _geolocator = null; CatchablePokemons.Clear(); NearbyPokemons.Clear(); NearbyPokestops.Clear(); }
/// <summary> /// Logs the user out by clearing data and timers /// </summary> public static void DoLogout() { // Clear stored token SettingsService.Instance.AccessTokenString = null; if (!SettingsService.Instance.RememberLoginData) { SettingsService.Instance.UserCredentials = null; } _heartbeat?.StopDispatcher(); if (_geolocator != null) { _geolocator.PositionChanged -= GeolocatorOnPositionChanged; } _geolocator = null; _lastGeopositionMapObjectsRequest = null; CatchablePokemons?.Clear(); NearbyPokemons?.Clear(); NearbyPokestops?.Clear(); }
/// <summary> /// Updates catcheable and nearby Pokemons + Pokestops. /// We're using a single method so that we don't need two separate calls to the server, making things faster. /// </summary> /// <returns></returns> private static async Task UpdateMapObjects() { // Get all map objects from server var mapObjects = (await GetMapObjects(Geoposition)).Item1; // Replace data with the new ones var catchableTmp = new List <MapPokemon>(mapObjects.MapCells.SelectMany(i => i.CatchablePokemons)); Logger.Write($"Found {catchableTmp.Count} catchable pokemons"); if (catchableTmp.Count != CatchablePokemons.Count) { MapPokemonUpdated?.Invoke(null, null); } CatchablePokemons.Clear(); foreach (var pokemon in catchableTmp) { CatchablePokemons.Add(new MapPokemonWrapper(pokemon)); } var nearbyTmp = new List <NearbyPokemon>(mapObjects.MapCells.SelectMany(i => i.NearbyPokemons)); Logger.Write($"Found {nearbyTmp.Count} nearby pokemons"); NearbyPokemons.Clear(); foreach (var pokemon in nearbyTmp) { NearbyPokemons.Add(pokemon); } // Retrieves PokeStops but not Gyms var pokeStopsTmp = new List <FortData>(mapObjects.MapCells.SelectMany(i => i.Forts) .Where(i => i.Type == FortType.Checkpoint)); Logger.Write($"Found {pokeStopsTmp.Count} nearby PokeStops"); NearbyPokestops.Clear(); foreach (var pokestop in pokeStopsTmp) { NearbyPokestops.Add(new FortDataWrapper(pokestop)); } Logger.Write("Finished updating map objects"); }