Search in sources :

Example 1 with GymsEvent

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

FortDataOuterClass (POGOProtos.Map.Fort.FortDataOuterClass)1 GymsEvent (com.omkarmoghe.pokemap.models.events.GymsEvent)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 Collection (java.util.Collection)1