Skip to content

Commit

Permalink
Merge pull request #95 from team-JMT/fix/restaurant_detail_scroll
Browse files Browse the repository at this point in the history
탭 레이아웃 및 상단 부분 스크롤되도록 변경(뷰 크기 고정 이슈)
  • Loading branch information
soopeach authored Mar 15, 2024
2 parents 47e14c3 + 41b0cee commit b6d4702
Show file tree
Hide file tree
Showing 13 changed files with 322 additions and 311 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import org.gdsc.domain.model.Review
import org.gdsc.presentation.databinding.ItemImageSlideBinding

data class ImageSliderItem(
val imageUrl: String
val imageUrl: String,
val review: Review
)

class ImageSlider(
private val onItemSelected: () -> Unit = {}
private val onItemSelected: () -> Unit = {},
private val onReviewRefreshed: (Review) -> Unit = {}
) :
ListAdapter<ImageSliderItem, ImageSlider.ImageSliderViewHolder>(
diffUtil
Expand All @@ -27,6 +30,7 @@ class ImageSlider(
.load(item.imageUrl)
.into(imageView)
}
onReviewRefreshed(item.review)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,25 @@ class RestaurantPhotoAdapter(
diffUtil
) {

private var width = 0
private var height = 0
private var width = 0
private var height = 0

inner class RestaurantPhotoViewHolder(private val binding: ItemPhotoRestaurantBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bind(item: RestaurantPhotoItem) {
with(binding) {
Glide.with(root)
.load(item.photoUrl)
.into(ivPhoto)

if (item.photoUrl != "BUTTON") {
Glide.with(root)
.load(item.photoUrl)
.into(ivPhoto)
} else {
morePhotoButton.visibility = ViewGroup.VISIBLE
morePhotoButton.setOnClickListener {
onItemSelected()
}
}

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.core.net.toUri
import androidx.core.widget.NestedScrollView
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.setFragmentResultListener
import androidx.lifecycle.lifecycleScope
Expand All @@ -21,12 +22,14 @@ import kotlinx.coroutines.launch
import okhttp3.MediaType
import okhttp3.MultipartBody
import okhttp3.RequestBody
import org.gdsc.domain.Empty
import org.gdsc.presentation.R
import org.gdsc.presentation.databinding.FragmentRestaurantDetailBinding
import org.gdsc.presentation.utils.BitmapUtils.getCompressedBitmapFromUri
import org.gdsc.presentation.utils.BitmapUtils.saveBitmapToFile
import org.gdsc.presentation.utils.CalculatorUtils
import org.gdsc.presentation.utils.repeatWhenUiStarted
import org.gdsc.presentation.view.MainActivity
import org.gdsc.presentation.view.mypage.adapter.PhotoWillBeUploadedAdapter
import org.gdsc.presentation.view.mypage.adapter.RestaurantDetailPagerAdapter
import org.gdsc.presentation.view.mypage.viewmodel.RestaurantDetailViewModel
Expand All @@ -39,6 +42,8 @@ class RestaurantDetailFragment : Fragment() {

private val viewModel: RestaurantDetailViewModel by activityViewModels()

private val parentActivity by lazy { activity as MainActivity }

private val adapter = PhotoWillBeUploadedAdapter {
viewModel.deletePhotoForReviewState(it)
}
Expand All @@ -63,6 +68,15 @@ class RestaurantDetailFragment : Fragment() {
}
}

binding.topScrollView.setOnScrollChangeListener(
NestedScrollView.OnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY ->
if (scrollY > binding.tvRestaurantName.height) {
parentActivity.changeToolbarTitle(binding.tvRestaurantName.text.toString())
} else {
parentActivity.changeToolbarTitle(String.Empty)
}
})

binding.rvImageListWillBeUploaded.adapter = adapter

binding.addImageIcon.setOnClickListener {
Expand Down Expand Up @@ -167,6 +181,7 @@ class RestaurantDetailFragment : Fragment() {

binding.restaurantDetailPager.adapter = RestaurantDetailPagerAdapter(this)
binding.restaurantDetailPager.isUserInputEnabled = false
binding.restaurantDetailPager.offscreenPageLimit = 1

TabLayoutMediator(binding.tabLayout, binding.restaurantDetailPager) { tab, position ->
when (position) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class RestaurantInfoFragment : Fragment() {
}

private val restaurantPhotoAdapter = RestaurantPhotoAdapter {

(parentFragment as RestaurantDetailFragment).changeCategory(RestaurantDetailPagerAdapter.PHOTO)
}

override fun onCreateView(
Expand Down Expand Up @@ -86,6 +86,10 @@ class RestaurantInfoFragment : Fragment() {
binding.cgRecommendDrink.addView(newChip(it))
}
}

photoAdapter.submitList(pictures.map {
ImagePagerItem(it)
})
}
}
}
Expand All @@ -98,13 +102,12 @@ class RestaurantInfoFragment : Fragment() {
}

viewLifecycleOwner.lifecycleScope.launch {
viewModel.restaurantInfo.collect {
it?.let { notNullRestaurantInfo ->
restaurantPhotoAdapter.submitList(
notNullRestaurantInfo.pictures.map { imageUrl ->
(RestaurantPhotoItem(imageUrl))
})
}

viewModel.reviews.collect { reviews ->
restaurantPhotoAdapter.submitList(
reviews.map { it.reviewImages }.flatten().take(8).map { imageUrl ->
(RestaurantPhotoItem(imageUrl))
} + RestaurantPhotoItem("BUTTON"))
}
}
}
Expand All @@ -113,17 +116,6 @@ class RestaurantInfoFragment : Fragment() {

binding.pagerPhotos.adapter = photoAdapter

photoAdapter.submitList(
listOf(
ImagePagerItem("https://picsum.photos/200/200"),
ImagePagerItem("https://picsum.photos/200/200"),
ImagePagerItem("https://picsum.photos/200/200"),
ImagePagerItem("https://picsum.photos/200/200"),
ImagePagerItem("https://picsum.photos/200/200"),
ImagePagerItem("https://picsum.photos/200/200"),
)
)

binding.rvReviews.adapter = restaurantReviewAdapter
binding.rvReviews.layoutManager = LinearLayoutManager(context)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,16 @@ class RestaurantPhotoDetailFragment : Fragment() {

private val imageSlider = ImageSlider(

)
) {
with(binding.reviewItem) {
Glide.with(root)
.load(it.reviewerImageUrl)
.into(ivProfile)

tvNickname.text = it.userName
tvContent.text = it.reviewContent
}
}

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
Expand All @@ -40,48 +49,30 @@ class RestaurantPhotoDetailFragment : Fragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

setAdapter()
observeData()

}

private fun observeData() {
viewLifecycleOwner.lifecycleScope.launch {
viewModel.reviews.collect { reviewList ->
if (reviewList.isNotEmpty()) {

// TODO: to be dynamic
val firstReview = reviewList.first()
with(binding.reviewItem) {
Glide.with(root)
.load(firstReview.reviewerImageUrl)
.into(ivProfile)

tvNickname.text = firstReview.userName
tvContent.text = firstReview.reviewContent
}
}
}
}
}

private fun setAdapter() {
binding.imageSlider.adapter = imageSlider

viewModel.restaurantInfo.value?.let { restaurantInfo ->
viewModel.reviews.value.let { reviews ->

val imageSliderItems = reviews.map { review ->
review.reviewImages.map { imageUrl ->
ImageSliderItem(imageUrl, review)
}
}.flatten()

binding.imageSlider.registerOnPageChangeCallback(object :
ViewPager2.OnPageChangeCallback() {
override fun onPageSelected(position: Int) {
super.onPageSelected(position)
parentActivity.changeToolbarTitle("${position + 1} / ${restaurantInfo.pictures.size}")
parentActivity.changeToolbarTitle("${position + 1} / ${imageSliderItems.size}")
}
})

imageSlider.submitList(restaurantInfo.pictures.map {
ImageSliderItem(it)
})
imageSlider.submitList(imageSliderItems)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,29 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.ViewTreeObserver
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.GridLayoutManager
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import org.gdsc.presentation.databinding.FragmentRestaurantPhotoBinding
import org.gdsc.presentation.model.RestaurantPhotoItem
import org.gdsc.presentation.view.mypage.adapter.RestaurantPhotoAdapter
import org.gdsc.presentation.view.mypage.viewmodel.RestaurantDetailViewModel

@AndroidEntryPoint
class RestaurantPhotoFragment : Fragment() {

private var _binding: FragmentRestaurantPhotoBinding? = null
private val binding get() = _binding!!

private val viewModel by activityViewModels<RestaurantDetailViewModel>()

private val restaurantPhotoAdapter = RestaurantPhotoAdapter {
findNavController().navigate(RestaurantDetailFragmentDirections.actionRestaurantDetailFragmentToRestaurantPhotoDetailFragment())
}

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
Expand All @@ -33,9 +43,6 @@ class RestaurantPhotoFragment : Fragment() {
}

private fun setAdapter() {
val restaurantPhotoAdapter = RestaurantPhotoAdapter {
findNavController().navigate(RestaurantDetailFragmentDirections.actionRestaurantDetailFragmentToRestaurantPhotoDetailFragment())
}

val spanCount = 3

Expand All @@ -51,28 +58,15 @@ class RestaurantPhotoFragment : Fragment() {
}
})

viewLifecycleOwner.lifecycleScope.launch {
viewModel.reviews.collect { reviews ->
restaurantPhotoAdapter.submitList(
reviews.map { it.reviewImages }.flatten().map { imageUrl ->
(RestaurantPhotoItem(imageUrl))
})
}
}

// TODO: supposed to be real data
restaurantPhotoAdapter.submitList(
listOf(
RestaurantPhotoItem("https://gdsc-jmt.s3.ap-northeast-2.amazonaws.com/profileImg/defaultImg/Default+image.png"),
RestaurantPhotoItem("https://gdsc-jmt.s3.ap-northeast-2.amazonaws.com/profileImg/defaultImg/Default+image.png"),
RestaurantPhotoItem("https://gdsc-jmt.s3.ap-northeast-2.amazonaws.com/profileImg/defaultImg/Default+image.png"),
RestaurantPhotoItem("https://gdsc-jmt.s3.ap-northeast-2.amazonaws.com/profileImg/defaultImg/Default+image.png"),
RestaurantPhotoItem("https://gdsc-jmt.s3.ap-northeast-2.amazonaws.com/profileImg/defaultImg/Default+image.png"),
RestaurantPhotoItem("https://gdsc-jmt.s3.ap-northeast-2.amazonaws.com/profileImg/defaultImg/Default+image.png"),
RestaurantPhotoItem("https://gdsc-jmt.s3.ap-northeast-2.amazonaws.com/profileImg/defaultImg/Default+image.png"),
RestaurantPhotoItem("https://gdsc-jmt.s3.ap-northeast-2.amazonaws.com/profileImg/defaultImg/Default+image.png"),
RestaurantPhotoItem("https://gdsc-jmt.s3.ap-northeast-2.amazonaws.com/profileImg/defaultImg/Default+image.png"),
RestaurantPhotoItem("https://gdsc-jmt.s3.ap-northeast-2.amazonaws.com/profileImg/defaultImg/Default+image.png"),
RestaurantPhotoItem("https://gdsc-jmt.s3.ap-northeast-2.amazonaws.com/profileImg/defaultImg/Default+image.png"),
RestaurantPhotoItem("https://gdsc-jmt.s3.ap-northeast-2.amazonaws.com/profileImg/defaultImg/Default+image.png"),
RestaurantPhotoItem("https://gdsc-jmt.s3.ap-northeast-2.amazonaws.com/profileImg/defaultImg/Default+image.png"),
RestaurantPhotoItem("https://gdsc-jmt.s3.ap-northeast-2.amazonaws.com/profileImg/defaultImg/Default+image.png"),
RestaurantPhotoItem("https://gdsc-jmt.s3.ap-northeast-2.amazonaws.com/profileImg/defaultImg/Default+image.png"),
RestaurantPhotoItem("https://gdsc-jmt.s3.ap-northeast-2.amazonaws.com/profileImg/defaultImg/Default+image.png"),
)
)
}

}
Binary file added presentation/src/main/res/drawable/ic_plus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit b6d4702

Please sign in to comment.