From 3e0e3f6d00e5b3b168e180e0818f66cea8ef0e34 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 16 Dec 2024 15:00:08 +0100 Subject: [PATCH] add thumbnail generation logic and fix UI Signed-off-by: alperozturk --- .../android/ui/adapter/OCFileListAdapter.java | 5 +- .../android/ui/adapter/OCFileListDelegate.kt | 36 +++++++---- .../ui/adapter/RecommendedFilesAdapter.kt | 59 ++--------------- app/src/main/res/drawable/ic_circle.xml | 19 ++++++ .../main/res/drawable/ic_dots_horizontal.xml | 19 ++++++ app/src/main/res/layout/list_header.xml | 42 +++++++++--- .../layout/recommended_files_list_item.xml | 64 ++++++++++++++----- app/src/main/res/values/dims.xml | 1 + app/src/main/res/values/strings.xml | 1 + 9 files changed, 152 insertions(+), 94 deletions(-) create mode 100644 app/src/main/res/drawable/ic_circle.xml create mode 100644 app/src/main/res/drawable/ic_dots_horizontal.xml 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 ea4ddc4e63..270d8df4e8 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 @@ -416,9 +416,6 @@ public class OCFileListAdapter extends RecyclerView.Adapter + setThumbnail(thumbnail, shimmerThumbnail, file) + } + } + + private fun setThumbnail(thumbnail: ImageView, shimmerThumbnail: LoaderImageView?, file: OCFile) { + DisplayUtils.setThumbnail( + file, + thumbnail, + user, + storageManager, + asyncTasks, + gridView, + context, + shimmerThumbnail, + preferences, + viewThemeUtils, + syncFolderProvider + ) + } + fun bindGridViewHolder( gridViewHolder: ListViewHolder, file: OCFile, @@ -204,19 +226,7 @@ class OCFileListDelegate( // thumbnail gridViewHolder.imageFileName?.text = file.fileName gridViewHolder.thumbnail.tag = file.fileId - DisplayUtils.setThumbnail( - file, - gridViewHolder.thumbnail, - user, - storageManager, - asyncTasks, - gridView, - context, - gridViewHolder.shimmerThumbnail, - preferences, - viewThemeUtils, - syncFolderProvider - ) + setThumbnail(gridViewHolder.thumbnail, gridViewHolder.shimmerThumbnail, file) // item layout + click listeners bindGridItemLayout(file, gridViewHolder) 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 571549c407..85521b57e8 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 @@ -8,21 +8,11 @@ package com.owncloud.android.ui.adapter import android.content.Context -import android.content.res.ColorStateList -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.ContextCompat -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( @@ -38,8 +28,8 @@ data class Recommendation( class RecommendedFilesAdapter( private val context: Context, - private val viewThemeUtils: ViewThemeUtils, - private val recommendations: List + private val recommendations: List, + private val delegate: OCFileListDelegate ) : RecyclerView.Adapter() { inner class RecommendedFilesViewHolder(val binding: RecommendedFilesListItemBinding) : @@ -65,47 +55,10 @@ class RecommendedFilesAdapter( 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) - - /* - val centerPixel = thumbnail.getPixel(thumbnail.width / 2, thumbnail.height / 2) - - val redValue = Color.red(centerPixel) - val blueValue = Color.blue(centerPixel) - val greenValue = Color.green(centerPixel) - - val centerColor = Color.argb(0.8f, redValue.toFloat(), greenValue.toFloat(), blueValue.toFloat()) - */ - - val containerColor = ContextCompat.getColor(context, R.color.primary) - holder.binding.container.backgroundTintList = ColorStateList.valueOf(containerColor) - 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 - ) + holder.binding.run { + name.text = item.name + timestamp.text = DisplayUtils.getRelativeTimestamp(context, item.timestamp) + delegate.setThumbnailFromFileId(thumbnail, shimmerThumbnail, item.id) } - - 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/drawable/ic_circle.xml b/app/src/main/res/drawable/ic_circle.xml new file mode 100644 index 0000000000..75bd4b37de --- /dev/null +++ b/app/src/main/res/drawable/ic_circle.xml @@ -0,0 +1,19 @@ + + + + + + + diff --git a/app/src/main/res/drawable/ic_dots_horizontal.xml b/app/src/main/res/drawable/ic_dots_horizontal.xml new file mode 100644 index 0000000000..432ba913f5 --- /dev/null +++ b/app/src/main/res/drawable/ic_dots_horizontal.xml @@ -0,0 +1,19 @@ + + + + + + + diff --git a/app/src/main/res/layout/list_header.xml b/app/src/main/res/layout/list_header.xml index 90d7a09e83..5be11bfdcb 100644 --- a/app/src/main/res/layout/list_header.xml +++ b/app/src/main/res/layout/list_header.xml @@ -8,9 +8,10 @@ ~ SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only --> @@ -26,17 +27,42 @@ - + android:orientation="vertical" + android:layout_height="wrap_content"> + + + + + + + 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 906cfc1847..3a41113817 100644 --- a/app/src/main/res/layout/recommended_files_list_item.xml +++ b/app/src/main/res/layout/recommended_files_list_item.xml @@ -5,33 +5,65 @@ ~ SPDX-License-Identifier: AGPL-3.0-or-later --> - + android:gravity="start"> + + + + + + + + + + - + + diff --git a/app/src/main/res/values/dims.xml b/app/src/main/res/values/dims.xml index 11d07b70af..ba7c078236 100644 --- a/app/src/main/res/values/dims.xml +++ b/app/src/main/res/values/dims.xml @@ -157,4 +157,5 @@ 108dp 18dp 18dp + 32dp diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8081780ac3..3dc4a806c9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -74,6 +74,7 @@ Input Output + Recommended Files Assistant All files