diff --git a/data/src/main/java/org/gdsc/data/datasource/RestaurantDataSource.kt b/data/src/main/java/org/gdsc/data/datasource/RestaurantDataSource.kt index c0417a97..597b23df 100644 --- a/data/src/main/java/org/gdsc/data/datasource/RestaurantDataSource.kt +++ b/data/src/main/java/org/gdsc/data/datasource/RestaurantDataSource.kt @@ -31,7 +31,7 @@ interface RestaurantDataSource { suspend fun postRestaurantLocationInfo(restaurantLocationInfo: RestaurantLocationInfo): String - suspend fun postRestaurantInfo(restaurantRegistrationRequest: RestaurantRegistrationRequest): String + suspend fun postRestaurantInfo(restaurantRegistrationRequest: RestaurantRegistrationRequest, groupId: Int): String suspend fun getRestaurants( userId: Int, locationData: Location, sortType: SortType, foodCategory: FoodCategory, drinkPossibility: DrinkPossibility diff --git a/data/src/main/java/org/gdsc/data/datasource/RestaurantDataSourceImpl.kt b/data/src/main/java/org/gdsc/data/datasource/RestaurantDataSourceImpl.kt index 2faa69fb..acac844c 100644 --- a/data/src/main/java/org/gdsc/data/datasource/RestaurantDataSourceImpl.kt +++ b/data/src/main/java/org/gdsc/data/datasource/RestaurantDataSourceImpl.kt @@ -87,7 +87,10 @@ class RestaurantDataSourceImpl @Inject constructor( return restaurantAPI.postRestaurantLocationInfo(restaurantLocationInfo).data } - override suspend fun postRestaurantInfo(restaurantRegistrationRequest: RestaurantRegistrationRequest): String { + override suspend fun postRestaurantInfo( + restaurantRegistrationRequest: RestaurantRegistrationRequest, + groupId: Int, + ): String { runCatching { restaurantAPI.postRestaurantInfo( mapOf( @@ -100,7 +103,7 @@ class RestaurantDataSourceImpl @Inject constructor( "goWellWithLiquor" to restaurantRegistrationRequest.goWellWithLiquor.toRequestBody(), "recommendMenu" to restaurantRegistrationRequest.recommendMenu.toRequestBody(), "restaurantLocationId" to restaurantRegistrationRequest.restaurantLocationAggregateId.toRequestBody(), - "groupId" to "10".toRequestBody() + "groupId" to groupId.toString().toRequestBody() ), pictures = restaurantRegistrationRequest.pictures ) diff --git a/data/src/main/java/org/gdsc/data/repository/RestaurantRepositoryImpl.kt b/data/src/main/java/org/gdsc/data/repository/RestaurantRepositoryImpl.kt index aa582bab..24616acd 100644 --- a/data/src/main/java/org/gdsc/data/repository/RestaurantRepositoryImpl.kt +++ b/data/src/main/java/org/gdsc/data/repository/RestaurantRepositoryImpl.kt @@ -47,8 +47,11 @@ class RestaurantRepositoryImpl @Inject constructor( return restaurantDataSource.postRestaurantLocationInfo(restaurantLocationInfo) } - override suspend fun postRestaurantInfo(restaurantRegistrationRequest: RestaurantRegistrationRequest): String { - return restaurantDataSource.postRestaurantInfo(restaurantRegistrationRequest) + override suspend fun postRestaurantInfo( + restaurantRegistrationRequest: RestaurantRegistrationRequest, + groupId: Int, + ): String { + return restaurantDataSource.postRestaurantInfo(restaurantRegistrationRequest, groupId) } override suspend fun getRestaurants( diff --git a/domain/src/main/java/org/gdsc/domain/model/RestaurantLocationInfo.kt b/domain/src/main/java/org/gdsc/domain/model/RestaurantLocationInfo.kt index e955a6f4..99172ea2 100644 --- a/domain/src/main/java/org/gdsc/domain/model/RestaurantLocationInfo.kt +++ b/domain/src/main/java/org/gdsc/domain/model/RestaurantLocationInfo.kt @@ -27,6 +27,4 @@ data class RestaurantLocationInfo( val x: String, @SerializedName("y") val y: String, - @SerializedName("differenceInDistance") - val differenceInDistance: String ): java.io.Serializable \ No newline at end of file diff --git a/domain/src/main/java/org/gdsc/domain/repository/RestaurantRepository.kt b/domain/src/main/java/org/gdsc/domain/repository/RestaurantRepository.kt index 80e609d2..4288c294 100644 --- a/domain/src/main/java/org/gdsc/domain/repository/RestaurantRepository.kt +++ b/domain/src/main/java/org/gdsc/domain/repository/RestaurantRepository.kt @@ -30,7 +30,7 @@ interface RestaurantRepository { suspend fun postRestaurantLocationInfo(restaurantLocationInfo: RestaurantLocationInfo): String - suspend fun postRestaurantInfo(restaurantRegistrationRequest: RestaurantRegistrationRequest): String + suspend fun postRestaurantInfo(restaurantRegistrationRequest: RestaurantRegistrationRequest, groupId: Int): String suspend fun getRestaurants( userId: Int, locationData: Location, sortType: SortType, foodCategory: FoodCategory, drinkPossibility: DrinkPossibility diff --git a/domain/src/main/java/org/gdsc/domain/usecase/PostRestaurantInfoUseCase.kt b/domain/src/main/java/org/gdsc/domain/usecase/PostRestaurantInfoUseCase.kt index 6dde4707..5cc52689 100644 --- a/domain/src/main/java/org/gdsc/domain/usecase/PostRestaurantInfoUseCase.kt +++ b/domain/src/main/java/org/gdsc/domain/usecase/PostRestaurantInfoUseCase.kt @@ -17,7 +17,8 @@ class PostRestaurantInfoUseCase @Inject constructor( canDrinkLiquor: Boolean, goWellWithLiquor: String, recommendMenu: String, - restaurantLocationAggregateIdg: String + restaurantLocationAggregateIdg: String, + groupId: Int, ): String { return restaurantRepository.postRestaurantInfo( RestaurantRegistrationRequest( @@ -30,6 +31,7 @@ class PostRestaurantInfoUseCase @Inject constructor( recommendMenu, restaurantLocationAggregateIdg ), + groupId, ) } } \ No newline at end of file diff --git a/presentation/src/main/java/org/gdsc/presentation/view/MainActivity.kt b/presentation/src/main/java/org/gdsc/presentation/view/MainActivity.kt index 2aeea933..6f2046a2 100644 --- a/presentation/src/main/java/org/gdsc/presentation/view/MainActivity.kt +++ b/presentation/src/main/java/org/gdsc/presentation/view/MainActivity.kt @@ -164,13 +164,13 @@ class MainActivity : BaseActivity() { binding.toolBar.isVisible = isVisible } - fun navigateToEditRestaurantInfo(restaurantId: Int) { - - val action = HomeFragmentDirections.actionHomeFragmentToRegisterRestaurantFragment( - targetRestaurantId = restaurantId - ) - navController.navigate(action) - } +// fun navigateToEditRestaurantInfo(restaurantId: Int) { +// +// val action = HomeFragmentDirections.actionHomeFragmentToRegisterRestaurantFragment( +// targetRestaurantId = restaurantId +// ) +// navController.navigate(action) +// } override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { diff --git a/presentation/src/main/java/org/gdsc/presentation/view/custom/BottomSheetDialog.kt b/presentation/src/main/java/org/gdsc/presentation/view/custom/BottomSheetDialog.kt index 039e9e51..6d9466d7 100644 --- a/presentation/src/main/java/org/gdsc/presentation/view/custom/BottomSheetDialog.kt +++ b/presentation/src/main/java/org/gdsc/presentation/view/custom/BottomSheetDialog.kt @@ -40,9 +40,14 @@ class BottomSheetDialog { } fun show() { + if (isShowing) return this.btmDlg.show() } + fun dismiss() { + if (!isShowing) return + this.btmDlg.dismiss() + } fun bindBuilder( binding: T, diff --git a/presentation/src/main/java/org/gdsc/presentation/view/home/HomeFragment.kt b/presentation/src/main/java/org/gdsc/presentation/view/home/HomeFragment.kt index 321e6809..859d37fd 100644 --- a/presentation/src/main/java/org/gdsc/presentation/view/home/HomeFragment.kt +++ b/presentation/src/main/java/org/gdsc/presentation/view/home/HomeFragment.kt @@ -3,7 +3,6 @@ package org.gdsc.presentation.view.home import android.content.Intent import android.graphics.PointF import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -13,6 +12,7 @@ import androidx.core.content.res.ResourcesCompat import androidx.core.view.isVisible import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels +import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.ConcatAdapter import androidx.recyclerview.widget.LinearLayoutManager @@ -25,9 +25,6 @@ import com.naver.maps.map.CameraUpdate import com.naver.maps.map.MapView import com.naver.maps.map.Projection import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.delay import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch import org.gdsc.domain.DrinkPossibility @@ -102,7 +99,6 @@ class HomeFragment : Fragment(), ViewHolderBindListener { private lateinit var concatAdapter: ConcatAdapter private val recommendPopularRestaurantList = listOf() - private val standardBottomSheetBehavior by lazy { BottomSheetBehavior.from(binding.bottomSheet) } override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -139,6 +135,7 @@ class HomeFragment : Fragment(), ViewHolderBindListener { setRestaurantListBottomSheet() setGroup() + setView() } @@ -179,10 +176,16 @@ class HomeFragment : Fragment(), ViewHolderBindListener { } } } + + private fun setView() { + binding.groupSearch.setOnClickListener { + findNavController().navigate(HomeFragmentDirections.actionHomeFragmentToAllSearchFragment()) + } + } private fun setGroup() { binding.groupArrow.setOnClickListener { - repeatWhenUiStarted { + lifecycleScope.launch { viewModel.getMyGroup().let { groupList -> viewModel.setGroupList(groupList) } @@ -254,14 +257,14 @@ class HomeFragment : Fragment(), ViewHolderBindListener { naverMap.uiSettings.isZoomControlEnabled = false naverMap.uiSettings.isScaleBarEnabled = false - repeatWhenUiStarted { + lifecycleScope.launch { viewModel.registeredPagingDataByMap().collect { mapMarkerAdapter.submitData(it) } } - repeatWhenUiStarted { + lifecycleScope.launch { val location = viewModel.getCurrentLocation() location?.let { val cameraUpdate = CameraUpdate.scrollTo(LatLng(it.latitude, it.longitude)) @@ -320,16 +323,26 @@ class HomeFragment : Fragment(), ViewHolderBindListener { private fun setRestaurantListBottomSheet() { + + binding.registButton.setOnClickListener { + findNavController().navigate(HomeFragmentDirections.actionHomeFragmentToSearchRestaurantLocationInfoFragment( + viewModel.currentGroup.value?.groupId ?: 0 + )) + } binding.scrollUpButton.setOnClickListener { binding.recyclerView.scrollToPosition(0) } binding.registRestaurantButton.setOnClickListener { - // TODO : 식당 등록 버튼 클릭 시 동작 정의 필요 - Log.d("testLog", "식당 등록 버튼 클릭") + findNavController().navigate(HomeFragmentDirections.actionHomeFragmentToSearchRestaurantLocationInfoFragment( + viewModel.currentGroup.value?.groupId ?: 0 + )) } + + val standardBottomSheetBehavior by lazy { BottomSheetBehavior.from(binding.bottomSheet) } + restaurantListAdapter.addLoadStateListener { loadState -> if (loadState.append.endOfPaginationReached) { if (restaurantListAdapter.itemCount < 1) { @@ -384,17 +397,11 @@ class HomeFragment : Fragment(), ViewHolderBindListener { override fun onSlide(bottomSheet: View, slideOffset: Float) {} }) - - CoroutineScope(Dispatchers.Main).launch { - delay(1000) - if (standardBottomSheetBehavior.state != BottomSheetBehavior.STATE_COLLAPSED) - standardBottomSheetBehavior.state = BottomSheetBehavior.STATE_HALF_EXPANDED - } } private fun observeState() { - repeatWhenUiStarted { + lifecycleScope.launch { viewModel.registeredPagingDataByGroup().collect { restaurantListAdapter.submitData(it) } @@ -410,7 +417,7 @@ class HomeFragment : Fragment(), ViewHolderBindListener { } } - repeatWhenUiStarted { + lifecycleScope.launch { viewModel.getMyGroup().let { groupList -> viewModel.setGroupList(groupList) } @@ -424,10 +431,7 @@ class HomeFragment : Fragment(), ViewHolderBindListener { if (groupList.isEmpty()) { viewModel.setCurrentGroup(null) - - if (bottomSheetDialog.isShowing.not()) { - bottomSheetDialog.show() - } + bottomSheetDialog.show() } else { groupList.forEach { if (it.isSelected) { @@ -435,6 +439,7 @@ class HomeFragment : Fragment(), ViewHolderBindListener { return@forEach } } + bottomSheetDialog.dismiss() } } @@ -470,8 +475,40 @@ class HomeFragment : Fragment(), ViewHolderBindListener { } } + + override fun onStart() { + super.onStart() + mapView.onStart() + } + + override fun onResume() { + super.onResume() + mapView.onResume() + } + + override fun onPause() { + super.onPause() + mapView.onPause() + } + + override fun onSaveInstanceState(outState: Bundle) { + super.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) + } + + override fun onStop() { + super.onStop() + mapView.onStop() + } + + override fun onLowMemory() { + super.onLowMemory() + mapView.onLowMemory() + } + override fun onDestroyView() { _binding = null super.onDestroyView() + mapView.onDestroy() } } \ No newline at end of file diff --git a/presentation/src/main/java/org/gdsc/presentation/view/restaurantregistration/ConfirmRestaurantRegistrationFragment.kt b/presentation/src/main/java/org/gdsc/presentation/view/restaurantregistration/ConfirmRestaurantRegistrationFragment.kt index 376acb3f..04c14051 100644 --- a/presentation/src/main/java/org/gdsc/presentation/view/restaurantregistration/ConfirmRestaurantRegistrationFragment.kt +++ b/presentation/src/main/java/org/gdsc/presentation/view/restaurantregistration/ConfirmRestaurantRegistrationFragment.kt @@ -29,6 +29,7 @@ class ConfirmRestaurantRegistrationFragment : Fragment() { private var _binding: FragmentConfirmRestaurantRegistrationBinding? = null private val binding get() = _binding!! private val navArgs by navArgs() + private val groupId by lazy { navArgs.groupId } private lateinit var mapView: MapView @@ -52,7 +53,10 @@ class ConfirmRestaurantRegistrationFragment : Fragment() { binding.selectButton.setOnClickListener { val action = ConfirmRestaurantRegistrationFragmentDirections - .actionConfirmRestaurantRegistrationFragmentToRegisterRestaurantFragment(navArgs.restaurantLocationInfo) + .actionConfirmRestaurantRegistrationFragmentToRegisterRestaurantFragment( + groupId, + navArgs.restaurantLocationInfo + ) findNavController().navigate(action) } 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 090ccd7d..2462fe80 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 @@ -49,6 +49,7 @@ class RegisterRestaurantFragment : BaseFragment() { private val viewModel: RegisterRestaurantViewModel by viewModels() private val navArgs by navArgs() + private val groupId by lazy { navArgs.groupId } private val foodCategoryDialog by lazy { FoodCategoryBottomSheetDialog { selectedItem -> @@ -341,7 +342,6 @@ class RegisterRestaurantFragment : BaseFragment() { MediaType.parse("image/png"), imageFile ) - val body = MultipartBody.Part.createFormData( "pictures", @@ -358,6 +358,7 @@ class RegisterRestaurantFragment : BaseFragment() { lifecycleScope.launch(Dispatchers.IO) { viewModel.registerRestaurant( pictures, + groupId, navArgs.restaurantLocationInfo ?: throw Exception() ) { restaurantId -> diff --git a/presentation/src/main/java/org/gdsc/presentation/view/restaurantregistration/SearchRestaurantLocationInfoFragment.kt b/presentation/src/main/java/org/gdsc/presentation/view/restaurantregistration/SearchRestaurantLocationInfoFragment.kt index f7b8829c..bf0ced5d 100644 --- a/presentation/src/main/java/org/gdsc/presentation/view/restaurantregistration/SearchRestaurantLocationInfoFragment.kt +++ b/presentation/src/main/java/org/gdsc/presentation/view/restaurantregistration/SearchRestaurantLocationInfoFragment.kt @@ -1,6 +1,7 @@ package org.gdsc.presentation.view.restaurantregistration import android.os.Bundle +import android.util.Log import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View @@ -9,6 +10,7 @@ import androidx.annotation.DrawableRes import androidx.fragment.app.viewModels import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.findNavController +import androidx.navigation.fragment.navArgs import androidx.recyclerview.widget.LinearLayoutManager import com.google.android.material.snackbar.Snackbar import dagger.hilt.android.AndroidEntryPoint @@ -29,6 +31,10 @@ class SearchRestaurantLocationInfoFragment : Fragment() { private var _binding: FragmentSearchRestaurantLocationInfoBinding? = null private val binding get() = _binding!! private val viewModel: SearchRestaurantLocationInfoViewModel by viewModels() + + private val navArgs: SearchRestaurantLocationInfoFragmentArgs by navArgs() + private val groupId by lazy { navArgs.groupId } + private val adapter by lazy { RestaurantLocationInfoAdapter { viewLifecycleOwner.lifecycleScope.launch { @@ -36,8 +42,9 @@ class SearchRestaurantLocationInfoFragment : Fragment() { val action = SearchRestaurantLocationInfoFragmentDirections .actionSearchRestaurantLocationInfoFragmentToConfirmRestaurantRegistrationFragment( + groupId, canRegister, - it + it, ) findNavController().navigate(action) } 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 2a051002..e540d895 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 @@ -154,6 +154,7 @@ class RegisterRestaurantViewModel @Inject constructor( fun registerRestaurant( pictures: List, + groupId: Int, restaurantLocationInfo: RestaurantLocationInfo, actionAfterRegisterSuccess: (String) -> Unit = {} ) { @@ -170,7 +171,8 @@ class RegisterRestaurantViewModel @Inject constructor( recommendMenu = recommendMenuListState.value.joinToString(" ") { "#$it" }, - restaurantLocationAggregateIdg = restaurantLocationInfoId + restaurantLocationAggregateIdg = restaurantLocationInfoId, + groupId = groupId, ) actionAfterRegisterSuccess(restaurantId) diff --git a/presentation/src/main/java/org/gdsc/presentation/view/webview/SpecificWebViewFragment.kt b/presentation/src/main/java/org/gdsc/presentation/view/webview/SpecificWebViewFragment.kt index bd7646cc..49579132 100644 --- a/presentation/src/main/java/org/gdsc/presentation/view/webview/SpecificWebViewFragment.kt +++ b/presentation/src/main/java/org/gdsc/presentation/view/webview/SpecificWebViewFragment.kt @@ -57,7 +57,7 @@ class SpecificWebViewFragment : Fragment() { parentActivity.slideDownBottomNavigationView() }, { - parentActivity.navigateToEditRestaurantInfo(it) +// parentActivity.navigateToEditRestaurantInfo(it) }, { repeatWhenUiStarted { diff --git a/presentation/src/main/res/layout/fragment_home.xml b/presentation/src/main/res/layout/fragment_home.xml index 959a44f5..49bdf6d8 100644 --- a/presentation/src/main/res/layout/fragment_home.xml +++ b/presentation/src/main/res/layout/fragment_home.xml @@ -13,7 +13,7 @@ android:layout_width="match_parent" android:layout_height="65dp" android:layout_weight="0" - android:paddingHorizontal="@dimen/default_spacing" + android:paddingStart="@dimen/default_spacing" android:background="@color/white"> diff --git a/presentation/src/main/res/navigation/main_nav_graph.xml b/presentation/src/main/res/navigation/main_nav_graph.xml index c32fe705..3d0539c7 100644 --- a/presentation/src/main/res/navigation/main_nav_graph.xml +++ b/presentation/src/main/res/navigation/main_nav_graph.xml @@ -16,6 +16,9 @@ + + + + + + + + + + + + +