Add a green frame around current small preview

This commit is contained in:
Benoit Marty 2020-02-13 20:45:03 +01:00
parent ecd547b86c
commit 385fa317c0
6 changed files with 81 additions and 3 deletions

View File

@ -0,0 +1,60 @@
/*
* 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.core.platform
import android.content.Context
import android.util.AttributeSet
import android.widget.Checkable
import androidx.appcompat.widget.AppCompatImageView
class CheckableImageView : AppCompatImageView, Checkable {
private var mChecked = false
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
override fun isChecked(): Boolean {
return mChecked
}
override fun setChecked(b: Boolean) {
if (b != mChecked) {
mChecked = b
refreshDrawableState()
}
}
override fun toggle() {
isChecked = !mChecked
}
override fun onCreateDrawableState(extraSpace: Int): IntArray {
val drawableState = super.onCreateDrawableState(extraSpace + 1)
if (isChecked) {
mergeDrawableStates(drawableState, CHECKED_STATE_SET)
}
return drawableState
}
companion object {
private val CHECKED_STATE_SET = intArrayOf(android.R.attr.state_checked)
}
}

View File

@ -45,6 +45,7 @@ class AttachmentMiniaturePreviewController @Inject constructor() : TypedEpoxyCon
attachmentMiniaturePreviewItem { attachmentMiniaturePreviewItem {
id(contentAttachmentData.path) id(contentAttachmentData.path)
attachment(contentAttachmentData) attachment(contentAttachmentData)
checked(data.currentAttachmentIndex == index)
clickListener { _ -> clickListener { _ ->
callback?.onAttachmentClicked(index, contentAttachmentData) callback?.onAttachmentClicked(index, contentAttachmentData)
} }

View File

@ -26,6 +26,7 @@ import im.vector.matrix.android.api.session.content.ContentAttachmentData
import im.vector.riotx.R import im.vector.riotx.R
import im.vector.riotx.core.epoxy.VectorEpoxyHolder import im.vector.riotx.core.epoxy.VectorEpoxyHolder
import im.vector.riotx.core.epoxy.VectorEpoxyModel import im.vector.riotx.core.epoxy.VectorEpoxyModel
import im.vector.riotx.core.platform.CheckableImageView
abstract class AttachmentPreviewItem<H : AttachmentPreviewItem.Holder> : VectorEpoxyModel<H>() { abstract class AttachmentPreviewItem<H : AttachmentPreviewItem.Holder> : VectorEpoxyModel<H>() {
@ -56,16 +57,19 @@ abstract class AttachmentMiniaturePreviewItem : AttachmentPreviewItem<Attachment
@EpoxyAttribute override lateinit var attachment: ContentAttachmentData @EpoxyAttribute override lateinit var attachment: ContentAttachmentData
@EpoxyAttribute @EpoxyAttribute
var clickListener: View.OnClickListener? = null var clickListener: View.OnClickListener? = null
@EpoxyAttribute
var checked: Boolean = false
override fun bind(holder: Holder) { override fun bind(holder: Holder) {
super.bind(holder) super.bind(holder)
holder.imageView.isChecked = checked
holder.view.setOnClickListener(clickListener) holder.view.setOnClickListener(clickListener)
} }
class Holder : AttachmentPreviewItem.Holder() { class Holder : AttachmentPreviewItem.Holder() {
override val imageView: ImageView override val imageView: CheckableImageView
get() = miniatureImageView get() = miniatureImageView
private val miniatureImageView by bind<ImageView>(R.id.attachmentMiniatureImageView) private val miniatureImageView by bind<CheckableImageView>(R.id.attachmentMiniatureImageView)
} }
} }

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/riotx_accent" android:state_checked="true" />
<item android:color="@android:color/transparent" />
</selector>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/checked_accent_color_selector"/>
</shape>

View File

@ -8,10 +8,12 @@
card_view:cardBackgroundColor="@android:color/transparent" card_view:cardBackgroundColor="@android:color/transparent"
card_view:cardElevation="0dp"> card_view:cardElevation="0dp">
<ImageView <im.vector.riotx.core.platform.CheckableImageView
android:id="@+id/attachmentMiniatureImageView" android:id="@+id/attachmentMiniatureImageView"
android:layout_width="64dp" android:layout_width="64dp"
android:layout_height="64dp" android:layout_height="64dp"
android:background="@drawable/background_checked_accent_color"
android:padding="2dp"
android:scaleType="centerCrop" android:scaleType="centerCrop"
tools:src="@tools:sample/backgrounds/scenic" /> tools:src="@tools:sample/backgrounds/scenic" />