Commit 1ee34fc6 authored by Konstantin Tskhovrebov's avatar Konstantin Tskhovrebov 🤖

Change member item avatar to AvatarView.

parent 50f56045
......@@ -11,4 +11,4 @@ data class Member(
@SerializedName("web_url") val webUrl: String?,
@SerializedName("expires_at") val expiresDate: String?,
@SerializedName("access_level") val accessLevel: Long
)
\ No newline at end of file
)
\ No newline at end of file
......@@ -71,7 +71,7 @@ class NavigationDrawerFragment : BaseFragment(), NavigationDrawerView, MessageDi
override fun setAccounts(accounts: List<UserAccount>, currentAccount: UserAccount) {
nickTV.text = currentAccount.userName
serverNameTV.text = currentAccount.serverPath
avatarImageView.bindUserAccount(currentAccount, true)
avatarImageView.bindUserAccount(currentAccount)
accountsContainer.removeAllViews()
accounts.forEach { acc ->
......
......@@ -8,7 +8,7 @@ import kotlinx.android.synthetic.main.item_member.view.*
import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.entity.Member
import ru.terrakok.gitlabclient.extension.inflate
import ru.terrakok.gitlabclient.extension.loadRoundedImage
import ru.terrakok.gitlabclient.ui.global.view.custom.bindMember
/**
* @author Valentin Logvinovitch (glvvl) on 28.02.19.
......@@ -46,7 +46,7 @@ class MembersAdapterDelegate(
fun bind(data: Member) {
this.data = data
with(itemView) {
avatarImageView.loadRoundedImage(data.avatarUrl)
avatarView.bindMember(data)
nameTextView.text = data.name
roleTextView.text = data.accessLevel.accessToString()
}
......
......@@ -16,6 +16,7 @@ import ru.terrakok.cicerone.Router
import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.di.DI
import ru.terrakok.gitlabclient.entity.Member
import ru.terrakok.gitlabclient.entity.Project
import ru.terrakok.gitlabclient.entity.ShortUser
import ru.terrakok.gitlabclient.entity.User
......@@ -56,8 +57,10 @@ class AvatarView @JvmOverloads constructor(
}
if (shortName.length == SHORT_NAME_LENGTH) {
avatarShortName.text = shortName
val shortNameBackgroundColor = shortNameBackgroundColors[(id % shortNameBackgroundColors.size).toInt()]
avatarShortName.background = context.getTintDrawable(R.drawable.circle, shortNameBackgroundColor)
val shortNameBackgroundColor =
shortNameBackgroundColors[(id % shortNameBackgroundColors.size).toInt()]
avatarShortName.background =
context.getTintDrawable(R.drawable.circle, shortNameBackgroundColor)
} else {
avatarImage.setImageResource(R.drawable.default_img)
}
......@@ -131,20 +134,40 @@ class AvatarView @JvmOverloads constructor(
}
}
fun AvatarView.bindShortUser(shortUser: ShortUser) {
fun AvatarView.bindShortUser(shortUser: ShortUser, withNavigation: Boolean = true) {
with(shortUser) {
val router = Toothpick.openScope(DI.APP_SCOPE).getInstance(Router::class.java)
setData(id, name, avatarUrl) { router.navigateTo(Screens.UserFlow(id)) }
if (withNavigation) {
val router = Toothpick.openScope(DI.APP_SCOPE).getInstance(Router::class.java)
setData(id, name, avatarUrl) { router.navigateTo(Screens.UserFlow(id)) }
} else {
setData(id, name, avatarUrl)
}
}
}
fun AvatarView.bindUser(user: User) {
fun AvatarView.bindUser(user: User, withNavigation: Boolean = true) {
with(user) {
setData(id, name, avatarUrl)
if (withNavigation) {
val router = Toothpick.openScope(DI.APP_SCOPE).getInstance(Router::class.java)
setData(id, name, avatarUrl) { router.navigateTo(Screens.UserFlow(id)) }
} else {
setData(id, name, avatarUrl)
}
}
}
fun AvatarView.bindMember(member: Member, withNavigation: Boolean = true) {
with(member) {
if (withNavigation) {
val router = Toothpick.openScope(DI.APP_SCOPE).getInstance(Router::class.java)
setData(id, name, avatarUrl) { router.navigateTo(Screens.UserFlow(id)) }
} else {
setData(id, name, avatarUrl)
}
}
}
fun AvatarView.bindUserAccount(userAccount: UserAccount, withNavigation: Boolean) {
fun AvatarView.bindUserAccount(userAccount: UserAccount, withNavigation: Boolean = true) {
with(userAccount) {
if (withNavigation) {
val router = Toothpick.openScope(DI.APP_SCOPE).getInstance(Router::class.java)
......
......@@ -13,7 +13,6 @@ import ru.terrakok.gitlabclient.extension.tryOpenLink
import ru.terrakok.gitlabclient.presentation.user.info.UserInfoPresenter
import ru.terrakok.gitlabclient.presentation.user.info.UserInfoView
import ru.terrakok.gitlabclient.ui.global.BaseFragment
import ru.terrakok.gitlabclient.ui.global.view.custom.bindShortUser
import ru.terrakok.gitlabclient.ui.global.view.custom.bindUser
/**
......@@ -59,7 +58,7 @@ class UserInfoFragment : BaseFragment(), UserInfoView {
override fun showUser(user: User) {
this.user = user
toolbar.title = user.username
avatarImageView.bindUser(user)
avatarImageView.bindUser(user, false)
usernameTextView.text = user.name
userIdTextView.text = "@${user.username}"
......
......@@ -6,14 +6,13 @@
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground">
<ImageView
android:id="@+id/avatarImageView"
<ru.terrakok.gitlabclient.ui.global.view.custom.AvatarView
android:id="@+id/avatarView"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="16dp"
android:layout_marginTop="12dp"
android:layout_marginBottom="12dp"
android:src="@drawable/default_img"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
......@@ -29,7 +28,7 @@
android:lines="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/roleTextView"
app:layout_constraintStart_toEndOf="@+id/avatarImageView"
app:layout_constraintStart_toEndOf="@+id/avatarView"
app:layout_constraintTop_toTopOf="parent"
tools:text="Konstantin Tskhovrebov" />
......
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