-
Notifications
You must be signed in to change notification settings - Fork 3
SCFirebase
This is an application level interface to allow the SpotCheck front end (Android app) communicate with the SpotCheck Firebase server.
To start using SCFirebase you must first create an instance:
SCFirebase scFirebase = new SCFirebase();
Then call methods on this scFirebase object (ie. scFirebase.createUser(...). The available methods and functionality are outlined in the following sections.
When using the get functions (ie. getSCUser or getParkingSpot) the object is returned as part of a SCFirebaseCallback. The following is an example of how to use a callback as demonstrated with getParkingSpot:
scFirebase.getParkingSpot(spotID, new SCFirebaseCallback<ParkingSpot>() {
@Override
public void callback(ParkingSpot data) {
if(data != null) {
// do something with the ParkingSpot object...
// If you want to update the UI with this new object (ie set parking spot name text field)...
// you have to run that code on the UI thread with the following method:
Handler mainHandler = new Handler(Looper.getMainLooper());
mainHandler.post(new Runnable() {
@Override
public void run() {
// code to interact with UI
}
});
} else {
// no data was returned from the server, display an error message or handle appropriately
}
}
});
Notice what must be done if wanting to update the UI.
-
public String createNewSpot(ParkingSpot spot)- Creates new parking spot data on server
- Parameters:
-
ParkingSpot spot: Object containing data to upload
-
- Returns:
Stringnewly generated spotID for object
-
public void getParkingSpot(String spotID, @NonNull final SCFirebaseCallback<ParkingSpot> finishedCallback)- Gets a parking spot object from the server
- Parameters:
-
String spotID: Unique ID of spot to get -
SCFirebaseCallback<ParkingSpot>: Callback to implement to get object/handle failure.
-
-
public void updateDatabaseUser(SpotCheckUser user)- Creates or updates user data on server
- Parameters:
-
SpotCheckUser user: Object containing data to upload
-
- Parameters:
- Creates or updates user data on server
-
public void getSCUser(String userID, @NonNull final SCFirebaseCallback<SpotCheckUser> finishedCallback)- Gets an user object from the server
- Parameters:
-
String userID: Unique ID of user to get -
SCFirebaseCallback<SpotCheckUser>: Callback to implement to get object/handle failure.
-