Skip to content

Commit

Permalink
refactor: 사용자를 찾을 수 없는 경우 뷰 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
RightHennessy committed Nov 21, 2023
1 parent 3845790 commit 543ebf0
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.View.INVISIBLE
import android.widget.ImageView
import android.widget.Toast
import androidx.activity.viewModels
Expand Down Expand Up @@ -67,7 +68,7 @@ class ProfileActivity :
profileViewModel.uiState.collectOnStarted(this) { uiState ->
when (uiState) {
is ProfileUiState.Success -> updateProfile(uiState.userProfile)
is ProfileUiState.Failure -> Unit
is ProfileUiState.Failure -> updateNonFoundProfile()
is ProfileUiState.Loading -> Unit
}
}
Expand All @@ -83,6 +84,19 @@ class ProfileActivity :
getString(R.string.profile_mustdo_success_rate_format).format(userProfile.profile.successfulRoundCount)
binding.tvProfileUserDescription.text = userProfile.profile.profileInformation.introduction
finishedStudyAdapter.submitList(userProfile.finishedStudies)
binding.layoutProfileTodoSuccessRate.isVisible = true
binding.layoutProfileStudySuccessRate.isVisible = true
}

private fun updateNonFoundProfile() {
binding.ivProfileImage.setImage(R.drawable.ic_my_page)
binding.tvProfileUserName.text = getString(R.string.profile_unexpected_user_name)
binding.viewProfileBorderLine.visibility = INVISIBLE
binding.viewProfileRateBoardBorderLine.visibility = INVISIBLE
binding.tvProfileUserDescription.visibility = INVISIBLE
binding.layoutProfileTodoSuccessRate.isVisible = false
binding.layoutProfileStudySuccessRate.isVisible = false
binding.tbProfile.menu.removeItem(R.id.menu_profile_report)
}

private fun ImageView.setImage(imageUrl: String?) {
Expand All @@ -93,6 +107,12 @@ class ProfileActivity :
}
}

private fun ImageView.setImage(image: Int) {
Glide.with(context)
.load(image)
.into(this)
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
val isMyProfile = intent.getBooleanExtra(KEY_MY_PROFILE, false)
when (isMyProfile) {
Expand Down

0 comments on commit 543ebf0

Please sign in to comment.