From 6d45cde9f7ab49aa0c429675421c48d3d2532301 Mon Sep 17 00:00:00 2001 From: Matthieu <61561059+Wv5twkFEKh54vo4tta9yu7dHa3@users.noreply.github.com> Date: Fri, 6 Mar 2020 11:52:29 +0100 Subject: [PATCH] Move into setContent function --- .../java/com/h/pixeldroid/ProfileActivity.kt | 56 ++++++++++--------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/com/h/pixeldroid/ProfileActivity.kt b/app/src/main/java/com/h/pixeldroid/ProfileActivity.kt index faa03266..1444d183 100644 --- a/app/src/main/java/com/h/pixeldroid/ProfileActivity.kt +++ b/app/src/main/java/com/h/pixeldroid/ProfileActivity.kt @@ -8,6 +8,7 @@ import android.widget.ImageView import android.widget.TextView import com.bumptech.glide.Glide import com.h.pixeldroid.api.PixelfedAPI +import com.h.pixeldroid.objects.Account import com.h.pixeldroid.objects.Status import retrofit2.Call import retrofit2.Callback @@ -35,32 +36,8 @@ class ProfileActivity : AppCompatActivity() { val account = statuses!![0].account - // ImageView : profile picture - val profilePicture = findViewById(R.id.profilePicture) - Glide.with(applicationContext).load(account.avatar).into(profilePicture) + setContent(account) - // TextView : description / bio - val description = findViewById(R.id.description) - description.setText(account.note) - - // TextView : account name - val accountName = findViewById(R.id.accountName) - accountName.setText(account.username) - - // TextView : number of posts - val nbPosts = findViewById(R.id.nbPosts) - nbPosts.text = account.statuses_count.toString() - nbPosts.setTypeface(null, Typeface.BOLD) - - // TextView : number of followers - val nbFollowers = findViewById(R.id.nbFollowers) - nbFollowers.text = account.followers_count.toString() - nbFollowers.setTypeface(null, Typeface.BOLD) - - // TextView : number of following - val nbFollowing = findViewById(R.id.nbFollowing) - nbFollowing.text = account.following_count.toString() - nbFollowing.setTypeface(null, Typeface.BOLD) } } } @@ -71,4 +48,33 @@ class ProfileActivity : AppCompatActivity() { }) } + + private fun setContent(account: Account) { + // ImageView : profile picture + val profilePicture = findViewById(R.id.profilePicture) + Glide.with(applicationContext).load(account.avatar).into(profilePicture) + + // TextView : description / bio + val description = findViewById(R.id.description) + description.text = account.note + + // TextView : account name + val accountName = findViewById(R.id.accountName) + accountName.text = account.username + + // TextView : number of posts + val nbPosts = findViewById(R.id.nbPosts) + nbPosts.text = account.statuses_count.toString() + nbPosts.setTypeface(null, Typeface.BOLD) + + // TextView : number of followers + val nbFollowers = findViewById(R.id.nbFollowers) + nbFollowers.text = account.followers_count.toString() + nbFollowers.setTypeface(null, Typeface.BOLD) + + // TextView : number of following + val nbFollowing = findViewById(R.id.nbFollowing) + nbFollowing.text = account.following_count.toString() + nbFollowing.setTypeface(null, Typeface.BOLD) + } }