Search in sources :

Example 1 with InternalExceptionEvent

use of com.omkarmoghe.pokemap.models.events.InternalExceptionEvent in project Pokemap by omkarmoghe.

the class NianticManager method getLuredPokemon.

public void getLuredPokemon(final double lat, final double longitude, final double alt) {
    final int myCurrentBatch = this.currentBatchCall;
    mHandler.post(new Runnable() {

        @Override
        public void run() {
            try {
                if (mPokemonGo != null && NianticManager.this.currentBatchCall == myCurrentBatch) {
                    Thread.sleep(133);
                    mPokemonGo.setLocation(lat, longitude, alt);
                    Thread.sleep(133);
                    List<CatchablePokemon> pokemon = new ArrayList<>();
                    for (Pokestop pokestop : mPokemonGo.getMap().getMapObjects().getPokestops()) {
                        if (!pokestop.getFortData().getLureInfo().equals(FortLureInfoOuterClass.FortLureInfo.getDefaultInstance())) {
                            Log.d(TAG, "run: hasFortInfo = " + pokestop.getFortData().getLureInfo());
                            pokemon.add(new CatchablePokemon(mPokemonGo, pokestop.getFortData()));
                        }
                    }
                    if (NianticManager.this.currentBatchCall == myCurrentBatch)
                        EventBus.getDefault().post(new LurePokemonEvent(pokemon, lat, longitude));
                }
            } catch (LoginFailedException e) {
                e.printStackTrace();
                Log.e(TAG, "Failed to fetch map information via getPokeStops(). Login credentials wrong or user banned. Raised: " + e.getMessage());
                EventBus.getDefault().post(new LoginEventResult(false, null, null));
            } catch (RemoteServerException e) {
                e.printStackTrace();
                Log.e(TAG, "Failed to fetch map information via getPokeStops(). Remote server unreachable. Raised: " + e.getMessage());
                EventBus.getDefault().post(new ServerUnreachableEvent(e));
            } catch (InterruptedException | RuntimeException e) {
                e.printStackTrace();
                Log.e(TAG, "Failed to fetch map information via getPokeStops(). PoGoAPI crashed. Raised: " + e.getMessage());
                EventBus.getDefault().post(new InternalExceptionEvent(e));
            }
        }
    });
}
Also used : LoginEventResult(com.omkarmoghe.pokemap.models.events.LoginEventResult) ServerUnreachableEvent(com.omkarmoghe.pokemap.models.events.ServerUnreachableEvent) CatchablePokemon(com.pokegoapi.api.map.pokemon.CatchablePokemon) LoginFailedException(com.pokegoapi.exceptions.LoginFailedException) LurePokemonEvent(com.omkarmoghe.pokemap.models.events.LurePokemonEvent) Pokestop(com.pokegoapi.api.map.fort.Pokestop) InternalExceptionEvent(com.omkarmoghe.pokemap.models.events.InternalExceptionEvent) List(java.util.List) ArrayList(java.util.ArrayList) RemoteServerException(com.pokegoapi.exceptions.RemoteServerException)

Example 2 with InternalExceptionEvent

use of com.omkarmoghe.pokemap.models.events.InternalExceptionEvent in project Pokemap by omkarmoghe.

the class NianticManager method getCatchablePokemon.

public void getCatchablePokemon(final double lat, final double longitude, final double alt) {
    final int myCurrentBatch = this.currentBatchCall;
    mHandler.post(new Runnable() {

        @Override
        public void run() {
            try {
                if (mPokemonGo != null && NianticManager.this.currentBatchCall == myCurrentBatch) {
                    Thread.sleep(133);
                    mPokemonGo.setLocation(lat, longitude, alt);
                    Thread.sleep(133);
                    List<CatchablePokemon> catchablePokemons = mPokemonGo.getMap().getCatchablePokemon();
                    if (NianticManager.this.currentBatchCall == myCurrentBatch)
                        EventBus.getDefault().post(new CatchablePokemonEvent(catchablePokemons, lat, longitude));
                }
            } catch (LoginFailedException e) {
                e.printStackTrace();
                Log.e(TAG, "Failed to fetch map information via getCatchablePokemon(). Login credentials wrong or user banned. Raised: " + e.getMessage());
                EventBus.getDefault().post(new LoginEventResult(false, null, null));
            } catch (RemoteServerException e) {
                e.printStackTrace();
                Log.e(TAG, "Failed to fetch map information via getCatchablePokemon(). Remote server unreachable. Raised: " + e.getMessage());
                EventBus.getDefault().post(new ServerUnreachableEvent(e));
            } catch (InterruptedException | RuntimeException e) {
                e.printStackTrace();
                Log.e(TAG, "Failed to fetch map information via getCatchablePokemon(). PoGoAPI crashed. Raised: " + e.getMessage());
                EventBus.getDefault().post(new InternalExceptionEvent(e));
            }
            NianticManager.this.currentScan++;
        }
    });
    this.pendingSearch++;
}
Also used : CatchablePokemonEvent(com.omkarmoghe.pokemap.models.events.CatchablePokemonEvent) LoginFailedException(com.pokegoapi.exceptions.LoginFailedException) InternalExceptionEvent(com.omkarmoghe.pokemap.models.events.InternalExceptionEvent) List(java.util.List) ArrayList(java.util.ArrayList) LoginEventResult(com.omkarmoghe.pokemap.models.events.LoginEventResult) ServerUnreachableEvent(com.omkarmoghe.pokemap.models.events.ServerUnreachableEvent) RemoteServerException(com.pokegoapi.exceptions.RemoteServerException)

Example 3 with InternalExceptionEvent

use of com.omkarmoghe.pokemap.models.events.InternalExceptionEvent in project Pokemap by omkarmoghe.

the class NianticManager method getPokeStops.

