Search in sources :

Example 1 with Appointment

use of com.jexapps.bloodhub.m_Model.Appointment in project BloodHub by kazijehangir.

the class AppointmentsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = (View) inflater.inflate(R.layout.fragment_appointments, container, false);
    db = FirebaseDatabase.getInstance().getReference().child("appointments");
    appointments = new ArrayList<Appointment>();
    keys = new ArrayList<String>();
    fetchData();
    numAppointments = (TextView) rootView.findViewById(R.id.num_appointments);
    mRecyclerView = (RecyclerView) rootView.findViewById(R.id.appointment_list_recycler_view);
    mRecyclerView.setHasFixedSize(true);
    mLayoutManager = new LinearLayoutManager(getActivity());
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    mRecyclerView.addItemDecoration(new RecycleMarginDecoration(getActivity()));
    mAdapter = new MyAppointmentDataAdapter(appointments, keys);
    mRecyclerView.setAdapter(mAdapter);
    return rootView;
}
Also used : Appointment(com.jexapps.bloodhub.m_Model.Appointment) MyAppointmentDataAdapter(com.jexapps.bloodhub.m_UI.MyAppointmentDataAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 2 with Appointment

use of com.jexapps.bloodhub.m_Model.Appointment in project BloodHub by kazijehangir.

the class MyAppointmentDataAdapter method onBindViewHolder.

// Replace the contents of a view (invoked by the layout manager)
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    Appointment appointment = appointments.get(position);
    holder.cv.setTag(keys.get(position));
    if (appointment.transport) {
        holder.mTransport.setText("Yes");
    } else {
        holder.mTransport.setText("No");
    }
    if (appointment.confirmed.equals(false)) {
        holder.mStatus.setText("Pending confirmation");
    } else {
        holder.mStatus.setText("Confirmed");
    }
    holder.mDate.setText(DateFormat.getDateInstance().format(new Date(appointment.date)));
    holder.mTime.setText(DateFormat.getTimeInstance(DateFormat.SHORT).format(new Date(appointment.date)));
    FirebaseDatabase.getInstance().getReference().child("users").child(appointment.orgid).addListenerForSingleValueEvent(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            User usr = dataSnapshot.getValue(User.class);
            holder.mName.setText(usr.username);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
}
Also used : Appointment(com.jexapps.bloodhub.m_Model.Appointment) User(com.jexapps.bloodhub.m_Model.User) DatabaseError(com.google.firebase.database.DatabaseError) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot) Date(java.util.Date)

Example 3 with Appointment

use of com.jexapps.bloodhub.m_Model.Appointment in project BloodHub by kazijehangir.

the class AddAppointmentActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_appointment);
    setTitle("Add Appointment");
    mAuth = FirebaseAuth.getInstance();
    user = mAuth.getCurrentUser();
    spinner = (Spinner) findViewById(R.id.spin1);
    set = (EditText) findViewById(R.id.editText);
    set1 = (EditText) findViewById(R.id.editText2);
    radioGroup = (RadioGroup) findViewById(R.id.radio);
    hospitals = new ArrayList<String>();
    keys = new ArrayList<String>();
    FirebaseDatabase.getInstance().getReference().child("users").orderByChild("account_type").equalTo("organization").addValueEventListener(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot child : dataSnapshot.getChildren()) {
                User user = child.getValue(User.class);
                hospitals.add(user.username);
                keys.add(child.getKey());
            }
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_dropdown_item, hospitals);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinner.setAdapter(adapter);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
    set.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            dialog = new Dialog(AddAppointmentActivity.this);
            dialog.setTitle("Set Date");
            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) {
                    day = datePicker.getDayOfMonth();
                    month = datePicker.getMonth();
                    year = datePicker.getYear();
                    Calendar calendar = Calendar.getInstance();
                    calendar.set(year, month, day);
                    pdate = calendar.getTime();
                    date = DateFormat.getDateInstance().format(pdate);
                    set.setText(date);
                    dialog.cancel();
                }
            });
        }
    });
    set1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            dialog = new Dialog(AddAppointmentActivity.this);
            dialog.setTitle("Set Time");
            dialog.setContentView(R.layout.set_time);
            dialog.show();
            final Button setTime = (Button) dialog.findViewById(R.id.set_time);
            final TimePicker timePicker = (TimePicker) dialog.findViewById(R.id.timePicker);
            setTime.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    hour = timePicker.getCurrentHour();
                    minute = timePicker.getCurrentMinute();
                    if (hour >= 12) {
                        time = "PM";
                    } else {
                        time = "AM";
                    }
                    if (hour > 12) {
                        hour = hour - 12;
                    }
                    if (minute > 10) {
                        time = minute + " " + time;
                    } else {
                        time = "0" + minute + " " + time;
                    }
                    if (hour > 10) {
                        time = hour + ":" + time;
                    } else {
                        time = "0" + hour + ":" + time;
                    }
                    set1.setText(time);
                    dialog.cancel();
                }
            });
        }
    });
    Button submit = (Button) findViewById(R.id.submit_button1);
    submit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            radioButton = (RadioButton) findViewById(radioGroup.getCheckedRadioButtonId());
            String transport_text = (String) radioButton.getText();
            if (transport_text.equals("Yes")) {
                transport = true;
            } else {
                transport = false;
            }
            Appointment appointment = new Appointment(user.getUid(), keys.get(spinner.getSelectedItemPosition()), date, time, transport);
            FirebaseDatabase.getInstance().getReference().child("appointments").push().setValue(appointment);
            dialog = new Dialog(AddAppointmentActivity.this);
            dialog.setTitle("Submit Request");
            dialog.setContentView(R.layout.popup_appointment_submit);
            dialog.show();
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            final Button request = (Button) dialog.findViewById(R.id.button_ok);
            request.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(AddAppointmentActivity.this, MainActivity.class);
                    startActivity(intent);
                }
            });
        }
    });
}
Also used : Appointment(com.jexapps.bloodhub.m_Model.Appointment) TimePicker(android.widget.TimePicker) User(com.jexapps.bloodhub.m_Model.User) FirebaseUser(com.google.firebase.auth.FirebaseUser) Calendar(java.util.Calendar) Intent(android.content.Intent) RadioButton(android.widget.RadioButton) DataSnapshot(com.google.firebase.database.DataSnapshot) View(android.view.View) DatabaseError(com.google.firebase.database.DatabaseError) ColorDrawable(android.graphics.drawable.ColorDrawable) RadioButton(android.widget.RadioButton) Button(android.widget.Button) Dialog(android.app.Dialog) ValueEventListener(com.google.firebase.database.ValueEventListener) DatePicker(android.widget.DatePicker) ArrayAdapter(android.widget.ArrayAdapter)

