package com.dbs.consent.demo.activity.activityEvent;

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.consent.demo.R;
import com.dbs.consent.demo.adapter.ConsentImageAdapter;
import com.dbs.consent.demo.model.ConsentImageVO;

import java.util.ArrayList;

public class ImageActivity extends AppCompatActivity {

  private static final String TAG = "ImageActivity";
  private AppCompatActivity mActivity;
  private Context mContext;

  private LinearLayoutManager linearLayoutManager;
  private ConsentImageAdapter consentImageAdapter;

  private ArrayList<ConsentImageVO> arrayList;

  private Button btnClose;
  private RecyclerView recyclerView;

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

    init();
  }

  private void init() {
    mActivity = this;
    mContext  = this;

    Intent intent = getIntent();
    arrayList     = (ArrayList<ConsentImageVO>) intent.getSerializableExtra("imageArray");

    setLayout();
    setEvent();
    setImageAdapter();
  }

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

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

  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();
  }
}
