Advertisement
fauziahikrar

Report

Apr 11th, 2020
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.74 KB | None | 0 0
  1. package com.example.myapplication.activity;
  2.  
  3. import android.app.ProgressDialog;
  4. import android.content.Context;
  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.widget.Toast;
  11.  
  12. import com.example.myapplication.Model.CategoryItem;
  13. import com.example.myapplication.R;
  14. import com.example.myapplication.adapter.ReportAdapter;
  15. import com.example.myapplication.apihelper.BaseApiService;
  16. import com.example.myapplication.apihelper.UtilsApi;
  17.  
  18. import java.util.ArrayList;
  19. import java.util.List;
  20.  
  21. import retrofit2.Call;
  22. import retrofit2.Callback;
  23. import retrofit2.Response;
  24.  
  25. public class report extends AppCompatActivity {
  26.  
  27.     RecyclerView rvReport;
  28.     ProgressDialog loading;
  29.  
  30.     Context mContext;
  31.     List<CategoryItem> categoryItemList = new ArrayList<>();
  32.     ReportAdapter reportAdapter;
  33.     BaseApiService mApiService;
  34.  
  35.     @Override
  36.     protected void onCreate(Bundle savedInstanceState) {
  37.         super.onCreate(savedInstanceState);
  38.         setContentView(R.layout.activity_report);
  39.  
  40.         rvReport = (RecyclerView) findViewById(R.id.card_recycler_view);
  41.         mContext = this;
  42.         mApiService = UtilsApi.getAPIService();
  43.  
  44.         reportAdapter = new ReportAdapter(this, categoryItemList);
  45.         RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(this);
  46.         rvReport.setLayoutManager(mLayoutManager);
  47.         rvReport.setItemAnimator(new DefaultItemAnimator());
  48.        
  49.         getResultListReport();
  50.     }
  51.  
  52.     private void getResultListReport() {
  53.         loading = ProgressDialog.show(this, null, "Harap Tunggu...", true, false);
  54.  
  55.         mApiService.getCategory().enqueue(new Callback<Response>() {
  56.             @Override
  57.             public void onResponse(Call<Response> call, Response<Response> response) {
  58.                 if (response.isSuccessful()){
  59.                     loading.dismiss();
  60.  
  61.                     final List<CategoryItem> categoryItems = response.body().getCategory();
  62.  
  63.                     rvReport.setAdapter(new ReportAdapter(mContext, categoryItems));
  64.                     reportAdapter.notifyDataSetChanged();
  65.                 } else {
  66.                     loading.dismiss();
  67.                     Toast.makeText(mContext, "Gagal mengambil data laporan", Toast.LENGTH_SHORT).show();
  68.                 }
  69.             }
  70.  
  71.             @Override
  72.             public void onFailure(Call<Response> call, Throwable t) {
  73.                 loading.dismiss();
  74.                 Toast.makeText(mContext, "Koneksi Internet Bermasalah", Toast.LENGTH_SHORT).show();
  75.             }
  76.         });
  77.  
  78.     }
  79.  
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement