Skip to content

Commit eb3ac94

Browse files
kyr0comann
authored andcommitted
Support for Gyms; massive performance improvements (#204)
* - Added support for showing all gyms in different team colors - Removed all unused drawables - Massive performance optimization to the marker rendering / remote image loading - Uncoupled fetching of pokemon, gym, poke-stop (Notification Service should not fetch PokeStops and Gyms!) - Also PokeStops and Gyms are only fetched 1 time now on long-tap -- not 19 times (range search)... * - Merge branch 'dev' of https://github.com/omkarmoghe/Pokemap into gyms - Also fixed translations, etc. # Fixed Conflicts: # app/src/main/java/com/omkarmoghe/pokemap/views/map/MapWrapperFragment.java # app/src/main/res/values/dimens.xml * - Added german translation for new logout prompt * - Finally also the new images for the filter - Therefore had to change caching map datatype to Bitmap * - Better images
1 parent bdb07f5 commit eb3ac94

File tree

175 files changed

+441
-113
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

175 files changed

+441
-113
lines changed

app/src/main/java/com/omkarmoghe/pokemap/controllers/net/NianticManager.java

+65-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import android.support.annotation.NonNull;
1212
import android.util.Log;
1313

14+
import com.omkarmoghe.pokemap.models.events.GymsEvent;
1415
import com.omkarmoghe.pokemap.models.events.InternalExceptionEvent;
1516
import com.omkarmoghe.pokemap.models.events.LoginEventResult;
1617
import com.omkarmoghe.pokemap.models.events.PokestopsEvent;
@@ -27,11 +28,13 @@
2728

2829
import java.io.IOException;
2930
import java.util.ArrayList;
31+
import java.util.Collection;
3032
import java.util.HashMap;
3133
import java.util.List;
3234
import java.util.concurrent.TimeUnit;
3335
import java.util.logging.Logger;
3436

37+
import POGOProtos.Map.Fort.FortDataOuterClass;
3538
import POGOProtos.Networking.Envelopes.RequestEnvelopeOuterClass.RequestEnvelope.AuthInfo;
3639

3740
import okhttp3.Cookie;
@@ -295,7 +298,7 @@ public void run() {
295298
});
296299
}
297300

298-
public void getMapInformation(final double lat, final double longitude, final double alt){
301+
public void getCatchablePokemon(final double lat, final double longitude, final double alt){
299302
mHandler.post(new Runnable() {
300303
@Override
301304
public void run() {
@@ -307,25 +310,83 @@ public void run() {
307310
mPokemonGo.setLocation(lat, longitude, alt);
308311
Thread.sleep(33);
309312
EventBus.getDefault().post(new CatchablePokemonEvent(mPokemonGo.getMap().getCatchablePokemon(), lat, longitude));
313+
}
314+
315+
} catch (LoginFailedException e) {
316+
e.printStackTrace();
317+
Log.e(TAG, "Failed to fetch map information via getCatchablePokemon(). Login credentials wrong or user banned. Raised: " + e.getMessage());
318+
EventBus.getDefault().post(new LoginEventResult(false, null, null));
319+
} catch (RemoteServerException e) {
320+
e.printStackTrace();
321+
Log.e(TAG, "Failed to fetch map information via getCatchablePokemon(). Remote server unreachable. Raised: " + e.getMessage());
322+
EventBus.getDefault().post(new ServerUnreachableEvent(e));
323+
} catch (InterruptedException | RuntimeException e) {
324+
e.printStackTrace();
325+
Log.e(TAG, "Failed to fetch map information via getCatchablePokemon(). PoGoAPI crashed. Raised: " + e.getMessage());
326+
EventBus.getDefault().post(new InternalExceptionEvent(e));
327+
}
328+
}
329+
});
330+
}
331+
332+
public void getPokeStops(final double lat, final double longitude, final double alt){
333+
mHandler.post(new Runnable() {
334+
@Override
335+
public void run() {
336+
try {
337+
338+
if (mPokemonGo != null) {
339+
310340
Thread.sleep(33);
311341
EventBus.getDefault().post(new PokestopsEvent(mPokemonGo.getMap().getMapObjects().getPokestops()));
312342
}
313343

314344
} catch (LoginFailedException e) {
315345
e.printStackTrace();
316-
Log.e(TAG, "Failed to fetch map information via getMapInformation(). Login credentials wrong or user banned. Raised: " + e.getMessage());
346+
Log.e(TAG, "Failed to fetch map information via getPokeStops(). Login credentials wrong or user banned. Raised: " + e.getMessage());
317347
EventBus.getDefault().post(new LoginEventResult(false, null, null));
318348
} catch (RemoteServerException e) {
319349
e.printStackTrace();
320-
Log.e(TAG, "Failed to fetch map information via getMapInformation(). Remote server unreachable. Raised: " + e.getMessage());
350+
Log.e(TAG, "Failed to fetch map information via getPokeStops(). Remote server unreachable. Raised: " + e.getMessage());
321351
EventBus.getDefault().post(new ServerUnreachableEvent(e));
322352
} catch (InterruptedException | RuntimeException e) {
323353
e.printStackTrace();
324-
Log.e(TAG, "Failed to fetch map information via getMapInformation(). PoGoAPI crashed. Raised: " + e.getMessage());
354+
Log.e(TAG, "Failed to fetch map information via getPokeStops(). PoGoAPI crashed. Raised: " + e.getMessage());
325355
EventBus.getDefault().post(new InternalExceptionEvent(e));
326356
}
327357
}
328358
});
329359
}
330360

