Skip to content

Commit 7767c66

Browse files
jLynxomkarmoghe
authored andcommitted
Fixes Snackbar spam pile up (#160)
1 parent 28c6813 commit 7767c66

File tree

3 files changed

+55
-40
lines changed

3 files changed

+55
-40
lines changed

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ public void onClick(View view) {
131131
mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
132132
@Override
133133
public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
134-
if (id == R.id.login || id == EditorInfo.IME_NULL) {
135-
validatePTCLoginForm();
136-
return true;
137-
}
138-
return false;
134+
if (id == R.id.login || id == EditorInfo.IME_NULL) {
135+
validatePTCLoginForm();
136+
return true;
137+
}
138+
return false;
139139
}
140140
});
141141

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,13 @@ public void onEvent(LoginEventResult result) {
138138
public void onEvent(SearchInPosition event) {
139139
SearchParams params = new SearchParams(SearchParams.DEFAULT_RADIUS * 3, new LatLng(event.getPosition().latitude, event.getPosition().longitude));
140140
List<LatLng> list = params.getSearchArea();
141+
MapWrapperFragment.pokeSnackbar.setText("Searching...");
142+
MapWrapperFragment.pokeSnackbar.show();
143+
MapWrapperFragment.pokemonFound = 0;
144+
MapWrapperFragment.positionNum = 0;
141145
for (LatLng p : list) {
142146
nianticManager.getMapInformation(p.latitude, p.longitude, 0D);
143147
}
144-
145-
146148
}
147149

148150
/**

app/src/main/java/com/omkarmoghe/pokemap/views/map/MapWrapperFragment.java

+46-33
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@
6868
* create an instance of this fragment.
6969
*/
7070
public class MapWrapperFragment extends Fragment implements OnMapReadyCallback,
71-
GoogleMap.OnMapLongClickListener,
72-
ActivityCompat.OnRequestPermissionsResultCallback {
71+
GoogleMap.OnMapLongClickListener,
72+
ActivityCompat.OnRequestPermissionsResultCallback {
7373

7474
private static final int LOCATION_PERMISSION_REQUEST = 19;
7575

@@ -85,6 +85,10 @@ public class MapWrapperFragment extends Fragment implements OnMapReadyCallback,
8585
private HashMap<String, PokemonMarkerExtended> markerList = new HashMap<>();
8686
private HashMap<String, PokestopMarkerExtended> pokestopsList = new HashMap<>();
8787

88+
public static Snackbar pokeSnackbar;
89+
public static int pokemonFound = 0;
90+
public static int positionNum = 0;
91+
8892
public MapWrapperFragment() {
8993
// Required empty public constructor
9094
}
@@ -179,6 +183,7 @@ public void onClick(View view) {
179183
}
180184

181185
private void initMap() {
186+
pokeSnackbar = Snackbar.make(getView(), "", Snackbar.LENGTH_LONG);
182187
if (mLocation != null && mGoogleMap != null) {
183188
if (ContextCompat.checkSelfPermission(mView.getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
184189
|| ContextCompat.checkSelfPermission(mView.getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
@@ -276,10 +281,10 @@ private void setPokestopsMarkers(final Collection<Pokestop> pokestops){
276281
}
277282

278283
private void setPokemonMarkers(final List<CatchablePokemon> pokeList){
284+
positionNum++;
279285
if (mGoogleMap != null) {
280286

281287
Set<String> markerKeys = markerList.keySet();
282-
int pokemonFound = 0;
283288
for (final CatchablePokemon poke : pokeList) {
284289

285290
if(!markerKeys.contains(poke.getSpawnPointId())) {
@@ -308,8 +313,17 @@ public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
308313
}
309314
}
310315
if(getView() != null) {
311-
String text = pokemonFound > 0 ? pokemonFound + " new catchable Pokemon have been found." : "No new Pokemon have been found.";
312-
Snackbar.make(getView(), text, Snackbar.LENGTH_SHORT).show();
316+
if(positionNum != LOCATION_PERMISSION_REQUEST) {
317+
String text = " Searching...." + pokemonFound + " Pokemon found";
318+
pokeSnackbar.setText(text);
319+
pokeSnackbar.show();
320+
321+
}
322+
else {
323+
String text = pokemonFound > 0 ? pokemonFound + " new catchable Pokemon have been found." : "No new Pokemon have been found.";
324+
pokeSnackbar.setText(text);
325+
pokeSnackbar.show();
326+
}
313327
}
314328
updateMarkers();
315329
} else {
@@ -392,7 +406,6 @@ public void onMapReady(GoogleMap googleMap) {
392406
mGoogleMap.setOnMapLongClickListener(this);
393407
//Disable for now coz is under FAB
394408
settings.setMapToolbarEnabled(false);
395-
initMap();
396409
}
397410

398411
@Override
@@ -407,41 +420,41 @@ public void onMapLongClick(LatLng position) {
407420
}
408421

409422
private void drawMarkerWithCircle(LatLng position){
410-
if (mGoogleMap != null) {
423+
if (mGoogleMap != null) {
411424

412425

413-
//Check and eventually remove old marker
414-
if (userSelectedPositionMarker != null && userSelectedPositionCircles != null) {
415-
userSelectedPositionMarker.remove();
416-
for (Circle circle : userSelectedPositionCircles) {
417-
circle.remove();
418-
}
419-
userSelectedPositionCircles.clear();
426+
//Check and eventually remove old marker
427+
if (userSelectedPositionMarker != null && userSelectedPositionCircles != null) {
428+
userSelectedPositionMarker.remove();
429+
for (Circle circle : userSelectedPositionCircles) {
430+
circle.remove();
420431
}
432+
userSelectedPositionCircles.clear();
433+
}
421434

422-
if(mPref.getShowScannedPlaces()) {
423-
double radiusInMeters = 100.0;
424-
int strokeColor = 0x4400CCFF; // outline
425-
int shadeColor = 0x4400CCFF; // fill
435+
if(mPref.getShowScannedPlaces()) {
436+
double radiusInMeters = 100.0;
437+
int strokeColor = 0x4400CCFF; // outline
438+
int shadeColor = 0x4400CCFF; // fill
426439

427-
SearchParams params = new SearchParams(SearchParams.DEFAULT_RADIUS * 3, new LatLng(position.latitude, position.longitude));
428-
List<LatLng> list = params.getSearchArea();
429-
for (LatLng p : list) {
430-
CircleOptions circleOptions = new CircleOptions().center(new LatLng(p.latitude, p.longitude)).radius(radiusInMeters).fillColor(shadeColor).strokeColor(strokeColor).strokeWidth(8);
431-
userSelectedPositionCircles.add(mGoogleMap.addCircle(circleOptions));
440+
SearchParams params = new SearchParams(SearchParams.DEFAULT_RADIUS * 3, new LatLng(position.latitude, position.longitude));
441+
List<LatLng> list = params.getSearchArea();
442+
for (LatLng p : list) {
443+
CircleOptions circleOptions = new CircleOptions().center(new LatLng(p.latitude, p.longitude)).radius(radiusInMeters).fillColor(shadeColor).strokeColor(strokeColor).strokeWidth(8);
444+
userSelectedPositionCircles.add(mGoogleMap.addCircle(circleOptions));
432445

433-
}
434446
}
435-
436-
userSelectedPositionMarker = mGoogleMap.addMarker(new MarkerOptions()
437-
.position(position)
438-
.title("Position Picked")
439-
.icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(getContext().getResources(),
440-
R.drawable.ic_my_location_white_24dp)))
441-
.anchor(0.5f, 0.5f));
442-
} else {
443-
showMapNotInitializedError();
444447
}
448+
449+
userSelectedPositionMarker = mGoogleMap.addMarker(new MarkerOptions()
450+
.position(position)
451+
.title("Position Picked")
452+
.icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(getContext().getResources(),
453+
R.drawable.ic_my_location_white_24dp)))
454+
.anchor(0.5f, 0.5f));
455+
} else {
456+
showMapNotInitializedError();
457+
}
445458
}
446459

447460
}

0 commit comments

Comments
 (0)