I'm newbie in using firebase. Now, I have a research to make car booking application with firebase nosql. I have a logic to check car availability. First, I selected vehicle id in child vehicle and then select child reserved that have that vehicle id. And then I used the comparison of the search date that the user wants with the rental date stored in firebase, and then if that case fulfilled, it will save the amount of vehicle in child reserved to list and get sum of that list. But when I run my application it was not excuted. Please help me to find the location of the error. So far, this is my code :
final ArrayList<Integer> list = new ArrayList<>();
String date1 = "3/10/2017";
String date2 = "5/10/2017";
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
try {
checkInUser = format.parse(date1);
checkOutUser = format.parse(date2);
} catch (ParseException e) {
e.printStackTrace();
}
mDatabase = FirebaseDatabase.getInstance().getReference();
mDatabase.child("vehicle").child(category).addValueEventListener(new com.google.firebase.database.ValueEventListener() {
@Override
public void onDataChange(com.google.firebase.database.DataSnapshot dataSnapshot) {
for (com.google.firebase.database.DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
VehicleModel vehicle = postSnapshot.getValue(VehicleModel.class);
Firebase ref = new Firebase("http://ift.tt/2yDbwqF");
com.firebase.client.Query query = ref.orderByChild("idVehicle").equalTo(vehicle.getIdVehicle);
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (com.firebase.client.DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
ReservedModel reserved = postSnapshot.getValue(ReservedModel.class);
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
try {
checkInReserved = format.parse(reserved.getCheckInReserved());
checkOutReserved = format.parse(reserved.getCheckOutReserved());
} catch (ParseException e) {
e.printStackTrace();
}
// IT IS NOT EXECUTED
if ((checkInUser.after(checkInReserved) && checkInUser.before(checkOutReserved)) || (checkOutUser.after(checkInReserved) && checkOutReserved.before(checkOutReserved))) {
a = reserved.getAmount();
list.add(a);
} else {
Toast.makeText(getApplicationContext(), "IF ELSE NOT EXECUTED", Toast.LENGTH_SHORT).show();
}
}
sum = 0;
for (int i = 0; i < list.size(); i++) {
sum += list.get(i);
total = sum;
}
String abc = String.valueOf(total);
view.setText(abc);
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
And this is my firebase :
Please help me.. Thankyou so much..
Aucun commentaire:
Enregistrer un commentaire