Skip to content

Commit

Permalink
Merge branch 'fix/home_detail_action' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim-swit committed Mar 16, 2024
2 parents 0d352da + 5594396 commit 0339a2a
Show file tree
Hide file tree
Showing 16 changed files with 132 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,4 @@ data class RestaurantLocationInfo(
val x: String,
@SerializedName("y")
val y: String,
@SerializedName("differenceInDistance")
val differenceInDistance: String
): java.io.Serializable
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -30,6 +31,7 @@ class PostRestaurantInfoUseCase @Inject constructor(
recommendMenu,
restaurantLocationAggregateIdg
),
groupId,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ class BottomSheetDialog {
}

fun show() {
if (isShowing) return
this.btmDlg.show()
}

fun dismiss() {
if (!isShowing) return
this.btmDlg.dismiss()
}

fun <T : ViewBinding> bindBuilder(
binding: T,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -102,7 +99,6 @@ class HomeFragment : Fragment(), ViewHolderBindListener {
private lateinit var concatAdapter: ConcatAdapter

private val recommendPopularRestaurantList = listOf<RegisteredRestaurant>()
private val standardBottomSheetBehavior by lazy { BottomSheetBehavior.from(binding.bottomSheet) }

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
Expand Down Expand Up @@ -139,6 +135,7 @@ class HomeFragment : Fragment(), ViewHolderBindListener {

setRestaurantListBottomSheet()
setGroup()
setView()

}

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand All @@ -410,7 +417,7 @@ class HomeFragment : Fragment(), ViewHolderBindListener {
}
}

repeatWhenUiStarted {
lifecycleScope.launch {
viewModel.getMyGroup().let { groupList ->
viewModel.setGroupList(groupList)
}
Expand All @@ -424,17 +431,15 @@ class HomeFragment : Fragment(), ViewHolderBindListener {

if (groupList.isEmpty()) {
viewModel.setCurrentGroup(null)

if (bottomSheetDialog.isShowing.not()) {
bottomSheetDialog.show()
}
bottomSheetDialog.show()
} else {
groupList.forEach {
if (it.isSelected) {
viewModel.setCurrentGroup(it)
return@forEach
}
}
bottomSheetDialog.dismiss()
}
}

Expand Down Expand Up @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ConfirmRestaurantRegistrationFragment : Fragment() {
private var _binding: FragmentConfirmRestaurantRegistrationBinding? = null
private val binding get() = _binding!!
private val navArgs by navArgs<ConfirmRestaurantRegistrationFragmentArgs>()
private val groupId by lazy { navArgs.groupId }

private lateinit var mapView: MapView

Expand All @@ -52,7 +53,10 @@ class ConfirmRestaurantRegistrationFragment : Fragment() {
binding.selectButton.setOnClickListener {

val action = ConfirmRestaurantRegistrationFragmentDirections
.actionConfirmRestaurantRegistrationFragmentToRegisterRestaurantFragment(navArgs.restaurantLocationInfo)
.actionConfirmRestaurantRegistrationFragmentToRegisterRestaurantFragment(
groupId,
navArgs.restaurantLocationInfo
)
findNavController().navigate(action)

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class RegisterRestaurantFragment : BaseFragment() {
private val viewModel: RegisterRestaurantViewModel by viewModels()

private val navArgs by navArgs<RegisterRestaurantFragmentArgs>()
private val groupId by lazy { navArgs.groupId }

private val foodCategoryDialog by lazy {
FoodCategoryBottomSheetDialog { selectedItem ->
Expand Down Expand Up @@ -341,7 +342,6 @@ class RegisterRestaurantFragment : BaseFragment() {
MediaType.parse("image/png"),
imageFile
)

val body =
MultipartBody.Part.createFormData(
"pictures",
Expand All @@ -358,6 +358,7 @@ class RegisterRestaurantFragment : BaseFragment() {
lifecycleScope.launch(Dispatchers.IO) {
viewModel.registerRestaurant(
pictures,
groupId,
navArgs.restaurantLocationInfo ?: throw Exception()
) { restaurantId ->

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -29,15 +31,20 @@ 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 {
val canRegister = viewModel.canRegisterRestaurant(it.id)

val action = SearchRestaurantLocationInfoFragmentDirections
.actionSearchRestaurantLocationInfoFragmentToConfirmRestaurantRegistrationFragment(
groupId,
canRegister,
it
it,
)
findNavController().navigate(action)
}
Expand Down
Loading

0 comments on commit 0339a2a

Please sign in to comment.