public void getPokeStops(final double lat, final double longitude, final double alt) {
    final int myCurrentBatch = this.currentBatchCall;
    mHandler.post(new Runnable() {

        @Override
        public void run() {
            try {
                if (mPokemonGo != null && NianticManager.this.currentBatchCall == myCurrentBatch) {
                    Thread.sleep(133);
                    mPokemonGo.setLocation(lat, longitude, alt);
                    Thread.sleep(133);
                    Collection<Pokestop> pokestops = mPokemonGo.getMap().getMapObjects().getPokestops();
                    if (NianticManager.this.currentBatchCall == myCurrentBatch)
                        EventBus.getDefault().post(new PokestopsEvent(pokestops, lat, longitude));
                }
            } catch (LoginFailedException e) {
                e.printStackTrace();
                Log.e(TAG, "Failed to fetch map information via getPokeStops(). Login credentials wrong or user banned. Raised: " + e.getMessage());
                EventBus.getDefault().post(new LoginEventResult(false, null, null));
            } catch (RemoteServerException e) {
                e.printStackTrace();
                Log.e(TAG, "Failed to fetch map information via getPokeStops(). Remote server unreachable. Raised: " + e.getMessage());
                EventBus.getDefault().post(new ServerUnreachableEvent(e));
            } catch (InterruptedException | RuntimeException e) {
                e.printStackTrace();
                Log.e(TAG, "Failed to fetch map information via getPokeStops(). PoGoAPI crashed. Raised: " + e.getMessage());
                EventBus.getDefault().post(new InternalExceptionEvent(e));
            }
        }
    });
}
Also used : LoginFailedException(com.pokegoapi.exceptions.LoginFailedException) PokestopsEvent(com.omkarmoghe.pokemap.models.events.PokestopsEvent) InternalExceptionEvent(com.omkarmoghe.pokemap.models.events.InternalExceptionEvent) Collection(java.util.Collection) LoginEventResult(com.omkarmoghe.pokemap.models.events.LoginEventResult) ServerUnreachableEvent(com.omkarmoghe.pokemap.models.events.ServerUnreachableEvent) RemoteServerException(com.pokegoapi.exceptions.RemoteServerException)

Example 4 with InternalExceptionEvent

use of com.omkarmoghe.pokemap.models.events.InternalExceptionEvent in project Pokemap by omkarmoghe.

the class NianticManager method getGyms.

public void getGyms(final double latitude, final double longitude, final double alt) {
    final int myCurrentBatch = this.currentBatchCall;
    mHandler.post(new Runnable() {

        @Override
        public void run() {
            try {
                if (mPokemonGo != null && NianticManager.this.currentBatchCall == myCurrentBatch) {
                    Thread.sleep(133);
                    mPokemonGo.setLocation(latitude, longitude, alt);
                    Thread.sleep(133);
                    Collection<FortDataOuterClass.FortData> gyms = mPokemonGo.getMap().getMapObjects().getGyms();
                    if (NianticManager.this.currentBatchCall == myCurrentBatch)
                        EventBus.getDefault().post(new GymsEvent(gyms, latitude, longitude));
                }
            } catch (LoginFailedException e) {
                e.printStackTrace();
                Log.e(TAG, "Failed to fetch map information via getGyms(). Login credentials wrong or user banned. Raised: " + e.getMessage());
                EventBus.getDefault().post(new LoginEventResult(false, null, null));
            } catch (RemoteServerException e) {
                e.printStackTrace();
                Log.e(TAG, "Failed to fetch map information via getGyms(). Remote server unreachable. Raised: " + e.getMessage());
                EventBus.getDefault().post(new ServerUnreachableEvent(e));
            } catch (InterruptedException | RuntimeException e) {
                e.printStackTrace();
                Log.e(TAG, "Failed to fetch map information via getGyms(). PoGoAPI crashed. Raised: " + e.getMessage());
                EventBus.getDefault().post(new InternalExceptionEvent(e));
            }
        }
    });
}
Also used : LoginFailedException(com.pokegoapi.exceptions.LoginFailedException) GymsEvent(com.omkarmoghe.pokemap.models.events.GymsEvent) InternalExceptionEvent(com.omkarmoghe.pokemap.models.events.InternalExceptionEvent) Collection(java.util.Collection) FortDataOuterClass(POGOProtos.Map.Fort.FortDataOuterClass) LoginEventResult(com.omkarmoghe.pokemap.models.events.LoginEventResult) ServerUnreachableEvent(com.omkarmoghe.pokemap.models.events.ServerUnreachableEvent) RemoteServerException(com.pokegoapi.exceptions.RemoteServerException)

Aggregations

InternalExceptionEvent (com.omkarmoghe.pokemap.models.events.InternalExceptionEvent)4 LoginEventResult (com.omkarmoghe.pokemap.models.events.LoginEventResult)4 ServerUnreachableEvent (com.omkarmoghe.pokemap.models.events.ServerUnreachableEvent)4 LoginFailedException (com.pokegoapi.exceptions.LoginFailedException)4 RemoteServerException (com.pokegoapi.exceptions.RemoteServerException)4 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 FortDataOuterClass (POGOProtos.Map.Fort.FortDataOuterClass)1 CatchablePokemonEvent (com.omkarmoghe.pokemap.models.events.CatchablePokemonEvent)1 GymsEvent (com.omkarmoghe.pokemap.models.events.GymsEvent)1 LurePokemonEvent (com.omkarmoghe.pokemap.models.events.LurePokemonEvent)1 PokestopsEvent (com.omkarmoghe.pokemap.models.events.PokestopsEvent)1 Pokestop (com.pokegoapi.api.map.fort.Pokestop)1 CatchablePokemon (com.pokegoapi.api.map.pokemon.CatchablePokemon)1