From 57e30d6367d20a38571953cf05b8a7405af7e7a0 Mon Sep 17 00:00:00 2001 From: sky8492002 Date: Mon, 12 Dec 2022 19:30:59 +0900 Subject: [PATCH 1/9] =?UTF-8?q?Issue=20#201=20feat=20:=20=EC=BB=A4?= =?UTF-8?q?=EB=AE=A4=EB=8B=88=ED=8B=B0=20=ED=99=94=EB=A9=B4=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=98=A4=ED=94=84=EB=9D=BC=EC=9D=B8=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mediator/SharedRoutineRemoteMediator.kt | 144 +++++++++--------- .../ui/share/SharedRoutineFragment.kt | 12 +- .../ui/share/SharedRoutineViewModel.kt | 47 ++++-- 3 files changed, 116 insertions(+), 87 deletions(-) diff --git a/app/src/main/java/com/lateinit/rightweight/data/mediator/SharedRoutineRemoteMediator.kt b/app/src/main/java/com/lateinit/rightweight/data/mediator/SharedRoutineRemoteMediator.kt index d05c654e..0efb3d42 100644 --- a/app/src/main/java/com/lateinit/rightweight/data/mediator/SharedRoutineRemoteMediator.kt +++ b/app/src/main/java/com/lateinit/rightweight/data/mediator/SharedRoutineRemoteMediator.kt @@ -20,8 +20,6 @@ import com.lateinit.rightweight.data.model.remote.StructuredQueryData import com.lateinit.rightweight.data.remote.model.IntValue import com.lateinit.rightweight.data.remote.model.TimeStampValue import kotlinx.coroutines.flow.first -import retrofit2.HttpException -import java.io.IOException @OptIn(ExperimentalPagingApi::class) class SharedRoutineRemoteMediator( @@ -41,96 +39,90 @@ class SharedRoutineRemoteMediator( loadType: LoadType, state: PagingState ): MediatorResult { - try { - var endOfPaginationReached = false + var endOfPaginationReached = false - var pagingFlag = when (loadType) { - LoadType.REFRESH -> "$INIT_MODIFIED_DATE_FLAG/$INIT_SHARED_COUNT_FLAG" - LoadType.PREPEND -> { - endOfPaginationReached = true - return MediatorResult.Success(endOfPaginationReached = endOfPaginationReached) - } - LoadType.APPEND -> { - val flag = appPreferencesDataStore.sharedRoutinePagingFlag.first() - flag.ifEmpty { "$INIT_MODIFIED_DATE_FLAG/$INIT_SHARED_COUNT_FLAG" } - } + var pagingFlag = when (loadType) { + LoadType.REFRESH -> "$INIT_MODIFIED_DATE_FLAG/$INIT_SHARED_COUNT_FLAG" + LoadType.PREPEND -> { + endOfPaginationReached = true + return MediatorResult.Success(endOfPaginationReached = endOfPaginationReached) + } + LoadType.APPEND -> { + val flag = appPreferencesDataStore.sharedRoutinePagingFlag.first() + flag.ifEmpty { "$INIT_MODIFIED_DATE_FLAG/$INIT_SHARED_COUNT_FLAG" } } + } - val splitedPagingFlag = pagingFlag.split("/") - var modifiedDateFlag = splitedPagingFlag[0] - var sharedCountFlag = splitedPagingFlag[1] - - when (sortType) { - SharedRoutineSortType.MODIFIED_DATE_FIRST -> { - runQueryBody = RunQueryBody( - StructuredQueryData( - from = FromData("shared_routine"), - orderBy = listOf( - OrderByData(FiledReferenceData("modified_date"), "DESCENDING"), - OrderByData(FiledReferenceData("shared_count.count"), "DESCENDING") - ), - limit = 10, - startAt = StartAtData( - listOf( - TimeStampValue(modifiedDateFlag), - IntValue(sharedCountFlag) - ) + val splitedPagingFlag = pagingFlag.split("/") + var modifiedDateFlag = splitedPagingFlag[0] + var sharedCountFlag = splitedPagingFlag[1] + + when (sortType) { + SharedRoutineSortType.MODIFIED_DATE_FIRST -> { + runQueryBody = RunQueryBody( + StructuredQueryData( + from = FromData("shared_routine"), + orderBy = listOf( + OrderByData(FiledReferenceData("modified_date"), "DESCENDING"), + OrderByData(FiledReferenceData("shared_count.count"), "DESCENDING") + ), + limit = 10, + startAt = StartAtData( + listOf( + TimeStampValue(modifiedDateFlag), + IntValue(sharedCountFlag) ) ) ) - } - SharedRoutineSortType.SHARED_COUNT_FIRST -> { - runQueryBody = RunQueryBody( - StructuredQueryData( - FromData("shared_routine"), - orderBy = listOf( - OrderByData(FiledReferenceData("shared_count.count"), "DESCENDING"), - OrderByData(FiledReferenceData("modified_date"), "DESCENDING") - ), - limit = 10, - startAt = StartAtData( - listOf( - IntValue(sharedCountFlag), - TimeStampValue(modifiedDateFlag) - ) + ) + } + SharedRoutineSortType.SHARED_COUNT_FIRST -> { + runQueryBody = RunQueryBody( + StructuredQueryData( + FromData("shared_routine"), + orderBy = listOf( + OrderByData(FiledReferenceData("shared_count.count"), "DESCENDING"), + OrderByData(FiledReferenceData("modified_date"), "DESCENDING") + ), + limit = 10, + startAt = StartAtData( + listOf( + IntValue(sharedCountFlag), + TimeStampValue(modifiedDateFlag) ) ) ) - } + ) } + } - val documentResponses = api.getSharedRoutines( - runQueryBody - ) + val documentResponses = api.getSharedRoutines( + runQueryBody + ) - db.withTransaction { - if (loadType == LoadType.REFRESH) { - appPreferencesDataStore.saveSharedRoutinePagingFlag("$INIT_MODIFIED_DATE_FLAG/$INIT_SHARED_COUNT_FLAG") - db.sharedRoutineDao().removeAllSharedRoutines() - } + db.withTransaction { + if (loadType == LoadType.REFRESH) { + appPreferencesDataStore.saveSharedRoutinePagingFlag("$INIT_MODIFIED_DATE_FLAG/$INIT_SHARED_COUNT_FLAG") + db.sharedRoutineDao().removeAllSharedRoutines() + } - documentResponses.forEach { documentResponse -> - if (documentResponse.document != null) { - db.sharedRoutineDao() - .insertSharedRoutine(documentResponse.document.toSharedRoutine()) - modifiedDateFlag = - documentResponse.document.fields.modifiedDate.value - sharedCountFlag = - documentResponse.document.fields.sharedCount.value.remoteData.count.value - pagingFlag = "$modifiedDateFlag/$sharedCountFlag" - } else { - endOfPaginationReached = true - } + documentResponses.forEach { documentResponse -> + if (documentResponse.document != null) { + db.sharedRoutineDao() + .insertSharedRoutine(documentResponse.document.toSharedRoutine()) + modifiedDateFlag = + documentResponse.document.fields.modifiedDate.value + sharedCountFlag = + documentResponse.document.fields.sharedCount.value.remoteData.count.value + pagingFlag = "$modifiedDateFlag/$sharedCountFlag" + } else { + endOfPaginationReached = true } - appPreferencesDataStore.saveSharedRoutinePagingFlag(pagingFlag) } - - return MediatorResult.Success(endOfPaginationReached = endOfPaginationReached) - } catch (e: IOException) { - return MediatorResult.Error(e) - } catch (e: HttpException) { - return MediatorResult.Error(e) + appPreferencesDataStore.saveSharedRoutinePagingFlag(pagingFlag) } + + return MediatorResult.Success(endOfPaginationReached = endOfPaginationReached) } companion object { diff --git a/app/src/main/java/com/lateinit/rightweight/ui/share/SharedRoutineFragment.kt b/app/src/main/java/com/lateinit/rightweight/ui/share/SharedRoutineFragment.kt index 92eeae18..ba35733d 100644 --- a/app/src/main/java/com/lateinit/rightweight/ui/share/SharedRoutineFragment.kt +++ b/app/src/main/java/com/lateinit/rightweight/ui/share/SharedRoutineFragment.kt @@ -1,6 +1,7 @@ package com.lateinit.rightweight.ui.share import android.os.Bundle +import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -46,11 +47,20 @@ class SharedRoutineFragment : Fragment(), SharedRoutineClickHandler { viewLifecycleOwner.collectOnLifecycle { viewModel.uiState.collect { uiState -> + Log.d("uiState", uiState.toString()) when (uiState) { is LatestSharedRoutineUiState.Success -> { sharedRoutinePagingAdapter.submitData(uiState.sharedRoutines) } - is LatestSharedRoutineUiState.Error -> Exception() + is LatestSharedRoutineUiState.Error -> { + Snackbar.make( + binding.root, + R.string.wrong_connection, + Snackbar.LENGTH_LONG + ).apply { + anchorView = binding.guideLineBottom + }.show() + } } } } diff --git a/app/src/main/java/com/lateinit/rightweight/ui/share/SharedRoutineViewModel.kt b/app/src/main/java/com/lateinit/rightweight/ui/share/SharedRoutineViewModel.kt index 181f57bf..c1b7a599 100644 --- a/app/src/main/java/com/lateinit/rightweight/ui/share/SharedRoutineViewModel.kt +++ b/app/src/main/java/com/lateinit/rightweight/ui/share/SharedRoutineViewModel.kt @@ -7,44 +7,71 @@ import androidx.paging.cachedIn import androidx.paging.map import com.lateinit.rightweight.data.mapper.local.toSharedRoutineSortType import com.lateinit.rightweight.data.repository.SharedRoutineRepository +import com.lateinit.rightweight.ui.login.NetworkState import com.lateinit.rightweight.ui.mapper.toSharedRoutineUiModel import com.lateinit.rightweight.ui.model.shared.SharedRoutineSortTypeUiModel import com.lateinit.rightweight.ui.model.shared.SharedRoutineUiModel import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch +import retrofit2.HttpException +import java.net.SocketException +import java.net.UnknownHostException import javax.inject.Inject @HiltViewModel class SharedRoutineViewModel @Inject constructor( private val sharedRoutineRepository: SharedRoutineRepository ) : ViewModel() { - private val _uiState = MutableStateFlow(LatestSharedRoutineUiState.Success(PagingData.empty())) + private val _uiState = + MutableStateFlow(LatestSharedRoutineUiState.Success(PagingData.empty())) val uiState: StateFlow = _uiState + val networkExceptionHandler = CoroutineExceptionHandler { _, throwable -> + when (throwable) { + is SocketException -> sendNetworkResultEvent(NetworkState.BAD_INTERNET) + is HttpException -> sendNetworkResultEvent(NetworkState.PARSE_ERROR) + is UnknownHostException -> sendNetworkResultEvent(NetworkState.WRONG_CONNECTION) + else -> sendNetworkResultEvent(NetworkState.OTHER_ERROR) + } + } + init { - viewModelScope.launch { - sharedRoutineRepository.getSharedRoutinesByPaging().cachedIn(this).collect{ sharedRoutinePagingData -> - val sharedRoutines = sharedRoutinePagingData.map { sharedRoutine -> - sharedRoutine.toSharedRoutineUiModel() + getSharedRoutinesByPaging() + } + + private fun getSharedRoutinesByPaging() { + viewModelScope.launch(networkExceptionHandler) { + sharedRoutineRepository.getSharedRoutinesByPaging().cachedIn(this) + .collect { sharedRoutinePagingData -> + val sharedRoutines = sharedRoutinePagingData.map { sharedRoutine -> + sharedRoutine.toSharedRoutineUiModel() + } + _uiState.value = LatestSharedRoutineUiState.Success(sharedRoutines) } - _uiState.value = LatestSharedRoutineUiState.Success(sharedRoutines) - } } } - fun setSharedRoutineSortType(sortTypeUiModel: SharedRoutineSortTypeUiModel){ + fun setSharedRoutineSortType(sortTypeUiModel: SharedRoutineSortTypeUiModel) { + getSharedRoutinesByPaging() viewModelScope.launch { sharedRoutineRepository.setSharedRoutineSortType(sortTypeUiModel.toSharedRoutineSortType()) } } + private fun sendNetworkResultEvent(state: NetworkState) { + viewModelScope.launch { + _uiState.value = LatestSharedRoutineUiState.Error(state) + } + } + } sealed class LatestSharedRoutineUiState { data class Success(val sharedRoutines: PagingData) : LatestSharedRoutineUiState() - data class Error(val exception: Throwable) : LatestSharedRoutineUiState() -} \ No newline at end of file + data class Error(val state: NetworkState) : LatestSharedRoutineUiState() +} From 850c2e44364e85d584c2d39d084d5c60152ff824 Mon Sep 17 00:00:00 2001 From: sky8492002 Date: Mon, 12 Dec 2022 20:15:05 +0900 Subject: [PATCH 2/9] =?UTF-8?q?Issue=20#201=20feat=20:=20=EA=B3=B5?= =?UTF-8?q?=EC=9C=A0=EB=90=9C=20=EB=A3=A8=ED=8B=B4=20=ED=99=94=EB=A9=B4?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=98=A4=ED=94=84=EB=9D=BC=EC=9D=B8=20?= =?UTF-8?q?=EC=83=81=ED=83=9C=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/share/SharedRoutineViewModel.kt | 12 ++-- .../detail/SharedRoutineDetailFragment.kt | 14 ++++- .../detail/SharedRoutineDetailViewModel.kt | 61 ++++++++++++++----- .../layout/fragment_shared_routine_detail.xml | 8 +++ 4 files changed, 73 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/com/lateinit/rightweight/ui/share/SharedRoutineViewModel.kt b/app/src/main/java/com/lateinit/rightweight/ui/share/SharedRoutineViewModel.kt index c1b7a599..baa8cc22 100644 --- a/app/src/main/java/com/lateinit/rightweight/ui/share/SharedRoutineViewModel.kt +++ b/app/src/main/java/com/lateinit/rightweight/ui/share/SharedRoutineViewModel.kt @@ -42,6 +42,12 @@ class SharedRoutineViewModel @Inject constructor( getSharedRoutinesByPaging() } + private fun sendNetworkResultEvent(state: NetworkState) { + viewModelScope.launch { + _uiState.value = LatestSharedRoutineUiState.Error(state) + } + } + private fun getSharedRoutinesByPaging() { viewModelScope.launch(networkExceptionHandler) { sharedRoutineRepository.getSharedRoutinesByPaging().cachedIn(this) @@ -61,12 +67,6 @@ class SharedRoutineViewModel @Inject constructor( } } - private fun sendNetworkResultEvent(state: NetworkState) { - viewModelScope.launch { - _uiState.value = LatestSharedRoutineUiState.Error(state) - } - } - } sealed class LatestSharedRoutineUiState { diff --git a/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailFragment.kt b/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailFragment.kt index 364ad5dc..a1727c9e 100644 --- a/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailFragment.kt +++ b/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailFragment.kt @@ -1,6 +1,7 @@ package com.lateinit.rightweight.ui.share.detail import android.os.Bundle +import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -9,6 +10,8 @@ import androidx.fragment.app.Fragment import androidx.fragment.app.setFragmentResult import androidx.fragment.app.viewModels import androidx.navigation.fragment.findNavController +import com.google.android.material.snackbar.Snackbar +import com.lateinit.rightweight.R import com.lateinit.rightweight.databinding.FragmentSharedRoutineDetailBinding import com.lateinit.rightweight.ui.model.routine.DayUiModel import com.lateinit.rightweight.ui.routine.detail.DetailExerciseAdapter @@ -75,6 +78,7 @@ class SharedRoutineDetailFragment : Fragment() { private fun setSharedRoutineDetailCollect() { viewLifecycleOwner.collectOnLifecycle { viewModel.uiState.collect { uiState -> + Log.d("uiState", uiState.toString()) when (uiState) { is LatestSharedRoutineDetailUiState.Success -> { binding.sharedRoutineUiModel = uiState.sharedRoutineUiModel @@ -89,7 +93,15 @@ class SharedRoutineDetailFragment : Fragment() { } } - is LatestSharedRoutineDetailUiState.Error -> Exception() + is LatestSharedRoutineDetailUiState.Error -> { + Snackbar.make( + binding.root, + R.string.wrong_connection, + Snackbar.LENGTH_LONG + ).apply { + anchorView = binding.guideLineBottom + }.show() + } } } } diff --git a/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailViewModel.kt b/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailViewModel.kt index 508e10ca..5cd612fc 100644 --- a/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailViewModel.kt +++ b/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailViewModel.kt @@ -14,12 +14,14 @@ import com.lateinit.rightweight.data.mapper.local.toRoutine import com.lateinit.rightweight.data.repository.RoutineRepository import com.lateinit.rightweight.data.repository.SharedRoutineRepository import com.lateinit.rightweight.data.repository.UserRepository +import com.lateinit.rightweight.ui.login.NetworkState import com.lateinit.rightweight.ui.mapper.toDayUiModel import com.lateinit.rightweight.ui.mapper.toSharedRoutineUiModel import com.lateinit.rightweight.ui.model.routine.DayUiModel import com.lateinit.rightweight.ui.model.shared.SharedRoutineUiModel import com.lateinit.rightweight.util.FIRST_DAY_POSITION import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted @@ -27,6 +29,9 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch +import retrofit2.HttpException +import java.net.SocketException +import java.net.UnknownHostException import java.util.UUID import javax.inject.Inject @@ -39,7 +44,7 @@ class SharedRoutineDetailViewModel @Inject constructor( val userInfo = userRepository.getUser().stateIn(viewModelScope, SharingStarted.Eagerly, null) - private val _uiState = MutableStateFlow( + private val _uiState = MutableStateFlow( LatestSharedRoutineDetailUiState.Success(null, mutableListOf()) ) val uiState: StateFlow = _uiState @@ -50,9 +55,24 @@ class SharedRoutineDetailViewModel @Inject constructor( private val _navigationEvent = MutableSharedFlow() val navigationEvent = _navigationEvent.asSharedFlow() + val networkExceptionHandler = CoroutineExceptionHandler { _, throwable -> + when (throwable) { + is SocketException -> sendNetworkResultEvent(NetworkState.BAD_INTERNET) + is HttpException -> sendNetworkResultEvent(NetworkState.PARSE_ERROR) + is UnknownHostException -> sendNetworkResultEvent(NetworkState.WRONG_CONNECTION) + else -> sendNetworkResultEvent(NetworkState.OTHER_ERROR) + } + } - fun getSharedRoutineDetail(routineId: String) { + private fun sendNetworkResultEvent(state: NetworkState) { viewModelScope.launch { + _uiState.value = LatestSharedRoutineDetailUiState.Error(state) + } + } + + + fun getSharedRoutineDetail(routineId: String) { + viewModelScope.launch(networkExceptionHandler) { sharedRoutineRepository.getSharedRoutineDetail(routineId) .collect { sharedRoutineWithDays -> @@ -67,30 +87,33 @@ class SharedRoutineDetailViewModel @Inject constructor( sharedRoutineWithDay.exercises ) } - ) - if (_uiState.value.dayUiModels.isNotEmpty()) { - initClickedDay() + ).apply { + if (this.dayUiModels.isNotEmpty()) { + initClickedDay(this) + } } } } } - private fun initClickedDay() { - val originDayUiModels = _uiState.value.dayUiModels.toMutableList() + private fun initClickedDay(successUiState:LatestSharedRoutineDetailUiState.Success) { + val originDayUiModels = successUiState.dayUiModels.toMutableList() originDayUiModels[FIRST_DAY_POSITION] = originDayUiModels[FIRST_DAY_POSITION].copy(selected = true) _currentDayPosition.value = FIRST_DAY_POSITION _uiState.value = LatestSharedRoutineDetailUiState.Success( - _uiState.value.sharedRoutineUiModel, + successUiState.sharedRoutineUiModel, originDayUiModels ) } fun clickDay(dayPosition: Int) { - if (_currentDayPosition.value == dayPosition) return + if (_currentDayPosition.value == dayPosition + || _uiState.value is LatestSharedRoutineDetailUiState.Error) return - val originDayUiModels = _uiState.value.dayUiModels.toMutableList() + val successUiState = _uiState.value as LatestSharedRoutineDetailUiState.Success + val originDayUiModels = successUiState.dayUiModels.toMutableList() val lastSelectedPosition = _currentDayPosition.value ?: return originDayUiModels[lastSelectedPosition] = @@ -99,14 +122,17 @@ class SharedRoutineDetailViewModel @Inject constructor( _currentDayPosition.value = dayPosition _uiState.value = LatestSharedRoutineDetailUiState.Success( - _uiState.value.sharedRoutineUiModel, + successUiState.sharedRoutineUiModel, originDayUiModels ) } fun clickExercise(exercisePosition: Int) { + if(_uiState.value is LatestSharedRoutineDetailUiState.Error) return + + val successUiState = _uiState.value as LatestSharedRoutineDetailUiState.Success val nowDayPosition = _currentDayPosition.value ?: return - val originDayUiModels = _uiState.value.dayUiModels.toMutableList() + val originDayUiModels = successUiState.dayUiModels.toMutableList() val originExerciseUiModels = originDayUiModels[nowDayPosition].exercises.toMutableList() val exerciseUiModel = originExerciseUiModels[exercisePosition] @@ -119,7 +145,7 @@ class SharedRoutineDetailViewModel @Inject constructor( _currentDayPosition.value = _currentDayPosition.value _uiState.value = LatestSharedRoutineDetailUiState.Success( - _uiState.value.sharedRoutineUiModel, + successUiState.sharedRoutineUiModel, originDayUiModels ) } @@ -148,7 +174,12 @@ class SharedRoutineDetailViewModel @Inject constructor( exercises.add(exerciseUiModel.toExerciseWithNewIds(dayId, exerciseId)) exerciseUiModel.exerciseSets.forEach { exerciseSetUiModel -> val exerciseSetId = createUUID() - exerciseSets.add(exerciseSetUiModel.toExerciseSetWithNewIds(exerciseId, exerciseSetId)) + exerciseSets.add( + exerciseSetUiModel.toExerciseSetWithNewIds( + exerciseId, + exerciseSetId + ) + ) } } } @@ -171,6 +202,6 @@ sealed class LatestSharedRoutineDetailUiState { val dayUiModels: List ) : LatestSharedRoutineDetailUiState() - data class Error(val exception: Throwable) : LatestSharedRoutineDetailUiState() + data class Error(val state: NetworkState) : LatestSharedRoutineDetailUiState() } diff --git a/app/src/main/res/layout/fragment_shared_routine_detail.xml b/app/src/main/res/layout/fragment_shared_routine_detail.xml index dc08c22f..0dbb8f69 100644 --- a/app/src/main/res/layout/fragment_shared_routine_detail.xml +++ b/app/src/main/res/layout/fragment_shared_routine_detail.xml @@ -172,5 +172,13 @@ app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" /> + + + \ No newline at end of file From 12b0e9ae4fb6503dd65e69d35c781365961a2ff2 Mon Sep 17 00:00:00 2001 From: sky8492002 Date: Mon, 12 Dec 2022 20:22:59 +0900 Subject: [PATCH 3/9] =?UTF-8?q?Issue=20#201=20feat=20:=20=EA=B3=B5?= =?UTF-8?q?=EC=9C=A0=EB=90=9C=20=EB=A3=A8=ED=8B=B4=20=ED=99=94=EB=A9=B4?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EA=B0=80=EC=A0=B8=EC=98=A4=EA=B8=B0=20?= =?UTF-8?q?=EB=B2=84=ED=8A=BC=20=ED=81=B4=EB=A6=AD=20=EC=8B=9C=20=EC=98=A4?= =?UTF-8?q?=ED=94=84=EB=9D=BC=EC=9D=B8=20=EC=83=81=ED=83=9C=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/share/detail/SharedRoutineDetailViewModel.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailViewModel.kt b/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailViewModel.kt index 5cd612fc..63d1ac5c 100644 --- a/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailViewModel.kt +++ b/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailViewModel.kt @@ -155,7 +155,7 @@ class SharedRoutineDetailViewModel @Inject constructor( dayUiModels: List ) { if (sharedRoutineUiModel != null) { - viewModelScope.launch { + viewModelScope.launch(networkExceptionHandler) { val sharedRoutineId = sharedRoutineUiModel.routineId val routine = sharedRoutineUiModel.toRoutine( createUUID(), @@ -184,8 +184,8 @@ class SharedRoutineDetailViewModel @Inject constructor( } } routineRepository.insertRoutine(routine, days, exercises, exerciseSets) - sharedRoutineRepository.increaseSharedCount(sharedRoutineId) _navigationEvent.emit(routine.routineId) + sharedRoutineRepository.increaseSharedCount(sharedRoutineId) } } } From ba80756a6c8a13508c3d4abd11848bf83e90b3e3 Mon Sep 17 00:00:00 2001 From: sky8492002 Date: Mon, 12 Dec 2022 20:37:01 +0900 Subject: [PATCH 4/9] =?UTF-8?q?Issue=20#201=20feat=20:=20=EA=B3=B5?= =?UTF-8?q?=EC=9C=A0=EB=90=9C=20=EB=A3=A8=ED=8B=B4=20=ED=99=94=EB=A9=B4?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EA=B0=80=EC=A0=B8=EC=98=A4=EA=B8=B0=20?= =?UTF-8?q?=EB=B2=84=ED=8A=BC=20=ED=81=B4=EB=A6=AD=20=EC=8B=9C=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../detail/SharedRoutineDetailFragment.kt | 19 ++++-- .../detail/SharedRoutineDetailViewModel.kt | 58 +++++++++---------- app/src/main/res/values/strings.xml | 1 + 3 files changed, 44 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailFragment.kt b/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailFragment.kt index a1727c9e..12710b69 100644 --- a/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailFragment.kt +++ b/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailFragment.kt @@ -86,10 +86,21 @@ class SharedRoutineDetailFragment : Fragment() { setCurrentDayPositionObserve(uiState.dayUiModels) binding.buttonRoutineImport.setOnClickListener { - viewModel.importSharedRoutineToMyRoutines( - uiState.sharedRoutineUiModel, - uiState.dayUiModels - ) + if(uiState.sharedRoutineUiModel != null){ + viewModel.importSharedRoutineToMyRoutines( + uiState.sharedRoutineUiModel, + uiState.dayUiModels + ) + } + else{ + Snackbar.make( + binding.root, + R.string.none_routine, + Snackbar.LENGTH_LONG + ).apply { + anchorView = binding.guideLineBottom + }.show() + } } } diff --git a/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailViewModel.kt b/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailViewModel.kt index 63d1ac5c..b0f8cd28 100644 --- a/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailViewModel.kt +++ b/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailViewModel.kt @@ -151,42 +151,40 @@ class SharedRoutineDetailViewModel @Inject constructor( } fun importSharedRoutineToMyRoutines( - sharedRoutineUiModel: SharedRoutineUiModel?, + sharedRoutineUiModel: SharedRoutineUiModel, dayUiModels: List ) { - if (sharedRoutineUiModel != null) { - viewModelScope.launch(networkExceptionHandler) { - val sharedRoutineId = sharedRoutineUiModel.routineId - val routine = sharedRoutineUiModel.toRoutine( - createUUID(), - userInfo.value?.displayName ?: "", - routineRepository.getHigherRoutineOrder()?.plus(1) ?: 0 - ) - val days = mutableListOf() - val exercises = mutableListOf() - val exerciseSets = mutableListOf() - - dayUiModels.forEach { dayUiModel -> - val dayId = createUUID() - days.add(dayUiModel.toDayWithNewIds(routine.routineId, dayId)) - dayUiModel.exercises.forEach { exerciseUiModel -> - val exerciseId = createUUID() - exercises.add(exerciseUiModel.toExerciseWithNewIds(dayId, exerciseId)) - exerciseUiModel.exerciseSets.forEach { exerciseSetUiModel -> - val exerciseSetId = createUUID() - exerciseSets.add( - exerciseSetUiModel.toExerciseSetWithNewIds( - exerciseId, - exerciseSetId - ) + viewModelScope.launch(networkExceptionHandler) { + val sharedRoutineId = sharedRoutineUiModel.routineId + val routine = sharedRoutineUiModel.toRoutine( + createUUID(), + userInfo.value?.displayName ?: "", + routineRepository.getHigherRoutineOrder()?.plus(1) ?: 0 + ) + val days = mutableListOf() + val exercises = mutableListOf() + val exerciseSets = mutableListOf() + + dayUiModels.forEach { dayUiModel -> + val dayId = createUUID() + days.add(dayUiModel.toDayWithNewIds(routine.routineId, dayId)) + dayUiModel.exercises.forEach { exerciseUiModel -> + val exerciseId = createUUID() + exercises.add(exerciseUiModel.toExerciseWithNewIds(dayId, exerciseId)) + exerciseUiModel.exerciseSets.forEach { exerciseSetUiModel -> + val exerciseSetId = createUUID() + exerciseSets.add( + exerciseSetUiModel.toExerciseSetWithNewIds( + exerciseId, + exerciseSetId ) - } + ) } } - routineRepository.insertRoutine(routine, days, exercises, exerciseSets) - _navigationEvent.emit(routine.routineId) - sharedRoutineRepository.increaseSharedCount(sharedRoutineId) } + routineRepository.insertRoutine(routine, days, exercises, exerciseSets) + _navigationEvent.emit(routine.routineId) + sharedRoutineRepository.increaseSharedCount(sharedRoutineId) } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cda4ca83..1ef2e41c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -67,6 +67,7 @@ stopwatch start and pause 프로필 이미지 인터넷 연결을 확인해주세요. + 가져올 루틴이 없습니다. 루틴이 저장되었습니다. 루틴명을 입력해주세요. 루틴 설명을 입력해주세요. From 8669e8d400f2d9306ca1b261055e368a47c96bec Mon Sep 17 00:00:00 2001 From: sky8492002 Date: Mon, 12 Dec 2022 20:38:12 +0900 Subject: [PATCH 5/9] =?UTF-8?q?Issue=20#201=20refactor=20:=20convention?= =?UTF-8?q?=EC=97=90=20=EB=A7=9E=EA=B2=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/share/detail/SharedRoutineDetailFragment.kt | 7 +++---- .../ui/share/detail/SharedRoutineDetailViewModel.kt | 7 ++++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailFragment.kt b/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailFragment.kt index 12710b69..7c7fcf32 100644 --- a/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailFragment.kt +++ b/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailFragment.kt @@ -86,13 +86,12 @@ class SharedRoutineDetailFragment : Fragment() { setCurrentDayPositionObserve(uiState.dayUiModels) binding.buttonRoutineImport.setOnClickListener { - if(uiState.sharedRoutineUiModel != null){ + if (uiState.sharedRoutineUiModel != null) { viewModel.importSharedRoutineToMyRoutines( uiState.sharedRoutineUiModel, uiState.dayUiModels ) - } - else{ + } else { Snackbar.make( binding.root, R.string.none_routine, @@ -129,7 +128,7 @@ class SharedRoutineDetailFragment : Fragment() { private fun handleNavigationEvent() { viewLifecycleOwner.collectOnLifecycle { - viewModel.navigationEvent.collect { + viewModel.navigationEvent.collect { setFragmentResult("routineCopy", bundleOf()) findNavController().navigateUp() } diff --git a/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailViewModel.kt b/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailViewModel.kt index b0f8cd28..0c24278c 100644 --- a/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailViewModel.kt +++ b/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailViewModel.kt @@ -97,7 +97,7 @@ class SharedRoutineDetailViewModel @Inject constructor( } } - private fun initClickedDay(successUiState:LatestSharedRoutineDetailUiState.Success) { + private fun initClickedDay(successUiState: LatestSharedRoutineDetailUiState.Success) { val originDayUiModels = successUiState.dayUiModels.toMutableList() originDayUiModels[FIRST_DAY_POSITION] = originDayUiModels[FIRST_DAY_POSITION].copy(selected = true) @@ -110,7 +110,8 @@ class SharedRoutineDetailViewModel @Inject constructor( fun clickDay(dayPosition: Int) { if (_currentDayPosition.value == dayPosition - || _uiState.value is LatestSharedRoutineDetailUiState.Error) return + || _uiState.value is LatestSharedRoutineDetailUiState.Error + ) return val successUiState = _uiState.value as LatestSharedRoutineDetailUiState.Success val originDayUiModels = successUiState.dayUiModels.toMutableList() @@ -128,7 +129,7 @@ class SharedRoutineDetailViewModel @Inject constructor( } fun clickExercise(exercisePosition: Int) { - if(_uiState.value is LatestSharedRoutineDetailUiState.Error) return + if (_uiState.value is LatestSharedRoutineDetailUiState.Error) return val successUiState = _uiState.value as LatestSharedRoutineDetailUiState.Success val nowDayPosition = _currentDayPosition.value ?: return From 1b5058383c1d77b9278b817aff6305e3f01823ef Mon Sep 17 00:00:00 2001 From: sky8492002 Date: Mon, 12 Dec 2022 21:29:19 +0900 Subject: [PATCH 6/9] =?UTF-8?q?Issue=20#201=20refactor=20:=20=EA=B0=80?= =?UTF-8?q?=EC=A0=B8=EC=98=A4=EA=B8=B0=20=EB=B2=84=ED=8A=BC=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EB=A1=9C=EC=A7=81=20=EB=A6=AC=ED=8E=99=ED=86=A0?= =?UTF-8?q?=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../detail/SharedRoutineDetailFragment.kt | 33 ++++----- .../detail/SharedRoutineDetailViewModel.kt | 70 +++++++++++-------- 2 files changed, 54 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailFragment.kt b/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailFragment.kt index 7c7fcf32..2b60fa29 100644 --- a/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailFragment.kt +++ b/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailFragment.kt @@ -51,6 +51,7 @@ class SharedRoutineDetailFragment : Fragment() { setRoutineDayAdapter() setExerciseAdapter() setSharedRoutineDetailCollect() + setButtonRoutineImportOnClickListener() handleNavigationEvent() } @@ -84,24 +85,6 @@ class SharedRoutineDetailFragment : Fragment() { binding.sharedRoutineUiModel = uiState.sharedRoutineUiModel routineDayAdapter.submitList(uiState.dayUiModels) setCurrentDayPositionObserve(uiState.dayUiModels) - - binding.buttonRoutineImport.setOnClickListener { - if (uiState.sharedRoutineUiModel != null) { - viewModel.importSharedRoutineToMyRoutines( - uiState.sharedRoutineUiModel, - uiState.dayUiModels - ) - } else { - Snackbar.make( - binding.root, - R.string.none_routine, - Snackbar.LENGTH_LONG - ).apply { - anchorView = binding.guideLineBottom - }.show() - } - - } } is LatestSharedRoutineDetailUiState.Error -> { Snackbar.make( @@ -117,6 +100,20 @@ class SharedRoutineDetailFragment : Fragment() { } } + private fun setButtonRoutineImportOnClickListener() { + binding.buttonRoutineImport.setOnClickListener { + if (viewModel.importSharedRoutineToMyRoutines().not()) { + Snackbar.make( + binding.root, + R.string.none_routine, + Snackbar.LENGTH_LONG + ).apply { + anchorView = binding.guideLineBottom + }.show() + } + } + } + private fun setCurrentDayPositionObserve(dayUiModels: List) { viewModel.currentDayPosition.observe(viewLifecycleOwner) { if (dayUiModels.size > it) { diff --git a/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailViewModel.kt b/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailViewModel.kt index 0c24278c..e2a99dba 100644 --- a/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailViewModel.kt +++ b/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailViewModel.kt @@ -151,41 +151,49 @@ class SharedRoutineDetailViewModel @Inject constructor( ) } - fun importSharedRoutineToMyRoutines( - sharedRoutineUiModel: SharedRoutineUiModel, - dayUiModels: List - ) { - viewModelScope.launch(networkExceptionHandler) { - val sharedRoutineId = sharedRoutineUiModel.routineId - val routine = sharedRoutineUiModel.toRoutine( - createUUID(), - userInfo.value?.displayName ?: "", - routineRepository.getHigherRoutineOrder()?.plus(1) ?: 0 - ) - val days = mutableListOf() - val exercises = mutableListOf() - val exerciseSets = mutableListOf() - - dayUiModels.forEach { dayUiModel -> - val dayId = createUUID() - days.add(dayUiModel.toDayWithNewIds(routine.routineId, dayId)) - dayUiModel.exercises.forEach { exerciseUiModel -> - val exerciseId = createUUID() - exercises.add(exerciseUiModel.toExerciseWithNewIds(dayId, exerciseId)) - exerciseUiModel.exerciseSets.forEach { exerciseSetUiModel -> - val exerciseSetId = createUUID() - exerciseSets.add( - exerciseSetUiModel.toExerciseSetWithNewIds( - exerciseId, - exerciseSetId + fun importSharedRoutineToMyRoutines(): Boolean { + if (_uiState.value is LatestSharedRoutineDetailUiState.Error) { + return false + } + + val successUiState = _uiState.value as LatestSharedRoutineDetailUiState.Success + + if (successUiState.sharedRoutineUiModel == null) { + return false + } else { + viewModelScope.launch(networkExceptionHandler) { + val sharedRoutineId = successUiState.sharedRoutineUiModel.routineId + val routine = successUiState.sharedRoutineUiModel.toRoutine( + createUUID(), + userInfo.value?.displayName ?: "", + routineRepository.getHigherRoutineOrder()?.plus(1) ?: 0 + ) + val days = mutableListOf() + val exercises = mutableListOf() + val exerciseSets = mutableListOf() + + successUiState.dayUiModels.forEach { dayUiModel -> + val dayId = createUUID() + days.add(dayUiModel.toDayWithNewIds(routine.routineId, dayId)) + dayUiModel.exercises.forEach { exerciseUiModel -> + val exerciseId = createUUID() + exercises.add(exerciseUiModel.toExerciseWithNewIds(dayId, exerciseId)) + exerciseUiModel.exerciseSets.forEach { exerciseSetUiModel -> + val exerciseSetId = createUUID() + exerciseSets.add( + exerciseSetUiModel.toExerciseSetWithNewIds( + exerciseId, + exerciseSetId + ) ) - ) + } } } + routineRepository.insertRoutine(routine, days, exercises, exerciseSets) + _navigationEvent.emit(routine.routineId) + sharedRoutineRepository.increaseSharedCount(sharedRoutineId) } - routineRepository.insertRoutine(routine, days, exercises, exerciseSets) - _navigationEvent.emit(routine.routineId) - sharedRoutineRepository.increaseSharedCount(sharedRoutineId) + return true } } From 700456c6b7f7056bfb94f319abe3d46e77685005 Mon Sep 17 00:00:00 2001 From: sky8492002 Date: Mon, 12 Dec 2022 21:30:07 +0900 Subject: [PATCH 7/9] =?UTF-8?q?Issue=20#201=20refactor=20:=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/lateinit/rightweight/ui/share/SharedRoutineFragment.kt | 2 -- .../rightweight/ui/share/detail/SharedRoutineDetailFragment.kt | 2 -- 2 files changed, 4 deletions(-) diff --git a/app/src/main/java/com/lateinit/rightweight/ui/share/SharedRoutineFragment.kt b/app/src/main/java/com/lateinit/rightweight/ui/share/SharedRoutineFragment.kt index ba35733d..5a8aa5d8 100644 --- a/app/src/main/java/com/lateinit/rightweight/ui/share/SharedRoutineFragment.kt +++ b/app/src/main/java/com/lateinit/rightweight/ui/share/SharedRoutineFragment.kt @@ -1,7 +1,6 @@ package com.lateinit.rightweight.ui.share import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -47,7 +46,6 @@ class SharedRoutineFragment : Fragment(), SharedRoutineClickHandler { viewLifecycleOwner.collectOnLifecycle { viewModel.uiState.collect { uiState -> - Log.d("uiState", uiState.toString()) when (uiState) { is LatestSharedRoutineUiState.Success -> { sharedRoutinePagingAdapter.submitData(uiState.sharedRoutines) diff --git a/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailFragment.kt b/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailFragment.kt index 2b60fa29..8c0f210f 100644 --- a/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailFragment.kt +++ b/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailFragment.kt @@ -1,7 +1,6 @@ package com.lateinit.rightweight.ui.share.detail import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -79,7 +78,6 @@ class SharedRoutineDetailFragment : Fragment() { private fun setSharedRoutineDetailCollect() { viewLifecycleOwner.collectOnLifecycle { viewModel.uiState.collect { uiState -> - Log.d("uiState", uiState.toString()) when (uiState) { is LatestSharedRoutineDetailUiState.Success -> { binding.sharedRoutineUiModel = uiState.sharedRoutineUiModel From 5306de5e725a4dc28db40eb03846a066736a1276 Mon Sep 17 00:00:00 2001 From: sky8492002 Date: Mon, 12 Dec 2022 22:15:54 +0900 Subject: [PATCH 8/9] =?UTF-8?q?Issue=20#201=20feat=20:=20=EB=A3=A8?= =?UTF-8?q?=ED=8B=B4=EC=9D=B4=20=EB=B9=84=EC=96=B4=EC=9E=88=EC=9C=BC?= =?UTF-8?q?=EB=A9=B4=20=EC=BB=A4=EB=AE=A4=EB=8B=88=ED=8B=B0=20=ED=99=94?= =?UTF-8?q?=EB=A9=B4=EC=9C=BC=EB=A1=9C=20=EB=90=98=EB=8F=8C=EC=95=84?= =?UTF-8?q?=EA=B0=80=EB=8F=84=EB=A1=9D=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rightweight/ui/share/detail/SharedRoutineDetailFragment.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailFragment.kt b/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailFragment.kt index 8c0f210f..eab5e1d8 100644 --- a/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailFragment.kt +++ b/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailFragment.kt @@ -92,6 +92,7 @@ class SharedRoutineDetailFragment : Fragment() { ).apply { anchorView = binding.guideLineBottom }.show() + findNavController().navigateUp() } } } From 3c5dbef5cebab86387911949f6abbcd23702adf3 Mon Sep 17 00:00:00 2001 From: sky8492002 Date: Mon, 12 Dec 2022 22:24:44 +0900 Subject: [PATCH 9/9] =?UTF-8?q?Issue=20#201=20refactor=20:=20=EB=B6=88?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20=EC=9A=94=EC=86=8C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/share/detail/SharedRoutineDetailViewModel.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailViewModel.kt b/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailViewModel.kt index e2a99dba..25b13efa 100644 --- a/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailViewModel.kt +++ b/app/src/main/java/com/lateinit/rightweight/ui/share/detail/SharedRoutineDetailViewModel.kt @@ -45,7 +45,7 @@ class SharedRoutineDetailViewModel @Inject constructor( val userInfo = userRepository.getUser().stateIn(viewModelScope, SharingStarted.Eagerly, null) private val _uiState = MutableStateFlow( - LatestSharedRoutineDetailUiState.Success(null, mutableListOf()) + LatestSharedRoutineDetailUiState.Success(null, emptyList()) ) val uiState: StateFlow = _uiState @@ -65,9 +65,7 @@ class SharedRoutineDetailViewModel @Inject constructor( } private fun sendNetworkResultEvent(state: NetworkState) { - viewModelScope.launch { - _uiState.value = LatestSharedRoutineDetailUiState.Error(state) - } + _uiState.value = LatestSharedRoutineDetailUiState.Error(state) }