use of com.google.firebase.database.ValueEventListener in project BloodHub by kazijehangir.
the class DonationsFragment method fetchData.
// Getting data from database
public ArrayList<BloodRequest> fetchData() {
donations = new ArrayList<BloodRequest>();
FirebaseAuth mAuth = FirebaseAuth.getInstance();
FirebaseUser user = mAuth.getCurrentUser();
db.orderByChild("userid").equalTo(user.getUid()).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot child : dataSnapshot.getChildren()) {
Donation donation = child.getValue(Donation.class);
if (donation != null) {
FirebaseDatabase.getInstance().getReference().child("bloodrequests").child(donation.requestid).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
BloodRequest request = dataSnapshot.getValue(BloodRequest.class);
if (request != null) {
donations.add(request);
numDonations.setText("LIVES SAVED: " + donations.size());
mAdapter.notifyDataSetChanged();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
FirebaseDatabase.getInstance().getReference().child("bloodrequests").child(donation.requestid).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
BloodRequest request = dataSnapshot.getValue(BloodRequest.class);
donations.add(request);
numDonations.setText("LIVES SAVED: " + donations.size());
mAdapter.notifyDataSetChanged();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
return donations;
}
use of com.google.firebase.database.ValueEventListener in project BloodHub by kazijehangir.
the class LoginActivity method setView.
/**
* Attempts to sign in or register the account specified by the login form.
* If there are form errors (invalid email, missing fields, etc.), the
* errors are presented and no actual login attempt is made.
*/
private void setView(String userId, final String email) {
final String uid = userId;
final Context context = getApplicationContext();
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
FirebaseDatabase.getInstance().getReference().child("users").child(uid).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
User user = dataSnapshot.getValue(User.class);
String account_type = user.account_type;
showProgress(false);
if (account_type.equals("individual")) {
Intent intent;
intent = new Intent(LoginActivity.this, MainActivity.class);
intent.putExtra("mEmail", email);
startActivity(intent);
} else if (account_type.equals("organization")) {
Intent intent;
intent = new Intent(LoginActivity.this, MainActivityOrg.class);
intent.putExtra("mEmail", email);
startActivity(intent);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
return;
}
use of com.google.firebase.database.ValueEventListener in project BloodHub by kazijehangir.
the class RequestDetail method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_request_detail);
mAuth = FirebaseAuth.getInstance();
user = mAuth.getCurrentUser();
setTitle("Donate blood");
if (savedInstanceState == null) {
Bundle extras = getIntent().getExtras();
if (extras == null) {
request = null;
} else {
request = extras.getString("request");
}
}
db = FirebaseDatabase.getInstance().getReference().child("donations");
if (request != null && !request.isEmpty()) {
FirebaseDatabase.getInstance().getReference().child("bloodrequests").child(request).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
BloodRequest data = dataSnapshot.getValue(BloodRequest.class);
TextView mName = (TextView) findViewById(R.id.request_detail_name);
mName.setText(data.name);
TextView mNeeds = (TextView) findViewById(R.id.request_detail_needs);
mNeeds.setText(data.quantity + " bags of " + data.blood_group);
TextView mLocation = (TextView) findViewById(R.id.request_detail_location);
mLocation.setText(data.location);
TextView mWhen = (TextView) findViewById(R.id.request_detail_when);
String date = DateFormat.getDateInstance().format(new Date(data.date));
mWhen.setText(date);
if (date.equals(DateFormat.getDateInstance().format(new Date()))) {
mWhen.setText("URGENT");
mWhen.setTextColor(0xFFFF0000);
}
TextView mDiagnosis = (TextView) findViewById(R.id.request_detail_diagnosis);
mDiagnosis.setText(data.diagnosis);
TextView mTransport = (TextView) findViewById(R.id.request_detail_transport);
if (data.transport) {
mTransport.setText("Available");
} else {
mTransport.setText("Not Available");
}
if (user.getUid().equals(data.userid)) {
isOwnRequest = true;
setTitle("Request Info");
Button donate = (Button) findViewById(R.id.request_detail_donate_button);
donate.setText("Open in My Requests");
donate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(view.getContext(), MyRequestDetail.class);
intent.putExtra("request", request);
view.getContext().startActivity(intent);
}
});
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
} else {
Toast.makeText(getApplicationContext(), "Error loading request", Toast.LENGTH_SHORT).show();
finish();
}
Button donate = (Button) findViewById(R.id.request_detail_donate_button);
if (!isOwnRequest) {
donate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Context context = getApplicationContext();
Donation donation = new Donation(user.getUid(), request);
try {
db.push().setValue(donation);
dialog = new Dialog(RequestDetail.this);
dialog.setTitle("Donation Confirmed");
dialog.setContentView(R.layout.popup_request_detail);
dialog.show();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
final Button submit = (Button) dialog.findViewById(R.id.request_detail_dialog_ok);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
} catch (DatabaseException e) {
Toast.makeText(context, "Error occurred", Toast.LENGTH_SHORT).show();
}
}
});
}
}
use of com.google.firebase.database.ValueEventListener in project BloodHub by kazijehangir.
the class UserProfile method onStart.
@Override
public void onStart() {
super.onStart();
final TextView name = (TextView) findViewById(R.id.name);
final TextView bgroup = (TextView) findViewById(R.id.blood_g);
final TextView number = (TextView) findViewById(R.id.con_num);
// add value event listener to the user
ValueEventListener userListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
User curruser = dataSnapshot.getValue(User.class);
name.setText(curruser.username);
bgroup.setText("Blood group: " + curruser.blood_group);
number.setText("Number : " + curruser.number);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
};
mUserReference.addValueEventListener(userListener);
}
use of com.google.firebase.database.ValueEventListener in project BloodHub by kazijehangir.
the class RequestListFragment method fetchData.
// Getting data from database
public void fetchData() {
requests = new ArrayList<BloodRequest>();
keys = new ArrayList<String>();
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
Date startDate = cal.getTime();
// Date endDate = new Date();
db.orderByChild("date").startAt(startDate.getTime()).limitToFirst(15).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot child : dataSnapshot.getChildren()) {
BloodRequest request = child.getValue(BloodRequest.class);
requests.add(request);
keys.add(child.getKey());
}
mAdapter.notifyDataSetChanged();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
return;
}
Aggregations