Skip to content

Commit

Permalink
[AN] refactor: 모임 수정 UI 개선 (#479)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinuemong authored Aug 20, 2024
1 parent f94879c commit fe2c6b1
Show file tree
Hide file tree
Showing 23 changed files with 308 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fun ClubDetailDto.toDomain(): ClubDetail {
return ClubDetail(
id = id,
title = title,
content = title,
content = content,
allowedGender = allowedGender.map { it.toDomain() },
allowedSize = allowedSize.map { it.toDomain() },
ownerMemberName = ownerMemberName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ fun ClubStateDto.toDomain(): ClubState {
return when (this) {
ClubStateDto.OPEN -> ClubState.OPEN
ClubStateDto.CLOSE -> ClubState.CLOSE
ClubStateDto.FULL -> ClubState.FULL
}
}

fun ClubState.toData(): ClubStateDto {
return when (this) {
ClubState.OPEN -> ClubStateDto.OPEN
ClubState.CLOSE -> ClubStateDto.CLOSE
ClubState.CLOSE, ClubState.FULL -> ClubStateDto.CLOSE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package com.happy.friendogly.data.model
enum class ClubStateDto {
OPEN,
CLOSE,
FULL,
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ enum class ClubState(
val clubStateName: String,
) {
OPEN("모집중"),
CLOSE("모집완료"),
CLOSE("모집종료"),
FULL("모집완료"),
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ fun ClubDetail.toPresentation(): ClubDetailUiModel {
clubDate = createdAt,
currentNumberOfPeople = currentMemberCount,
clubLeaderName = ownerMemberName,
clubState = status,
clubLeaderImage = ownerImageUrl?.ifEmpty { null },
clubLocation = address.toPresentation(),
clubPoster = imageUrl?.ifEmpty { null },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ fun Club.toPresentation(): ClubItemUiModel {
currentNumberOfPeople = currentMemberCount,
content = content,
clubPets = petImageUrls.map { ClubPet(it?.ifEmpty { null }) },
canParticipate = status.toPresentation(),
clubState = status,
)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.happy.friendogly.presentation.ui.club.common.model

import com.happy.friendogly.domain.model.ClubState
import com.happy.friendogly.presentation.ui.club.common.model.clubfilter.ClubFilter
import kotlinx.datetime.LocalDateTime

data class ClubItemUiModel(
val clubId: Long,
val filters: List<ClubFilter>,
val clubPoster: String?,
val canParticipate: Boolean,
val clubState: ClubState,
val title: String,
val content: String,
val maximumNumberOfPeople: Int,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.happy.friendogly.presentation.ui.club.detail

import com.happy.friendogly.domain.model.ClubState
import com.happy.friendogly.presentation.ui.club.common.model.clubfilter.ClubFilter
import com.happy.friendogly.presentation.ui.club.detail.model.ClubDetailProfileUiModel
import com.happy.friendogly.presentation.ui.club.detail.model.ClubDetailViewType
Expand All @@ -16,6 +17,7 @@ data class ClubDetailUiModel(
val content: String,
val maximumNumberOfPeople: Int,
val currentNumberOfPeople: Int,
val clubState: ClubState,
val clubLocation: String,
val clubLeaderName: String,
val clubLeaderImage: String? = null,
Expand All @@ -27,7 +29,7 @@ data class ClubDetailUiModel(
return ClubModifyUiModel(
title = title,
content = content,
clubPoster = clubPoster,
clubState = clubState,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,12 @@ package com.happy.friendogly.presentation.ui.club.list
import android.widget.TextView
import androidx.databinding.BindingAdapter
import com.happy.friendogly.R
import com.happy.friendogly.domain.model.ClubState
import com.happy.friendogly.domain.model.UserAddress
import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.toJavaLocalDateTime
import java.time.Duration

@BindingAdapter("applyCanParticipation")
fun TextView.bindCanParticipationType(canParticipation: Boolean) {
this.text =
if (canParticipation) {
context.getString(R.string.club_participate_name)
} else {
context.getString(R.string.club_complete_participate_name)
}
}

@BindingAdapter("clubDateTime")
fun TextView.bindClubDateTime(dateTime: LocalDateTime?) {
dateTime ?: return
Expand Down Expand Up @@ -45,3 +36,13 @@ fun TextView.bindMyLocation(userAddress: UserAddress?) {
this.text =
userAddress?.adminArea ?: context.getString(R.string.club_list_my_location_default)
}

@BindingAdapter("clubStateTextStyle")
fun TextView.bindClubStateTextStyle(clubState: ClubState) {
val textStyle =
when (clubState) {
ClubState.OPEN -> context.getColor(R.color.coral500)
ClubState.CLOSE, ClubState.FULL -> context.getColor(R.color.gray700)
}
this.setTextColor(textStyle)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ interface ClubModifyActionHandler {

fun submitModify()

fun selectClubImage()
fun openSelectState()
}
Original file line number Diff line number Diff line change
@@ -1,43 +1,28 @@
package com.happy.friendogly.presentation.ui.club.modify

import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.net.Uri
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.core.net.toUri
import com.canhub.cropper.CropImageContract
import com.canhub.cropper.CropImageContractOptions
import com.canhub.cropper.CropImageOptions
import com.happy.friendogly.R
import com.happy.friendogly.databinding.ActivityClubModifyBinding
import com.happy.friendogly.presentation.base.BaseActivity
import com.happy.friendogly.presentation.base.observeEvent
import com.happy.friendogly.presentation.ui.profilesetting.bottom.EditProfileImageBottomSheet
import com.happy.friendogly.presentation.ui.club.modify.bottom.ClubRecruitmentBottomSheet
import com.happy.friendogly.presentation.utils.customOnFocusChangeListener
import com.happy.friendogly.presentation.utils.hideKeyboard
import com.happy.friendogly.presentation.utils.intentSerializable
import com.happy.friendogly.presentation.utils.putSerializable
import com.happy.friendogly.presentation.utils.toBitmap

class ClubModifyActivity :
BaseActivity<ActivityClubModifyBinding>(R.layout.activity_club_modify) {
private val viewModel: ClubModifyViewModel by viewModels()

private lateinit var imagePickerLauncher: ActivityResultLauncher<String>
private lateinit var imageCropLauncher: ActivityResultLauncher<CropImageContractOptions>
private lateinit var cropImageOptions: CropImageOptions

override fun initCreateView() {
initDataBinding()
initEditText()
initObserver()
initUiModel()
initImageLaunchers()
}

private fun initDataBinding() {
Expand All @@ -49,7 +34,6 @@ class ClubModifyActivity :
intent.intentSerializable(CLUB_MODIFY_UI_MODEL, ClubModifyUiModel.serializer())
clubModifyUiModel?.let {
viewModel.initUiModel(
posterBitmap = clubModifyUiModel.clubPoster?.toUri()?.toBitmap(this),
clubModifyUiModel = clubModifyUiModel,
)
}
Expand All @@ -71,61 +55,25 @@ class ClubModifyActivity :
viewModel.modifyEvent.observeEvent(this) { event ->
when (event) {
ClubModifyEvent.Navigation.NavigatePrev -> finish()
ClubModifyEvent.Navigation.NavigateToSelectClubPoster -> openClubPosterBottomSheet()

ClubModifyEvent.Navigation.NavigateSubmit -> {
intent.putExtra(SUCCESS_MODIFY_STATE, true)
setResult(Activity.RESULT_OK, intent)
setResult(RESULT_OK, intent)
finish()
}

ClubModifyEvent.Navigation.NavigateSelectState -> openSelectState()
ClubModifyEvent.FailModify -> showSnackbar(getString(R.string.club_modify_fail))
}
}
}

private fun initImageLaunchers() {
cropImageOptions =
CropImageOptions(
fixAspectRatio = true,
aspectRatioX = 1,
aspectRatioY = 1,
toolbarColor = Color.WHITE,
toolbarBackButtonColor = Color.BLACK,
toolbarTintColor = Color.BLACK,
allowFlipping = false,
allowRotation = false,
cropMenuCropButtonTitle = getString(R.string.image_cropper_done),
imageSourceIncludeCamera = false,
)

imagePickerLauncher =
registerForActivityResult(ActivityResultContracts.GetContent()) { uri ->
if (uri == null) return@registerForActivityResult
val cropOptions = CropImageContractOptions(uri, cropImageOptions)
imageCropLauncher.launch(cropOptions)
}

imageCropLauncher =
registerForActivityResult(CropImageContract()) { result ->
if (result.isSuccessful) {
val uri = result.uriContent ?: return@registerForActivityResult
handleCroppedImage(uri = uri)
}
private fun openSelectState() {
val bottomSheet =
ClubRecruitmentBottomSheet { state ->
viewModel.updateClubState(state)
}
}

private fun handleCroppedImage(uri: Uri) {
val bitmap = uri.toBitmap(this)
viewModel.updateClubPoster(bitmap)
}

private fun openClubPosterBottomSheet() {
val dialog =
EditProfileImageBottomSheet(
clickGallery = { imagePickerLauncher.launch("image/*") },
clickDefaultImage = { viewModel.updateClubPoster() },
)

dialog.show(supportFragmentManager, "TAG")
bottomSheet.show(supportFragmentManager, "TAG")
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.happy.friendogly.presentation.ui.club.modify

import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.databinding.BindingAdapter
import com.happy.friendogly.R
import com.happy.friendogly.domain.model.ClubState

@BindingAdapter("selectModifyStateBackground")
fun View.bindSelectModifyStateBackground(clubState: ClubState) {
val backgroundTint =
if (clubState == ClubState.FULL) {
ContextCompat.getColorStateList(
context,
R.color.gray300,
)
} else {
ContextCompat.getColorStateList(
context,
R.color.coral300,
)
}
this.backgroundTintList = backgroundTint
}

@BindingAdapter("selectModifyStateTypeStyle")
fun TextView.bindSelectModifyStateTypeStyle(clubState: ClubState) {
val textStyle =
if (clubState == ClubState.FULL) {
R.style.Theme_AppCompat_TextView_SemiBold_Gray07_Size14
} else {
R.style.Theme_AppCompat_TextView_SemiBold_White_Size14
}
this.setTextAppearance(textStyle)
}

@BindingAdapter("selectModifyStateImageTint")
fun ImageView.bindSelectModifyStateImageTint(clubState: ClubState) {
val backgroundTint =
if (clubState == ClubState.FULL) {
ContextCompat.getColorStateList(
context,
R.color.gray700,
)
} else {
ContextCompat.getColorStateList(
context,
R.color.white,
)
}
this.imageTintList = backgroundTint
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package com.happy.friendogly.presentation.ui.club.modify

sealed interface ClubModifyEvent {
sealed interface Navigation : ClubModifyEvent {
data object NavigateToSelectClubPoster : Navigation

data object NavigatePrev : Navigation

data object NavigateSubmit : Navigation

data object NavigateSelectState : Navigation
}

data object FailModify : ClubModifyEvent
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.happy.friendogly.presentation.ui.club.modify

import com.happy.friendogly.domain.model.ClubState
import kotlinx.serialization.Serializable

@Serializable
data class ClubModifyUiModel(
val title: String,
val content: String,
val clubPoster: String?,
val clubState: ClubState,
)
Loading

0 comments on commit fe2c6b1

Please sign in to comment.