mirror of
https://github.com/nextcloud/android.git
synced 2024-12-21 16:24:32 +03:00
add thumbnail generation logic and fix UI
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
450adaf697
commit
3e0e3f6d00
9 changed files with 152 additions and 94 deletions
|
@ -416,9 +416,6 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||
LayoutInflater.from(parent.getContext()),
|
||||
parent,
|
||||
false);
|
||||
ViewGroup.LayoutParams layoutParams = binding.headerView.getLayoutParams();
|
||||
layoutParams.height = (int) (parent.getHeight() * 0.3);
|
||||
binding.headerView.setLayoutParams(layoutParams);
|
||||
return new OCFileListHeaderViewHolder(binding);
|
||||
}
|
||||
}
|
||||
|
@ -493,7 +490,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||
"Marked as important"
|
||||
)));
|
||||
|
||||
final var adapter = new RecommendedFilesAdapter(activity, viewThemeUtils, mockData);
|
||||
final var adapter = new RecommendedFilesAdapter(activity, mockData, ocFileListDelegate);
|
||||
recommendedFiles.setAdapter(adapter);
|
||||
|
||||
PreviewTextFragment.setText(headerViewHolder.getHeaderText(), text, null, activity, true, true, viewThemeUtils);
|
||||
|
|
|
@ -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(
|
||||
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)
|
||||
|
|
|
@ -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<Recommendation>
|
||||
private val recommendations: List<Recommendation>,
|
||||
private val delegate: OCFileListDelegate
|
||||
) : RecyclerView.Adapter<RecommendedFilesAdapter.RecommendedFilesViewHolder>() {
|
||||
|
||||
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)
|
||||
holder.binding.run {
|
||||
name.text = item.name
|
||||
timestamp.text = DisplayUtils.getRelativeTimestamp(context, item.timestamp)
|
||||
delegate.setThumbnailFromFileId(thumbnail, shimmerThumbnail, item.id)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
19
app/src/main/res/drawable/ic_circle.xml
Normal file
19
app/src/main/res/drawable/ic_circle.xml
Normal 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>
|
19
app/src/main/res/drawable/ic_dots_horizontal.xml
Normal file
19
app/src/main/res/drawable/ic_dots_horizontal.xml
Normal 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>
|
|
@ -8,9 +8,10 @@
|
|||
~ SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only
|
||||
-->
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/headerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:showDividers="none">
|
||||
|
||||
|
@ -26,17 +27,42 @@
|
|||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/standard_padding"
|
||||
android:contentDescription="@null"
|
||||
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
|
||||
android:id="@+id/recommended_files_recycler_view"
|
||||
android:paddingLeft="@dimen/standard_padding"
|
||||
android:paddingTop="@dimen/standard_padding"
|
||||
android:paddingRight="@dimen/standard_padding"
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
|
|
|
@ -5,33 +5,65 @@
|
|||
~ SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
-->
|
||||
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/container"
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="80dp"
|
||||
android:layout_width="180dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:background="@drawable/rounded_rect_8dp"
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/standard_padding"
|
||||
android:gravity="center">
|
||||
android:gravity="start">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_gravity="center|start"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:id="@+id/thumbnail"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="120dp"
|
||||
android:background="@drawable/rounded_rect_8dp"
|
||||
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
|
||||
android:text="aaa"
|
||||
android:text="to Pay up.pdf"
|
||||
android:layout_marginTop="@dimen/standard_half_margin"
|
||||
android:id="@+id/name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textStyle="bold"
|
||||
android:gravity="start|center"
|
||||
android:textSize="12sp"
|
||||
android:textColor="@color/text_color"
|
||||
android:ellipsize="end"
|
||||
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>
|
||||
|
|
|
@ -157,4 +157,5 @@
|
|||
<dimen name="adaptive_icon_size">108dp</dimen>
|
||||
<dimen name="adaptive_icon_padding">18dp</dimen>
|
||||
<dimen name="tag_height">18dp</dimen>
|
||||
<dimen name="more_icon_size">32dp</dimen>
|
||||
</resources>
|
||||
|
|
|
@ -74,6 +74,7 @@
|
|||
|
||||
<string name="assistant_task_detail_screen_input_button_title">Input</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_all_files">All files</string>
|
||||
|
|
Loading…
Reference in a new issue