Commit 82ecfb54 authored by Corentin Mors's avatar Corentin Mors
Browse files

Fix refreshing of map and positions updates

parent c299e9f6
......@@ -397,6 +397,7 @@ public class ChatFragment extends Fragment {
addLog(getResources().getString(R.string.message_user_left, username));
addParticipantsLog(numUsers);
removeTyping(username);
}
});
}
......
......@@ -157,6 +157,7 @@ public class MainActivity extends AppCompatActivity {
ChatApplication app = (ChatApplication) getApplication();
mSocket = app.getSocket();
mSocket.on("geoloc", onGeoloc);
mSocket.on("user left", onUserLeft);
Button settingsButton = findViewById(R.id.accessSettings);
......@@ -182,11 +183,17 @@ public class MainActivity extends AppCompatActivity {
locationMarker.setIcon(icon);
locationMarker.setTitle("Your location");
if(userMarkers.containsKey(mUsername)){
userMarkers.remove(mUsername);
}
userMarkers.put(mUsername, locationMarker);
map.getOverlays().clear();
map.getOverlays().add(locationMarker);
for (Marker value : userMarkers.values()) {
map.getOverlays().add(value);
}
map.invalidate();
}
}
......@@ -223,12 +230,20 @@ public class MainActivity extends AppCompatActivity {
userMarkers.put(username, locationMarker);
map.getOverlays().clear();
map.getOverlays().add(locationMarker);
for (Marker value : userMarkers.values()) {
map.getOverlays().add(value);
}
map.invalidate();
}
public void removeParticipant(String username){
userMarkers.remove(username);
map.getOverlays().clear();
for (Marker value : userMarkers.values()) {
map.getOverlays().add(value);
}
map.invalidate();
}
private int getUsernameColor(String username) {
......@@ -241,6 +256,26 @@ public class MainActivity extends AppCompatActivity {
}
private Emitter.Listener onUserLeft = new Emitter.Listener() {
@Override
public void call(final Object... args) {
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
JSONObject data = (JSONObject) args[0];
String username;
try {
username = data.getString("username");
} catch (JSONException e) {
Log.e("OM_LOG", e.getMessage());
return;
}
removeParticipant(username);
}
});
}
};
private Emitter.Listener onGeoloc = new Emitter.Listener() {
@Override
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment