use of com.jexapps.bloodhub.m_Model.BloodRequest in project BloodHub by kazijehangir.
the class MyRequestDetail method onCreateView.
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mAuth = FirebaseAuth.getInstance();
user = mAuth.getCurrentUser();
if (savedInstanceState == null) {
Bundle extras = getIntent().getExtras();
if (extras == null) {
request = null;
} else {
request = extras.getString("request");
}
}
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.name);
mName.setText(data.name);
TextView mTime = (TextView) findViewById(R.id.time);
String date = DateFormat.getDateInstance().format(new Date(data.date));
mTime.setText(date);
TextView mLocation = (TextView) findViewById(R.id.location);
mLocation.setText(data.location);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
View rootView = inflater.inflate(R.layout.fragment_my_request_details, container, false);
db = FirebaseDatabase.getInstance().getReference().child("donations");
fetchData();
mRecyclerView = (RecyclerView) rootView.findViewById(R.id.respondent_list_recycler_view);
mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
mRecyclerView.addItemDecoration(new RecycleMarginDecoration(this));
mAdapter = new RespondentListDataAdapter(users, this);
mRecyclerView.setAdapter(mAdapter);
return rootView;
}
use of com.jexapps.bloodhub.m_Model.BloodRequest 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.BloodRequest 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.BloodRequest 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;
}
use of com.jexapps.bloodhub.m_Model.BloodRequest in project BloodHub by kazijehangir.
the class AddRequestActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
mAuth = FirebaseAuth.getInstance();
user = mAuth.getCurrentUser();
mEmail = user.getEmail();
// INITIALIZE FIREBASE DB
db = FirebaseDatabase.getInstance().getReference().child("bloodrequests");
mStorageRef = FirebaseStorage.getInstance().getReference().child("bloodrequests");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_request);
setTitle("Add Request");
name = (AutoCompleteTextView) findViewById(R.id.name);
bloodgroup = (Spinner) findViewById(R.id.spin);
quantity = (Spinner) findViewById(R.id.spin1);
number = (EditText) findViewById(R.id.contact_num);
location = (AutoCompleteTextView) findViewById(R.id.loc);
when = (EditText) findViewById(R.id.editText);
diagnosis = (Spinner) findViewById(R.id.diagnosis);
transport_group = (RadioGroup) findViewById(R.id.transport);
image = (TextView) findViewById(R.id.image_text);
String[] hospitals = getResources().getStringArray(R.array.organizations_array);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, hospitals);
location.setAdapter(adapter);
final EditText set = (EditText) findViewById(R.id.editText);
set.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog = new Dialog(AddRequestActivity.this);
dialog.setTitle("Set Date and Time");
dialog.setContentView(R.layout.set_date);
dialog.show();
final Button setDate = (Button) dialog.findViewById(R.id.set_date);
final DatePicker datePicker = (DatePicker) dialog.findViewById(R.id.datePicker);
datePicker.setMinDate(System.currentTimeMillis() - 1000);
setDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
date = datePicker.getDayOfMonth();
month = datePicker.getMonth();
year = datePicker.getYear();
Calendar calendar = Calendar.getInstance();
calendar.set(year, month, date);
pdate = calendar.getTime();
String date = DateFormat.getDateInstance().format(pdate);
set.setText(date);
dialog.cancel();
}
});
}
});
Button image_btn = (Button) findViewById(R.id.upload_image_button);
image_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Context context = getApplicationContext();
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, GALLERY_INTENT);
}
});
Button submit = (Button) findViewById(R.id.submit_button);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
pname = name.getText().toString();
bgroup = bloodgroup.getSelectedItem().toString();
quan = quantity.getSelectedItem().toString();
diag = diagnosis.getSelectedItem().toString();
num = number.getText().toString();
loc = location.getText().toString();
transport_btn = (RadioButton) findViewById(transport_group.getCheckedRadioButtonId());
String transport_text = (String) transport_btn.getText();
if (transport_text.equals("Available")) {
transport = true;
} else if (transport_text.equals("Not Available")) {
transport = false;
}
new_request = db.push();
String address = loc + ", Pakistan";
new GetCoordinates().execute(address.replace(" ", "+"));
if (image_file != null) {
mStorageRef.child(new_request.getKey()).putFile(image_file).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// Toast.makeText(getApplicationContext(),"Image uploaded",
// Toast.LENGTH_SHORT).show();
String regToken = FirebaseInstanceId.getInstance().getToken();
BloodRequest request = new BloodRequest(user.getUid(), pname, bgroup, quan, num, loc, lat, lng, diag, pdate.getTime(), transport, regToken);
new_request.setValue(request);
request_added = true;
dialog = new Dialog(AddRequestActivity.this);
dialog.setContentView(R.layout.popup_submit);
dialog.show();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
final Button submit = (Button) dialog.findViewById(R.id.button_ok);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(AddRequestActivity.this, MainActivity.class);
startActivity(intent);
}
});
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Toast.makeText(getApplicationContext(), "Error uploading image", Toast.LENGTH_SHORT).show();
}
});
} else {
String regToken = FirebaseInstanceId.getInstance().getToken();
BloodRequest request = new BloodRequest(user.getUid(), pname, bgroup, quan, num, loc, lat, lng, diag, pdate.getTime(), transport, regToken);
new_request.setValue(request);
request_added = true;
dialog = new Dialog(AddRequestActivity.this);
dialog.setContentView(R.layout.popup_submit);
dialog.show();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
final Button submit = (Button) dialog.findViewById(R.id.button_ok);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(AddRequestActivity.this, MainActivity.class);
startActivity(intent);
}
});
}
}
});
}
Aggregations