use of com.google.firebase.database.ChildEventListener in project EC2018App by Manan-YMCA.
the class StarNightFragment method attachDatabaseListener.
private void attachDatabaseListener() {
if (mChildEventListener == null) {
mChildEventListener = new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
if (dataSnapshot.getKey().equals("starnight")) {
BrixxEventModel w = dataSnapshot.getValue(BrixxEventModel.class);
updateUI(w);
}
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
try {
if (dataSnapshot.getKey().equals("starnight")) {
BrixxEventModel w = dataSnapshot.getValue(BrixxEventModel.class);
updateUI(w);
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
};
mDatabaseReference.addChildEventListener(mChildEventListener);
}
}
use of com.google.firebase.database.ChildEventListener in project FindMyHome by DjangoBlockchained.
the class ShelterDetailActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
Intent i = getIntent();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shelter_details);
ListView list = findViewById(R.id.shelterdetails);
Button claimButton = findViewById(R.id.claimbutton);
adapter = new ArrayAdapter<>(ShelterDetailActivity.this, android.R.layout.simple_list_item_1, details);
username = i.getStringExtra("username");
String name = i.getStringExtra("Shelter Name");
FirebaseDatabase shelterDB = FirebaseDatabase.getInstance();
DatabaseReference shelterRefPre = shelterDB.getReference();
DatabaseReference shelterRef = shelterRefPre.child("shelters");
DatabaseReference nameRef = shelterRef.child(name);
claimButton.setOnClickListener((view) -> {
Intent intent = new Intent(ShelterDetailActivity.this, ClaimScreenActivity.class);
intent.putExtra("username", username);
intent.putExtra("Shelter Name", name);
startActivity(intent);
});
nameRef.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Object data = dataSnapshot.getValue();
details.add(getLabel(dataSnapshot.getKey(), data));
adapter.notifyDataSetChanged();
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
Object data = dataSnapshot.getValue();
String key = dataSnapshot.getKey();
// Find the current row for the key and replace it with the new value.
int index = -1;
boolean found = false;
for (int i = 0; (i < details.size()) && (!found); i++) {
String ss = details.get(i);
if (ss.contains(key)) {
index = i;
found = true;
}
}
if (index != -1) {
details.set(index, getLabel(dataSnapshot.getKey(), data));
} else {
details.add(getLabel(dataSnapshot.getKey(), data));
}
adapter.notifyDataSetChanged();
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
list.setAdapter(adapter);
}
use of com.google.firebase.database.ChildEventListener in project FindMyHome by DjangoBlockchained.
the class ShelterListActivity method showSearchedShelter.
private void showSearchedShelter(String name, CharSequence gender, CharSequence age) {
shelterRef.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Object value = dataSnapshot.getValue();
Map string = (Map) value;
if (string != null) {
Object o = string.get("restrictions");
if (o != null) {
Object nameObj = string.get("name");
if (matchesSearch(string, name, gender, age)) {
names.add(nameObj.toString());
adapter.notifyDataSetChanged();
}
}
}
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
list.setAdapter(adapter);
list.setOnItemClickListener((parent, view, position, id) -> {
String selected = (String) list.getItemAtPosition(position);
Intent intent = new Intent(ShelterListActivity.this, ShelterDetailActivity.class);
intent.putExtra("username", username);
intent.putExtra("Shelter Name", selected);
startActivity(intent);
});
}
use of com.google.firebase.database.ChildEventListener in project iosched by google.
the class FeedPresenter method initializeDataListener.
@Override
public void initializeDataListener(DatabaseReference databaseReference) {
if (mEventListener == null) {
mEventListener = new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
try {
FeedMessage feedMessage = dataSnapshot.getValue(FeedMessage.class);
mView.addFeedMessage(feedMessage);
} catch (DatabaseException e) {
mView.showErrorMessage();
LOGE(TAG, "Firebase error - " + e);
}
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
try {
FeedMessage feedMessage = dataSnapshot.getValue(FeedMessage.class);
mView.updateFeedMessage(feedMessage);
} catch (DatabaseException e) {
mView.showErrorMessage();
LOGE(TAG, "Firebase error - " + e);
}
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
try {
FeedMessage feedMessage = dataSnapshot.getValue(FeedMessage.class);
mView.removeFeedMessage(feedMessage);
} catch (DatabaseException e) {
mView.showErrorMessage();
LOGE(TAG, "Firebase error - " + e);
}
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
try {
FeedMessage feedMessage = dataSnapshot.getValue(FeedMessage.class);
mView.updateFeedMessage(feedMessage);
} catch (DatabaseException e) {
mView.showErrorMessage();
LOGE(TAG, "Firebase error - " + e);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
mView.showErrorMessage();
}
};
}
databaseReference.addChildEventListener(mEventListener);
}
use of com.google.firebase.database.ChildEventListener in project GogoNew by kuldeep725.
the class MapsActivity method showMarkers.
private void showMarkers() {
if (checkBusSelection != 0) {
showInternetStatus();
if (!isInternetOn())
return;
// Log.d(TAG, "showMarkers IS FIRED...");
String BUS = "b" + checkBusSelection;
final DatabaseReference routeDatabase = mDatabase.child(USER).child(BUS).child(ROUTE);
routeDatabase.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
String bus = "b" + checkBusSelection;
if (!routeDatabase.toString().equals(mDatabase.child(USER).child(bus).child(ROUTE).toString()))
return;
GenericTypeIndicator<Map<String, String>> genericTypeIndicator = new GenericTypeIndicator<Map<String, String>>() {
};
// Log.d(TAG, "Data : " + dataSnapshot.getValue(genericTypeIndicator));
Map<String, String> map = dataSnapshot.getValue(genericTypeIndicator);
assert map != null;
String latitudeStr = map.get("latitude");
String longitudeStr = map.get("longitude");
// Log.d(TAG, "Latitude = " + latitudeStr);
// Log.d(TAG, "Longitude = " + longitudeStr);
double latitude = Double.parseDouble(latitudeStr);
double longitude = Double.parseDouble(longitudeStr);
String busName = "BUS " + checkBusSelection;
// Geocoder geocoder = new Geocoder(getApplicationContext());
// try {
// List<android.location.Address> addressList = geocoder.getFromLocation(latitude, longitude, 1);
// String str = "";
// if (addressList.get(0).getSubLocality() != null) {
// str = addressList.get(0).getSubLocality()+",";
// }
// str += addressList.get(0).getLocality();
// str += addressList.get(0).getCountryName();
String str = "";
str += /*" (" + */
dataSnapshot.getKey();
LatLng latlng = new LatLng(latitude, longitude);
Marker marker = mMap.addMarker(new MarkerOptions().position(latlng).title(str));
marker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.red_stop_10));
markerMap.put(latlng, marker);
markerNameList.put(latlng, str);
// mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), 12.0f));
// }
// catch (IOException e) {
// e.printStackTrace();
// mMap.addMarker(new MarkerOptions()
// .position(new LatLng(latitude, longitude))
// .title(busName))
// .setIcon(BitmapDescriptorFactory.fromResource(R.drawable.red_stop_10));
// // mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), 12.0f));
// Log.e(TAG, "GEOCODER DIDN'T WORK.");
// }
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
Aggregations