Example 4 with Appointment

use of com.jexapps.bloodhub.m_Model.Appointment in project BloodHub by kazijehangir.

the class AppointmentsFragment method fetchData.

// Getting data from database
public void fetchData() {
    FirebaseAuth mAuth = FirebaseAuth.getInstance();
    FirebaseUser user = mAuth.getCurrentUser();
    db.orderByChild("userid").equalTo(user.getUid()).addValueEventListener(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            appointments.clear();
            keys.clear();
            for (DataSnapshot child : dataSnapshot.getChildren()) {
                Appointment appointment = child.getValue(Appointment.class);
                appointments.add(appointment);
                keys.add(child.getKey());
            }
            numAppointments.setText("Appointments: " + appointments.size());
            mAdapter.notifyDataSetChanged();
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
    return;
}
Also used : Appointment(com.jexapps.bloodhub.m_Model.Appointment) DatabaseError(com.google.firebase.database.DatabaseError) FirebaseUser(com.google.firebase.auth.FirebaseUser) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot) FirebaseAuth(com.google.firebase.auth.FirebaseAuth)

Example 5 with Appointment

use of com.jexapps.bloodhub.m_Model.Appointment in project BloodHub by kazijehangir.

the class AppointmentsOrgFragment method fetchData.

// Getting data from database
public void fetchData() {
    FirebaseAuth mAuth = FirebaseAuth.getInstance();
    FirebaseUser user = mAuth.getCurrentUser();
    db.orderByChild("orgid").equalTo(user.getUid()).addValueEventListener(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            appointments.clear();
            keys.clear();
            for (DataSnapshot child : dataSnapshot.getChildren()) {
                Appointment appointment = child.getValue(Appointment.class);
                appointments.add(appointment);
                keys.add(child.getKey());
            }
            numAppointments.setText("Appointments: " + appointments.size());
            mAdapter.notifyDataSetChanged();
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
    return;
}
Also used : Appointment(com.jexapps.bloodhub.m_Model.Appointment) DatabaseError(com.google.firebase.database.DatabaseError) FirebaseUser(com.google.firebase.auth.FirebaseUser) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot) FirebaseAuth(com.google.firebase.auth.FirebaseAuth)

Aggregations

Appointment (com.jexapps.bloodhub.m_Model.Appointment)7 DataSnapshot (com.google.firebase.database.DataSnapshot)5 DatabaseError (com.google.firebase.database.DatabaseError)5 ValueEventListener (com.google.firebase.database.ValueEventListener)5 View (android.view.View)4 RecyclerView (android.support.v7.widget.RecyclerView)3 TextView (android.widget.TextView)3 FirebaseUser (com.google.firebase.auth.FirebaseUser)3 User (com.jexapps.bloodhub.m_Model.User)3 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 FirebaseAuth (com.google.firebase.auth.FirebaseAuth)2 Date (java.util.Date)2 Dialog (android.app.Dialog)1 Intent (android.content.Intent)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 CardView (android.support.v7.widget.CardView)1 ArrayAdapter (android.widget.ArrayAdapter)1 Button (android.widget.Button)1 DatePicker (android.widget.DatePicker)1