use of com.jexapps.bloodhub.m_Model.BloodRequest in project BloodHub by kazijehangir.
the class MyRequestDetail method onCreate.
// @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_my_request_details);
mAuth = FirebaseAuth.getInstance();
user = mAuth.getCurrentUser();
if (savedInstanceState == null) {
Bundle extras = getIntent().getExtras();
if (extras == null) {
request = null;
} else {
request = extras.getString("request");
}
}
db = FirebaseDatabase.getInstance().getReference().child("donations");
fetchData();
mRecyclerView = (RecyclerView) findViewById(R.id.respondent_list_recycler_view);
// mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(getApplicationContext());
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
mRecyclerView.addItemDecoration(new RecycleMarginDecoration(this));
mAdapter = new RespondentListDataAdapter(users, this);
mRecyclerView.setAdapter(mAdapter);
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);
// return rootView;
}
use of com.jexapps.bloodhub.m_Model.BloodRequest in project BloodHub by kazijehangir.
the class MyRequestsFragment method fetchData.
// Getting data from database
public void fetchData() {
requests = new ArrayList<BloodRequest>();
keys = new ArrayList<String>();
FirebaseAuth mAuth = FirebaseAuth.getInstance();
FirebaseUser user = mAuth.getCurrentUser();
db.orderByChild("userid").equalTo(user.getUid()).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
requests.clear();
keys.clear();
for (DataSnapshot child : dataSnapshot.getChildren()) {
BloodRequest request = child.getValue(BloodRequest.class);
requests.add(request);
keys.add(child.getKey());
}
numRequests.setText("Total Requests: " + requests.size());
mAdapter.notifyDataSetChanged();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
return;
}
use of com.jexapps.bloodhub.m_Model.BloodRequest in project BloodHub by kazijehangir.
the class MyDonationDataAdapter method onBindViewHolder.
// Replace the contents of a view (invoked by the layout manager)
@Override
public void onBindViewHolder(MyDonationDataAdapter.ViewHolder holder, int position) {
try {
BloodRequest request = (BloodRequest) requests.get(position);
holder.mName.setText(request.name);
holder.mLocation.setText(request.location);
holder.mWhen.setText(DateFormat.getDateInstance().format(new Date(request.date)));
} catch (Exception e) {
}
;
}
use of com.jexapps.bloodhub.m_Model.BloodRequest in project BloodHub by kazijehangir.
the class RequestListDataAdapter method onBindViewHolder.
// Replace the contents of a view (invoked by the layout manager)
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
BloodRequest request = requests.get(position);
String key = keys.get(position);
holder.cv.setTag(key);
holder.mName.setText(request.name);
holder.mNeeds.setText(request.quantity + " bags of " + request.blood_group);
holder.mLocation.setText(request.location);
String date = DateFormat.getDateInstance().format(new Date(request.date));
holder.mWhen.setText(date);
if (date.equals(DateFormat.getDateInstance().format(new Date()))) {
holder.mWhen.setText("URGENT");
holder.mWhen.setTextColor(0xFFFF0000);
}
holder.mDiagnosis.setText(request.diagnosis);
if (request.transport) {
holder.mTransport.setText("Available");
holder.mTransportImage.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_car));
} else {
holder.mTransport.setText("Not Available");
holder.mTransportImage.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_car));
}
try {
final File localFile = File.createTempFile("images", "jpg");
FirebaseStorage.getInstance().getReference().child("bloodrequests").child(key).getFile(localFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
// Successfully downloaded data to local file
holder.mImage.setImageDrawable(Drawable.createFromPath(localFile.getPath()));
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
holder.mImage.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.girl));
// Toast.makeText(mContext,"Error loading image: " + exception.toString(),
// Toast.LENGTH_LONG).show();
}
});
} catch (Exception e) {
// IOException: error making temp image
// Toast.makeText(mContext, e.toString(), Toast.LENGTH_LONG);
}
}
use of com.jexapps.bloodhub.m_Model.BloodRequest in project BloodHub by kazijehangir.
the class MyRequestDataAdapter method onBindViewHolder.
// Replace the contents of a view (invoked by the layout manager)
@Override
public void onBindViewHolder(MyRequestDataAdapter.ViewHolder holder, int position) {
BloodRequest request = (BloodRequest) requests.get(position);
String key = keys.get(position);
holder.cv.setTag(key);
holder.mName.setText(request.name);
holder.mLocation.setText(request.location);
holder.mWhen.setText(DateFormat.getDateInstance().format(new Date(request.date)));
}
Aggregations