361+
public void getGyms(final double latitude, final double longitude, final double alt) {
362+
363+
mHandler.post(new Runnable() {
364+
@Override
365+
public void run() {
366+
try {
367+
368+
if (mPokemonGo != null) {
369+
370+
Thread.sleep(33);
371+
mPokemonGo.setLocation(latitude, longitude, alt);
372+
Thread.sleep(33);
373+
EventBus.getDefault().post(new GymsEvent(mPokemonGo.getMap().getMapObjects().getGyms()));
374+
}
375+
376+
} catch (LoginFailedException e) {
377+
e.printStackTrace();
378+
Log.e(TAG, "Failed to fetch map information via getGyms(). Login credentials wrong or user banned. Raised: " + e.getMessage());
379+
EventBus.getDefault().post(new LoginEventResult(false, null, null));
380+
} catch (RemoteServerException e) {
381+
e.printStackTrace();
382+
Log.e(TAG, "Failed to fetch map information via getGyms(). Remote server unreachable. Raised: " + e.getMessage());
383+
EventBus.getDefault().post(new ServerUnreachableEvent(e));
384+
} catch (InterruptedException | RuntimeException e) {
385+
e.printStackTrace();
386+
Log.e(TAG, "Failed to fetch map information via getGyms(). PoGoAPI crashed. Raised: " + e.getMessage());
387+
EventBus.getDefault().post(new InternalExceptionEvent(e));
388+
}
389+
}
390+
});
391+
}
331392
}

