use of com.google.firebase.database.DatabaseReference in project SEProject by NicholasBarreyre.
the class MapsActivity method onCreate.
/**
* This method sets up the fields and handles GPS permissions.
* @param savedInstanceState not used
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
((MapFragment) getFragmentManager().findFragmentById(R.id.record_map)).getMapAsync(this);
timer = findViewById(R.id.record_chrono);
recordButton = findViewById(R.id.record_button);
pauseButton = findViewById(R.id.pause_button);
userLocationPool = Executors.newScheduledThreadPool(1);
userLocationPool.scheduleAtFixedRate(userLocRun, 0, 10, TimeUnit.SECONDS);
if (checkForLocPermission()) {
createLocationParameters();
requestLocationUpdates();
} else {
requestLocPermissions();
}
Intent intent = getIntent();
user = (User) intent.getSerializableExtra("user");
boolean instantRecord = intent.getBooleanExtra("instantRecord", false);
FirebaseDatabase db = FirebaseDatabase.getInstance();
DatabaseReference myRef = db.getReference(getString(R.string.activity_user_information_firebase, user.getUsername()));
myRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
userInformation = dataSnapshot.getValue(UserInformation.class);
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.e("MAPS", "DB call to UserInfo cancelled");
}
});
if (instantRecord)
toggleRecordStatus(null);
Switch toggle = (Switch) findViewById(R.id.toggle_report);
toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
isPublishing = isChecked;
}
});
}
use of com.google.firebase.database.DatabaseReference in project SEProject by NicholasBarreyre.
the class MapsActivity method retrieveUserLocs.
private void retrieveUserLocs() {
FirebaseDatabase db = FirebaseDatabase.getInstance();
DatabaseReference myRef = db.getReference(getString(R.string.activity_maps_firebase_user_locs));
myRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Iterator<DataSnapshot> it = dataSnapshot.getChildren().iterator();
friendLocationList.clear();
while (it.hasNext()) {
UserLocation userLocation = it.next().getValue(UserLocation.class);
friendLocationList.add(userLocation);
}
populateMapMarkers();
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.e("MAPSACTIVITY", "Failed to retrieve user locs from Firebase.");
}
});
}
use of com.google.firebase.database.DatabaseReference in project SEProject by NicholasBarreyre.
the class MapsActivityUnitTests method initUserLoc.
@BeforeClass
public static void initUserLoc() {
FirebaseDatabase db = FirebaseDatabase.getInstance();
DatabaseReference myRef = db.getReference("user_locations");
UserLocation zLoc = new UserLocation(TEST_FRIEND, System.currentTimeMillis(), 0, 0.0, 0.0);
myRef.child(TEST_FRIEND).setValue(zLoc);
}
use of com.google.firebase.database.DatabaseReference in project SEProject by NicholasBarreyre.
the class AccountManager method getUser.
/**
* Retrieves the user account associated with the specified username. User will be available
* to the provided callback.
*
* @param username Username of the user to be loaded
* @param listener Callback to handle response
*/
public static void getUser(String username, @NonNull final UserObjectListener listener) {
Objects.requireNonNull(listener, "Null value for UserObjectListener is not valid.");
Objects.requireNonNull(user, "Get user called in offline mode before logging in");
if (!online) {
if (username.equals(user.getUsername())) {
listener.onUserPopulated(user);
} else {
listener.onUserPopulated(null);
}
return;
}
// retrieve a reference to the users node
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference usersReference = database.getReference("users/" + username);
// attach a listener for data changes of the users reference. this will occur when
// the reference is populated
usersReference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// otherwise return null
if (dataSnapshot.exists()) {
listener.onUserPopulated(dataSnapshot.getValue(User.class));
} else {
listener.onUserPopulated(null);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
use of com.google.firebase.database.DatabaseReference in project SEProject by NicholasBarreyre.
the class TestingHelper method resetTestUserExercises.
/**
* Test helper to reset the testuser's exercise list
*/
public static void resetTestUserExercises() {
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference usersReference = database.getReference("users/testuser");
usersReference.child("userExercises").setValue(null);
}
Aggregations