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

[FIX/#208] 투두 생성, 조회 뷰 / 메모 빈칸 대응 수정 #210

Merged
merged 5 commits into from
Mar 1, 2024
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 @@ -13,6 +13,8 @@ import com.going.presentation.R
import com.going.presentation.databinding.ActivityTodoCreateBinding
import com.going.presentation.todo.TodoActivity.Companion.EXTRA_TRIP_ID
import com.going.ui.base.BaseActivity
import com.going.ui.extension.colorOf
import com.going.ui.extension.drawableOf
import com.going.ui.extension.setOnSingleClickListener
import com.going.ui.extension.toast
import com.going.ui.state.UiState
Expand Down Expand Up @@ -48,6 +50,7 @@ class TodoCreateActivity : BaseActivity<ActivityTodoCreateBinding>(R.layout.acti
setEtTodoMemoArguments()
observeNameTextChanged()
observeMemoTextChanged()
observeEndDateSelected()
}

private fun initViewModel() {
Expand Down Expand Up @@ -163,6 +166,18 @@ class TodoCreateActivity : BaseActivity<ActivityTodoCreateBinding>(R.layout.acti
}
}

private fun observeEndDateSelected() {
viewModel.endDate.observe(this) {
if (!viewModel.endDate.value.isNullOrEmpty()) {
with(binding) {
etTodoCreateDate.background = drawableOf(R.drawable.shape_rect_4_gray700_line)
tvTodoCreateDateHint.setTextColor(colorOf(R.color.gray_700))
ivTodoCreateDate.setImageResource(R.drawable.ic_dropdown_gray700)
Comment on lines +170 to +175
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오오 굿굿 깔끔하네욥

}
}
}
}

override fun onDestroy() {
super.onDestroy()
_adapter = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ class TodoCreateViewModel @Inject constructor(
private val todoRepository: TodoRepository,
) : ViewModel() {

val todo = MutableLiveData("")
private val todo = MutableLiveData("")
private val memo = MutableLiveData("")
Comment on lines +22 to +23
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

어떤경우에 LiveData를 사용하고, 어떤 경우에 StateFlow를 사용하는지 선택 기준이 궁금합니다!
저는 대부분 초기값이 있어야 하는 경우는 StateFlow를 사용하는 것 같습니다 :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 궁금합니다..!!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 저도 최근에 같은 고민했었습니다😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StateFlow를 사용하는 것을 권장드리긴 합니다만,
LiveData를 사용해둔 부분들은 모두 xml과의 데이터바인딩이 연결된 변수들입니다!

StateFlow와 같은 경우는 계속해서 상태값을 지니고 있기에 백패킹(_달아주는거)으로 안정성을 보장해주는 것이 꼭 권장되는데,
백패킹으로 설정해두게 되면 데이터바인딩을 활용이 어려워졌었던 것 같아서 우선은 LiveData로 구현해뒀습니다.

LiveData가 이후에 deprecated된다면 데이터바인딩도 함께 사라질테니,
지금 상황처럼 데이터바인딩만을 위해서 변수 설정을 해두는 경우라면 LiveDat로 두어도 문제는 없을 것 같습니다 !


val endDate = MutableLiveData("")
val memo = MutableLiveData("")

private val isTodoAvailable = MutableLiveData(false)
private val isMemoAvailable = MutableLiveData(false)
private val isMemoAvailable = MutableLiveData(true)
val isFinishAvailable = MutableLiveData(false)

private val _todoCreateState = MutableStateFlow<UiState<Unit>>(UiState.Empty)
Expand All @@ -43,13 +44,13 @@ class TodoCreateViewModel @Inject constructor(

fun setMemoState(memoText: String, state: EditTextState) {
memo.value = memoText
isMemoAvailable.value = state == EditTextState.SUCCESS
isMemoAvailable.value = state != EditTextState.OVER
checkIsFinishAvailable()
}

fun checkIsFinishAvailable() {
isFinishAvailable.value =
isTodoAvailable.value == true && isMemoAvailable.value == true && participantModelList.any { it.isSelected }
isTodoAvailable.value == true && isMemoAvailable.value == true && !endDate.value.isNullOrEmpty() && participantModelList.any { it.isSelected }
}

fun postToCreateTodoFromServer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.activity.viewModels
import androidx.core.view.isVisible
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import com.going.presentation.R
import com.going.presentation.databinding.ActivityTodoDetailBinding
import com.going.presentation.todo.create.TodoCreateActivity
import com.going.ui.base.BaseActivity
import com.going.ui.extension.colorOf
import com.going.ui.extension.drawableOf
import com.going.ui.extension.setOnSingleClickListener
import com.going.ui.extension.stringOf
import com.going.ui.extension.toast
import com.going.ui.state.EnumUiState
import com.going.ui.state.UiState
Expand Down Expand Up @@ -94,13 +98,21 @@ class TodoDetailActivity :

is UiState.Success -> {
if (isPublic) {
adapter.submitList(state.data)
adapter.submitList(state.data.allocators)
} else {
with(binding) {
rvOurTodoDetailPerson.visibility = View.INVISIBLE
layoutMyTodoCreatePerson.visibility = View.VISIBLE
}
}
if (state.data.memo.isBlank()) {
with(binding) {
etTodoCreateMemo.background = drawableOf(R.drawable.shape_rect_4_gray200_line)
etTodoCreateMemo.text = stringOf(R.string.my_todo_create_tv_memo_hint)
Comment on lines +108 to +111
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with(binding) 습관화 하시는 것 같은데 좋네요!!

etTodoCreateMemo.setTextColor(colorOf(R.color.gray_200))
tvTodoMemoCounter.isVisible = false
}
}
}

is UiState.Failure -> toast(getString(R.string.server_error))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.going.domain.entity.response.TodoAllocatorModel
import com.going.domain.entity.response.TodoDetailModel
import com.going.domain.repository.TodoRepository
import com.going.ui.state.EnumUiState
import com.going.ui.state.UiState
Expand All @@ -22,8 +23,8 @@ class TodoDetailViewModel @Inject constructor(
val endDate = MutableLiveData("")
val memo = MutableLiveData("")

private val _todoDetailState = MutableStateFlow<UiState<List<TodoAllocatorModel>>>(UiState.Empty)
val todoDetailState: StateFlow<UiState<List<TodoAllocatorModel>>> = _todoDetailState
private val _todoDetailState = MutableStateFlow<UiState<TodoDetailModel>>(UiState.Empty)
val todoDetailState: StateFlow<UiState<TodoDetailModel>> = _todoDetailState

private val _todoDeleteState = MutableStateFlow<EnumUiState>(EnumUiState.EMPTY)
val todoDeleteState: StateFlow<EnumUiState> = _todoDeleteState
Expand All @@ -36,7 +37,7 @@ class TodoDetailViewModel @Inject constructor(
todo.value = response.title
endDate.value = response.endDate
memo.value = response.memo
_todoDetailState.value = UiState.Success(response.allocators)
_todoDetailState.value = UiState.Success(response)
}
.onFailure {
_todoDetailState.value = UiState.Failure(it.message.toString())
Expand Down
9 changes: 9 additions & 0 deletions presentation/src/main/res/drawable/ic_dropdown_gray700.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="25dp"
android:height="24dp"
android:viewportWidth="25"
android:viewportHeight="24">
<path
android:pathData="M11.765,16.205C12.161,16.633 12.839,16.633 13.235,16.205L17.878,11.179C18.469,10.538 18.015,9.5 17.143,9.5H7.857C6.985,9.5 6.531,10.538 7.122,11.179L11.765,16.205Z"
android:fillColor="#1D1F29"/>
</vector>
Loading