From 868d9cf55c06ac786d407ec4fce460fb308dfcaa Mon Sep 17 00:00:00 2001 From: Valere Date: Thu, 9 Jul 2020 10:11:10 +0200 Subject: [PATCH] Cleaning (remove audio and file as not supported yet) --- .../AttachmentSourceProvider.kt | 4 +- .../attachmentviewer/AttachmentsAdapter.kt | 38 +++------------- .../riotx/attachmentviewer/BaseViewHolder.kt | 45 +++++++++++++++++++ 3 files changed, 53 insertions(+), 34 deletions(-) create mode 100644 attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/BaseViewHolder.kt diff --git a/attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/AttachmentSourceProvider.kt b/attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/AttachmentSourceProvider.kt index ce725afec2..92a4f1d9e4 100644 --- a/attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/AttachmentSourceProvider.kt +++ b/attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/AttachmentSourceProvider.kt @@ -23,8 +23,8 @@ sealed class AttachmentInfo(open val uid: String) { data class Image(override val uid: String, val url: String, val data: Any?) : AttachmentInfo(uid) data class AnimatedImage(override val uid: String, val url: String, val data: Any?) : AttachmentInfo(uid) data class Video(override val uid: String, val url: String, val data: Any, val thumbnail: Image?) : AttachmentInfo(uid) - data class Audio(override val uid: String, val url: String, val data: Any) : AttachmentInfo(uid) - data class File(override val uid: String, val url: String, val data: Any) : AttachmentInfo(uid) +// data class Audio(override val uid: String, val url: String, val data: Any) : AttachmentInfo(uid) +// data class File(override val uid: String, val url: String, val data: Any) : AttachmentInfo(uid) } interface AttachmentSourceProvider { diff --git a/attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/AttachmentsAdapter.kt b/attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/AttachmentsAdapter.kt index 2f453b58a8..90020f2cb0 100644 --- a/attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/AttachmentsAdapter.kt +++ b/attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/AttachmentsAdapter.kt @@ -17,36 +17,10 @@ package im.vector.riotx.attachmentviewer import android.view.LayoutInflater -import android.view.View import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView -abstract class BaseViewHolder constructor(itemView: View) : - RecyclerView.ViewHolder(itemView) { - - open fun onRecycled() { - boundResourceUid = null - } - - open fun onAttached() {} - open fun onDetached() {} - open fun entersBackground() {} - open fun entersForeground() {} - open fun onSelected(selected: Boolean) {} - - open fun handleCommand(commands: AttachmentCommands) {} - - var boundResourceUid: String? = null - - open fun bind(attachmentInfo: AttachmentInfo) { - boundResourceUid = attachmentInfo.uid - } -} - -class AttachmentViewHolder constructor(itemView: View) : - BaseViewHolder(itemView) - -class AttachmentsAdapter() : RecyclerView.Adapter() { +class AttachmentsAdapter : RecyclerView.Adapter() { var attachmentSourceProvider: AttachmentSourceProvider? = null set(value) { @@ -71,7 +45,7 @@ class AttachmentsAdapter() : RecyclerView.Adapter() { R.layout.item_image_attachment -> ZoomableImageViewHolder(itemView) R.layout.item_animated_image_attachment -> AnimatedImageViewHolder(itemView) R.layout.item_video_attachment -> VideoViewHolder(itemView) - else -> AttachmentViewHolder(itemView) + else -> UnsupportedViewHolder(itemView) } } @@ -81,8 +55,8 @@ class AttachmentsAdapter() : RecyclerView.Adapter() { is AttachmentInfo.Image -> R.layout.item_image_attachment is AttachmentInfo.Video -> R.layout.item_video_attachment is AttachmentInfo.AnimatedImage -> R.layout.item_animated_image_attachment - is AttachmentInfo.Audio -> TODO() - is AttachmentInfo.File -> TODO() +// is AttachmentInfo.Audio -> TODO() +// is AttachmentInfo.File -> TODO() } } @@ -103,8 +77,8 @@ class AttachmentsAdapter() : RecyclerView.Adapter() { is AttachmentInfo.Video -> { attachmentSourceProvider?.loadVideo((holder as VideoViewHolder).target, it) } - else -> { - } +// else -> { +//// } } } } diff --git a/attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/BaseViewHolder.kt b/attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/BaseViewHolder.kt new file mode 100644 index 0000000000..49b47c11ff --- /dev/null +++ b/attachment-viewer/src/main/java/im/vector/riotx/attachmentviewer/BaseViewHolder.kt @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2020 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.riotx.attachmentviewer + +import android.view.View +import androidx.recyclerview.widget.RecyclerView + +abstract class BaseViewHolder constructor(itemView: View) : + RecyclerView.ViewHolder(itemView) { + + open fun onRecycled() { + boundResourceUid = null + } + + open fun onAttached() {} + open fun onDetached() {} + open fun entersBackground() {} + open fun entersForeground() {} + open fun onSelected(selected: Boolean) {} + + open fun handleCommand(commands: AttachmentCommands) {} + + var boundResourceUid: String? = null + + open fun bind(attachmentInfo: AttachmentInfo) { + boundResourceUid = attachmentInfo.uid + } +} + +class UnsupportedViewHolder constructor(itemView: View) : + BaseViewHolder(itemView)