Advertisement
Guest User

WorkcenterListActivity.java

a guest
Mar 19th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. package com.example.shopfloorv20.Activity;
  2.  
  3. import android.app.ProgressDialog;
  4. import android.nfc.Tag;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.os.Bundle;
  7. import android.support.v7.widget.DefaultItemAnimator;
  8. import android.support.v7.widget.LinearLayoutManager;
  9. import android.support.v7.widget.RecyclerView;
  10. import android.util.Log;
  11. import android.widget.TextView;
  12.  
  13. import com.androidnetworking.AndroidNetworking;
  14. import com.androidnetworking.common.Priority;
  15. import com.androidnetworking.error.ANError;
  16. import com.androidnetworking.interfaces.JSONObjectRequestListener;
  17. import com.androidnetworking.internal.ANRequestQueue;
  18. import com.example.shopfloorv20.Adapter.WorkcenterAdapter;
  19. import com.example.shopfloorv20.Model.Workcenter;
  20. import com.example.shopfloorv20.R;
  21. import com.example.shopfloorv20.Utils.GlobarVars;
  22. import com.google.gson.Gson;
  23.  
  24. import org.json.JSONArray;
  25. import org.json.JSONException;
  26. import org.json.JSONObject;
  27.  
  28. import java.util.ArrayList;
  29. import java.util.List;
  30.  
  31. public class WorkcenterListActivity extends AppCompatActivity {
  32. private RecyclerView rv;
  33. private WorkcenterAdapter adapter;
  34. private Gson gson;
  35. private List<Workcenter> allList;
  36. private TextView tvName_wc, tvCode_wc;
  37.  
  38. @Override
  39. protected void onCreate(Bundle savedInstanceState) {
  40. super.onCreate(savedInstanceState);
  41. setContentView(R.layout.activity_workcenter_list);
  42.  
  43. gson = new Gson();
  44. allList = new ArrayList<>();
  45. rv = findViewById(R.id.rvWorkcenterList);
  46.  
  47. adapter = new WorkcenterAdapter(this);
  48.  
  49. LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
  50. rv.setLayoutManager(linearLayoutManager);
  51. // rv.setItemAnimator(new DefaultItemAnimator());
  52.  
  53. rv.setAdapter(adapter);
  54.  
  55. loadData();
  56.  
  57. }
  58.  
  59. private void loadData() {
  60. final ProgressDialog progress = new ProgressDialog(this);
  61. progress.setMessage("Sedang Proses");
  62. progress.setTitle("Sedang Proses");
  63. progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
  64. progress.show();
  65.  
  66. if (adapter != null)
  67. adapter.clearAll();
  68.  
  69. AndroidNetworking.get(GlobarVars.BASE_IP + "index.php/workcenter")
  70. .setPriority(Priority.MEDIUM)
  71. .build()
  72. .getAsJSONObject(new JSONObjectRequestListener() {
  73. public void onResponse(JSONObject response) {
  74. List<Workcenter> results = new ArrayList<>();
  75. try {
  76. Log.e("resp", response.toString(1));
  77.  
  78. if (results != null)
  79. results.clear();
  80.  
  81. String message = response.getString("message");
  82.  
  83. if (message.equals("Workcenter were found")) {
  84. String records = response.getString("data");
  85.  
  86. JSONArray dataArr = new JSONArray(records);
  87.  
  88. if (dataArr.length() > 0) {
  89.  
  90. for (int i = 0; i < dataArr.length(); i++) {
  91. // System.out.println("res "+dataArr.getJSONObject(i).toString());
  92.  
  93. Workcenter workcenter = gson.fromJson(dataArr.getJSONObject(i).toString(), Workcenter.class);
  94. results.add(workcenter);
  95. }
  96. }
  97. }
  98.  
  99. progress.dismiss();
  100.  
  101. } catch (JSONException e) {
  102. e.printStackTrace();
  103.  
  104. progress.dismiss();
  105.  
  106. }
  107.  
  108. adapter.addAll(results);
  109. }
  110.  
  111. public void onError(ANError anError) {
  112. progress.dismiss();
  113. }
  114. });
  115. }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement