Search in sources :

Example 1 with CatchablePokemonEvent

use of com.omkarmoghe.pokemap.models.events.CatchablePokemonEvent 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)

Aggregations

CatchablePokemonEvent (com.omkarmoghe.pokemap.models.events.CatchablePokemonEvent)1 InternalExceptionEvent (com.omkarmoghe.pokemap.models.events.InternalExceptionEvent)1 LoginEventResult (com.omkarmoghe.pokemap.models.events.LoginEventResult)1 ServerUnreachableEvent (com.omkarmoghe.pokemap.models.events.ServerUnreachableEvent)1 LoginFailedException (com.pokegoapi.exceptions.LoginFailedException)1 RemoteServerException (com.pokegoapi.exceptions.RemoteServerException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1