Skip to content

Commit

Permalink
[Merge] feature/fix-delete-running-record -> develop
Browse files Browse the repository at this point in the history
[FIX] 러닝 기록 / 삭제 버튼 활성화 오류
  • Loading branch information
unam98 authored Nov 14, 2023
2 parents 929d9dd + 90b738a commit db27254
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class MyHistoryActivity : BindingActivity<ActivityMyHistoryBinding>(R.layout.act
binding.rvMyPageHistory.addItemDecoration(RecyclerOffsetDecorationHeight(this, 10))
}

private fun getRecord(){
private fun getRecord() {
viewModel.getRecord()
}

Expand Down Expand Up @@ -88,7 +88,7 @@ class MyHistoryActivity : BindingActivity<ActivityMyHistoryBinding>(R.layout.act
binding.btnMyPageHistoryEditHistory.setOnClickListener {
handleEditClicked()
}
binding.tvMyPageHistoryDelete.setOnClickListener {
binding.btnMyPageHistoryDelete.setOnClickListener {
handleDeleteButtonClicked(it)
}
}
Expand All @@ -102,11 +102,11 @@ class MyHistoryActivity : BindingActivity<ActivityMyHistoryBinding>(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()
}
Expand All @@ -129,7 +129,7 @@ class MyHistoryActivity : BindingActivity<ActivityMyHistoryBinding>(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()
Expand All @@ -145,8 +145,8 @@ class MyHistoryActivity : BindingActivity<ActivityMyHistoryBinding>(R.layout.act
exitEditMode()
}
}
viewModel.selectedItemsCount.observe(this) { count ->
updateDeleteButton(count)
viewModel.itemsToDeleteLiveData.observe(this) {
updateDeleteButton(it.size)
}
}

Expand Down Expand Up @@ -195,15 +195,18 @@ class MyHistoryActivity : BindingActivity<ActivityMyHistoryBinding>(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)
}
}

Expand All @@ -215,7 +218,6 @@ class MyHistoryActivity : BindingActivity<ActivityMyHistoryBinding>(R.layout.act
}
}


override fun selectItem(data: HistoryInfoDTO): Boolean {
return if (viewModel.editMode.value == true) {
viewModel.modifyItemsToDelete(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,24 +33,14 @@ class MyHistoryViewModel @Inject constructor(private val userRepository: UserRep
val editMode: LiveData<Boolean>
get() = _editMode

private var itemsToDeleteLiveData = MutableLiveData<List<Int>>()
private var _itemsToDeleteLiveData = MutableLiveData<List<Int>>()
val itemsToDeleteLiveData: MutableLiveData<List<Int>>
get() = _itemsToDeleteLiveData

private var _itemsToDelete: MutableList<Int> = mutableListOf()
val itemsToDelete: List<Int>
get() = _itemsToDelete

val selectCountMediator = MediatorLiveData<List<Int>>()

init {
selectCountMediator.addSource(itemsToDeleteLiveData) {
setSelectedItemsCount(_itemsToDelete.count())
}
}

private var _selectedItemsCount = MutableLiveData(DEFAULT_SELECTED_COUNT)
val selectedItemsCount: LiveData<Int>
get() = _selectedItemsCount

val errorMessage = MutableLiveData<String>()

fun modifyItemsToDelete(id: Int) {
Expand All @@ -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}"
}
Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/res/layout/activity_my_history.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,17 @@
</androidx.cardview.widget.CardView>
</androidx.appcompat.widget.LinearLayoutCompat>

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_my_page_history_delete"
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/btn_my_page_history_delete"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginHorizontal="15dp"
android:layout_marginBottom="18dp"
android:background="@drawable/all_finish_btn_selector"
android:background="@drawable/radius_10_g3_button"
android:enabled="false"
android:fontFamily="@font/pretendard_semibold"
android:gravity="center"
android:outlineProvider="none"
android:text="@string/history_delete"
android:textColor="@color/W1"
android:textSize="15sp"
Expand Down

0 comments on commit db27254

Please sign in to comment.