Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AN] 마이페이지 수정 및 보기 기능 개선 #602

Merged
merged 25 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c493caa
refactor: 간단 소개 multiLine 지정 및 autoLink 설정
inseonyun Nov 2, 2023
fa1efb2
refactor: 필수 투두 -> Must Do
inseonyun Nov 2, 2023
264c137
refactor: profile, nickname StateFlow로 변경
inseonyun Nov 2, 2023
5c8b837
refactor: ProfileType StateFlow로 변경
inseonyun Nov 2, 2023
dd7a23a
refactor: NicknameState StateFlow로 변경
inseonyun Nov 2, 2023
829d605
refactor: Introduction StateFlow로 변경
inseonyun Nov 2, 2023
3c4dfb9
refactor: modifyProfileState StateFlow로 변경
inseonyun Nov 2, 2023
8110519
refactor: MyPageEvent 구현
inseonyun Nov 2, 2023
6c38e2b
refactor: DataBinding -> ViewBinding
inseonyun Nov 2, 2023
7fd38b9
refactor: 누군가 파놓은 Profile 중복 옵저빙 제거
inseonyun Nov 2, 2023
b181627
refactor: 불필요한 함수 제거 및 함수 분리
inseonyun Nov 2, 2023
39db7ee
refactor: 닉네임 검증 입력 반응 0.7초간 없을 경우 수행
inseonyun Nov 2, 2023
88fc692
refactor: 프로필 수정 취소 리셋 함수 수정
inseonyun Nov 2, 2023
1be2271
refactor: 프로필 수정 상태 시 nickname EditText 언더 라인 및 drawable 표시
inseonyun Nov 2, 2023
cc6016b
refactor: 프로필 수정 상태 시 introduction EditText 보더 라인 컬러 변경
inseonyun Nov 2, 2023
dba6c67
refactor: State enum class로 관리
inseonyun Nov 7, 2023
0ef0bef
refactor: strings 오탈자 수정
inseonyun Nov 7, 2023
71c2000
refactor: set function prefix 수정
inseonyun Nov 7, 2023
fca93bf
chore: conflict 해결
inseonyun Nov 7, 2023
8d3920e
refactor: BindingViewFragment 사용
inseonyun Nov 7, 2023
c582543
refactor: MyPage 스터디 성공률 및 Must Do 성공률 커스텀 뷰 작성
inseonyun Nov 7, 2023
4803819
refactor: 프로필 수정 액티비티 추가
inseonyun Nov 8, 2023
058d484
refactor: 프로필 수정 뷰 Dialog로 변경
inseonyun Nov 9, 2023
24ce134
refactor: layout 태그 제거
inseonyun Nov 9, 2023
e97f2b7
refactor: back 버튼 클릭 시 dismiss 하도록 수정
inseonyun Nov 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
android:theme="@style/Theme.Team201"
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:name=".presentation.myPage.ModifyProfileActivity"
android:exported="false" />
<activity
android:name=".presentation.certificationCheck.CertificationCheckActivity"
android:exported="false"
Expand Down Expand Up @@ -117,4 +120,4 @@
</provider>
</application>

</manifest>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package com.created.team201.presentation.myPage

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.widget.ImageView
import android.widget.Toast
import androidx.activity.viewModels
import androidx.core.widget.doOnTextChanged
import com.bumptech.glide.Glide
import com.created.team201.R
import com.created.team201.databinding.ActivityModifyProfileBinding
import com.created.team201.presentation.common.BindingViewActivity
import com.created.team201.util.collectOnStarted
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class ModifyProfileActivity :
BindingViewActivity<ActivityModifyProfileBinding>(ActivityModifyProfileBinding::inflate) {
private val myPageViewModel: MyPageViewModel by viewModels()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setupActionBar()
setupEditTextChangeListener()
collectMyProfile()
collectMyProfileInformation()
collectModifyProfileState()
collectNicknameState()
}

private fun collectMyProfile() {
myPageViewModel.profile.collectOnStarted(this) { profile ->
binding.ivModifyProfile.loadImageUrl(profile.profileImageUrl)
binding.tvModifyProfileId.text = profile.githubId
binding.etModifyProfileNickname.setText(profile.profileInformation.nickname.nickname)
binding.etModifyProfileIntroduction.setText(profile.profileInformation.introduction)
}
}

private fun setupActionBar() {
setSupportActionBar(binding.tbModifyMyPage)
supportActionBar?.setHomeActionContentDescription(R.string.toolbar_back_text)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_back)
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.menu_modify_profile, menu)
return super.onCreateOptionsMenu(menu)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.menu_modify_profile_save -> {
myPageViewModel.patchMyProfile()
true
}

android.R.id.home -> {
finish()
true
}

else -> false
}
}

private fun setupEditTextChangeListener() {
binding.etModifyProfileNickname.filters = myPageViewModel.getInputFilter()
binding.etModifyProfileNickname.doOnTextChanged { text, _, _, _ ->
myPageViewModel.setNickname(text.toString())
}
binding.etModifyProfileIntroduction.doOnTextChanged { text, _, _, _ ->
myPageViewModel.setIntroduction(text.toString())
}
}

private fun collectMyProfileInformation() {
myPageViewModel.nickname.collectOnStarted(this) { nickname ->
if (binding.etModifyProfileNickname.text.toString() == nickname) return@collectOnStarted
binding.etModifyProfileNickname.setText(nickname)
}

myPageViewModel.introduction.collectOnStarted(this) { introduction ->
if (binding.etModifyProfileIntroduction.text.toString() == introduction) return@collectOnStarted
binding.etModifyProfileIntroduction.setText(introduction)
}
}

private fun collectModifyProfileState() {
myPageViewModel.modifyProfileState.collectOnStarted(this) { modifyProfileState ->
when (modifyProfileState) {
MyPageViewModel.State.Loading -> Unit
MyPageViewModel.State.Success -> {
myPageViewModel.changeMyPageEvent(
MyPageViewModel.Event.ShowToast(getString(R.string.myPage_toast_modify_profile_success))
)
}

MyPageViewModel.State.Fail -> {
myPageViewModel.changeMyPageEvent(
MyPageViewModel.Event.ShowToast(getString(R.string.myPage_toast_modify_profile_failed))
)
}
}
}
}

private fun collectNicknameState() {
myPageViewModel.nicknameState.collectOnStarted(this) { state ->
with(binding.tvModifyMyPageNicknameValidateIntroduction) {
text = getString(state.introduction)
setTextColor(getColor(state.color))
}
}
}

private fun collectMyPageEvent() {
myPageViewModel.myPageEvent.collectOnStarted(this) { event ->
when (event) {
is MyPageViewModel.Event.ShowToast -> showToast(event.message)

MyPageViewModel.Event.ModifyMyPage -> myPageViewModel.patchMyProfile()
else -> Unit
}
}
}

private fun showToast(message: String) =
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()

private fun ImageView.loadImageUrl(imageUrl: String?) {
Glide.with(this)
.load(imageUrl)
.into(this)
}

companion object {
fun getIntent(context: Context): Intent =
Intent(context, ModifyProfileActivity::class.java)
}
}
Loading