package com.medical.medicate;


import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

import java.util.ArrayList;
import java.util.List;


/**
 * A simple {@link Fragment} subclass.
 */
public class My_Appointment extends Fragment {


    private FirebaseDatabase mdatabase;
    private DatabaseReference mReference;
    private ProgressDialog pDialog;
    private ListView listView;



    public My_Appointment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_my__appointment, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        final String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
        mdatabase = FirebaseDatabase.getInstance();
        mReference = mdatabase.getReference();

        listView = (ListView) view.findViewById(R.id.list);

        pDialog = new ProgressDialog(getContext());
        pDialog.setCancelable(false);

        pDialog.setMessage("Fetching Form...Please Wait");
        showDialog();

        mReference.child("users").child(userId).child("Book Appointment").addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {

                final List<String> namesList = new ArrayList<String>();

                for (DataSnapshot messageSnapshot : dataSnapshot.getChildren()) {
                     Message msg = messageSnapshot.getValue(Message.class);
                   if(msg!=null){
                     namesList.add(msg.Fullname);
                   }
                }

                ArrayAdapter<String> areasAdapter = new ArrayAdapter<String>(getActivity(), R.layout.activity_listview, R.id.textView,namesList);
                listView.setAdapter(areasAdapter);
                hideDialog();
               // Toast.makeText(getActivity(),"i am out",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
                // Getting Post failed, log a message
                Log.w("Error", "loadPost:onCancelled", databaseError.toException());
                // ...
            }
        });
    }

    public static class  Message{
        String Fullname;
        Message(){}
        Message(String Fullname){
            this.Fullname=Fullname;
        }
    }

    private void showDialog()
    {
        if (!pDialog.isShowing())
            pDialog.show();
    }

    private void hideDialog()
    {
        if (pDialog.isShowing())
            pDialog.dismiss();
    }
}

@@ -25,16 +25,49 @@
 cate;%0A%0A%0A
+import android.app.ListFragment;%0A
 import a
@@ -760,16 +760,39 @@
 ayList;%0A
+import java.util.Date;%0A
 import j
@@ -899,17 +899,16 @@
 Fragment
- 
 %7B%0A%0A%0A    
@@ -1422,24 +1422,98 @@
 se);%0A    %7D%0A%0A
+    @Override%0A    public void onStart() %7B%0A        super.onStart();%0A    %7D%0A%0A
     @Overrid
@@ -1939,15 +1939,16 @@
 (get
-Context
+Activity
 ());
@@ -2358,24 +2358,241 @@
 %3CString%3E();%0A
+                final List%3CString%3E datelist = new ArrayList%3CString%3E();%0A                final List%3CString%3E timelist = new ArrayList%3CString%3E();%0A                final List%3CString%3E approvelist = new ArrayList%3CString%3E();%0A%0A
 %0A           
@@ -2818,24 +2818,166 @@
 .Fullname);%0A
+                     datelist.add(msg.Date);%0A                     timelist.add(msg.Time);%0A                     approvelist.add(msg.Approved);%0A
             
@@ -3609,16 +3609,18 @@
     %7D);%0A
+%0A%0A
     %7D%0A%0A 
@@ -3667,32 +3667,51 @@
  String Fullname
+,Date,Time,Approved
 ;%0A        Messag
@@ -3751,45 +3751,178 @@
 name
-)%7B%0A            this.Fullname=Fullname
+,String Date,String Time,String Approved )%7B%0A            this.Fullname=Fullname;%0A            this.Date=Date;%0A            this.Time=Time;%0A            this.Approved=Approved
 ;%0A  

complete pranjal