Search in sources :

Example 6 with BloodRequest

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;
}
Also used : RespondentListDataAdapter(com.jexapps.bloodhub.m_UI.RespondentListDataAdapter) Bundle(android.os.Bundle) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DataSnapshot(com.google.firebase.database.DataSnapshot) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) Date(java.util.Date) DatabaseError(com.google.firebase.database.DatabaseError) TextView(android.widget.TextView) ValueEventListener(com.google.firebase.database.ValueEventListener) BloodRequest(com.jexapps.bloodhub.m_Model.BloodRequest)

Example 7 with BloodRequest

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;
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) FirebaseUser(com.google.firebase.auth.FirebaseUser) ValueEventListener(com.google.firebase.database.ValueEventListener) BloodRequest(com.jexapps.bloodhub.m_Model.BloodRequest) DataSnapshot(com.google.firebase.database.DataSnapshot) FirebaseAuth(com.google.firebase.auth.FirebaseAuth)

Example 8 with BloodRequest

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) {
    }
    ;
}
Also used : BloodRequest(com.jexapps.bloodhub.m_Model.BloodRequest) Date(java.util.Date)

Example 9 with BloodRequest

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);
    }
}
Also used : FileDownloadTask(com.google.firebase.storage.FileDownloadTask) BloodRequest(com.jexapps.bloodhub.m_Model.BloodRequest) File(java.io.File) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) Date(java.util.Date) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 10 with BloodRequest

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)));
}
Also used : BloodRequest(com.jexapps.bloodhub.m_Model.BloodRequest) Date(java.util.Date)

Aggregations

BloodRequest (com.jexapps.bloodhub.m_Model.BloodRequest)11 Date (java.util.Date)8 DataSnapshot (com.google.firebase.database.DataSnapshot)7 DatabaseError (com.google.firebase.database.DatabaseError)7 ValueEventListener (com.google.firebase.database.ValueEventListener)7 TextView (android.widget.TextView)4 Intent (android.content.Intent)3 Bundle (android.os.Bundle)3 View (android.view.View)3 Calendar (java.util.Calendar)3 Dialog (android.app.Dialog)2 Context (android.content.Context)2 ColorDrawable (android.graphics.drawable.ColorDrawable)2 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 Button (android.widget.Button)2 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)2 FirebaseAuth (com.google.firebase.auth.FirebaseAuth)2 FirebaseUser (com.google.firebase.auth.FirebaseUser)2 Donation (com.jexapps.bloodhub.m_Model.Donation)2