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