diff --git a/presentation/src/main/java/org/gdsc/presentation/view/restaurantregistration/RegisterRestaurantFragment.kt b/presentation/src/main/java/org/gdsc/presentation/view/restaurantregistration/RegisterRestaurantFragment.kt index cb689751..776ef278 100644 --- a/presentation/src/main/java/org/gdsc/presentation/view/restaurantregistration/RegisterRestaurantFragment.kt +++ b/presentation/src/main/java/org/gdsc/presentation/view/restaurantregistration/RegisterRestaurantFragment.kt @@ -17,6 +17,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import com.google.android.material.chip.Chip import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch import okhttp3.MediaType import okhttp3.MultipartBody @@ -267,6 +268,12 @@ class RegisterRestaurantFragment : BaseFragment() { } } } + + repeatWhenUiStarted { + viewModel.canRegisterState.collectLatest { + binding.registerButton.isEnabled = it + } + } } private fun setFoodCategoryContainer() { diff --git a/presentation/src/main/java/org/gdsc/presentation/view/restaurantregistration/viewmodel/RegisterRestaurantViewModel.kt b/presentation/src/main/java/org/gdsc/presentation/view/restaurantregistration/viewmodel/RegisterRestaurantViewModel.kt index 0f8d70ee..b38470f8 100644 --- a/presentation/src/main/java/org/gdsc/presentation/view/restaurantregistration/viewmodel/RegisterRestaurantViewModel.kt +++ b/presentation/src/main/java/org/gdsc/presentation/view/restaurantregistration/viewmodel/RegisterRestaurantViewModel.kt @@ -8,6 +8,7 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch @@ -77,6 +78,20 @@ class RegisterRestaurantViewModel @Inject constructor( MutableStateFlow(emptyArray()) val isFoodImagesListState = _isFoodImagesListState.asStateFlow() + val canRegisterState: StateFlow + get() = combine( + foodCategoryState, + introductionTextState, + recommendMenuListState + ) { foodCategoryState, introductionState, recommendMenuListState -> + foodCategoryState != FoodCategoryItem.INIT && introductionState.isNotBlank() && recommendMenuListState.isNotEmpty() + }.stateIn( + scope = viewModelScope, + started = SharingStarted.WhileSubscribed(), + initialValue = false + ) + + fun setFoodImagesListState(list: Array) { _isFoodImagesListState.value = list } @@ -188,7 +203,7 @@ class RegisterRestaurantViewModel @Inject constructor( }, categoryId = foodCategoryState.value.categoryItem.id.toInt(), id = restaurantId, - ) + ) ) } }