Advertisement
hasancse1991

Untitled

Feb 25th, 2019
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 15.82 KB | None | 0 0
  1. package com.webandcrafts.healwire;
  2.  
  3. import android.app.ProgressDialog;
  4. import android.content.Intent;
  5. import android.support.v4.widget.SwipeRefreshLayout;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.os.Bundle;
  8. import android.support.v7.widget.Toolbar;
  9. import android.util.Log;
  10. import android.view.View;
  11. import android.widget.AdapterView;
  12. import android.widget.ListView;
  13. import android.widget.TextView;
  14. import android.widget.Toast;
  15.  
  16. import com.android.volley.AuthFailureError;
  17. import com.android.volley.Request;
  18. import com.android.volley.Response;
  19. import com.android.volley.VolleyError;
  20. import com.android.volley.toolbox.StringRequest;
  21. import com.google.gson.JsonObject;
  22. import com.orhanobut.logger.AndroidLogAdapter;
  23. import com.orhanobut.logger.Logger;
  24. import com.webandcrafts.healwire.util.AppController;
  25.  
  26. import org.json.JSONArray;
  27. import org.json.JSONObject;
  28.  
  29. import java.util.ArrayList;
  30. import java.util.HashMap;
  31. import java.util.List;
  32. import java.util.Map;
  33.  
  34. import butterknife.BindView;
  35. import butterknife.ButterKnife;
  36.  
  37. import static com.webandcrafts.healwire.HomeActivity.paidPrescription;
  38. import static com.webandcrafts.healwire.HomeActivity.unpaidPrescription;
  39.  
  40. public class MyPrescriptionActivity extends AppCompatActivity {
  41.  
  42.     private Toolbar mToolbar;
  43.     ProgressDialog progressDialog;
  44.     String prescriptionStatus,responseMessage, email;
  45.  
  46.     @BindView(R.id.swipeRefreshLayout)
  47.     SwipeRefreshLayout swipeRefreshLayout;
  48.  
  49.     TextView textViewEmpty;
  50.  
  51.     SharedPreferenceHandler sharedPreferenceHandlerStatus;
  52.  
  53.     private List<Prescription> prescriptionList = new ArrayList<Prescription>();
  54.     private ListView listViewPrescription;
  55.     private MyPrescriptionListAdapter listPrescriptionAdapter;
  56.  
  57.     @Override
  58.     protected void onCreate(Bundle savedInstanceState) {
  59.         super.onCreate(savedInstanceState);
  60.         setContentView(R.layout.activity_my_prescription);
  61.         ButterKnife.bind(this);
  62.         Logger.addLogAdapter(new AndroidLogAdapter());
  63.  
  64.         final SharedPreferenceHandler sharedPreferenceHandler = new SharedPreferenceHandler();
  65.         email = sharedPreferenceHandler.getUserEmail(getApplicationContext());
  66.  
  67.         mToolbar = (Toolbar) findViewById(R.id.toolbar);
  68.         setSupportActionBar(mToolbar);
  69.  
  70.         textViewEmpty = (TextView) findViewById(android.R.id.empty);
  71.  
  72.         listViewPrescription = (ListView) findViewById(R.id.listViewPrescription);
  73.         listPrescriptionAdapter = new MyPrescriptionListAdapter(this, prescriptionList);
  74.         listViewPrescription.setAdapter(listPrescriptionAdapter);
  75.  
  76.         progressDialog = new ProgressDialog(this);
  77.  
  78.         getPrescriptionThumb(email);
  79.  
  80.         listViewPrescription.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  81.             @Override
  82.             public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
  83.  
  84.                 AppController.invoice_Id_position = i;
  85.  
  86.                 Intent intentPrescriptionDetails = new Intent(MyPrescriptionActivity.this, PrescriptionDetailsActivity.class);
  87.                 startActivity(intentPrescriptionDetails);
  88.  
  89.             }
  90.         });
  91.  
  92.         swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
  93.             @Override
  94.             public void onRefresh() {
  95.                 getPrescriptionThumb(email);
  96.             }
  97.         });
  98.  
  99.     }
  100.  
  101.  
  102.  
  103.     //To load detials of My Prescription of a user
  104.  
  105.     public synchronized void getPrescriptionThumb(final String email){
  106.  
  107.         progressDialog.setMessage("Please wait...");
  108.         progressDialog.setCanceledOnTouchOutside(false);
  109.         progressDialog.show();
  110.  
  111.         StringRequest doLogin = new StringRequest(Request.Method.POST,AppController.GET_PRESCRIPTION_THUMB_URL,
  112.                 new Response.Listener<String>() {
  113.  
  114.                     @Override
  115.                     public void onResponse(String response) {
  116.                         if (swipeRefreshLayout.isRefreshing())
  117.                             swipeRefreshLayout.setRefreshing(false);
  118.  
  119.                         Logger.d(response);
  120.  
  121. //                        Toast.makeText(getApplicationContext(),response,Toast.LENGTH_LONG).show();
  122.  
  123.                         progressDialog.dismiss();
  124.  
  125.  
  126.                         try{
  127.                             JSONObject mainResponse = new JSONObject(response);
  128.  
  129.                             prescriptionStatus = mainResponse.getString("status");
  130.                             responseMessage = mainResponse.getString("msg");
  131.  
  132.                             if(prescriptionStatus.equals("SUCCESS")){
  133.  
  134.                                 JSONObject jsonObjectData = mainResponse.getJSONObject("data");
  135.                                 JSONArray jsonArrayPrescriptions = jsonObjectData.getJSONArray("prescriptions");
  136.  
  137.                                 //test start
  138. //                                for(int i = 0;i<jsonArrayPrescriptions.length();i++) {
  139. //
  140. //                                    int invoice_status_id = jsonArrayPrescriptions.getJSONObject(i).getInt("invoice_status_id");
  141. //
  142. //                                    JSONObject jsonObjectPrescription = jsonArrayPrescriptions.getJSONObject(i);
  143. //
  144. //                                    if(invoice_status_id == 1 || invoice_status_id == 3 || invoice_status_id == 4){
  145. //                                        unpaidPrescription.add(jsonObjectPrescription);
  146. //                                    }
  147. //                                    else{
  148. //                                        paidPrescription.add(jsonObjectPrescription);
  149. //                                    }
  150. //                                }
  151.                                 //test end
  152.  
  153.  
  154.                                 if(unpaidPrescription.size() == 0){
  155.  
  156.                                     textViewEmpty.setVisibility(View.VISIBLE);
  157.                                 }
  158.                                 else{
  159.  
  160.                                     textViewEmpty.setVisibility(View.GONE);
  161.  
  162.                                 }
  163.  
  164.                                 for(int i = 0; i<unpaidPrescription.size(); i++){
  165.  
  166.                                     //-----------------------------------------------------------------------------------------------
  167.  
  168.  
  169.                                     String create_on = unpaidPrescription.get(i).getString("created_on");
  170.  
  171.                                     Log.d("Dates",String.valueOf(create_on));
  172.  
  173.                                     String pres_status = unpaidPrescription.get(i).getString("pres_status");
  174.                                     String path =  unpaidPrescription.get(i).getString("path");
  175.                                     int invoice_id =  unpaidPrescription.get(i).getInt("invoice_id");
  176.                                     int pres_status_id =  unpaidPrescription.get(i).getInt("pres_status_id");
  177.  
  178.                                     int invoice_status_id = unpaidPrescription.get(i).getInt("invoice_status_id");
  179.  
  180.                                     String invoice_status = unpaidPrescription.get(i).getString("invoice_status");
  181.                                     String shippingCode = unpaidPrescription.get(i).getString("shipping_code");
  182.  
  183.  
  184.  
  185.                                     //------------------------------------------------------------------------------------------
  186.  
  187.  
  188.  
  189. //                                    String create_on = jsonArrayPrescriptions.getJSONObject(i).getString("created_on");
  190. //                                    String pres_status = jsonArrayPrescriptions.getJSONObject(i).getString("pres_status");
  191. //                                    String path = jsonArrayPrescriptions.getJSONObject(i).getString("path");
  192. //                                    int invoice_id = jsonArrayPrescriptions.getJSONObject(i).getInt("invoice_id");
  193. //                                    int pres_status_id = jsonArrayPrescriptions.getJSONObject(i).getInt("pres_status_id");
  194. //
  195. //                                    int invoice_status_id = jsonArrayPrescriptions.getJSONObject(i).getInt("invoice_status_id");
  196. //
  197. //                                    String invoice_status = jsonArrayPrescriptions.getJSONObject(i).getString("invoice_status");
  198.  
  199.  
  200.  
  201.  
  202.                                     Prescription prescription = new Prescription();
  203.  
  204.  
  205.                                     prescription.setDate(create_on);
  206.                                     prescription.setStatus(pres_status);
  207.                                     prescription.setStatusId(pres_status_id);
  208.                                     prescription.setImageUrl(path);
  209.                                     prescription.setInvoice_Id(invoice_id);
  210.                                     prescription.setShippingCode(shippingCode);
  211.  
  212.                                     prescriptionList.add(prescription);
  213.  
  214.  
  215.                                     AppController.invoiceIdList.add(invoice_id);
  216.  
  217.                                     Log.d("INVOICE_IDS",String.valueOf(AppController.invoiceIdList.get(i)));
  218.  
  219. //                                    if(invoice_status_id == 1 || invoice_status_id == 3 || invoice_status_id == 4){
  220. //
  221. //                                        prescriptionList.add(prescription);
  222. //
  223. //
  224. //
  225. //                                    }
  226.  
  227.  
  228.                                 }
  229.  
  230.                                 listPrescriptionAdapter.notifyDataSetChanged();
  231.                             }
  232.                         }catch(Exception e){
  233.                             // messageHandler.sendEmptyMessage(99);
  234.                         }
  235.                     }
  236.                 }, new Response.ErrorListener() {
  237.             @Override
  238.             public void onErrorResponse(VolleyError error) {
  239.                 if (swipeRefreshLayout.isRefreshing())
  240.                     swipeRefreshLayout.setRefreshing(false);
  241.                 //  messageHandler.sendEmptyMessage(98);
  242.  
  243.                 Log.d("EMPTY","NO DATA FROM SERVER");
  244.  
  245.                 progressDialog.dismiss();
  246.                 textViewEmpty.setVisibility(View.VISIBLE);
  247.  
  248.  
  249.  
  250.  
  251.             }
  252.         }){
  253.             @Override
  254.             protected Map<String, String> getParams()
  255.             {
  256.                 Map<String, String>  params = new HashMap<String, String>();
  257.  
  258.                 params.put("phoneNumber",email);
  259.  
  260. //                Toast.makeText(getApplicationContext(),"mail:"+phoneNumber,Toast.LENGTH_LONG).show();
  261.  
  262.  
  263.  
  264.  
  265.                 return params;
  266.             }
  267.  
  268.  
  269.             @Override
  270.             public Map<String, String> getHeaders() throws AuthFailureError {
  271.  
  272.                 Map headers = new HashMap();
  273.                 SharedPreferenceHandler sharedPreferenceHandler = new SharedPreferenceHandler();
  274.  
  275.                 if(!sharedPreferenceHandler.getCookie(getApplicationContext()).equals(""))
  276.                     headers.put("Cookie", sharedPreferenceHandler.getCookie(getApplicationContext()));
  277.  
  278.                 Log.d("HEADER_LOG",headers.toString());
  279.  
  280.                 // return super.getHeaders();
  281.                 return headers;
  282.  
  283.             }
  284.  
  285.  
  286.  
  287.         };
  288.         AppController.getInstance().addToRequestQueue(doLogin);
  289. //        doLogin.setRetryPolicy(new DefaultRetryPolicy(
  290. //                (int) TimeUnit.SECONDS.toMillis(20),
  291. //                DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
  292. //                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
  293.  
  294.     }//volley
  295.  
  296.  
  297.     //To load detials of My Prescription of a user
  298.  
  299.     public synchronized void getPrescriptionThumbComplete(final String phoneNumber){
  300.  
  301.         progressDialog.setMessage("Please wait...");
  302.         progressDialog.setCanceledOnTouchOutside(false);
  303.         progressDialog.show();
  304.  
  305.  
  306.  
  307.         StringRequest doLogin = new StringRequest(Request.Method.POST,AppController.GET_PRESCRIPTION_THUMB_URL,
  308.                 new Response.Listener<String>() {
  309.  
  310.                     @Override
  311.                     public void onResponse(String response) {
  312.  
  313.  
  314. //                        Toast.makeText(getApplicationContext(),response,Toast.LENGTH_LONG).show();
  315.  
  316.                         progressDialog.dismiss();
  317.  
  318.  
  319.                         try{
  320.  
  321.                             JSONObject mainResponse = new JSONObject(response);
  322.  
  323.  
  324.  
  325.                             prescriptionStatus = mainResponse.getString("status");
  326.                             responseMessage = mainResponse.getString("msg");
  327.  
  328.                             if(prescriptionStatus.equals("SUCCESS")){
  329.  
  330.                                 JSONObject jsonObjectData = mainResponse.getJSONObject("data");
  331.                                 JSONArray jsonArrayPrescriptions = jsonObjectData.getJSONArray("prescriptions");
  332.  
  333.  
  334.                                 //Toast.makeText(getApplicationContext(),"Array : "+jsonArrayPrescriptions.length(),Toast.LENGTH_LONG).show();
  335.  
  336.  
  337.                                 for(int i = 0;i<jsonArrayPrescriptions.length();i++){
  338.  
  339.  
  340.  
  341.  
  342.                                     int invoice_id = jsonArrayPrescriptions.getJSONObject(i).getInt("invoice_id");
  343.  
  344.  
  345.                                     int invoice_status_id = jsonArrayPrescriptions.getJSONObject(i).getInt("invoice_status_id");
  346.  
  347.                                     JSONObject jsonObjectPrescription = jsonArrayPrescriptions.getJSONObject(i);
  348.  
  349.  
  350.  
  351.  
  352.                                     if(invoice_status_id == 1 || invoice_status_id == 3 || invoice_status_id == 4){
  353.  
  354.  
  355.                                        unpaidPrescription.add(jsonObjectPrescription);
  356.  
  357.  
  358.                                     }
  359.                                     else{
  360.  
  361.                                        paidPrescription.add(jsonObjectPrescription);
  362.  
  363.                                     }
  364.  
  365.  
  366.  
  367.  
  368.                                 }
  369.  
  370.  
  371.                                 Toast.makeText(getApplicationContext(),"UNPAID Array : "+unpaidPrescription.size(),Toast.LENGTH_LONG).show();
  372.                                 Toast.makeText(getApplicationContext(),"PAID Array : "+paidPrescription.size(),Toast.LENGTH_LONG).show();
  373.  
  374.  
  375.                                 Log.d("UNPAID JSONOBJECT",String.valueOf(unpaidPrescription));
  376.                                 Log.d("PAID JSONOBJECT",String.valueOf(paidPrescription));
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.                                 //listPrescriptionAdapter.notifyDataSetChanged();
  385.                             }
  386.                         }catch(Exception e){
  387.                             // messageHandler.sendEmptyMessage(99);
  388.                         }
  389.                     }
  390.                 }, new Response.ErrorListener() {
  391.             @Override
  392.             public void onErrorResponse(VolleyError error) {
  393.                 //  messageHandler.sendEmptyMessage(98);
  394.             }
  395.         }){
  396.             @Override
  397.             protected Map<String, String> getParams()
  398.             {
  399.                 Map<String, String>  params = new HashMap<String, String>();
  400.  
  401.                 params.put("phoneNumber",phoneNumber);
  402.  
  403.  
  404.  
  405.                 return params;
  406.             }
  407.  
  408.  
  409.             @Override
  410.             public Map<String, String> getHeaders() throws AuthFailureError {
  411.  
  412.                 Map headers = new HashMap();
  413.                 SharedPreferenceHandler sharedPreferenceHandler = new SharedPreferenceHandler();
  414.  
  415.                 if(!sharedPreferenceHandler.getCookie(getApplicationContext()).equals(""))
  416.                     headers.put("Cookie", sharedPreferenceHandler.getCookie(getApplicationContext()));
  417.  
  418.                 Log.d("HEADER_LOG",headers.toString());
  419.  
  420.                 // return super.getHeaders();
  421.                 return headers;
  422.  
  423.             }
  424.  
  425.  
  426.  
  427.         };
  428.         AppController.getInstance().addToRequestQueue(doLogin);
  429. //        doLogin.setRetryPolicy(new DefaultRetryPolicy(
  430. //                (int) TimeUnit.SECONDS.toMillis(20),
  431. //                DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
  432. //                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
  433.  
  434.     }//volley
  435.  
  436. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement