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

[FEAT] 일러스트 적용 #143

Merged
merged 9 commits into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,34 @@ package com.polzzak_android.presentation.common.util

import android.widget.ImageView
import androidx.annotation.DrawableRes
import androidx.databinding.BindingAdapter
import com.bumptech.glide.Glide

@BindingAdapter("imageUrl")
fun ImageView.loadImageUrl(imageUrl: String?) {
Glide.with(this.context).load(imageUrl).into(this)
fun ImageView.loadImageUrl(imageUrl: String?, @DrawableRes placeHolderRes: Int? = null) {
Glide.with(this.context).load(imageUrl).run {
placeHolderRes?.let { placeholder(placeHolderRes) } ?: this
}.into(this)
}

@BindingAdapter("imageDrawableRes")
fun ImageView.loadImageDrawableRes(@DrawableRes drawableRes: Int) {
Glide.with(this.context).load(drawableRes).into(this)
fun ImageView.loadImageDrawableRes(
@DrawableRes drawableRes: Int,
@DrawableRes placeHolderRes: Int? = null
) {
Glide.with(this.context).load(drawableRes).run {
placeHolderRes?.let { placeholder(placeHolderRes) } ?: this
}.into(this)
}

@BindingAdapter("imageUrlCircleCrop")
fun ImageView.loadCircleImageUrl(imageUrl: String?) {
Glide.with(this.context).load(imageUrl).circleCrop().into(this)
fun ImageView.loadCircleImageUrl(imageUrl: String?, @DrawableRes placeHolderRes: Int? = null) {
Glide.with(this.context).load(imageUrl).circleCrop().run {
placeHolderRes?.let { placeholder(placeHolderRes) } ?: this
}.into(this)
}

@BindingAdapter("imageDrawableResCircleCrop")
fun ImageView.loadCircleImageDrawableRes(@DrawableRes drawableRes: Int) {
Glide.with(this.context).load(drawableRes).circleCrop().into(this)
fun ImageView.loadCircleImageDrawableRes(
@DrawableRes drawableRes: Int,
@DrawableRes placeHolderRes: Int? = null
) {
Glide.with(this.context).load(drawableRes).circleCrop().run {
placeHolderRes?.let { placeholder(placeHolderRes) } ?: this
}.into(this)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.polzzak_android.presentation.common.util.getSocialLoginManager
import com.polzzak_android.presentation.common.util.shotBackPressed
import com.polzzak_android.presentation.component.PolzzakSnackBar
import com.polzzak_android.presentation.component.errorOf
import com.polzzak_android.presentation.feature.auth.login.model.LoginInfoUiModel
import com.polzzak_android.presentation.feature.auth.login.model.LoginInfoModel
import com.polzzak_android.presentation.feature.auth.model.SocialLoginType
import com.polzzak_android.presentation.feature.auth.signup.SignUpFragment
import com.polzzak_android.presentation.feature.root.MainViewModel
Expand Down Expand Up @@ -124,8 +124,8 @@ class LoginFragment : BaseFragment<FragmentLoginBinding>() {
is ModelState.Loading -> binding.clLoading.isVisible = true
is ModelState.Success -> {
when (it.data) {
is LoginInfoUiModel.SignUp -> signUp(model = it.data)
is LoginInfoUiModel.Login -> login(model = it.data)
is LoginInfoModel.SignUp -> signUp(model = it.data)
is LoginInfoModel.Login -> login(model = it.data)
}
binding.clLoading.isVisible = false

Expand All @@ -145,7 +145,7 @@ class LoginFragment : BaseFragment<FragmentLoginBinding>() {
}
}

private fun signUp(model: LoginInfoUiModel.SignUp) {
private fun signUp(model: LoginInfoModel.SignUp) {
val signUpBundle = Bundle().apply {
putString(SignUpFragment.ARGUMENT_USER_ID_KEY, model.userName)
putParcelable(
Expand All @@ -164,7 +164,7 @@ class LoginFragment : BaseFragment<FragmentLoginBinding>() {
)
}

private fun login(model: LoginInfoUiModel.Login) {
private fun login(model: LoginInfoModel.Login) {
mainViewModel.accessToken = model.accessToken
lastSocialLoginViewModel.saveLastSocialLoginType(model.socialType)
val navAction = when (model.memberType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.polzzak_android.data.repository.MemberTypeRepository
import com.polzzak_android.data.repository.UserRepository
import com.polzzak_android.presentation.common.model.ModelState
import com.polzzak_android.presentation.common.model.asMemberTypeOrNull
import com.polzzak_android.presentation.feature.auth.login.model.LoginInfoUiModel
import com.polzzak_android.presentation.feature.auth.login.model.LoginInfoModel
import com.polzzak_android.presentation.feature.auth.model.MemberTypeDetail
import com.polzzak_android.presentation.feature.auth.model.SocialLoginType
import com.polzzak_android.presentation.feature.auth.model.asMemberTypeDetail
Expand All @@ -29,8 +29,8 @@ class LoginViewModel @Inject constructor(
private val memberTypeRepository: MemberTypeRepository,
private val userRepository: UserRepository
) : ViewModel() {
private val _loginInfoLiveData = MutableLiveData<EventWrapper<ModelState<LoginInfoUiModel>>>()
val loginInfoLiveData: LiveData<EventWrapper<ModelState<LoginInfoUiModel>>> = _loginInfoLiveData
private val _loginInfoLiveData = MutableLiveData<EventWrapper<ModelState<LoginInfoModel>>>()
val loginInfoLiveData: LiveData<EventWrapper<ModelState<LoginInfoModel>>> = _loginInfoLiveData

private var loginJob: Job? = null

Expand Down Expand Up @@ -89,13 +89,13 @@ class LoginViewModel @Inject constructor(
setLoginResultError()
return@onSuccess
}
val loginInfoUiModel =
LoginInfoUiModel.Login(
val loginInfoModel =
LoginInfoModel.Login(
accessToken = accessToken,
memberType = memberType,
socialType = socialType
)
setLoginResultSuccess(data = loginInfoUiModel)
setLoginResultSuccess(data = loginInfoModel)
}.onError { exception, _ ->
setLoginResultError(exception = exception)
}
Expand All @@ -106,13 +106,13 @@ class LoginViewModel @Inject constructor(
val parentTypes = it?.memberTypeDetailList?.map { responseData ->
asMemberTypeDetail(memberTypeDetailResponseData = responseData)
}?.filterIsInstance<MemberTypeDetail.Parent>() ?: emptyList()
val loginInfoUiModel =
LoginInfoUiModel.SignUp(
val loginInfoModel =
LoginInfoModel.SignUp(
userName = userName,
socialType = socialType,
parentTypes = parentTypes
)
setLoginResultSuccess(data = loginInfoUiModel)
setLoginResultSuccess(data = loginInfoModel)
}.onError { exception, _ ->
setLoginResultError(exception = exception)
}
Expand All @@ -122,7 +122,7 @@ class LoginViewModel @Inject constructor(
_loginInfoLiveData.value = EventWrapper(ModelState.Loading())
}

private fun setLoginResultSuccess(data: LoginInfoUiModel) {
private fun setLoginResultSuccess(data: LoginInfoModel) {
_loginInfoLiveData.value = EventWrapper(ModelState.Success(data = data))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import com.polzzak_android.presentation.feature.auth.model.SocialLoginType
import com.polzzak_android.presentation.feature.auth.model.MemberTypeDetail
import com.polzzak_android.presentation.common.model.MemberType

sealed interface LoginInfoUiModel {
sealed interface LoginInfoModel {
data class Login(
val accessToken: String,
val memberType: MemberType,
val socialType: SocialLoginType
) : LoginInfoUiModel
) : LoginInfoModel

data class SignUp(
val userName: String,
val socialType: SocialLoginType,
val parentTypes: List<MemberTypeDetail.Parent>
) : LoginInfoUiModel
) : LoginInfoModel
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import com.polzzak_android.presentation.component.errorOf
import com.polzzak_android.presentation.feature.auth.model.MemberTypeDetail
import com.polzzak_android.presentation.feature.auth.model.SocialLoginType
import com.polzzak_android.presentation.feature.auth.signup.adapter.ParentTypeRollableAdapter
import com.polzzak_android.presentation.feature.auth.signup.model.NickNameUiModel
import com.polzzak_android.presentation.feature.auth.signup.model.MemberTypeModel
import com.polzzak_android.presentation.feature.auth.signup.model.NickNameModel
import com.polzzak_android.presentation.feature.auth.signup.model.NickNameValidationState
import com.polzzak_android.presentation.feature.auth.signup.model.SignUpPage
import com.polzzak_android.presentation.feature.auth.signup.model.SignUpTermsOfServiceModel
Expand Down Expand Up @@ -226,7 +227,7 @@ class SignUpFragment : BaseFragment<FragmentSignupBinding>() {
}
})
etInput.setOnFocusChangeListener { _, isFocused ->
val textUiModel = signUpViewModel.nickNameLiveData.value ?: NickNameUiModel()
val textUiModel = signUpViewModel.nickNameLiveData.value ?: NickNameModel()
etInput.isSelected = true
setNickNameResultTextView(isFocused = isFocused, uiModel = textUiModel)
}
Expand Down Expand Up @@ -367,6 +368,9 @@ class SignUpFragment : BaseFragment<FragmentSignupBinding>() {
clSelectParentCard.isSelected = (it.isParent())
clSelectKidCard.isSelected = (it.isKid())
}
val profileDrawableRes =
if (it.isParent()) R.drawable.ic_sign_up_parent_select_image else R.drawable.ic_sign_up_kid_select_image
binding.inSelectProfileImage.ivImage.loadCircleImageDrawableRes(profileDrawableRes)
refreshNextButton()
}

Expand Down Expand Up @@ -407,11 +411,17 @@ class SignUpFragment : BaseFragment<FragmentSignupBinding>() {

private fun observeProfileImageLiveData() {
signUpViewModel.profileImageLiveData.observe(viewLifecycleOwner) {
val imageRes = when (signUpViewModel.memberTypeLiveData.value?.selectedType) {
MemberTypeModel.Type.PARENT -> R.drawable.ic_sign_up_parent_select_image
MemberTypeModel.Type.KID -> R.drawable.ic_sign_up_kid_select_image
else -> null
}
with(binding.inSelectProfileImage) {
it.path?.let { path ->
ivImage.loadCircleImageUrl(imageUrl = path)
} ?: run {
ivImage.loadCircleImageDrawableRes(drawableRes = R.drawable.ic_launcher_background)
ivImage.loadCircleImageUrl(
imageUrl = path,
placeHolderRes = imageRes
)
}
}
}
Expand Down Expand Up @@ -458,7 +468,7 @@ class SignUpFragment : BaseFragment<FragmentSignupBinding>() {
})
}

private fun setNickNameResultTextView(isFocused: Boolean, uiModel: NickNameUiModel) {
private fun setNickNameResultTextView(isFocused: Boolean, uiModel: NickNameModel) {
with(binding.inSetNickName) {
tvCheckDuplicatedResult.text = createDuplicatedResultText(
isFocused = isFocused,
Expand Down Expand Up @@ -493,7 +503,7 @@ class SignUpFragment : BaseFragment<FragmentSignupBinding>() {
private fun createDuplicatedResultText(
isFocused: Boolean,
isSelected: Boolean,
uiModel: NickNameUiModel
uiModel: NickNameModel
): String {
return when {
!isSelected -> ""
Expand All @@ -511,7 +521,7 @@ class SignUpFragment : BaseFragment<FragmentSignupBinding>() {
private fun createDuplicatedEditTextBackgroundResId(
isFocused: Boolean,
isSelected: Boolean,
uiModel: NickNameUiModel
uiModel: NickNameModel
): Int {
return when {
!isSelected -> R.drawable.shape_rectangle_white_stroke_gray_300_r8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import com.polzzak_android.data.repository.SignUpRepository
import com.polzzak_android.presentation.common.model.ModelState
import com.polzzak_android.presentation.feature.auth.model.MemberTypeDetail.Companion.KID_TYPE_ID
import com.polzzak_android.presentation.feature.auth.model.SocialLoginType
import com.polzzak_android.presentation.feature.auth.signup.model.MemberTypeUiModel
import com.polzzak_android.presentation.feature.auth.signup.model.NickNameUiModel
import com.polzzak_android.presentation.feature.auth.signup.model.MemberTypeModel
import com.polzzak_android.presentation.feature.auth.signup.model.NickNameModel
import com.polzzak_android.presentation.feature.auth.signup.model.NickNameValidationState
import com.polzzak_android.presentation.feature.auth.signup.model.ProfileImageUiModel
import com.polzzak_android.presentation.feature.auth.signup.model.ProfileImageModel
import com.polzzak_android.presentation.feature.auth.signup.model.SignUpPage
import com.polzzak_android.presentation.feature.auth.signup.model.SignUpResultUiModel
import com.polzzak_android.presentation.feature.auth.signup.model.SignUpResultModel
import com.polzzak_android.presentation.feature.auth.signup.model.SignUpTermsOfServiceModel
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
Expand All @@ -32,18 +32,18 @@ class SignUpViewModel @AssistedInject constructor(
private val _pageLiveData = MutableLiveData<SignUpPage>()
val pageLiveData: LiveData<SignUpPage> = _pageLiveData

private val _nickNameLiveData = MutableLiveData<NickNameUiModel>()
val nickNameLiveData: LiveData<NickNameUiModel> = _nickNameLiveData
private val _nickNameLiveData = MutableLiveData<NickNameModel>()
val nickNameLiveData: LiveData<NickNameModel> = _nickNameLiveData

private val _memberTypeLiveData = MutableLiveData<MemberTypeUiModel>()
val memberTypeLiveData: LiveData<MemberTypeUiModel> = _memberTypeLiveData
private val _memberTypeLiveData = MutableLiveData<MemberTypeModel>()
val memberTypeLiveData: LiveData<MemberTypeModel> = _memberTypeLiveData

private val _profileImageLiveData = MutableLiveData<ProfileImageUiModel>(ProfileImageUiModel())
val profileImageLiveData: LiveData<ProfileImageUiModel> = _profileImageLiveData
private val _profileImageLiveData = MutableLiveData<ProfileImageModel>(ProfileImageModel())
val profileImageLiveData: LiveData<ProfileImageModel> = _profileImageLiveData

private val _signUpResultLiveData =
MutableLiveData<EventWrapper<ModelState<SignUpResultUiModel>>>()
val signUpResultLiveData: LiveData<EventWrapper<ModelState<SignUpResultUiModel>>> =
MutableLiveData<EventWrapper<ModelState<SignUpResultModel>>>()
val signUpResultLiveData: LiveData<EventWrapper<ModelState<SignUpResultModel>>> =
_signUpResultLiveData

private val _termsOfServiceLiveData = MutableLiveData<SignUpTermsOfServiceModel>()
Expand Down Expand Up @@ -106,34 +106,34 @@ class SignUpViewModel @AssistedInject constructor(

fun selectTypeParent() {
if (memberTypeLiveData.value?.isParent() == true) return
_memberTypeLiveData.value = MemberTypeUiModel(selectedType = MemberTypeUiModel.Type.PARENT)
_memberTypeLiveData.value = MemberTypeModel(selectedType = MemberTypeModel.Type.PARENT)
}

fun selectTypeKid() {
if (memberTypeLiveData.value?.isKid() == true) return
_memberTypeLiveData.value =
MemberTypeUiModel(
selectedType = MemberTypeUiModel.Type.KID,
MemberTypeModel(
selectedType = MemberTypeModel.Type.KID,
selectedTypeId = KID_TYPE_ID
)
}

fun selectParentType(selectedTypeId: Int?) {
val memberTypeUiModel = memberTypeLiveData.value ?: MemberTypeUiModel()
_memberTypeLiveData.value = memberTypeUiModel.copy(selectedTypeId = selectedTypeId)
val memberTypeModel = memberTypeLiveData.value ?: MemberTypeModel()
_memberTypeLiveData.value = memberTypeModel.copy(selectedTypeId = selectedTypeId)
}

fun setNickNameValue(nickName: String) {
checkNickNameValidationJob?.cancel()
val prevData = _nickNameLiveData.value ?: NickNameUiModel()
_nickNameLiveData.value = NickNameUiModel(
val prevData = _nickNameLiveData.value ?: NickNameModel()
_nickNameLiveData.value = NickNameModel(
nickName = nickName,
isEdited = prevData.isEdited || nickName.isNotEmpty()
)
}

fun setProfileImagePath(path: String?) {
_profileImageLiveData.value = ProfileImageUiModel(path = path)
_profileImageLiveData.value = ProfileImageModel(path = path)
}

fun requestCheckNickNameValidation() {
Expand Down Expand Up @@ -184,9 +184,9 @@ class SignUpViewModel @AssistedInject constructor(
profileImagePath = profileImageLiveData.value?.path
).onSuccess { signUpResponseData ->
signUpResponseData?.accessToken?.let {
val signUpResultUiModel =
SignUpResultUiModel(accessToken = it, memberTypeId = memberTypeId)
setSignUpResultSuccess(data = signUpResultUiModel)
val signUpResultModel =
SignUpResultModel(accessToken = it, memberTypeId = memberTypeId)
setSignUpResultSuccess(data = signUpResultModel)
} ?: run {
setSignUpResultError()
}
Expand Down Expand Up @@ -216,7 +216,7 @@ class SignUpViewModel @AssistedInject constructor(
_signUpResultLiveData.value = EventWrapper(ModelState.Loading())
}

private fun setSignUpResultSuccess(data: SignUpResultUiModel) {
private fun setSignUpResultSuccess(data: SignUpResultModel) {
_signUpResultLiveData.value = EventWrapper(ModelState.Success(data = data))

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.polzzak_android.presentation.feature.auth.signup.model

data class MemberTypeUiModel(
data class MemberTypeModel(
val selectedType: Type? = null,
val selectedTypeId: Int? = null
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.polzzak_android.presentation.feature.auth.signup.model

data class NickNameUiModel(
data class NickNameModel(
val nickName: String? = null,
val nickNameState: NickNameValidationState = NickNameValidationState.Unchecked,
val isEdited: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.polzzak_android.presentation.feature.auth.signup.model

data class ProfileImageUiModel(
data class ProfileImageModel(
val path: String? = null
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.polzzak_android.presentation.feature.auth.signup.model

data class SignUpResultUiModel(
data class SignUpResultModel(
val accessToken: String,
val memberTypeId: Int
)
Loading