mirror of
https://github.com/nextcloud/talk-android
synced 2025-03-06 14:27:24 +00:00
add adapter + design for list view
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
745fc65117
commit
29f5d73f05
@ -11,6 +11,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import com.nextcloud.talk.R
|
||||
import com.nextcloud.talk.adapters.SharedItemsAdapter
|
||||
import com.nextcloud.talk.adapters.SharedItemsListAdapter
|
||||
import com.nextcloud.talk.databinding.ActivitySharedItemsBinding
|
||||
import com.nextcloud.talk.models.database.UserEntity
|
||||
import com.nextcloud.talk.utils.DisplayUtils
|
||||
@ -61,21 +62,29 @@ class SharedItemsActivity : AppCompatActivity() {
|
||||
|
||||
viewModel.media.observe(this) {
|
||||
Log.d(TAG, "Items received: $it")
|
||||
val adapter = SharedItemsAdapter()
|
||||
adapter.items = it.items
|
||||
adapter.authHeader = it.authHeader
|
||||
binding.imageRecycler.adapter = adapter
|
||||
|
||||
if (currentTab == "media") {
|
||||
if (currentTab == TAB_MEDIA) {
|
||||
val adapter = SharedItemsAdapter()
|
||||
adapter.items = it.items
|
||||
adapter.authHeader = it.authHeader
|
||||
binding.imageRecycler.adapter = adapter
|
||||
|
||||
val layoutManager = GridLayoutManager(this, 4)
|
||||
binding.imageRecycler.layoutManager = layoutManager
|
||||
|
||||
adapter.notifyDataSetChanged()
|
||||
} else {
|
||||
val adapter = SharedItemsListAdapter()
|
||||
adapter.items = it.items
|
||||
adapter.authHeader = it.authHeader
|
||||
binding.imageRecycler.adapter = adapter
|
||||
|
||||
val layoutManager = LinearLayoutManager(this)
|
||||
layoutManager.orientation = LinearLayoutManager.VERTICAL
|
||||
binding.imageRecycler.layoutManager = layoutManager
|
||||
}
|
||||
|
||||
adapter.notifyDataSetChanged()
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,8 +50,6 @@ class SharedItemsAdapter : RecyclerView.Adapter<SharedItemsAdapter.ViewHolder>()
|
||||
.build()
|
||||
holder.binding.image.controller = draweeController
|
||||
|
||||
// } else if () { TODO check if voice message etc..
|
||||
|
||||
} else {
|
||||
when (currentItem.mimeType) {
|
||||
"video/mp4",
|
||||
|
@ -0,0 +1,94 @@
|
||||
package com.nextcloud.talk.adapters
|
||||
|
||||
import android.net.Uri
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.facebook.drawee.backends.pipeline.Fresco
|
||||
import com.facebook.drawee.interfaces.DraweeController
|
||||
import com.facebook.imagepipeline.common.RotationOptions
|
||||
import com.facebook.imagepipeline.request.ImageRequestBuilder
|
||||
import com.nextcloud.talk.R
|
||||
import com.nextcloud.talk.databinding.AttachmentListItemBinding
|
||||
import com.nextcloud.talk.repositories.SharedItem
|
||||
import com.nextcloud.talk.utils.FileViewerUtils
|
||||
|
||||
class SharedItemsListAdapter : RecyclerView.Adapter<SharedItemsListAdapter.ViewHolder>() {
|
||||
|
||||
companion object {
|
||||
private val TAG = SharedItemsListAdapter::class.simpleName
|
||||
}
|
||||
|
||||
class ViewHolder(val binding: AttachmentListItemBinding, itemView: View) : RecyclerView.ViewHolder(itemView)
|
||||
|
||||
var authHeader: Map<String, String> = emptyMap()
|
||||
var items: List<SharedItem> = emptyList()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val binding = AttachmentListItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
return ViewHolder(binding, binding.root)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
|
||||
val currentItem = items[position]
|
||||
|
||||
holder.binding.fileName.text = currentItem.name
|
||||
|
||||
if (currentItem.previewAvailable) {
|
||||
val imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(currentItem.previewLink))
|
||||
.setProgressiveRenderingEnabled(true)
|
||||
.setRotationOptions(RotationOptions.autoRotate())
|
||||
.disableDiskCache()
|
||||
.setHeaders(authHeader)
|
||||
.build()
|
||||
|
||||
val draweeController: DraweeController = Fresco.newDraweeControllerBuilder()
|
||||
.setOldController(holder.binding.fileImage.controller)
|
||||
.setAutoPlayAnimations(true)
|
||||
.setImageRequest(imageRequest)
|
||||
.build()
|
||||
holder.binding.fileImage.controller = draweeController
|
||||
} else {
|
||||
when (currentItem.mimeType) {
|
||||
"video/mp4",
|
||||
"video/quicktime",
|
||||
"video/ogg"
|
||||
-> holder.binding.fileImage.setImageResource(R.drawable.ic_mimetype_video)
|
||||
"audio/mpeg",
|
||||
"audio/wav",
|
||||
"audio/ogg",
|
||||
-> holder.binding.fileImage.setImageResource(R.drawable.ic_mimetype_audio)
|
||||
"image/png",
|
||||
"image/jpeg",
|
||||
"image/gif"
|
||||
-> holder.binding.fileImage.setImageResource(R.drawable.ic_mimetype_image)
|
||||
"text/markdown",
|
||||
"text/plain"
|
||||
-> holder.binding.fileImage.setImageResource(R.drawable.ic_mimetype_text)
|
||||
else
|
||||
-> holder.binding.fileImage.setImageResource(R.drawable.ic_mimetype_file)
|
||||
}
|
||||
}
|
||||
holder.binding.fileItem.setOnClickListener {
|
||||
val fileViewerUtils = FileViewerUtils(it.context, currentItem.userEntity)
|
||||
|
||||
fileViewerUtils.openFile(
|
||||
currentItem.id,
|
||||
currentItem.name,
|
||||
currentItem.fileSize,
|
||||
currentItem.path,
|
||||
currentItem.link,
|
||||
currentItem.mimeType,
|
||||
null,
|
||||
null,
|
||||
holder.binding.fileImage
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return items.size
|
||||
}
|
||||
}
|
72
app/src/main/res/layout/attachment_list_item.xml
Normal file
72
app/src/main/res/layout/attachment_list_item.xml
Normal file
@ -0,0 +1,72 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ Nextcloud Talk application
|
||||
~
|
||||
~ @author Tim Krüger
|
||||
~ Copyright (C) 2022 Tim Krüger <t@timkrueger.me>
|
||||
~
|
||||
~ This program is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by
|
||||
~ the Free Software Foundation, either version 3 of the License, or
|
||||
~ at your option) any later version.
|
||||
~
|
||||
~ This program is distributed in the hope that it will be useful,
|
||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
~ GNU General Public License for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/file_item"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/standard_margin"
|
||||
android:layout_marginTop="@dimen/standard_half_margin"
|
||||
android:layout_marginEnd="@dimen/standard_margin"
|
||||
android:layout_marginBottom="@dimen/standard_half_margin"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.facebook.drawee.view.SimpleDraweeView
|
||||
xmlns:fresco="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/file_image"
|
||||
android:layout_width="@dimen/file_icon_size"
|
||||
android:layout_height="@dimen/file_icon_size"
|
||||
android:padding="4dp"
|
||||
android:src="@drawable/ic_mimetype_file"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginEnd="@dimen/standard_margin"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:placeholderImageScaleType="fitCenter"
|
||||
fresco:actualImageScaleType="centerCrop"
|
||||
fresco:failureImage="@drawable/ic_mimetype_file"
|
||||
fresco:placeholderImage="@drawable/ic_mimetype_file"
|
||||
fresco:roundedCornerRadius="4dp" />
|
||||
|
||||
<androidx.emoji.widget.EmojiTextView
|
||||
android:id="@+id/file_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toEndOf="@id/file_image"
|
||||
android:ellipsize="end"
|
||||
android:lines="1"
|
||||
android:textAlignment="viewStart"
|
||||
android:textAppearance="@style/ListItem"
|
||||
tools:text="Filename" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -35,6 +35,7 @@
|
||||
<dimen name="avatar_size">40dp</dimen>
|
||||
<dimen name="avatar_size_app_bar">30dp</dimen>
|
||||
<dimen name="avatar_size_big">96dp</dimen>
|
||||
<dimen name="file_icon_size">40dp</dimen>
|
||||
|
||||
<dimen name="chat_text_size">14sp</dimen>
|
||||
<dimen name="message_bubble_corners_radius">6dp</dimen>
|
||||
|
Loading…
Reference in New Issue
Block a user