package com.dbs.mplus.fatima.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.dbs.mplus.fatima.R;
import com.dbs.mplus.fatima.adapter.ConsentImageAdapter;
import com.dbs.mplus.fatima.model.ConsentImageListVO;

import java.util.ArrayList;

public class ImageActivity extends AppCompatActivity {

  private AppCompatActivity mActivity;
  private Context mContext;

  private ArrayList<ConsentImageListVO> arrayList;

  private LinearLayoutManager linearLayoutManager;
  private ConsentImageAdapter consentImageAdapter;

  private Button btnClose;
  private RecyclerView recyclerView;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_image);

    init();
    setEvent();
    setImageAdapter();
  }

  private void init() {
    Intent intent = getIntent();
    arrayList = (ArrayList<ConsentImageListVO>) intent.getSerializableExtra("imageArray");
    setLayout();
  }

  private void setEvent() {
    btnClose.setOnClickListener(onClickListener);
  }

  private void setLayout() {
    btnClose     = (Button) findViewById(R.id.btnClose);
    recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
  }

  private void setImageAdapter() {
    if (consentImageAdapter == null) {
      consentImageAdapter = new ConsentImageAdapter(arrayList);
      linearLayoutManager = new LinearLayoutManager(mContext, RecyclerView.VERTICAL, false);

      recyclerView.setLayoutManager(linearLayoutManager);
      recyclerView.setAdapter(consentImageAdapter);
    }
  }

  private View.OnClickListener onClickListener = new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      if (v == btnClose) {
        finish();
      }
    }
  };

  @Override
  public void onDestroy() {
    super.onDestroy();
  }
}
