Commit 724a1eae authored by Eugene Shapovalov's avatar Eugene Shapovalov 💬

Resolve discussion comments.

parent dd7f500e
......@@ -36,7 +36,7 @@ class AssigneesAdapterDelegate : AdapterDelegate<MutableList<ShortUser>>() {
with(itemView) {
titleTextView.text = item.name
subtitleTextView.text = item.username
avatarImageView.bindShortUser(item, true)
avatarImageView.bindShortUser(item)
}
}
}
......
......@@ -37,7 +37,7 @@ class CommitAdapterDelegate : AdapterDelegate<MutableList<Any>>() {
with(itemView) {
val shortUser = commitWithShortUser.shortUser
if (shortUser != null) {
avatarImageView.bindShortUser(shortUser, true)
avatarImageView.bindShortUser(shortUser)
}
titleTextView.text = commitWithShortUser.commit.title
descriptionTextView.text = String.format(
......
......@@ -71,7 +71,7 @@ class TargetHeaderPublicAdapterDelegate(
titleTextView.text = item.title.getHumanName(resources)
Markwon.setText(descriptionTextView, item.body)
descriptionTextView.movementMethod = null //disable internal link click
avatarImageView.bindShortUser(item.author, true)
avatarImageView.bindShortUser(item.author)
iconImageView.setImageResource(item.icon.getIcon())
dateTextView.text = item.date.humanTime(resources)
......
......@@ -37,7 +37,7 @@ class UserNoteAdapterDelegate : AdapterDelegate<MutableList<Any>>() {
fun bind(data: NoteWithFormattedBody) {
this.note = data.note
with(itemView) {
avatarImageView.bindShortUser(note.author, true)
avatarImageView.bindShortUser(note.author)
titleTextView.text = note.author.name
subtitleTextView.text = note.createdAt.humanTime(context.resources)
Markwon.setText(descriptionTextView, data.body)
......
......@@ -3,7 +3,6 @@ package ru.terrakok.gitlabclient.ui.global.view.custom
import android.content.Context
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.util.TypedValue
import android.view.View
import android.widget.FrameLayout
import com.bumptech.glide.Glide
......@@ -30,7 +29,7 @@ class AvatarView @JvmOverloads constructor(
defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {
private val nameBackgroundColors = intArrayOf(
private val shortNameBackgroundColors = intArrayOf(
R.color.green,
R.color.silver,
R.color.grey,
......@@ -41,37 +40,32 @@ class AvatarView @JvmOverloads constructor(
R.color.mariner
)
private var nameBackgroundColor = R.color.green
private var isTextSizeSet = false
init {
View.inflate(context, R.layout.view_avatar, this)
}
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
if (!isTextSizeSet && measuredWidth > 0) {
val width = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 48f, resources.displayMetrics).toInt()
val textSize = when {
measuredWidth < width -> 16f
measuredWidth == width -> 18f
else -> 22f
}
avatarName.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize)
isTextSizeSet = true
}
}
fun setData(id: Long, name: String, avatarUrl: String?, clickAction: () -> Unit = {}) {
nameBackgroundColor = nameBackgroundColors[(id % nameBackgroundColors.size).toInt()]
Glide.with(avatarImage)
.clear(avatarImage)
val names = name.split(" ")
val shortName = when (names.size) {
0 -> ""
1 -> getShortNameFromSingleWord(names[0])
else -> getShortNameFromMultipleWords(names)
}
if (shortName.length == SHORT_NAME_LENGTH) {
avatarShortName.text = shortName
val shortNameBackgroundColor = shortNameBackgroundColors[(id % shortNameBackgroundColors.size).toInt()]
avatarShortName.background = context.getTintDrawable(R.drawable.circle, shortNameBackgroundColor)
avatarShortName.visible(true)
} else {
avatarImage.setImageResource(R.drawable.default_img)
avatarShortName.visible(false)
}
Glide.with(avatarImage)
.load(avatarUrl)
.apply(RequestOptions.placeholderOf(R.drawable.default_img))
.listener(
object : RequestListener<Drawable> {
override fun onLoadFailed(
......@@ -80,7 +74,6 @@ class AvatarView @JvmOverloads constructor(
target: Target<Drawable>?,
isFirstResource: Boolean
): Boolean {
handleLoadFailed(name)
return true
}
......@@ -91,6 +84,7 @@ class AvatarView @JvmOverloads constructor(
dataSource: DataSource?,
isFirstResource: Boolean
): Boolean {
avatarShortName.visible(false)
return false
}
}
......@@ -101,26 +95,6 @@ class AvatarView @JvmOverloads constructor(
setOnClickListener { clickAction() }
}
private fun handleLoadFailed(name: String) {
val names = name.split(" ")
val shortName = when (names.size) {
0 -> ""
1 -> getShortNameFromSingleWord(names[0])
else -> getShortNameFromMultipleWords(names)
}
if (shortName.length == SHORT_NAME_LENGTH) {
avatarName.text = shortName
avatarName.background = context.getTintDrawable(R.drawable.circle, nameBackgroundColor)
avatarImage.visible(false)
avatarName.visible(true)
} else {
avatarImage.setImageResource(R.drawable.default_img)
avatarImage.visible(true)
avatarName.visible(false)
}
}
private fun getShortNameFromSingleWord(name: String): String {
val result = StringBuilder()
name.forEach {
......@@ -153,7 +127,7 @@ class AvatarView @JvmOverloads constructor(
}
}
fun AvatarView.bindShortUser(shortUser: ShortUser, withNavigation: Boolean) {
fun AvatarView.bindShortUser(shortUser: ShortUser, withNavigation: Boolean = true) {
with(shortUser) {
if (withNavigation) {
val router = Toothpick.openScope(DI.APP_SCOPE).getInstance(Router::class.java)
......@@ -175,8 +149,13 @@ fun AvatarView.bindUserAccount(userAccount: UserAccount, withNavigation: Boolean
}
}
fun AvatarView.bindProject(project: Project) {
fun AvatarView.bindProject(project: Project, withNavigation: Boolean = true) {
with(project) {
setData(id, name, avatarUrl, {})
if (withNavigation) {
val router = Toothpick.openScope(DI.APP_SCOPE).getInstance(Router::class.java)
setData(id, name, avatarUrl) { router.navigateTo(Screens.ProjectFlow(id)) }
} else {
setData(id, name, avatarUrl)
}
}
}
\ No newline at end of file
......@@ -57,7 +57,7 @@ class IssueDetailsFragment : BaseFragment(), IssueDetailsView {
}
}
}
avatarImageView.bindShortUser(issue.author, true)
avatarImageView.bindShortUser(issue.author)
Markwon.setText(descriptionTextView, mdDescription)
}
......
......@@ -71,7 +71,7 @@ class MergeRequestDetailsFragment : BaseFragment(), MergeRequestDetailsView {
}
}
}
avatarImageView.bindShortUser(mr.author, true)
avatarImageView.bindShortUser(mr.author)
Markwon.setText(descriptionTextView, mdDescription)
}
......
......@@ -47,7 +47,7 @@ class ProjectInfoFragment : BaseFragment(), ProjectInfoView {
starsTextView.text = project.starCount.toString()
forksTextView.text = project.forksCount.toString()
avatarImageView.bindProject(project)
avatarImageView.bindProject(project, false)
iconImageView.setBackgroundResource(R.drawable.circle)
iconImageView.setImageResource(
when (project.visibility) {
......
......@@ -4,28 +4,28 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_height="48dp"
tools:layout_width="48dp"
tools:layout_height="72dp"
tools:layout_width="72dp"
tools:parentTag="FrameLayout">
<ImageView
android:id="@+id/avatarImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:src="@drawable/default_img"/>
tools:src="@drawable/default_img" />
<TextView
android:id="@+id/avatarName"
android:id="@+id/avatarShortName"
style="@style/TextSubtitle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="10dp"
android:textColor="@color/white"
android:textStyle="bold"
android:visibility="gone"
app:autoSizePresetSizes="@array/avatar_short_name_text_sizes"
app:autoSizeTextType="uniform"
tools:background="@drawable/circle"
tools:text="ES"
tools:textSize="18sp"
tools:visibility="gone" />
tools:text="ES" />
</merge>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="avatar_short_name_text_sizes">
<item>14sp</item>
<item>18sp</item>
<item>24sp</item>
</array>
</resources>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment