use of com.jexapps.bloodhub.m_Model.Donation 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.jexapps.bloodhub.m_Model.Donation 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.jexapps.bloodhub.m_Model.Donation in project BloodHub by kazijehangir.
the class MyRequestDetail method fetchData.
public void fetchData() {
donations = new ArrayList<Donation>();
keys = new ArrayList<String>();
users = new ArrayList<User>();
final DatabaseReference dbUsers = FirebaseDatabase.getInstance().getReference().child("users");
// dbBloodRequests.orderByChild("userid").equalTo(user.getUid()).addValueEventListener(new ValueEventListener() {
// @Override
// public void onDataChange(DataSnapshot dataSnapshot) {
// requests.clear();
// // keys.clear();
// for (DataSnapshot child: dataSnapshot.getChildren()) {
// requests.add(child.getKey());
// }
// }
// @Override
// public void onCancelled(DatabaseError databaseError) {
// }
// });
db.orderByChild("requestid").equalTo(request).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot child : dataSnapshot.getChildren()) {
Donation donation = child.getValue(Donation.class);
dbUsers.child(donation.userid).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
User user = dataSnapshot.getValue(User.class);
users.add(user);
mAdapter.notifyDataSetChanged();
}
// mAdapter.;
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
mAdapter.notifyDataSetChanged();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
Aggregations