use of com.google.firebase.firestore.CollectionReference in project snippets-android by firebase.
the class DocSnippets method orderAndLimitInvalid.
public void orderAndLimitInvalid() {
CollectionReference citiesRef = db.collection("cities");
// [START invalid_filter_and_order]
citiesRef.whereGreaterThan("population", 100000).orderBy("country");
// [END invalid_filter_and_order]
}
use of com.google.firebase.firestore.CollectionReference in project snippets-android by firebase.
the class DocSnippets method inQueries.
public void inQueries() {
// [START in_filter]
CollectionReference citiesRef = db.collection("cities");
citiesRef.whereIn("country", Arrays.asList("USA", "Japan"));
// [END in_filter]
// [START not_in_filter]
citiesRef.whereNotIn("country", Arrays.asList("USA", "Japan"));
// [END not_in_filter]
// [START in_filter_with_array]
citiesRef.whereIn("regions", Arrays.asList(new String[] { "west_coast" }, new String[] { "east_coast" }));
// [END in_filter_with_array]
}
use of com.google.firebase.firestore.CollectionReference in project QR-Game by CMPUT301W22T15.
the class ExistingUser method onCreate.
/**
* This method creates the initial interface and obtains the necessary permissions.
* @param savedInstanceState
* Expects a Bundle object.
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_existing_user);
scanButton = findViewById(R.id.scan_button);
rememberMe = (CheckBox) findViewById(R.id.login_checkbox_existing);
db = FirebaseFirestore.getInstance();
CollectionReference collectionReference = db.collection("Players");
// Obtain list of players
collectionReference.addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException error) {
allPlayers.clear();
for (QueryDocumentSnapshot doc : queryDocumentSnapshots) {
Player p = doc.toObject(Player.class);
allPlayers.add(p);
}
}
});
// Open ScannerView2 to scan a new QRcode
scanButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(ExistingUser.this, ScannerView2.class);
startActivityForResult(intent, 1);
}
});
}
use of com.google.firebase.firestore.CollectionReference in project QR-Game by CMPUT301W22T15.
the class ExistingUser method login.
/**
* This method is called when the user taps the Log In button, and it opens the user menu activity
* if the user successfully logs in.
* @param view
* Expects an object from the View class.
*/
public void login(View view) {
EditText usernameEdit = (EditText) findViewById(R.id.username1_text);
String username = usernameEdit.getText().toString();
if (rememberMe.isChecked()) {
// Create key-value pair using SharedPreferences
SharedPreferences preferences = getSharedPreferences("rememberMeBox", MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("remember", username);
editor.apply();
Toast.makeText(ExistingUser.this, "Persistence Enabled", Toast.LENGTH_SHORT).show();
} else if (!rememberMe.isChecked()) {
// Create key-value pair using SharedPreferences
SharedPreferences preferences = getSharedPreferences("rememberMeBox", MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("remember", "");
editor.apply();
Toast.makeText(ExistingUser.this, "Persistence Disabled", Toast.LENGTH_SHORT).show();
}
// Setup player so that they can referenced throughout the app
singletonPlayer.player.setUsername(username);
db = FirebaseFirestore.getInstance();
final CollectionReference collectionReference = db.collection("Players");
final CollectionReference collectionReferenceQR = db.collection("QRCodes");
DocumentReference playerDocRef = db.collection("Players").document(username);
playerDocRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot documentSnapshot = task.getResult();
if (documentSnapshot.exists()) {
singletonPlayer.player = documentSnapshot.toObject(Player.class);
Log.d("Success", "12");
if (singletonPlayer.player.getOwner() == true) {
// Open new activity
Intent intent = new Intent(getApplicationContext(), OwnerMenu.class);
startActivity(intent);
} else {
// Open new activity
Intent intent = new Intent(getApplicationContext(), UserMenu.class);
intent.putExtra("userMenu_session", (String) null);
startActivity(intent);
}
}
}
}
});
}
use of com.google.firebase.firestore.CollectionReference in project QR-Game by CMPUT301W22T15.
the class MyScans method updateTotalScans.
/**
* Updates the total scans after user deletes.
*/
private void updateTotalScans() {
// Initialize Variable
int totalNumberScans = singletonPlayer.player.numberOfCode();
int totalSums = singletonPlayer.player.getTotalScore();
// Update count
totalScans.setText("Total Scans: " + String.valueOf(totalNumberScans));
// Update sum
totalScore.setText("Total Score: " + String.valueOf(totalSums));
// Update user information
singletonPlayer.player.setScore(totalSums);
// Access a Cloud FireStore instance from Activity
db = FirebaseFirestore.getInstance();
final CollectionReference collectionReference = db.collection("Players");
String TAG = "working";
collectionReference.document(singletonPlayer.player.getUsername()).set(singletonPlayer.player).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void unused) {
Log.d(TAG, "message");
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e("MYAPP", "exception: " + e.getMessage());
Log.e("MYAPP", "exception: " + e.toString());
}
});
}
Aggregations