Skip to content

Commit

Permalink
[AN] feat: 프로필 편집 (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
junjange authored and takoyakimchi committed Oct 23, 2024
1 parent dfa8c8a commit a1578c0
Show file tree
Hide file tree
Showing 26 changed files with 253 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ fun MemberDto.toDomain(): Member {
name = name,
tag = tag,
email = email,
imageUrl = imageUrl,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ data class MemberDto(
val name: String,
val tag: String,
val email: String,
val imageUrl: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ data class Member(
val name: String,
val tag: String,
val email: String,
val imageUrl: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ data class Pet(
) {
val age: Int
get() {
val currentDate = getCurrentDate()
return if (isAtLeastOneYearOld) {
currentDate.year - birthDate.year
} else {
Expand All @@ -26,11 +27,15 @@ data class Pet(
}

val isAtLeastOneYearOld: Boolean
get() = currentDate.year - birthDate.year > 0
get() = getCurrentDate().year - birthDate.year > MINIMUM_AGE

private fun getCurrentDate(): LocalDate {
val now: Instant = Clock.System.now()
val timeZone = TimeZone.currentSystemDefault()
return now.toLocalDateTime(timeZone).date
}

companion object {
private val now: Instant = Clock.System.now()
private val timeZone = TimeZone.currentSystemDefault()
private val currentDate = now.toLocalDateTime(timeZone).date
const val MINIMUM_AGE = 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import com.happy.friendogly.presentation.ui.mypage.MyPageFragment
import com.happy.friendogly.presentation.ui.permission.MultiPermission
import com.happy.friendogly.presentation.ui.petdetail.PetDetailActivity
import com.happy.friendogly.presentation.ui.petdetail.PetsDetail
import com.happy.friendogly.presentation.ui.profilesetting.ProfileSettingActivity
import com.happy.friendogly.presentation.ui.profilesetting.model.Profile
import com.happy.friendogly.presentation.ui.registerdog.RegisterDogActivity
import com.happy.friendogly.presentation.ui.setting.SettingActivity
import com.happy.friendogly.presentation.ui.woof.WoofFragment
Expand Down Expand Up @@ -102,6 +104,10 @@ class MainActivity :
startActivity(RegisterDogActivity.getIntent(this))
}

override fun navigateToProfileSetting(profile: Profile?) {
startActivity(ProfileSettingActivity.getIntent(this, profile))
}

override fun navigateToPetDetail(
currentPage: Int,
petsDetail: PetsDetail,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.happy.friendogly.presentation.ui

import com.happy.friendogly.presentation.ui.petdetail.PetsDetail
import com.happy.friendogly.presentation.ui.profilesetting.model.Profile

interface MainActivityActionHandler {
fun navigateToGroupDetailActivity(groupId: Long)
Expand All @@ -9,6 +10,8 @@ interface MainActivityActionHandler {

fun navigateToRegisterDog()

fun navigateToProfileSetting(profile: Profile?)

fun navigateToPetDetail(
currentPage: Int,
petsDetail: PetsDetail,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ class MyPageFragment : BaseFragment<FragmentMyPageBinding>(R.layout.fragment_my_

is MyPageNavigationAction.NavigateToDogRegister -> (activity as MainActivityActionHandler).navigateToRegisterDog()

is MyPageNavigationAction.NavigateToProfileEdit -> {}
is MyPageNavigationAction.NavigateToProfileEdit ->
(activity as MainActivityActionHandler).navigateToProfileSetting(profile = action.profile)

is MyPageNavigationAction.NavigateToMyClubManger -> {}
is MyPageNavigationAction.NavigateToMyParticipation -> {}
is MyPageNavigationAction.NavigateToPetEdit -> {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.happy.friendogly.presentation.ui.mypage

import com.happy.friendogly.presentation.ui.petdetail.PetsDetail
import com.happy.friendogly.presentation.ui.profilesetting.model.Profile

sealed interface MyPageNavigationAction {
data object NavigateToProfileEdit : MyPageNavigationAction
data class NavigateToProfileEdit(val profile: Profile?) : MyPageNavigationAction

data object NavigateToSetting : MyPageNavigationAction

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime
import java.time.LocalDate

data class MyPageUiState(
val id: Long = -1,
val id: Long = INVALID_ID,
val nickname: String = "",
val email: String = "",
val tag: String = "",
val profilePath: String? = null,
val imageUrl: String? = null,
val pets: List<PetViewType> = emptyList(),
)
) {
companion object {
private const val INVALID_ID = -1L
}
}

sealed interface PetViewType {
val id: Long
Expand All @@ -33,6 +36,7 @@ data class PetView(
) : PetViewType {
val age: Int
get() {
val currentDate = getCurrentDate()
return if (isAtLeastOneYearOld) {
currentDate.year - birthDate.year
} else {
Expand All @@ -41,12 +45,16 @@ data class PetView(
}

val isAtLeastOneYearOld: Boolean
get() = currentDate.year - birthDate.year > 0
get() = getCurrentDate().year - birthDate.year > MINIMUM_AGE

private fun getCurrentDate(): kotlinx.datetime.LocalDate {
val now: Instant = Clock.System.now()
val timeZone = TimeZone.currentSystemDefault()
return now.toLocalDateTime(timeZone).date
}

companion object {
private val now: Instant = Clock.System.now()
private val timeZone = TimeZone.currentSystemDefault()
private val currentDate = now.toLocalDateTime(timeZone).date
const val MINIMUM_AGE = 0

fun from(pet: Pet): PetView {
return PetView(
Expand All @@ -70,14 +78,3 @@ data class PetAddView(
private const val INVALID_ID = -1L
}
}

// TODO 더미 데이터 모델
data class Dog(
val name: String,
val description: String,
val birthDate: LocalDate,
val sizeType: String,
val gender: String,
val isNeutered: Boolean,
val image: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.happy.friendogly.presentation.base.Event
import com.happy.friendogly.presentation.base.emit
import com.happy.friendogly.presentation.ui.petdetail.PetDetail
import com.happy.friendogly.presentation.ui.petdetail.PetsDetail
import com.happy.friendogly.presentation.ui.profilesetting.model.Profile
import kotlinx.coroutines.launch

class MyPageViewModel(
Expand Down Expand Up @@ -44,6 +45,7 @@ class MyPageViewModel(
nickname = member.name,
email = member.email,
tag = member.tag,
imageUrl = member.imageUrl,
)
}.onFailure {
// TODO 예외 처리
Expand Down Expand Up @@ -100,7 +102,13 @@ class MyPageViewModel(
}

override fun navigateToProfileEdit() {
_navigateAction.emit(MyPageNavigationAction.NavigateToProfileEdit)
val state = uiState.value ?: return
val profile =
Profile(
name = state.nickname,
imageUrl = state.imageUrl,
)
_navigateAction.emit(MyPageNavigationAction.NavigateToProfileEdit(profile = profile))
}

fun navigateToSetting() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fun ImageView.bindGenderDrawable(gender: Gender) {
fun TextView.bindNeuteredTitle(gender: Gender) {
when (gender) {
Gender.MALE_NEUTERED, Gender.FEMALE_NEUTERED -> {
text = "중성화를 했어요"
text = context.getString(R.string.neuterd_status)
visibility = View.VISIBLE
}

Expand All @@ -74,9 +74,9 @@ fun TextView.bindNeuteredTitle(gender: Gender) {
fun TextView.bindDogSize(sizeType: SizeType) {
text =
when (sizeType) {
SizeType.SMALL -> "소형견이에요"
SizeType.MEDIUM -> "중현견이에요"
SizeType.LARGE -> "대형견이에요"
SizeType.SMALL -> context.getString(R.string.small_pet_description)
SizeType.MEDIUM -> context.getString(R.string.medium_pet_description)
SizeType.LARGE -> context.getString(R.string.large_pet_description)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ data class PetDetail(
) {
val age: Int
get() {
val currentDate = getCurrentDate()
return if (isAtLeastOneYearOld) {
currentDate.year - birthDate.year
} else {
Expand All @@ -38,11 +39,15 @@ data class PetDetail(
}

val isAtLeastOneYearOld: Boolean
get() = currentDate.year - birthDate.year > 0
get() = getCurrentDate().year - birthDate.year > MINIMUM_AGE

private fun getCurrentDate(): LocalDate {
val now: Instant = Clock.System.now()
val timeZone = TimeZone.currentSystemDefault()
return now.toLocalDateTime(timeZone).date
}

companion object {
private val now: Instant = Clock.System.now()
private val timeZone = TimeZone.currentSystemDefault()
private val currentDate = now.toLocalDateTime(timeZone).date
const val MINIMUM_AGE = 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ import androidx.core.content.ContextCompat
import androidx.databinding.BindingAdapter
import com.happy.friendogly.R

@BindingAdapter("profileSettingTitle")
fun TextView.bindProfileSettingTitle(isFirstTimeSetup: Boolean) {
text =
if (isFirstTimeSetup) {
context.getString(R.string.make_profile_title)
} else {
context.getString(R.string.make_profile_edit_title)
}
}

@SuppressLint("SetTextI18n")
@BindingAdapter("editTextLength")
fun TextView.bindEditTextLength(contents: String?) {
Expand All @@ -19,17 +29,15 @@ fun TextView.bindEditTextLength(contents: String?) {
}

this.apply {
text = "$length/15"
text = context.getString(R.string.user_name_length, length)
setTextColor(color)
}
}

@SuppressLint("UseCompatLoadingForDrawables")
@BindingAdapter("editBtnBackgroundTextColor")
fun TextView.bindEditBtnBackground(contents: String?) {
val length = contents?.length ?: 0

if (length > 0) {
fun TextView.bindEditBtnBackground(isButtonActive: Boolean) {
if (isButtonActive) {
this.background = context.getDrawable(R.drawable.rect_coral04_fill_16)
this.setTextColor(context.getColor(R.color.gray100))
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import com.happy.friendogly.presentation.base.BaseActivity
import com.happy.friendogly.presentation.base.observeEvent
import com.happy.friendogly.presentation.ui.MainActivity
import com.happy.friendogly.presentation.ui.profilesetting.bottom.EditProfileImageBottomSheet
import com.happy.friendogly.presentation.ui.profilesetting.model.Profile
import com.happy.friendogly.presentation.utils.customOnFocusChangeListener
import com.happy.friendogly.presentation.utils.hideKeyboard
import com.happy.friendogly.presentation.utils.putSerializable
import com.happy.friendogly.presentation.utils.saveBitmapToFile
import com.happy.friendogly.presentation.utils.toBitmap
import com.happy.friendogly.presentation.utils.toMultipartBody
Expand Down Expand Up @@ -122,8 +124,16 @@ class ProfileSettingActivity :
}

companion object {
fun getIntent(context: Context): Intent {
return Intent(context, ProfileSettingActivity::class.java)
const val PUT_EXTRA_PROFILE = "PUT_EXTRA_PROFILE"

fun getIntent(
context: Context,
profile: Profile?,
): Intent {
return Intent(context, ProfileSettingActivity::class.java).apply {
profile ?: return@apply
putSerializable(PUT_EXTRA_PROFILE, profile, Profile.serializer())
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import android.graphics.Bitmap
import okhttp3.MultipartBody

data class ProfileSettingUiState(
val isFirstTimeSetup: Boolean = true,
val beforeName: String = "",
val beforeProfileImageUrl: String? = null,
val profileImage: Bitmap? = null,
val profileImageUrl: String? = null,
val profilePath: MultipartBody.Part? = null,
)
Loading

0 comments on commit a1578c0

Please sign in to comment.