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 all commits
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
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@
</provider>
</application>

</manifest>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ import androidx.lifecycle.viewModelScope
import com.created.team201.data.model.UserStudyEntity
import com.created.team201.data.repository.UserStudyRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import javax.inject.Inject

@HiltViewModel
Expand All @@ -33,4 +31,4 @@ sealed interface HomeUiState {
data class Success(val userStudies: List<UserStudyEntity>) : HomeUiState
object Loading : HomeUiState
object Failed : HomeUiState
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package com.created.team201.presentation.myPage

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.Toast
import androidx.core.content.ContextCompat
import androidx.core.widget.doOnTextChanged
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.activityViewModels
import com.bumptech.glide.Glide
import com.created.team201.R
import com.created.team201.databinding.FragmentModifyProfileBinding
import com.created.team201.presentation.myPage.MyPageViewModel.Event.MODIFY_PROFILE
import com.created.team201.presentation.myPage.MyPageViewModel.Event.SAVE_FAILURE
import com.created.team201.presentation.myPage.MyPageViewModel.Event.SAVE_SUCCESS
import com.created.team201.util.collectOnStarted

class ModifyProfileFragment : DialogFragment() {
private val myPageViewModel: MyPageViewModel by activityViewModels()

private var _binding: FragmentModifyProfileBinding? = null
private val binding: FragmentModifyProfileBinding get() = _binding!!

override fun getTheme(): Int = R.style.NoMarginDialog

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentModifyProfileBinding.inflate(layoutInflater)
return binding.root
}

override fun onDestroyView() {
super.onDestroyView()

_binding = null
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

setupDialogView()
setupActionBar()
setupEditTextChangeListener()
collectMyProfile()
collectMyPageEvent()
collectNicknameState()
}

private fun setupDialogView() {
dialog?.window?.setLayout(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
)
}

private fun setupActionBar() {
binding.tbModifyMyPage.setNavigationOnClickListener {
dismiss()
}

binding.tbModifyMyPage.setOnMenuItemClickListener { item ->
when (item.itemId) {
R.id.menu_modify_profile_save -> {
myPageViewModel.changeMyPageEvent(MODIFY_PROFILE)
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 collectMyProfile() {
myPageViewModel.profile.collectOnStarted(viewLifecycleOwner) { 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 collectNicknameState() {
myPageViewModel.nicknameState.collectOnStarted(viewLifecycleOwner) { state ->
with(binding.tvModifyMyPageNicknameValidateIntroduction) {
text = getString(state.introduction)
setTextColor(ContextCompat.getColor(requireContext(), state.color))
}
}
}

private fun collectMyPageEvent() {
myPageViewModel.myPageEvent.collectOnStarted(viewLifecycleOwner) { event ->
when (event) {
SAVE_SUCCESS -> showToast(getString(R.string.myPage_toast_modify_profile_success))
SAVE_FAILURE -> showToast(getString(R.string.myPage_toast_modify_profile_failed))
MODIFY_PROFILE -> myPageViewModel.patchMyProfile()
else -> Unit
}
}
}

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

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

companion object {
const val TAG_MODIFY_FRAGMENT = "TAG_MODIFY_FRAGMENT"
}
}

This file was deleted.

This file was deleted.

Loading