fix(chat): 기본 이미지를 제거하고 빈 요청을 정리한다
This commit is contained in:
@@ -8,7 +8,6 @@ import android.view.ViewTreeObserver
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import coil.load
|
||||
import coil.transform.RoundedCornersTransformation
|
||||
import kr.co.vividnext.sodalive.R
|
||||
import kr.co.vividnext.sodalive.databinding.ItemCharacterBinding
|
||||
import kr.co.vividnext.sodalive.extensions.dpToPx
|
||||
|
||||
@@ -58,7 +57,6 @@ class CharacterAdapter(
|
||||
|
||||
binding.ivCharacter.load(character.imageUrl) {
|
||||
crossfade(true)
|
||||
placeholder(R.drawable.ic_logo_service_center)
|
||||
transformations(RoundedCornersTransformation(16f.dpToPx()))
|
||||
}
|
||||
|
||||
|
||||
-2
@@ -64,8 +64,6 @@ class CharacterCommentListFragment : BaseFragment<FragmentCharacterCommentListBi
|
||||
|
||||
binding.ivCommentProfile.load(SharedPreferenceManager.profileImage) {
|
||||
crossfade(true)
|
||||
placeholder(R.drawable.ic_placeholder_profile)
|
||||
error(R.drawable.ic_placeholder_profile)
|
||||
transformations(CircleCropTransformation())
|
||||
}
|
||||
|
||||
|
||||
+5
-7
@@ -6,8 +6,8 @@ import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import coil.load
|
||||
import coil.dispose
|
||||
import coil.transform.CircleCropTransformation
|
||||
import kr.co.vividnext.sodalive.R
|
||||
import kr.co.vividnext.sodalive.databinding.ItemCharacterCommentBinding
|
||||
import kr.co.vividnext.sodalive.databinding.ItemCharacterCommentReplyBinding
|
||||
|
||||
@@ -64,12 +64,11 @@ class CharacterReplyHeaderVH(
|
||||
if (data.memberProfileImage.isNotBlank()) {
|
||||
binding.ivCommentProfile.load(data.memberProfileImage) {
|
||||
crossfade(true)
|
||||
placeholder(R.drawable.ic_placeholder_profile)
|
||||
error(R.drawable.ic_placeholder_profile)
|
||||
transformations(CircleCropTransformation())
|
||||
}
|
||||
} else {
|
||||
binding.ivCommentProfile.setImageResource(R.drawable.ic_placeholder_profile)
|
||||
binding.ivCommentProfile.dispose()
|
||||
binding.ivCommentProfile.setImageDrawable(null)
|
||||
}
|
||||
binding.tvCommentNickname.text = data.memberNickname
|
||||
binding.tvCommentDate.text = formatCommentTime(context, data.createdAt)
|
||||
@@ -91,12 +90,11 @@ class CharacterReplyItemVH(
|
||||
if (data.memberProfileImage.isNotBlank()) {
|
||||
binding.ivCommentProfile.load(data.memberProfileImage) {
|
||||
crossfade(true)
|
||||
placeholder(R.drawable.ic_placeholder_profile)
|
||||
error(R.drawable.ic_placeholder_profile)
|
||||
transformations(CircleCropTransformation())
|
||||
}
|
||||
} else {
|
||||
binding.ivCommentProfile.setImageResource(R.drawable.ic_placeholder_profile)
|
||||
binding.ivCommentProfile.dispose()
|
||||
binding.ivCommentProfile.setImageDrawable(null)
|
||||
}
|
||||
|
||||
binding.tvCommentNickname.text = data.memberNickname
|
||||
|
||||
-2
@@ -86,8 +86,6 @@ class CharacterCommentReplyFragment : BaseFragment<FragmentCharacterCommentReply
|
||||
|
||||
binding.ivCommentProfile.load(SharedPreferenceManager.profileImage) {
|
||||
crossfade(true)
|
||||
placeholder(R.drawable.ic_placeholder_profile)
|
||||
error(R.drawable.ic_placeholder_profile)
|
||||
transformations(CircleCropTransformation())
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -5,6 +5,7 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import coil.load
|
||||
import coil.dispose
|
||||
import coil.transform.CircleCropTransformation
|
||||
import kr.co.vividnext.sodalive.R
|
||||
import kr.co.vividnext.sodalive.databinding.ItemCharacterCommentBinding
|
||||
@@ -24,12 +25,11 @@ class CharacterCommentsAdapter(
|
||||
if (item.memberProfileImage.isNotBlank()) {
|
||||
binding.ivCommentProfile.load(item.memberProfileImage) {
|
||||
crossfade(true)
|
||||
placeholder(R.drawable.ic_placeholder_profile)
|
||||
error(R.drawable.ic_placeholder_profile)
|
||||
transformations(CircleCropTransformation())
|
||||
}
|
||||
} else {
|
||||
binding.ivCommentProfile.setImageResource(R.drawable.ic_placeholder_profile)
|
||||
binding.ivCommentProfile.dispose()
|
||||
binding.ivCommentProfile.setImageDrawable(null)
|
||||
}
|
||||
|
||||
binding.tvCommentNickname.text = item.memberNickname
|
||||
|
||||
+6
-17
@@ -11,6 +11,7 @@ import androidx.core.net.toUri
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import coil.load
|
||||
import coil.dispose
|
||||
import coil.transform.CircleCropTransformation
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||
@@ -257,17 +258,11 @@ class CharacterDetailFragment : BaseFragment<FragmentCharacterDetailBinding>(
|
||||
if (profileUrl.isNotBlank()) {
|
||||
binding.ivCommentProfile.load(profileUrl) {
|
||||
crossfade(true)
|
||||
placeholder(R.drawable.ic_placeholder_profile)
|
||||
error(R.drawable.ic_placeholder_profile)
|
||||
transformations(CircleCropTransformation())
|
||||
}
|
||||
} else {
|
||||
binding.ivMyProfile.load(R.drawable.ic_placeholder_profile) {
|
||||
crossfade(true)
|
||||
placeholder(R.drawable.ic_placeholder_profile)
|
||||
error(R.drawable.ic_placeholder_profile)
|
||||
transformations(CircleCropTransformation())
|
||||
}
|
||||
binding.ivCommentProfile.dispose()
|
||||
binding.ivCommentProfile.setImageDrawable(null)
|
||||
}
|
||||
|
||||
binding.tvLatestComment.text = latest.comment.ifBlank {
|
||||
@@ -277,22 +272,16 @@ class CharacterDetailFragment : BaseFragment<FragmentCharacterDetailBinding>(
|
||||
binding.llLatestComment.visibility = View.GONE
|
||||
binding.llNoComment.visibility = View.VISIBLE
|
||||
|
||||
// 내 프로필 이미지는 SharedPreference의 profileImage 사용 (fallback: placeholder)
|
||||
// 내 프로필 이미지는 SharedPreference의 profileImage 사용
|
||||
val myProfileUrl = SharedPreferenceManager.profileImage
|
||||
if (myProfileUrl.isNotBlank()) {
|
||||
binding.ivMyProfile.load(myProfileUrl) {
|
||||
crossfade(true)
|
||||
placeholder(R.drawable.ic_placeholder_profile)
|
||||
error(R.drawable.ic_placeholder_profile)
|
||||
transformations(CircleCropTransformation())
|
||||
}
|
||||
} else {
|
||||
binding.ivMyProfile.load(R.drawable.ic_placeholder_profile) {
|
||||
crossfade(true)
|
||||
placeholder(R.drawable.ic_placeholder_profile)
|
||||
error(R.drawable.ic_placeholder_profile)
|
||||
transformations(CircleCropTransformation())
|
||||
}
|
||||
binding.ivMyProfile.dispose()
|
||||
binding.ivMyProfile.setImageDrawable(null)
|
||||
}
|
||||
|
||||
binding.ivSendComment.setOnClickListener {
|
||||
|
||||
-2
@@ -6,7 +6,6 @@ import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import coil.load
|
||||
import coil.transform.RoundedCornersTransformation
|
||||
import kr.co.vividnext.sodalive.R
|
||||
import kr.co.vividnext.sodalive.databinding.ItemOtherCharacterBinding
|
||||
import kr.co.vividnext.sodalive.extensions.dpToPx
|
||||
|
||||
@@ -45,7 +44,6 @@ class OtherCharacterAdapter(
|
||||
binding.tvTags.text = item.tags
|
||||
binding.ivThumb.load(item.imageUrl) {
|
||||
crossfade(true)
|
||||
placeholder(R.drawable.ic_place_holder)
|
||||
transformations(RoundedCornersTransformation(16f.dpToPx()))
|
||||
}
|
||||
|
||||
|
||||
-2
@@ -7,7 +7,6 @@ import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import coil.load
|
||||
import coil.transform.RoundedCornersTransformation
|
||||
import kr.co.vividnext.sodalive.R
|
||||
import kr.co.vividnext.sodalive.chat.character.Character
|
||||
import kr.co.vividnext.sodalive.databinding.ItemNewCharacterAllBinding
|
||||
import kr.co.vividnext.sodalive.extensions.dpToPx
|
||||
@@ -24,7 +23,6 @@ class NewCharactersAllAdapter(
|
||||
binding.tvCharacterDescription.text = item.description
|
||||
binding.ivCharacter.load(item.imageUrl) {
|
||||
crossfade(true)
|
||||
placeholder(R.drawable.ic_logo_service_center)
|
||||
transformations(RoundedCornersTransformation(16f.dpToPx()))
|
||||
}
|
||||
binding.tvNew.visibility = if (item.isNew) {
|
||||
|
||||
@@ -6,7 +6,6 @@ import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import coil.load
|
||||
import coil.transform.RoundedCornersTransformation
|
||||
import kr.co.vividnext.sodalive.R
|
||||
import kr.co.vividnext.sodalive.databinding.ItemOriginalWorkBinding
|
||||
import kr.co.vividnext.sodalive.extensions.dpToPx
|
||||
|
||||
@@ -21,7 +20,6 @@ class OriginalWorkListAdapter(
|
||||
binding.tvTitle.text = item.title
|
||||
binding.tvContentType.text = item.contentType
|
||||
binding.ivCover.load(item.imageUrl) {
|
||||
placeholder(R.drawable.ic_logo_service_center)
|
||||
transformations(RoundedCornersTransformation(16f.dpToPx()))
|
||||
}
|
||||
binding.root.setOnClickListener { onClick(item.id) }
|
||||
|
||||
+3
-2
@@ -4,6 +4,7 @@ import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import coil.load
|
||||
import coil.dispose
|
||||
import coil.size.Scale
|
||||
import coil.transform.RoundedCornersTransformation
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
@@ -142,12 +143,12 @@ class OriginalWorkDetailActivity : BaseActivity<ActivityOriginalWorkDetailBindin
|
||||
scale(Scale.FILL)
|
||||
}
|
||||
} else {
|
||||
binding.ivBg.setImageResource(R.drawable.bg_placeholder)
|
||||
binding.ivBg.dispose()
|
||||
binding.ivBg.setImageDrawable(null)
|
||||
}
|
||||
|
||||
binding.ivCover.load(data.imageUrl) {
|
||||
crossfade(true)
|
||||
placeholder(R.drawable.bg_placeholder)
|
||||
transformations(RoundedCornersTransformation(16f.dpToPx()))
|
||||
}
|
||||
|
||||
|
||||
-2
@@ -8,7 +8,6 @@ import androidx.recyclerview.widget.RecyclerView
|
||||
import coil.load
|
||||
import coil.transform.RoundedCornersTransformation
|
||||
import com.orhanobut.logger.Logger
|
||||
import kr.co.vividnext.sodalive.R
|
||||
import kr.co.vividnext.sodalive.chat.character.Character
|
||||
import kr.co.vividnext.sodalive.databinding.ItemOriginalDetailCharacterBinding
|
||||
import kr.co.vividnext.sodalive.extensions.dpToPx
|
||||
@@ -25,7 +24,6 @@ class OriginalWorkDetailAdapter(
|
||||
binding.tvCharacterDescription.text = item.description
|
||||
binding.ivCharacter.load(item.imageUrl) {
|
||||
crossfade(true)
|
||||
placeholder(R.drawable.ic_logo_service_center)
|
||||
transformations(RoundedCornersTransformation(16f.dpToPx()))
|
||||
}
|
||||
binding.tvNew.visibility = if (item.isNew) {
|
||||
|
||||
+1
-4
@@ -176,10 +176,7 @@ class ChatBackgroundPickerDialogFragment : DialogFragment() {
|
||||
private val onClick: (BgItem) -> Unit
|
||||
) : RecyclerView.ViewHolder(binding.root) {
|
||||
fun bind(item: BgItem, selectedId: Long?) {
|
||||
binding.ivImage.load(item.url) {
|
||||
placeholder(R.drawable.ic_placeholder_profile)
|
||||
error(R.drawable.ic_placeholder_profile)
|
||||
}
|
||||
binding.ivImage.load(item.url)
|
||||
val selected = when {
|
||||
selectedId != null -> item.id == selectedId
|
||||
else -> item.id == 0L // 저장된 ID가 없으면 프로필(id=0)을 선택으로 간주
|
||||
|
||||
@@ -14,6 +14,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.SimpleItemAnimator
|
||||
import coil.load
|
||||
import coil.dispose
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||
import kr.co.vividnext.sodalive.R
|
||||
@@ -93,13 +94,8 @@ class ChatRoomActivity : BaseActivity<ActivityChatRoomBinding>(
|
||||
.show(supportFragmentManager, "ChatRoomMoreDialog")
|
||||
}
|
||||
|
||||
// 5.3: characterInfo가 있으면 헤더 바인딩, 없으면 기본 플레이스홀더 유지
|
||||
characterInfo?.let { bindHeader(it) } ?: run {
|
||||
// 기본값: 이름 숨김 또는 플레이스 홀더 표시
|
||||
binding.tvName.text = ""
|
||||
binding.ivProfile.setImageResource(R.drawable.ic_placeholder_profile)
|
||||
binding.ivBackgroundProfile.setImageResource(R.drawable.ic_placeholder_profile)
|
||||
// 배경은 서버 응답 수신 시 적용 (기본은 플레이스홀더 유지)
|
||||
// 배지는 기본 Clone으로 둔다가 실제 값으로 갱신 (디자인 기본 배경도 clone)
|
||||
val badge = getString(R.string.chat_character_type_clone)
|
||||
binding.tvCharacterTypeBadge.text = badge
|
||||
@@ -571,7 +567,8 @@ class ChatRoomActivity : BaseActivity<ActivityChatRoomBinding>(
|
||||
if (bgUrl.isNotBlank()) {
|
||||
setChatBackground(bgUrl)
|
||||
} else {
|
||||
binding.ivBackgroundProfile.setImageResource(R.drawable.ic_placeholder_profile)
|
||||
binding.ivBackgroundProfile.dispose()
|
||||
binding.ivBackgroundProfile.setImageDrawable(null)
|
||||
}
|
||||
|
||||
// 메시지 정렬(오래된 -> 최신) + 동시간대는 messageId 오름차순으로 안정화
|
||||
@@ -806,10 +803,7 @@ class ChatRoomActivity : BaseActivity<ActivityChatRoomBinding>(
|
||||
}
|
||||
|
||||
fun setChatBackground(url: String) {
|
||||
binding.ivBackgroundProfile.load(url) {
|
||||
placeholder(R.drawable.ic_placeholder_profile)
|
||||
error(R.drawable.ic_placeholder_profile)
|
||||
}
|
||||
binding.ivBackgroundProfile.load(url)
|
||||
}
|
||||
|
||||
fun getCharacterId(): Long = characterInfo?.characterId ?: 0L
|
||||
|
||||
@@ -1,44 +1,35 @@
|
||||
/*
|
||||
* 이미지 로딩 유틸리티
|
||||
* - Coil을 사용하여 프로필 이미지를 로딩한다.
|
||||
* - 플레이스홀더/에러 이미지는 ic_placeholder_profile을 사용한다.
|
||||
* - URL이 없으면 이전 요청과 이미지를 비운다.
|
||||
* - 둥근 모서리 변환을 기본 적용한다.
|
||||
*/
|
||||
package kr.co.vividnext.sodalive.chat.talk.room
|
||||
|
||||
import android.widget.ImageView
|
||||
import androidx.annotation.DrawableRes
|
||||
import coil.dispose
|
||||
import coil.load
|
||||
import coil.transform.CircleCropTransformation
|
||||
import kr.co.vividnext.sodalive.R
|
||||
|
||||
/**
|
||||
* 프로필 이미지 로딩 공용 함수
|
||||
*
|
||||
* @param url 이미지 URL (null 또는 빈 값이면 플레이스홀더로 대체)
|
||||
* @param placeholderRes 플레이스홀더/에러 리소스
|
||||
* @param url 이미지 URL (null 또는 빈 값이면 이미지 제거)
|
||||
*/
|
||||
fun loadProfileImage(
|
||||
imageView: ImageView,
|
||||
url: String?,
|
||||
@DrawableRes placeholderRes: Int = R.drawable.ic_placeholder_profile
|
||||
url: String?
|
||||
) {
|
||||
val targetUrl = url?.takeIf { it.isNotBlank() }
|
||||
|
||||
if (targetUrl != null) {
|
||||
imageView.load(targetUrl) {
|
||||
placeholder(placeholderRes)
|
||||
error(placeholderRes)
|
||||
transformations(CircleCropTransformation())
|
||||
crossfade(true)
|
||||
}
|
||||
} else {
|
||||
imageView.load(placeholderRes) {
|
||||
placeholder(placeholderRes)
|
||||
error(placeholderRes)
|
||||
transformations(CircleCropTransformation())
|
||||
crossfade(true)
|
||||
}
|
||||
imageView.dispose()
|
||||
imageView.setImageDrawable(null)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,25 +40,18 @@ fun loadProfileImage(
|
||||
fun loadRoundedImage(
|
||||
imageView: ImageView,
|
||||
url: String?,
|
||||
radiusDp: Float = 10f,
|
||||
@DrawableRes placeholderRes: Int = R.drawable.ic_placeholder_profile
|
||||
radiusDp: Float = 10f
|
||||
) {
|
||||
val density = imageView.resources.displayMetrics.density
|
||||
val radiusPx = radiusDp * density
|
||||
val targetUrl = url?.takeIf { it.isNotBlank() }
|
||||
if (targetUrl != null) {
|
||||
imageView.load(targetUrl) {
|
||||
placeholder(placeholderRes)
|
||||
error(placeholderRes)
|
||||
transformations(coil.transform.RoundedCornersTransformation(radiusPx))
|
||||
crossfade(true)
|
||||
}
|
||||
} else {
|
||||
imageView.load(placeholderRes) {
|
||||
placeholder(placeholderRes)
|
||||
error(placeholderRes)
|
||||
transformations(coil.transform.RoundedCornersTransformation(radiusPx))
|
||||
crossfade(true)
|
||||
}
|
||||
imageView.dispose()
|
||||
imageView.setImageDrawable(null)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.SimpleItemAnimator
|
||||
import coil.transform.CircleCropTransformation
|
||||
import kr.co.vividnext.sodalive.R
|
||||
import kr.co.vividnext.sodalive.base.BaseActivity
|
||||
import kr.co.vividnext.sodalive.common.LoadingDialog
|
||||
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
|
||||
@@ -66,8 +65,6 @@ class DmChatRoomActivity : BaseActivity<ActivityDmChatRoomBinding>(
|
||||
|
||||
private fun setupHeader() {
|
||||
binding.ivBack.setOnClickListener { finish() }
|
||||
binding.ivProfile.setImageResource(R.drawable.ic_placeholder_profile)
|
||||
binding.ivBackgroundProfile.setImageResource(R.drawable.ic_placeholder_profile)
|
||||
}
|
||||
|
||||
private fun setupRecyclerView() {
|
||||
@@ -145,14 +142,9 @@ class DmChatRoomActivity : BaseActivity<ActivityDmChatRoomBinding>(
|
||||
val shouldScrollToBottom = isNearBottom()
|
||||
binding.tvName.text = state.opponentNickname
|
||||
binding.ivProfile.loadUrl(state.opponentProfileImageUrl) {
|
||||
placeholder(R.drawable.ic_placeholder_profile)
|
||||
error(R.drawable.ic_placeholder_profile)
|
||||
transformations(CircleCropTransformation())
|
||||
}
|
||||
binding.ivBackgroundProfile.loadUrl(SharedPreferenceManager.profileImage) {
|
||||
placeholder(R.drawable.ic_placeholder_profile)
|
||||
error(R.drawable.ic_placeholder_profile)
|
||||
}
|
||||
binding.ivBackgroundProfile.loadUrl(SharedPreferenceManager.profileImage)
|
||||
messageAdapter.submitItems(
|
||||
state.messages.toTimelineItems(Locale(LanguageManager.getEffectiveLanguage(this)), TimeZone.getDefault())
|
||||
)
|
||||
|
||||
@@ -146,8 +146,6 @@ class DmChatMessageAdapter(
|
||||
tvTime.text = formatMessageTime(item.createdAt)
|
||||
tvMessage.maxWidth = (itemView.resources.displayMetrics.widthPixels * MESSAGE_MAX_WIDTH_RATIO).toInt()
|
||||
ivProfile.loadUrl(item.senderProfileImageUrl) {
|
||||
placeholder(R.drawable.ic_placeholder_profile)
|
||||
error(R.drawable.ic_placeholder_profile)
|
||||
transformations(CircleCropTransformation())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,6 @@
|
||||
android:layout_height="36dp"
|
||||
android:layout_marginStart="12dp"
|
||||
android:contentDescription="@string/a11y_profile_image"
|
||||
android:src="@drawable/ic_placeholder_profile"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/iv_back"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
@@ -57,7 +57,6 @@
|
||||
android:layout_marginStart="12dp"
|
||||
android:contentDescription="@string/a11y_profile_image"
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@drawable/ic_placeholder_profile"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/iv_back"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
@@ -430,8 +430,7 @@
|
||||
android:id="@+id/iv_comment_profile"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:contentDescription="@null"
|
||||
android:src="@drawable/ic_placeholder_profile" />
|
||||
android:contentDescription="@null" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_latest_comment"
|
||||
@@ -457,8 +456,7 @@
|
||||
android:id="@+id/iv_my_profile"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:contentDescription="@null"
|
||||
android:src="@drawable/ic_placeholder_profile" />
|
||||
android:contentDescription="@null" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ll_comment_input_box"
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
android:layout_marginEnd="8dp"
|
||||
android:contentDescription="@string/a11y_ai_profile_image"
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@drawable/ic_placeholder_profile"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/message_group" />
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
android:layout_marginEnd="8dp"
|
||||
android:contentDescription="@string/a11y_ai_profile_image"
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@drawable/ic_placeholder_profile"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/message_group" />
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
android:layout_height="32dp"
|
||||
android:contentDescription="@string/a11y_profile_image"
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@drawable/ic_placeholder_profile"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/message_group" />
|
||||
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
package kr.co.vividnext.sodalive.chat.talk.room
|
||||
|
||||
import android.app.Application
|
||||
import android.app.Activity
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.net.Uri
|
||||
import android.os.Looper
|
||||
import android.widget.ImageView
|
||||
import coil.Coil
|
||||
import coil.EventListener
|
||||
import coil.ImageLoader
|
||||
import coil.decode.DataSource
|
||||
import coil.fetch.DrawableResult
|
||||
import coil.fetch.Fetcher
|
||||
import coil.load
|
||||
import coil.request.ErrorResult
|
||||
import coil.request.ImageRequest
|
||||
import coil.request.SuccessResult
|
||||
import coil.transform.CircleCropTransformation
|
||||
import coil.transform.RoundedCornersTransformation
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.Robolectric
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.Shadows.shadowOf
|
||||
import org.robolectric.annotation.Config
|
||||
import java.io.IOException
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], application = Application::class)
|
||||
class ImageLoaderTest {
|
||||
private val requests = mutableListOf<ImageRequest>()
|
||||
private var failures = 0
|
||||
private var successes = 0
|
||||
private lateinit var loader: ImageLoader
|
||||
private lateinit var activity: Activity
|
||||
private val delayedFetch = CompletableDeferred<Unit>()
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
activity = Robolectric.buildActivity(Activity::class.java).setup().visible().get()
|
||||
loader = ImageLoader.Builder(RuntimeEnvironment.getApplication())
|
||||
.dispatcher(Dispatchers.Unconfined)
|
||||
.components {
|
||||
add(
|
||||
Fetcher.Factory<Uri> { data, _, _ ->
|
||||
if (data.scheme != "https") {
|
||||
null
|
||||
} else {
|
||||
Fetcher {
|
||||
if (data.lastPathSegment == "failure") throw IOException("test image fetch failure")
|
||||
if (data.lastPathSegment == "delayed") delayedFetch.await()
|
||||
DrawableResult(ColorDrawable(Color.GREEN), false, DataSource.NETWORK)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
.eventListenerFactory {
|
||||
object : EventListener {
|
||||
override fun onStart(request: ImageRequest) {
|
||||
requests += request
|
||||
}
|
||||
|
||||
override fun onSuccess(request: ImageRequest, result: SuccessResult) {
|
||||
successes++
|
||||
}
|
||||
|
||||
override fun onError(request: ImageRequest, result: ErrorResult) {
|
||||
failures++
|
||||
}
|
||||
}
|
||||
}
|
||||
.build()
|
||||
Coil.setImageLoader(loader)
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
activity.finish()
|
||||
Coil.reset()
|
||||
loader.shutdown()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `프로필 URL 요청은 대체 이미지 없이 원본과 원형 변환을 유지한다`() {
|
||||
val image = imageView()
|
||||
|
||||
loadProfileImage(image, "https://example.com/profile")
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
|
||||
val request = requests.single()
|
||||
assertEquals("https://example.com/profile", request.data)
|
||||
assertEquals(listOf(CircleCropTransformation()), request.transformations)
|
||||
assertNull(request.placeholder)
|
||||
assertNull(request.error)
|
||||
assertNull(request.fallback)
|
||||
assertEquals(1, successes)
|
||||
assertNotNull(image.drawable)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `둥근 이미지 URL 요청은 대체 이미지 없이 원본과 모서리 변환을 유지한다`() {
|
||||
val image = imageView()
|
||||
|
||||
loadRoundedImage(image, "https://example.com/rounded", 12f)
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
|
||||
val request = requests.single()
|
||||
assertEquals("https://example.com/rounded", request.data)
|
||||
assertEquals(listOf(RoundedCornersTransformation(12f * image.resources.displayMetrics.density)), request.transformations)
|
||||
assertNull(request.placeholder)
|
||||
assertNull(request.error)
|
||||
assertNull(request.fallback)
|
||||
assertEquals(1, successes)
|
||||
assertNotNull(image.drawable)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `이미지 fetch 실패는 이전 그림과 오류 대체 이미지를 남기지 않는다`() {
|
||||
val image = imageView()
|
||||
image.setImageDrawable(ColorDrawable(Color.RED))
|
||||
|
||||
loadProfileImage(image, "https://example.com/failure")
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
|
||||
assertEquals(1, failures)
|
||||
assertTrue(requests.single().data.toString().endsWith("failure"))
|
||||
assertNull(image.drawable)
|
||||
}
|
||||
|
||||
private fun imageView() = ImageView(activity).apply {
|
||||
activity.setContentView(this)
|
||||
layout(0, 0, 64, 64)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `빈 프로필 source는 이전 요청을 해제하고 기본 리소스 요청 없이 그림을 비운다`() {
|
||||
listOf(null, "", " ").forEach { source ->
|
||||
val image = imageView()
|
||||
val previous = image.load("https://example.com/delayed", loader)
|
||||
image.setImageDrawable(ColorDrawable(Color.RED))
|
||||
requests.clear()
|
||||
|
||||
loadProfileImage(image, source)
|
||||
|
||||
assertTrue(previous.isDisposed)
|
||||
assertNull(image.drawable)
|
||||
assertTrue(requests.isEmpty())
|
||||
}
|
||||
delayedFetch.complete(Unit)
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
assertEquals(0, successes)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `빈 둥근 이미지 source는 이전 요청을 해제하고 지연된 결과도 다시 표시하지 않는다`() {
|
||||
listOf(null, "", " ").forEach { source ->
|
||||
val image = imageView()
|
||||
val previous = image.load("https://example.com/delayed", loader)
|
||||
image.setImageDrawable(ColorDrawable(Color.RED))
|
||||
requests.clear()
|
||||
|
||||
loadRoundedImage(image, source)
|
||||
|
||||
assertTrue(previous.isDisposed)
|
||||
assertNull(image.drawable)
|
||||
assertTrue(requests.isEmpty())
|
||||
}
|
||||
delayedFetch.complete(Unit)
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
assertEquals(0, successes)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user