Skip to content

Commit

Permalink
アバターのアイコンを読み込む時にサムネイルとしてblurhashを元にした画像を表示するようにした。
Browse files Browse the repository at this point in the history
  • Loading branch information
pantasystem committed Oct 8, 2023
1 parent fb8695b commit 2684d62
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,25 @@ import androidx.appcompat.widget.AppCompatImageView
import androidx.databinding.BindingAdapter
import net.pantasystem.milktea.common.R
import net.pantasystem.milktea.common.glide.GlideApp
import net.pantasystem.milktea.common.glide.blurhash.BlurHashSource

class AvatarIconView : AppCompatImageView {

companion object {
const val SHAPE_CIRCLE = 0
const val SHAPE_ROUNDED_CORNER = 1

@BindingAdapter("imageUrl")
@BindingAdapter("imageUrl", "blurhash")
@JvmStatic
fun setImageUrl(iconView: AvatarIconView, url: String?) {
fun setImageUrl(iconView: AvatarIconView, url: String?, blurhash: String?) {
GlideApp.with(iconView.context)
.load(url)
.thumbnail(
GlideApp.with(iconView.context)
.load(blurhash?.let {
BlurHashSource(it)
})
)
.error(R.drawable.ic_cloud_off_black_24dp)
.into(iconView)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
android:layout_height="25dp"
tools:src="@drawable/ic_person_black_24dp"
app:imageUrl="@{userViewData.user.avatarUrl}"
app:blurhash="@{userViewData.user.avatarBlurhash}"
app:iconShape="circle"
tools:ignore="ContentDescription"
android:layout_gravity="center_vertical"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
android:layout_marginEnd="8dp"
android:contentDescription="@string/avataricon"
app:imageUrl='@{note.avatarUrl}'
app:blurhash="@{note.toShowNote.user.avatarBlurhash}"
app:iconShape="@{note.config.avatarIconShapeType.value}"
app:transitionDestinationUser="@{note.toShowNote.user}"
tools:srcCompat="@android:drawable/sym_def_app_icon"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
android:scaleType="centerCrop"
app:iconShape="@{note.config.avatarIconShapeType.value}"
app:imageUrl="@{note.avatarUrl}"
app:blurhash="@{note.toShowNote.user.avatarBlurhash}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:transitionDestinationUser="@{note.toShowNote.user}"
Expand Down Expand Up @@ -285,6 +286,7 @@
android:scaleType="centerCrop"
app:iconShape="@{note.config.avatarIconShapeType.value}"
app:imageUrl="@{note.subNoteAvatarUrl}"
app:blurhash="@{note.subNote.user.avatarBlurhash}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:transitionDestinationUser="@{note.subNote.user}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
android:layout_marginTop="-50dp"
android:layout_marginStart="16dp"
app:imageUrl="@{userViewModel.userState.avatarUrl}"
app:blurhash="@{userViewModel.userState.avatarBlurhash}"
app:iconShape="@{userViewModel.config.avatarIconShapeType.value}"
tools:srcCompat="@drawable/ic_follow"
android:layout_marginBottom="8dp"
Expand Down

0 comments on commit 2684d62

Please sign in to comment.