app/src/main/java/com/omkarmoghe/pokemap/controllers/service/PokemonNotificationService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public void run() {
177177
LatLng currentLocation = locationManager.getLocation();
178178

179179
if(currentLocation != null){
180-
nianticManager.getMapInformation(currentLocation.latitude,currentLocation.longitude,0);
180+
nianticManager.getCatchablePokemon(currentLocation.latitude,currentLocation.longitude,0);
181181
}else {
182182
locationManager = LocationManager.getInstance(PokemonNotificationService.this);
183183
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.omkarmoghe.pokemap.helpers;
2+
3+
import android.app.Activity;
4+
import android.content.Context;
5+
import android.graphics.Bitmap;
6+
7+
import com.bumptech.glide.Glide;
8+
import com.bumptech.glide.load.engine.DiskCacheStrategy;
9+
import com.bumptech.glide.request.animation.GlideAnimation;
10+
import com.bumptech.glide.request.target.SimpleTarget;
11+
import com.google.android.gms.maps.model.BitmapDescriptor;
12+
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
13+
14+
import java.util.HashMap;
15+
import java.util.Map;
16+
17+
/**
18+
* Created by aronhomberg on 26.07.16.
19+
*/
20+
public class RemoteImageLoader {
21+
22+
private static Map<String, Bitmap> bitmapCache = new HashMap<>();
23+
24+
public static void load(final String url, int pxWidth, int pxHeight, Context context, final Callback onFetch) {
25+
26+
// ultra-fast cache reply
27+
if (bitmapCache.containsKey(url)) {
28+
29+
onFetch.onFetch(bitmapCache.get(url));
30+
31+
} else {
32+
33+
Glide.with(context).load(url)
34+
.asBitmap()
35+
.skipMemoryCache(false)
36+
.diskCacheStrategy(DiskCacheStrategy.ALL)
37+
.into(new SimpleTarget<Bitmap>(pxWidth, pxHeight) {
38+
@Override
39+
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
40+
bitmapCache.put(url, bitmap);
41+
onFetch.onFetch(bitmap);
42+
}
43+
});
44+
}
45+
}
46+
47+
public interface Callback {
48+
void onFetch(Bitmap bitmap);
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.omkarmoghe.pokemap.models.events;
2+
3+
import java.util.Collection;
4+
5+
import POGOProtos.Map.Fort.FortDataOuterClass;
6+
7+
/**
8+
* Created by aronhomberg on 7/23/2016.
9+
*/
10+
public class GymsEvent implements IEvent {
11+
12+
private Collection<FortDataOuterClass.FortData> gyms;
13+
14+
public GymsEvent(Collection<FortDataOuterClass.FortData> gyms) {
15+
this.gyms = gyms;
16+
}
17+
18+
public Collection<FortDataOuterClass.FortData> getGyms() {
19+
return gyms;
20+
}
21+
22+
public void setGyms(Collection<FortDataOuterClass.FortData> gyms) {
23+
this.gyms = gyms;
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.omkarmoghe.pokemap.models.map;
2+
3+
import com.google.android.gms.maps.model.Marker;
4+
import com.pokegoapi.api.map.fort.Pokestop;
5+
6+
import POGOProtos.Map.Fort.FortDataOuterClass;
7+
8+
/**
9+
* Created by aronhomberg on 7/26/2016.
10+
*/
11+
public class GymMarkerExtended {
12+
13+
14+
private FortDataOuterClass.FortData gym;
15+
private Marker marker;
16+
17+
public GymMarkerExtended(FortDataOuterClass.FortData gym, Marker marker) {
18+
this.gym = gym;
19+
this.marker = marker;
20+
}
21+
22+
public FortDataOuterClass.FortData getGym() {
23+
return gym;
24+
}
25+
26+
public void setGym(FortDataOuterClass.FortData gym) {
27+
this.gym = gym;
28+
}
29+
30+
public Marker getMarker() {
31+
return marker;
32+
}
33+
34+
public void setMarker(Marker marker) {
35+
this.marker = marker;
36+
}
37+
}

app/src/main/java/com/omkarmoghe/pokemap/util/PokemonIdUtils.java

+9-25
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,6 @@
1717
*/
1818
public class PokemonIdUtils {
1919

20-
/**
21-
* try to resolve PokemonName from Resources
22-
*
23-
* @param pokemonId the PokemonID from the API.
24-
* @return a localized name of the pokemon.
25-
*/
26-
public static String getLocalePokemonName(Resources resources,
27-
PokemonIdOuterClass.PokemonId pokemonId) {
28-
String apiPokeName = pokemonId.name();
29-
int resId = 0;
30-
try {
31-
Class resClass = R.string.class;
32-
Field field = resClass.getField(apiPokeName.toLowerCase());
33-
resId = field.getInt(null);
34-
} catch (Exception e) {
35-
Log.e("PokemonTranslation", "Failure to get Name", e);
36-
resId = -1;
37-
}
38-
return resId > 0 ? resources.getString(resId) : apiPokeName;
39-
}
40-
4120
//Getting correct pokemon Id eg: 1 must be 001, 10 must be 010
4221
public static String getCorrectPokemonImageId(int pokemonNumber) {
4322
String actualNumber = String.valueOf(pokemonNumber);
@@ -50,9 +29,14 @@ public static String getCorrectPokemonImageId(int pokemonNumber) {
5029
}
5130
}
5231

53-
public static int getPokemonIconResource(Context context,
54-
int position) {
55-
String iconName = "p" + position;
56-
return context.getResources().getIdentifier(iconName, "drawable", context.getPackageName());
32+
/**
33+
* try to resolve PokemonName from Resources
34+
* @param apiPokeName
35+
* @return
36+
*/
37+
public static String getLocalePokemonName(Context context, String apiPokeName){
38+
39+
int resId = context.getResources().getIdentifier(apiPokeName.toLowerCase(), "string", context.getPackageName());
40+
return resId > 0 ? context.getString(resId) : apiPokeName;
5741
}
5842
}

app/src/main/java/com/omkarmoghe/pokemap/views/MainActivity.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public void onEvent(LoginEventResult result) {
176176
LatLng latLng = LocationManager.getInstance(MainActivity.this).getLocation();
177177

178178
if (latLng != null) {
179-
nianticManager.getMapInformation(latLng.latitude, latLng.longitude, 0D);
179+
nianticManager.getCatchablePokemon(latLng.latitude, latLng.longitude, 0D);
180180
} else {
181181
Snackbar.make(findViewById(R.id.root), getString(R.string.toast_login_error), Snackbar.LENGTH_LONG).show();
182182
}
@@ -196,8 +196,12 @@ public void onEvent(SearchInPosition event) {
196196
MapWrapperFragment.pokeSnackbar.show();
197197
MapWrapperFragment.pokemonFound = 0;
198198
MapWrapperFragment.positionNum = 0;
199+
200+
nianticManager.getGyms(event.getPosition().latitude, event.getPosition().longitude, 0D);
201+
nianticManager.getPokeStops(event.getPosition().latitude, event.getPosition().longitude, 0D);
202+
199203
for (LatLng p : list) {
200-
nianticManager.getMapInformation(p.latitude, p.longitude, 0D);
204+
nianticManager.getCatchablePokemon(p.latitude, p.longitude, 0D);
201205
}
202206
}
203207

0 commit comments

Comments
 (0)