content: package id.merahmuda.bcd.activity;
  
  import android.content.Context;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.support.v7.widget.DefaultItemAnimator;
  import android.support.v7.widget.GridLayoutManager;
  import android.support.v7.widget.RecyclerView;
  import android.util.Log;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.animation.AnimationUtils;
  import android.view.animation.LayoutAnimationController;
  import android.widget.Toast;
  
  import com.facebook.shimmer.ShimmerFrameLayout;
  
  import java.util.List;
  
  import es.dmoral.toasty.Toasty;
  import id.merahmuda.bcd.R;
  import id.merahmuda.bcd.adapter.PengaduanAdapter;
  import id.merahmuda.bcd.adapter.ReviewAdapter;
  import id.merahmuda.bcd.helper.Constant;
  import id.merahmuda.bcd.model.Pengaduan;
  import id.merahmuda.bcd.model.Review;
  import id.merahmuda.bcd.model.response.ResponsePengaduan;
  import id.merahmuda.bcd.model.response.ResponseReview;
  import id.merahmuda.bcd.rest.ApiInterface;
  import retrofit2.Call;
  import retrofit2.Callback;
  import retrofit2.Response;
  
  public class PengaduanActivity extends BaseActivity {
  
      private RecyclerView recyclerView;
      private PengaduanAdapter pengaduanAdapter;
      Context context;
      ApiInterface apiInterface;
      private ShimmerFrameLayout mShimmerViewContainer;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_pengaduan);
          setTitle("Pengaduan");
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
          getSupportActionBar().setDisplayShowHomeEnabled(true);
          findViews();
          initViews();
          initListeners();
          loadData();
      }
  
      @Override
      public void findViews() {
          recyclerView = findViewById(R.id.recycler_view);
          mShimmerViewContainer = findViewById(R.id.shimmer_view_container);
      }
  
      @Override
      public void initViews() {
          apiInterface = Constant.getAPIService();
      }
  
      @Override
      public void initListeners() {
  
      }
  
      private void loadData() {
          Call<ResponsePengaduan> call = apiInterface.pengaduan();
          Log.wtf("URL Called", call.request().url() + "");
  
          call.enqueue(new Callback<ResponsePengaduan>() {
              @Override
              public void onResponse(Call<ResponsePengaduan> call, Response<ResponsePengaduan> response) {
                  if (response.isSuccessful()){
                      generateListPengaduan(response.body().getData());
                  }else {
  
                      Toast.makeText(PengaduanActivity.this, "Gagal mengambil data.", Toast.LENGTH_SHORT).show();
                  }
                  mShimmerViewContainer.stopShimmerAnimation();
                  mShimmerViewContainer.setVisibility(View.GONE);
              }
  
              @Override
              public void onFailure(Call<ResponsePengaduan> call, Throwable t) {
                  Toasty.error(PengaduanActivity.this, "Koneksi Internet Bermasalah", Toast.LENGTH_SHORT, true).show();
              }
          });
      }
  
      public void generateListPengaduan(List<Pengaduan> pengaduanList){
          try{
              int resId = R.anim.layout_animation_from_down;
              LayoutAnimationController animation = AnimationUtils.loadLayoutAnimation(this, resId);
  
              pengaduanAdapter = new PengaduanAdapter(this, pengaduanList);
              RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(this, 1);
              recyclerView.setLayoutManager(mLayoutManager);
              recyclerView.setItemAnimator(new DefaultItemAnimator());
              recyclerView.setLayoutAnimation(animation);
              recyclerView.setAdapter(pengaduanAdapter);
          }catch (Exception e){
  
          }
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // handle arrow click here
          if (item.getItemId() == android.R.id.home) {
              finish(); // close this activity and return to preview activity (if there is any)
          }
  
          return super.onOptionsItemSelected(item);
      }
  
      @Override
      public void onResume() {
          mShimmerViewContainer.startShimmerAnimation();
          super.onResume();
      }
  
      @Override
      public void onPause() {
          mShimmerViewContainer.stopShimmerAnimation();
          super.onPause();
      }
  }
  