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 4e9bc9bd1d..ea4ddc4e63 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 @@ -82,6 +82,7 @@ import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Date; import java.util.List; @@ -97,6 +98,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import me.zhanghai.android.fastscroll.PopupTextProvider; @@ -433,6 +435,67 @@ public class OCFileListAdapter extends RecyclerView.Adapter mockData = new ArrayList<>(Arrays.asList( + new Recommendation( + 1L, + System.currentTimeMillis(), + "Document1", + "/documents", + "pdf", + "application/pdf", + true, + "Recently opened" + ), + new Recommendation( + 2L, + System.currentTimeMillis() - 3600000, + "Image1", + "/pictures", + "jpg", + "image/jpeg", + true, + "Frequently viewed" + ), + new Recommendation( + 3L, + System.currentTimeMillis() - 7200000, + "Presentation1", + "/presentations", + "pptx", + "application/vnd.ms-powerpoint", + false, + "Shared with you" + ), + new Recommendation( + 4L, + System.currentTimeMillis() - 86400000, + "Video1", + "/videos", + "mp4", + "video/mp4", + true, + "Recent download" + ), + new Recommendation( + 5L, + System.currentTimeMillis() - 604800000, + "Spreadsheet1", + "/spreadsheets", + "xlsx", + "application/vnd.ms-excel", + false, + "Marked as important" + ))); + + final var adapter = new RecommendedFilesAdapter(activity, viewThemeUtils, mockData); + recommendedFiles.setAdapter(adapter); + PreviewTextFragment.setText(headerViewHolder.getHeaderText(), text, null, activity, true, true, viewThemeUtils); headerViewHolder.getHeaderView().setOnClickListener(v -> ocFileListFragmentInterface.onHeaderClicked()); } else { @@ -766,11 +829,13 @@ public class OCFileListAdapter extends RecyclerView.Adapter + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +package com.owncloud.android.ui.adapter + +import android.content.Context +import android.graphics.Bitmap +import android.graphics.Color +import android.graphics.drawable.ColorDrawable +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.core.content.res.ResourcesCompat +import androidx.recyclerview.widget.RecyclerView +import com.owncloud.android.R +import com.owncloud.android.databinding.RecommendedFilesListItemBinding +import com.owncloud.android.utils.BitmapUtils +import com.owncloud.android.utils.DisplayUtils +import com.owncloud.android.utils.MimeTypeUtil +import com.owncloud.android.utils.theme.ViewThemeUtils + +// TODO delete mock data +data class Recommendation( + val id: Long, + val timestamp: Long, + val name: String, + val directory: String, + val extension: String, + val mimeType: String, + val hasPreview: Boolean, + val reason: String +) + +class RecommendedFilesAdapter( + private val context: Context, + private val viewThemeUtils: ViewThemeUtils, + private val recommendations: List +) : 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 + } + } + } + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecommendedFilesViewHolder { + val binding = RecommendedFilesListItemBinding + .inflate(LayoutInflater.from(parent.context), parent, false) + return RecommendedFilesViewHolder(binding) + } + + override fun getItemCount(): Int = recommendations.size + + override fun onBindViewHolder(holder: RecommendedFilesViewHolder, position: Int) { + val item = recommendations[position] + + holder.binding.name.text = item.name + holder.binding.timestamp.text = DisplayUtils.getRelativeTimestamp(context, item.timestamp) + + val thumbnail = getThumbnail(item) + holder.binding.icon.setImageBitmap(thumbnail) + } + + private fun getThumbnail(item: Recommendation): Bitmap { + var drawable = MimeTypeUtil.getFileTypeIcon( + item.mimeType, + item.name, + context, + viewThemeUtils + ) + + if (drawable == null) { + drawable = ResourcesCompat.getDrawable( + context.resources, + R.drawable.file_image, + null + ) + } + + if (drawable == null) { + drawable = ColorDrawable(Color.GRAY) + } + + val width = DisplayUtils.convertPixelToDp(40, context).toInt() + return BitmapUtils.drawableToBitmap(drawable, width / 2, width / 2) + } +} diff --git a/app/src/main/res/layout/list_header.xml b/app/src/main/res/layout/list_header.xml index eb000b18bb..700e506c17 100644 --- a/app/src/main/res/layout/list_header.xml +++ b/app/src/main/res/layout/list_header.xml @@ -29,4 +29,10 @@ android:layout_height="match_parent" android:contentDescription="@null" android:src="@drawable/preview_markdown_gradient_shape" /> + + diff --git a/app/src/main/res/layout/recommended_files_list_item.xml b/app/src/main/res/layout/recommended_files_list_item.xml new file mode 100644 index 0000000000..3b9b48cec6 --- /dev/null +++ b/app/src/main/res/layout/recommended_files_list_item.xml @@ -0,0 +1,41 @@ + + + + + + + + + + +