From e8e989770f70ef2f71bc10487e53c1b4b68206b3 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 16 Dec 2024 15:19:08 +0100 Subject: [PATCH] setOnClickListener Signed-off-by: alperozturk --- .../android/ui/adapter/OCFileListAdapter.java | 14 ++++++++-- .../ui/adapter/RecommendedFilesAdapter.kt | 27 +++++++++++-------- .../layout/recommended_files_list_item.xml | 1 + 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java b/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java index 270d8df4e804..6577efc9a627 100644 --- a/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java +++ b/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java @@ -108,7 +108,7 @@ */ public class OCFileListAdapter extends RecyclerView.Adapter implements DisplayUtils.AvatarGenerationListener, - CommonOCFileListAdapterInterface, PopupTextProvider { + CommonOCFileListAdapterInterface, PopupTextProvider, RecommendedFilesAdapter.OnItemClickListener { private static final int showFilenameColumnThreshold = 4; private final String userId; @@ -490,7 +490,7 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi "Marked as important" ))); - final var adapter = new RecommendedFilesAdapter(activity, mockData, ocFileListDelegate); + final var adapter = new RecommendedFilesAdapter(activity, mockData, ocFileListDelegate, this); recommendedFiles.setAdapter(adapter); PreviewTextFragment.setText(headerViewHolder.getHeaderText(), text, null, activity, true, true, viewThemeUtils); @@ -1321,4 +1321,14 @@ public int getFilesCount() { public void notifyItemChanged(@NonNull OCFile file) { notifyItemChanged(getItemPosition(file)); } + + @Override + public void selectRecommendedFile(long fileId) { + // TODO Implement + } + + @Override + public void showRecommendedFileMoreActions(long fileId) { + // TODO Implement + } } diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/RecommendedFilesAdapter.kt b/app/src/main/java/com/owncloud/android/ui/adapter/RecommendedFilesAdapter.kt index 85521b57e862..7c2698860d31 100644 --- a/app/src/main/java/com/owncloud/android/ui/adapter/RecommendedFilesAdapter.kt +++ b/app/src/main/java/com/owncloud/android/ui/adapter/RecommendedFilesAdapter.kt @@ -29,21 +29,18 @@ data class Recommendation( class RecommendedFilesAdapter( private val context: Context, private val recommendations: List, - private val delegate: OCFileListDelegate + private val delegate: OCFileListDelegate, + private val onItemClickListener: OnItemClickListener ) : RecyclerView.Adapter() { - inner class RecommendedFilesViewHolder(val binding: RecommendedFilesListItemBinding) : - RecyclerView.ViewHolder(binding.root) { - init { - binding.root.setOnClickListener { - val position = bindingAdapterPosition - if (position != RecyclerView.NO_POSITION) { - // TODO onclick item - } - } - } + interface OnItemClickListener { + fun selectRecommendedFile(fileId: Long) + fun showRecommendedFileMoreActions(fileId: Long) } + inner class RecommendedFilesViewHolder(val binding: RecommendedFilesListItemBinding) : + RecyclerView.ViewHolder(binding.root) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecommendedFilesViewHolder { val binding = RecommendedFilesListItemBinding .inflate(LayoutInflater.from(parent.context), parent, false) @@ -59,6 +56,14 @@ class RecommendedFilesAdapter( name.text = item.name timestamp.text = DisplayUtils.getRelativeTimestamp(context, item.timestamp) delegate.setThumbnailFromFileId(thumbnail, shimmerThumbnail, item.id) + + container.setOnClickListener { + onItemClickListener.selectRecommendedFile(item.id) + } + + moreAction.setOnClickListener { + onItemClickListener.showRecommendedFileMoreActions(item.id) + } } } } diff --git a/app/src/main/res/layout/recommended_files_list_item.xml b/app/src/main/res/layout/recommended_files_list_item.xml index 529687bfd3cf..c4d18e463de4 100644 --- a/app/src/main/res/layout/recommended_files_list_item.xml +++ b/app/src/main/res/layout/recommended_files_list_item.xml @@ -27,6 +27,7 @@ android:src="@drawable/file" />