set on click listener

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-12-16 16:19:21 +01:00 committed by Alper Öztürk
parent 4f5600a0e6
commit 860e7d3f4e
3 changed files with 31 additions and 39 deletions

View file

@ -440,7 +440,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
// TODO use actual data // TODO use actual data
ArrayList<Recommendation> mockData = new ArrayList<>(Arrays.asList( ArrayList<Recommendation> mockData = new ArrayList<>(Arrays.asList(
new Recommendation( new Recommendation(
1L, 2124L,
System.currentTimeMillis(), System.currentTimeMillis(),
"Document1", "Document1",
"/documents", "/documents",
@ -450,7 +450,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
"Recently opened" "Recently opened"
), ),
new Recommendation( new Recommendation(
2L, 2130L,
System.currentTimeMillis() - 3600000, System.currentTimeMillis() - 3600000,
"Image1", "Image1",
"/pictures", "/pictures",
@ -460,7 +460,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
"Frequently viewed" "Frequently viewed"
), ),
new Recommendation( new Recommendation(
3L, 2131L,
System.currentTimeMillis() - 7200000, System.currentTimeMillis() - 7200000,
"Presentation1", "Presentation1",
"/presentations", "/presentations",
@ -470,27 +470,18 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
"Shared with you" "Shared with you"
), ),
new Recommendation( new Recommendation(
4L, 2126L,
System.currentTimeMillis() - 86400000, System.currentTimeMillis() - 7200000,
"Video1", "Presentation1",
"/videos", "/presentations",
"mp4", "pptx",
"video/mp4", "application/vnd.ms-powerpoint",
true,
"Recent download"
),
new Recommendation(
5L,
System.currentTimeMillis() - 604800000,
"Spreadsheet1",
"/spreadsheets",
"xlsx",
"application/vnd.ms-excel",
false, false,
"Marked as important" "Shared with you"
))); ))
);
final var adapter = new RecommendedFilesAdapter(activity, mockData, ocFileListDelegate, this); final var adapter = new RecommendedFilesAdapter(activity, mockData, ocFileListDelegate, this, mStorageManager);
recommendedFiles.setAdapter(adapter); recommendedFiles.setAdapter(adapter);
PreviewTextFragment.setText(headerViewHolder.getHeaderText(), text, null, activity, true, true, viewThemeUtils); PreviewTextFragment.setText(headerViewHolder.getHeaderText(), text, null, activity, true, true, viewThemeUtils);
@ -1323,12 +1314,12 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
} }
@Override @Override
public void selectRecommendedFile(long fileId) { public void selectRecommendedFile(@NonNull OCFile file) {
// TODO Implement ocFileListFragmentInterface.onItemClicked(file);
} }
@Override @Override
public void showRecommendedFileMoreActions(long fileId) { public void showRecommendedFileMoreActions(@NonNull OCFile file, @NonNull View view) {
// TODO Implement ocFileListFragmentInterface.onOverflowIconClicked(file, view);
} }
} }

View file

@ -195,13 +195,7 @@ class OCFileListDelegate(
} }
} }
fun setThumbnailFromFileId(thumbnail: ImageView, shimmerThumbnail: LoaderImageView?, fileId: Long) { fun setThumbnail(thumbnail: ImageView, shimmerThumbnail: LoaderImageView?, file: OCFile) {
storageManager.getFileById(fileId)?.let { file ->
setThumbnail(thumbnail, shimmerThumbnail, file)
}
}
private fun setThumbnail(thumbnail: ImageView, shimmerThumbnail: LoaderImageView?, file: OCFile) {
DisplayUtils.setThumbnail( DisplayUtils.setThumbnail(
file, file,
thumbnail, thumbnail,

View file

@ -9,9 +9,12 @@ package com.owncloud.android.ui.adapter
import android.content.Context import android.content.Context
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.owncloud.android.databinding.RecommendedFilesListItemBinding import com.owncloud.android.databinding.RecommendedFilesListItemBinding
import com.owncloud.android.datamodel.FileDataStorageManager
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.utils.DisplayUtils import com.owncloud.android.utils.DisplayUtils
// TODO delete mock data // TODO delete mock data
@ -30,12 +33,13 @@ class RecommendedFilesAdapter(
private val context: Context, private val context: Context,
private val recommendations: List<Recommendation>, private val recommendations: List<Recommendation>,
private val delegate: OCFileListDelegate, private val delegate: OCFileListDelegate,
private val onItemClickListener: OnItemClickListener private val onItemClickListener: OnItemClickListener,
private val storageManager: FileDataStorageManager
) : RecyclerView.Adapter<RecommendedFilesAdapter.RecommendedFilesViewHolder>() { ) : RecyclerView.Adapter<RecommendedFilesAdapter.RecommendedFilesViewHolder>() {
interface OnItemClickListener { interface OnItemClickListener {
fun selectRecommendedFile(fileId: Long) fun selectRecommendedFile(file: OCFile)
fun showRecommendedFileMoreActions(fileId: Long) fun showRecommendedFileMoreActions(file: OCFile, view: View)
} }
inner class RecommendedFilesViewHolder(val binding: RecommendedFilesListItemBinding) : inner class RecommendedFilesViewHolder(val binding: RecommendedFilesListItemBinding) :
@ -55,14 +59,17 @@ class RecommendedFilesAdapter(
holder.binding.run { holder.binding.run {
name.text = item.name name.text = item.name
timestamp.text = DisplayUtils.getRelativeTimestamp(context, item.timestamp) timestamp.text = DisplayUtils.getRelativeTimestamp(context, item.timestamp)
delegate.setThumbnailFromFileId(thumbnail, shimmerThumbnail, item.id)
val file = storageManager.getFileById(item.id) ?: return
delegate.setThumbnail(thumbnail, shimmerThumbnail, file)
container.setOnClickListener { container.setOnClickListener {
onItemClickListener.selectRecommendedFile(item.id) onItemClickListener.selectRecommendedFile(file)
} }
moreAction.setOnClickListener { moreAction.setOnClickListener {
onItemClickListener.showRecommendedFileMoreActions(item.id) onItemClickListener.showRecommendedFileMoreActions(file, holder.itemView)
} }
} }
} }