add thumbnail generation logic and fix UI

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-12-16 15:00:08 +01:00
parent c3d8c05e7e
commit 533ef35967
No known key found for this signature in database
GPG key ID: 4E577DC593B59BDF
9 changed files with 152 additions and 94 deletions

View file

@ -416,9 +416,6 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
LayoutInflater.from(parent.getContext()), LayoutInflater.from(parent.getContext()),
parent, parent,
false); false);
ViewGroup.LayoutParams layoutParams = binding.headerView.getLayoutParams();
layoutParams.height = (int) (parent.getHeight() * 0.3);
binding.headerView.setLayoutParams(layoutParams);
return new OCFileListHeaderViewHolder(binding); return new OCFileListHeaderViewHolder(binding);
} }
} }
@ -493,7 +490,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
"Marked as important" "Marked as important"
))); )));
final var adapter = new RecommendedFilesAdapter(activity, viewThemeUtils, mockData); final var adapter = new RecommendedFilesAdapter(activity, mockData, ocFileListDelegate);
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);

View file

@ -195,6 +195,28 @@ class OCFileListDelegate(
} }
} }
fun setThumbnailFromFileId(thumbnail: ImageView, shimmerThumbnail: LoaderImageView?, fileId: Long) {
storageManager.getFileById(fileId)?.let { file ->
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( fun bindGridViewHolder(
gridViewHolder: ListViewHolder, gridViewHolder: ListViewHolder,
file: OCFile, file: OCFile,
@ -204,19 +226,7 @@ class OCFileListDelegate(
// thumbnail // thumbnail
gridViewHolder.imageFileName?.text = file.fileName gridViewHolder.imageFileName?.text = file.fileName
gridViewHolder.thumbnail.tag = file.fileId gridViewHolder.thumbnail.tag = file.fileId
DisplayUtils.setThumbnail( setThumbnail(gridViewHolder.thumbnail, gridViewHolder.shimmerThumbnail, file)
file,
gridViewHolder.thumbnail,
user,
storageManager,
asyncTasks,
gridView,
context,
gridViewHolder.shimmerThumbnail,
preferences,
viewThemeUtils,
syncFolderProvider
)
// item layout + click listeners // item layout + click listeners
bindGridItemLayout(file, gridViewHolder) bindGridItemLayout(file, gridViewHolder)

View file

@ -8,21 +8,11 @@
package com.owncloud.android.ui.adapter package com.owncloud.android.ui.adapter
import android.content.Context 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.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.owncloud.android.R
import com.owncloud.android.databinding.RecommendedFilesListItemBinding import com.owncloud.android.databinding.RecommendedFilesListItemBinding
import com.owncloud.android.utils.BitmapUtils
import com.owncloud.android.utils.DisplayUtils import com.owncloud.android.utils.DisplayUtils
import com.owncloud.android.utils.MimeTypeUtil
import com.owncloud.android.utils.theme.ViewThemeUtils
// TODO delete mock data // TODO delete mock data
data class Recommendation( data class Recommendation(
@ -38,8 +28,8 @@ data class Recommendation(
class RecommendedFilesAdapter( class RecommendedFilesAdapter(
private val context: Context, private val context: Context,
private val viewThemeUtils: ViewThemeUtils, private val recommendations: List<Recommendation>,
private val recommendations: List<Recommendation> private val delegate: OCFileListDelegate
) : RecyclerView.Adapter<RecommendedFilesAdapter.RecommendedFilesViewHolder>() { ) : RecyclerView.Adapter<RecommendedFilesAdapter.RecommendedFilesViewHolder>() {
inner class RecommendedFilesViewHolder(val binding: RecommendedFilesListItemBinding) : inner class RecommendedFilesViewHolder(val binding: RecommendedFilesListItemBinding) :
@ -65,47 +55,10 @@ class RecommendedFilesAdapter(
override fun onBindViewHolder(holder: RecommendedFilesViewHolder, position: Int) { override fun onBindViewHolder(holder: RecommendedFilesViewHolder, position: Int) {
val item = recommendations[position] val item = recommendations[position]
holder.binding.name.text = item.name holder.binding.run {
// holder.binding.timestamp.text = DisplayUtils.getRelativeTimestamp(context, item.timestamp) name.text = item.name
timestamp.text = DisplayUtils.getRelativeTimestamp(context, item.timestamp)
val thumbnail = getThumbnail(item) delegate.setThumbnailFromFileId(thumbnail, shimmerThumbnail, item.id)
/*
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
)
}
if (drawable == null) {
drawable = ColorDrawable(Color.GRAY)
}
val width = DisplayUtils.convertPixelToDp(40, context).toInt()
return BitmapUtils.drawableToBitmap(drawable, width / 2, width / 2)
} }
} }

View file

@ -0,0 +1,19 @@
<!--
~ Nextcloud - Android Client
~
~ SPDX-FileCopyrightText: 2018-2024 Google LLC
~ SPDX-License-Identifier: Apache-2.0
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#000000"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M12,2C6.47,2 2,6.47 2,12s4.47,10 10,10 10,-4.47 10,-10S17.53,2 12,2z" />
</vector>

View file

@ -0,0 +1,19 @@
<!--
~ Nextcloud - Android Client
~
~ SPDX-FileCopyrightText: 2018-2024 Google LLC
~ SPDX-License-Identifier: Apache-2.0
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#FFFFFF"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M6,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM18,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM12,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2z" />
</vector>

View file

@ -8,9 +8,10 @@
~ SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only ~ SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only
--> -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/headerView" android:id="@+id/headerView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:showDividers="none"> android:showDividers="none">
@ -26,17 +27,42 @@
<ImageView <ImageView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:paddingBottom="@dimen/standard_padding" android:paddingBottom="@dimen/standard_padding"
android:contentDescription="@null" android:contentDescription="@null"
android:src="@drawable/preview_markdown_gradient_shape" /> android:src="@drawable/preview_markdown_gradient_shape" />
<LinearLayout
android:id="@+id/recommended_files_layout"
android:layout_marginTop="150dp"
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<TextView
android:id="@+id/recommended_files_title"
android:text="@string/recommended_files_title"
app:drawableStartCompat="@drawable/ic_star"
app:drawableTint="@color/text_color"
android:gravity="center|start"
android:drawablePadding="@dimen/standard_half_padding"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/standard_padding"
android:paddingTop="@dimen/standard_padding"
android:paddingRight="@dimen/standard_padding"
android:paddingBottom="@dimen/zero"
android:textColor="@color/text_color" />
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/recommended_files_recycler_view" android:id="@+id/recommended_files_recycler_view"
android:paddingLeft="@dimen/standard_padding" android:paddingLeft="@dimen/standard_padding"
android:paddingTop="@dimen/standard_padding" android:paddingTop="@dimen/standard_padding"
android:paddingRight="@dimen/standard_padding" android:paddingRight="@dimen/standard_padding"
android:layout_gravity="bottom"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"/> android:layout_height="wrap_content"/>
</LinearLayout>
</FrameLayout> </FrameLayout>

View file

@ -5,33 +5,65 @@
~ SPDX-License-Identifier: AGPL-3.0-or-later ~ SPDX-License-Identifier: AGPL-3.0-or-later
--> -->
<LinearLayout <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container" android:id="@+id/container"
android:layout_width="80dp" android:layout_width="180dp"
android:layout_height="80dp" android:layout_height="wrap_content"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:background="@drawable/rounded_rect_8dp"
android:orientation="vertical" android:orientation="vertical"
android:padding="@dimen/standard_padding" android:gravity="start">
android:gravity="center">
<FrameLayout
android:layout_gravity="center|start"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView <ImageView
android:id="@+id/icon" android:id="@+id/thumbnail"
android:layout_width="30dp" android:layout_width="match_parent"
android:layout_height="30dp" android:layout_height="120dp"
android:background="@drawable/rounded_rect_8dp"
android:contentDescription="@string/preview_image_description" android:contentDescription="@string/preview_image_description"
android:src="@drawable/preview_image_gradient_shape" /> android:src="@drawable/file" />
<ImageButton
android:src="@drawable/ic_dots_horizontal"
android:contentDescription="@string/preview_image_description"
android:background="@drawable/ic_circle"
android:layout_gravity="top|end"
android:layout_width="@dimen/more_icon_size"
android:layout_height="@dimen/more_icon_size"/>
<com.elyeproj.loaderviewlibrary.LoaderImageView
android:id="@+id/shimmer_thumbnail"
android:layout_width="match_parent"
android:layout_height="120dp" />
</FrameLayout>
<TextView <TextView
android:text="aaa" android:text="to Pay up.pdf"
android:layout_marginTop="@dimen/standard_half_margin"
android:id="@+id/name" android:id="@+id/name"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textStyle="bold" android:gravity="start|center"
android:textSize="12sp" android:textSize="12sp"
android:textColor="@color/text_color" android:textColor="@color/text_color"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1"/> android:maxLines="1"/>
<TextView
android:text="Dropbox"
android:layout_marginTop="@dimen/standard_half_margin"
android:id="@+id/timestamp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start|center"
android:textSize="11sp"
android:textColor="@color/secondary_text_color"
android:ellipsize="end"
android:maxLines="1"/>
</LinearLayout> </LinearLayout>

View file

@ -157,4 +157,5 @@
<dimen name="adaptive_icon_size">108dp</dimen> <dimen name="adaptive_icon_size">108dp</dimen>
<dimen name="adaptive_icon_padding">18dp</dimen> <dimen name="adaptive_icon_padding">18dp</dimen>
<dimen name="tag_height">18dp</dimen> <dimen name="tag_height">18dp</dimen>
<dimen name="more_icon_size">32dp</dimen>
</resources> </resources>

View file

@ -74,6 +74,7 @@
<string name="assistant_task_detail_screen_input_button_title">Input</string> <string name="assistant_task_detail_screen_input_button_title">Input</string>
<string name="assistant_task_detail_screen_output_button_title">Output</string> <string name="assistant_task_detail_screen_output_button_title">Output</string>
<string name="recommended_files_title">Recommended Files</string>
<string name="drawer_item_assistant">Assistant</string> <string name="drawer_item_assistant">Assistant</string>
<string name="drawer_item_all_files">All files</string> <string name="drawer_item_all_files">All files</string>