diff --git a/app/src/main/java/com/runnect/runnect/presentation/mypage/history/detail/MyHistoryDetailActivity.kt b/app/src/main/java/com/runnect/runnect/presentation/mypage/history/detail/MyHistoryDetailActivity.kt index 1d4a8d109..5ed2e7f85 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/mypage/history/detail/MyHistoryDetailActivity.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/mypage/history/detail/MyHistoryDetailActivity.kt @@ -29,8 +29,6 @@ import dagger.hilt.android.AndroidEntryPoint class MyHistoryDetailActivity : BindingActivity(R.layout.activity_my_history_detail) { private val viewModel: MyHistoryDetailViewModel by viewModels() - private var currentScreenMode: ScreenMode = ScreenMode.ReadOnlyMode - private var temporarilySavedTitle: String = "" override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -62,29 +60,21 @@ class MyHistoryDetailActivity : } private fun enterReadMode() { - updateCurrentScreenMode(ScreenMode.ReadOnlyMode) + viewModel.updateCurrentScreenMode(ScreenMode.ReadOnlyMode) updateTitleInputType() updateMoreButtonVisibility(true) updateConstraintForReadMode() } private fun enterEditMode() { - updateCurrentScreenMode(ScreenMode.EditMode) + viewModel.updateCurrentScreenMode(ScreenMode.EditMode) updateTitleInputType() updateMoreButtonVisibility(false) updateConstraintForEditMode() // 중간에 수정을 취소하면 원래 제목으로 되돌리기 위해 - // 현재 제목을 전역 변수에 저장해둔다. - saveTemporarilyCurrentTitle() - } - - private fun saveTemporarilyCurrentTitle() { - temporarilySavedTitle = viewModel.title - } - - private fun updateCurrentScreenMode(mode: ScreenMode) { - currentScreenMode = mode + // 현재 제목을 뷰모델에 저장해둔다. + viewModel.saveCurrentTitle() } private fun updateMoreButtonVisibility(isVisible: Boolean) { @@ -115,7 +105,7 @@ class MyHistoryDetailActivity : } private fun handleBackButtonByCurrentScreenMode() { - when (currentScreenMode) { + when (viewModel.currentScreenMode) { is ScreenMode.ReadOnlyMode -> navigateToPreviousScreen() is ScreenMode.EditMode -> showStopEditingDialog() } @@ -251,7 +241,7 @@ class MyHistoryDetailActivity : } private fun updateTitleInputType() { - when (currentScreenMode) { + when (viewModel.currentScreenMode) { is ScreenMode.ReadOnlyMode -> { binding.etCourseTitle.inputType = InputType.TYPE_NULL } @@ -284,7 +274,7 @@ class MyHistoryDetailActivity : onNegativeButtonClicked = {}, onPositiveButtonClicked = { // 편집 모드 -> 뒤로가기 버튼 -> 편집 중단 확인 -> 뷰에 원래 제목으로 보여줌. - viewModel.updateHistoryTitle(temporarilySavedTitle) + viewModel.restoreOriginalTitle() enterReadMode() } ) diff --git a/app/src/main/java/com/runnect/runnect/presentation/mypage/history/detail/MyHistoryDetailViewModel.kt b/app/src/main/java/com/runnect/runnect/presentation/mypage/history/detail/MyHistoryDetailViewModel.kt index 03495adc2..87891da6f 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/mypage/history/detail/MyHistoryDetailViewModel.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/mypage/history/detail/MyHistoryDetailViewModel.kt @@ -34,6 +34,10 @@ class MyHistoryDetailViewModel @Inject constructor(private val userRepository: U val isValidTitle: LiveData = _title.map { it.isNotBlank() } + private var _currentScreenMode: ScreenMode = ScreenMode.ReadOnlyMode + val currentScreenMode get() = _currentScreenMode + + private var savedTitle: String = "" private var historyId: Int = -1 fun updateHistoryTitle(title: String) { @@ -44,6 +48,18 @@ class MyHistoryDetailViewModel @Inject constructor(private val userRepository: U historyId = id } + fun saveCurrentTitle() { + savedTitle = title + } + + fun restoreOriginalTitle() { + _title.value = savedTitle + } + + fun updateCurrentScreenMode(mode: ScreenMode) { + _currentScreenMode = mode + } + fun deleteHistory() { viewModelScope.launch { _historyDeleteState.value = UiStateV2.Loading