From 03d78b12009ed2d6f96514db7377182e52aa3e6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 25 Jan 2024 12:06:21 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=A4=E3=83=99=E3=83=B3=E3=83=88=E3=83=AA?= =?UTF-8?q?=E3=82=B9=E3=83=8A=E3=81=AB=E5=AF=BE=E5=BF=9C=E3=81=97=E3=81=9F?= =?UTF-8?q?=E5=AE=9F=E8=A3=85=E3=82=92=E4=BD=9C=E6=88=90=20WIP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shared/ui/LacertaSelectDirDialog.java | 5 +- .../shared/ui/SelectDirDialogItemAdapter.java | 79 ++++++++++++------- 2 files changed, 53 insertions(+), 31 deletions(-) diff --git a/shared/ui/src/main/java/one/nem/lacerta/shared/ui/LacertaSelectDirDialog.java b/shared/ui/src/main/java/one/nem/lacerta/shared/ui/LacertaSelectDirDialog.java index ba85c49f..4faebf45 100644 --- a/shared/ui/src/main/java/one/nem/lacerta/shared/ui/LacertaSelectDirDialog.java +++ b/shared/ui/src/main/java/one/nem/lacerta/shared/ui/LacertaSelectDirDialog.java @@ -23,7 +23,10 @@ public class LacertaSelectDirDialog extends DialogFragment { RecyclerView recyclerView = view.findViewById(R.id.select_dir_recycler_view); recyclerView.setHasFixedSize(true); - SelectDirDialogItemAdapter adapter = new SelectDirDialogItemAdapter(); + SelectDirDialogItemAdapter adapter = new SelectDirDialogItemAdapter((name, itemId) -> { + Toast.makeText(getContext(), "Called", Toast.LENGTH_SHORT).show(); + dismiss(); + }); recyclerView.setAdapter(adapter); recyclerView.setLayoutManager(new androidx.recyclerview.widget.LinearLayoutManager(getContext())); diff --git a/shared/ui/src/main/java/one/nem/lacerta/shared/ui/SelectDirDialogItemAdapter.java b/shared/ui/src/main/java/one/nem/lacerta/shared/ui/SelectDirDialogItemAdapter.java index ede9a51e..81ffc6ec 100644 --- a/shared/ui/src/main/java/one/nem/lacerta/shared/ui/SelectDirDialogItemAdapter.java +++ b/shared/ui/src/main/java/one/nem/lacerta/shared/ui/SelectDirDialogItemAdapter.java @@ -8,37 +8,56 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; +import java.util.ArrayList; + +import one.nem.lacerta.model.ListItem; + public class SelectDirDialogItemAdapter extends RecyclerView.Adapter { - @Override - public SelectDirDialogItemAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.common_list_item, parent, false); - return new SelectDirDialogItemAdapter.ViewHolder(view); - } - - @Override - public void onBindViewHolder(SelectDirDialogItemAdapter.ViewHolder holder, int position) { - holder.title.setText("title"); - holder.description.setText("description"); - } - - @Override - public int getItemCount() { - return 100; - } - - public class ViewHolder extends RecyclerView.ViewHolder { - - TextView title; - TextView description; - - - public ViewHolder(@NonNull View itemView) { - super(itemView); - - title = itemView.findViewById(R.id.item_title); - description = itemView.findViewById(R.id.item_description); - - } + ArrayList listItems; + LacertaSelectDirDialogEventListener listener; + + public SelectDirDialogItemAdapter(LacertaSelectDirDialogEventListener listener) { + this.listener = listener; + } + + public void setListItems(ArrayList listItems) { + this.listItems = listItems; + } + + @Override + public SelectDirDialogItemAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.common_list_item, parent, false); + return new SelectDirDialogItemAdapter.ViewHolder(view); + } + + @Override + public void onBindViewHolder(SelectDirDialogItemAdapter.ViewHolder holder, int position) { + ListItem listItem = listItems.get(position); + holder.title.setText(listItem.getTitle()); + holder.description.setText(listItem.getDescription()); + holder.itemView.setOnClickListener(v -> { + listener.onDirSelected(listItem.getTitle(), listItem.getItemId()); + }); + } + + @Override + public int getItemCount() { + return listItems.size(); + } + + public class ViewHolder extends RecyclerView.ViewHolder { + + TextView title; + TextView description; + + + public ViewHolder(@NonNull View itemView) { + super(itemView); + + title = itemView.findViewById(R.id.item_title); + description = itemView.findViewById(R.id.item_description); + } + } }