Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.shopfloorv20.Activity;
- import android.app.ProgressDialog;
- import android.nfc.Tag;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.support.v7.widget.DefaultItemAnimator;
- import android.support.v7.widget.LinearLayoutManager;
- import android.support.v7.widget.RecyclerView;
- import android.util.Log;
- import android.widget.TextView;
- import com.androidnetworking.AndroidNetworking;
- import com.androidnetworking.common.Priority;
- import com.androidnetworking.error.ANError;
- import com.androidnetworking.interfaces.JSONObjectRequestListener;
- import com.androidnetworking.internal.ANRequestQueue;
- import com.example.shopfloorv20.Adapter.WorkcenterAdapter;
- import com.example.shopfloorv20.Model.Workcenter;
- import com.example.shopfloorv20.R;
- import com.example.shopfloorv20.Utils.GlobarVars;
- import com.google.gson.Gson;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.util.ArrayList;
- import java.util.List;
- public class WorkcenterListActivity extends AppCompatActivity {
- private RecyclerView rv;
- private WorkcenterAdapter adapter;
- private Gson gson;
- private List<Workcenter> allList;
- private TextView tvName_wc, tvCode_wc;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_workcenter_list);
- gson = new Gson();
- allList = new ArrayList<>();
- rv = findViewById(R.id.rvWorkcenterList);
- adapter = new WorkcenterAdapter(this);
- LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
- rv.setLayoutManager(linearLayoutManager);
- // rv.setItemAnimator(new DefaultItemAnimator());
- rv.setAdapter(adapter);
- loadData();
- }
- private void loadData() {
- final ProgressDialog progress = new ProgressDialog(this);
- progress.setMessage("Sedang Proses");
- progress.setTitle("Sedang Proses");
- progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
- progress.show();
- if (adapter != null)
- adapter.clearAll();
- AndroidNetworking.get(GlobarVars.BASE_IP + "index.php/workcenter")
- .setPriority(Priority.MEDIUM)
- .build()
- .getAsJSONObject(new JSONObjectRequestListener() {
- public void onResponse(JSONObject response) {
- List<Workcenter> results = new ArrayList<>();
- try {
- Log.e("resp", response.toString(1));
- if (results != null)
- results.clear();
- String message = response.getString("message");
- if (message.equals("Workcenter were found")) {
- String records = response.getString("data");
- JSONArray dataArr = new JSONArray(records);
- if (dataArr.length() > 0) {
- for (int i = 0; i < dataArr.length(); i++) {
- // System.out.println("res "+dataArr.getJSONObject(i).toString());
- Workcenter workcenter = gson.fromJson(dataArr.getJSONObject(i).toString(), Workcenter.class);
- results.add(workcenter);
- }
- }
- }
- progress.dismiss();
- } catch (JSONException e) {
- e.printStackTrace();
- progress.dismiss();
- }
- adapter.addAll(results);
- }
- public void onError(ANError anError) {
- progress.dismiss();
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement