Skip to content

Commit

Permalink
[feat/naver_map_with_bottom_sheet]: Map EmptyView 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
dogdduddy committed Feb 27, 2024
1 parent 38193ae commit 1ea9a7b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.gdsc.presentation.view.home

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import org.gdsc.presentation.R

class EmptyAdapter: RecyclerView.Adapter<EmptyAdapter.EmptyViewHolder>() {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EmptyViewHolder {
val inflater = LayoutInflater.from(parent.context)
val view = inflater.inflate(R.layout.item_empty_, parent, false)
return EmptyViewHolder(view)
}

override fun getItemCount(): Int = 1

override fun onBindViewHolder(holder: EmptyViewHolder, position: Int) { }

class EmptyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class HomeFragment : Fragment(), ViewHolderBindListener {
private val recommendPopularRestaurantWrapperAdapter by lazy { RecommendPopularRestaurantWrapperAdapter(recommendPopularRestaurantList)}
private val restaurantFilterAdapter by lazy { RestaurantFilterAdapter(this) }
private val mapMarkerAdapter by lazy { MapMarkerWithRestaurantsAdatper() }
private val emptyAdapter by lazy { EmptyAdapter() }
private lateinit var concatAdapter: ConcatAdapter

private val recommendPopularRestaurantList = listOf<RegisteredRestaurant>()

Expand All @@ -67,7 +69,7 @@ class HomeFragment : Fragment(), ViewHolderBindListener {
setMap(savedInstanceState)
observeState()

val adapter = if (recommendPopularRestaurantList.isNotEmpty()) {
concatAdapter = if (recommendPopularRestaurantList.isNotEmpty()) {
ConcatAdapter(
recommendPopularRestaurantTitleAdapter,
recommendPopularRestaurantWrapperAdapter,
Expand All @@ -80,11 +82,13 @@ class HomeFragment : Fragment(), ViewHolderBindListener {
mapMarkerAdapter
)
}
setRecyclerView()
return binding.root
}

binding.recyclerView.adapter = adapter
fun setRecyclerView() {
binding.recyclerView.adapter = concatAdapter
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())

return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -193,6 +197,17 @@ class HomeFragment : Fragment(), ViewHolderBindListener {
val zoom = CameraUpdate.zoomTo(17.0)
naverMap.moveCamera(zoom)
}

mapMarkerAdapter.addLoadStateListener { loadState ->
if (loadState.append.endOfPaginationReached) {
if (mapMarkerAdapter.itemCount < 1) {
concatAdapter.addAdapter(emptyAdapter)
} else {
concatAdapter.removeAdapter(emptyAdapter)
}
setRecyclerView()
}
}
mapMarkerAdapter.registerAdapterDataObserver(object: RecyclerView.AdapterDataObserver() {
fun setMark() {
CoroutineScope(Dispatchers.Main).launch {
Expand Down
29 changes: 29 additions & 0 deletions presentation/src/main/res/layout/item_empty_.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="@drawable/jmt_character"
android:layout_marginBottom="32dp"
app:layout_constraintBottom_toTopOf="@+id/not_yet_text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:contentDescription="@string/jmt_character_image"/>

<TextView
android:id="@+id/not_yet_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/result_empty"
android:textAppearance="@style/text_large_bold"
android:textColor="@color/grey300"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 1ea9a7b

Please sign in to comment.