diff --git a/app/src/main/java/com/runnect/runnect/presentation/mypage/history/MyHistoryActivity.kt b/app/src/main/java/com/runnect/runnect/presentation/mypage/history/MyHistoryActivity.kt index a9d0fb049..eff3a1420 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/mypage/history/MyHistoryActivity.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/mypage/history/MyHistoryActivity.kt @@ -57,7 +57,7 @@ class MyHistoryActivity : BindingActivity(R.layout.act binding.rvMyPageHistory.addItemDecoration(RecyclerOffsetDecorationHeight(this, 10)) } - private fun getRecord(){ + private fun getRecord() { viewModel.getRecord() } @@ -88,7 +88,7 @@ class MyHistoryActivity : BindingActivity(R.layout.act binding.btnMyPageHistoryEditHistory.setOnClickListener { handleEditClicked() } - binding.tvMyPageHistoryDelete.setOnClickListener { + binding.btnMyPageHistoryDelete.setOnClickListener { handleDeleteButtonClicked(it) } } @@ -102,11 +102,11 @@ class MyHistoryActivity : BindingActivity(R.layout.act private fun handleEditClicked() { viewModel.convertMode() - binding.tvMyPageHistoryDelete.isVisible = viewModel.editMode.value!! + binding.btnMyPageHistoryDelete.isVisible = viewModel.editMode.value!! } private fun handleDeleteButtonClicked(it: View) { - if (it.isActivated) { + if (it.isEnabled) { setDialogClickEvent() dialog.show() } @@ -129,7 +129,7 @@ class MyHistoryActivity : BindingActivity(R.layout.act } } viewModel.historyDeleteState.observe(this) { - updateDeleteButton(viewModel.selectedItemsCount.value ?: 0) + updateDeleteButton(viewModel.itemsToDelete.size) when (it) { UiState.Loading -> binding.indeterminateBar.isVisible = true UiState.Success -> handleSuccessfulHistoryDeletion() @@ -145,8 +145,8 @@ class MyHistoryActivity : BindingActivity(R.layout.act exitEditMode() } } - viewModel.selectedItemsCount.observe(this) { count -> - updateDeleteButton(count) + viewModel.itemsToDeleteLiveData.observe(this) { + updateDeleteButton(it.size) } } @@ -195,15 +195,18 @@ class MyHistoryActivity : BindingActivity(R.layout.act btnMyPageHistoryEditHistory.text = EDIT_MODE tvMyPageHistoryTotalCourseCount.text = viewModel.getHistoryCount() if (::adapter.isInitialized) adapter.clearSelection() - tvMyPageHistoryDelete.isVisible = viewModel.editMode.value!! + btnMyPageHistoryDelete.isVisible = viewModel.editMode.value ?: true viewModel.clearItemsToDelete() } } private fun updateDeleteButton(count: Int) { - with(binding.tvMyPageHistoryDelete) { - isActivated = count != 0 + val deleteBtnColor = + if (count > 0) R.drawable.radius_10_m1_button else R.drawable.radius_10_g3_button + with(binding.btnMyPageHistoryDelete) { + isEnabled = count != 0 text = updateDeleteButtonLabel(count) + setBackgroundResource(deleteBtnColor) } } @@ -215,7 +218,6 @@ class MyHistoryActivity : BindingActivity(R.layout.act } } - override fun selectItem(data: HistoryInfoDTO): Boolean { return if (viewModel.editMode.value == true) { viewModel.modifyItemsToDelete( diff --git a/app/src/main/java/com/runnect/runnect/presentation/mypage/history/MyHistoryViewModel.kt b/app/src/main/java/com/runnect/runnect/presentation/mypage/history/MyHistoryViewModel.kt index 416fc413c..dc4749af7 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/mypage/history/MyHistoryViewModel.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/mypage/history/MyHistoryViewModel.kt @@ -11,6 +11,7 @@ import com.runnect.runnect.domain.UserRepository import com.runnect.runnect.presentation.state.UiState import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch +import timber.log.Timber import javax.inject.Inject @HiltViewModel @@ -32,24 +33,14 @@ class MyHistoryViewModel @Inject constructor(private val userRepository: UserRep val editMode: LiveData get() = _editMode - private var itemsToDeleteLiveData = MutableLiveData>() + private var _itemsToDeleteLiveData = MutableLiveData>() + val itemsToDeleteLiveData: MutableLiveData> + get() = _itemsToDeleteLiveData private var _itemsToDelete: MutableList = mutableListOf() val itemsToDelete: List get() = _itemsToDelete - val selectCountMediator = MediatorLiveData>() - - init { - selectCountMediator.addSource(itemsToDeleteLiveData) { - setSelectedItemsCount(_itemsToDelete.count()) - } - } - - private var _selectedItemsCount = MutableLiveData(DEFAULT_SELECTED_COUNT) - val selectedItemsCount: LiveData - get() = _selectedItemsCount - val errorMessage = MutableLiveData() fun modifyItemsToDelete(id: Int) { @@ -66,11 +57,6 @@ class MyHistoryViewModel @Inject constructor(private val userRepository: UserRep itemsToDeleteLiveData.value = _itemsToDelete } - private fun setSelectedItemsCount(count: Int) { - _selectedItemsCount.value = count - } - - fun getHistoryCount(): String { return "총 기록 ${_historyItems.size}개" } @@ -104,9 +90,7 @@ class MyHistoryViewModel @Inject constructor(private val userRepository: UserRep viewModelScope.launch { runCatching { _historyDeleteState.value = UiState.Loading - setSelectedItemsCount( - count = DEFAULT_SELECTED_COUNT - ) + userRepository.putDeleteHistory( RequestDeleteHistoryDto( recordIdList = _itemsToDelete diff --git a/app/src/main/res/layout/activity_my_history.xml b/app/src/main/res/layout/activity_my_history.xml index 701523555..397e8985a 100644 --- a/app/src/main/res/layout/activity_my_history.xml +++ b/app/src/main/res/layout/activity_my_history.xml @@ -188,15 +188,17 @@ -