From 1515e53484e805d9470a0d537ef2df29a9127691 Mon Sep 17 00:00:00 2001 From: r-ca Date: Mon, 29 Jan 2024 00:06:28 +0900 Subject: [PATCH] =?UTF-8?q?Adapter=E5=AE=9F=E8=A3=85=20WIP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/LacertaApplyTagAdapter.java | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 component/common/src/main/java/one/nem/lacerta/component/common/LacertaApplyTagAdapter.java diff --git a/component/common/src/main/java/one/nem/lacerta/component/common/LacertaApplyTagAdapter.java b/component/common/src/main/java/one/nem/lacerta/component/common/LacertaApplyTagAdapter.java new file mode 100644 index 00000000..08440304 --- /dev/null +++ b/component/common/src/main/java/one/nem/lacerta/component/common/LacertaApplyTagAdapter.java @@ -0,0 +1,78 @@ +package one.nem.lacerta.component.common; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.CheckBox; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import java.util.ArrayList; + +import one.nem.lacerta.model.document.tag.DocumentTag; + +public class LacertaApplyTagAdapter extends RecyclerView.Adapter{ + + // Listener + public interface LacertaApplyTagDialogListener { + void itemChecked(View view, int position); + void itemUnchecked(View view, int position); + } + + // Variables + private ArrayList documentTagArrayList; + private LacertaApplyTagDialogListener listener; + + // Setter + public LacertaApplyTagAdapter setListener(LacertaApplyTagDialogListener listener) { + this.listener = listener; + return this; + } + + public LacertaApplyTagAdapter setDocumentTagArrayList(ArrayList documentTagArrayList) { + this.documentTagArrayList = documentTagArrayList; + return this; + } + + // Constructor + public LacertaApplyTagAdapter(ArrayList documentTagArrayList) { + this.documentTagArrayList = documentTagArrayList; + } + + @NonNull + @Override + public LacertaApplyTagAdapter.LacertaApplyTagViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.lacerta_dialog_apply_tag, parent, false); + return new LacertaApplyTagAdapter.LacertaApplyTagViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull LacertaApplyTagAdapter.LacertaApplyTagViewHolder holder, int position) { + DocumentTag documentTag = documentTagArrayList.get(position); + holder.checkBox.setText(documentTag.getName()); + holder.checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> { + if (isChecked) { + listener.itemChecked(buttonView, position); + } else { + listener.itemUnchecked(buttonView, position); + } + }); + } + + @Override + public int getItemCount() { + return documentTagArrayList == null ? 0 : documentTagArrayList.size(); + } + + public class LacertaApplyTagViewHolder extends RecyclerView.ViewHolder { + + CheckBox checkBox; + + public LacertaApplyTagViewHolder(@NonNull View itemView) { + super(itemView); + + checkBox = itemView.findViewById(R.id.checkBox); + } + } +}