@@ -36,6 +36,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
3636 private lateinit var binding: ActivityMainBinding
3737
3838 private lateinit var viewPager: ViewPager2
39+ private var restaurantAdapter: RestaurantAdapter ? = null
3940 private lateinit var locationPermissionDialog: LocationPermissionDialog
4041
4142 override fun onCreate (savedInstanceState : Bundle ? ) {
@@ -100,19 +101,25 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
100101
101102 private fun handleEvent (event : Event ) = when (event) {
102103 is Event .ShowToast -> Toast .makeText(this , event.text, Toast .LENGTH_SHORT ).show()
104+ is Event .FetchRestaurantInfo -> {
105+ if (restaurantAdapter != null ) {
106+ restaurantAdapter?.setData(event.data)
107+ viewPager.adapter?.notifyDataSetChanged()
108+ } else { }
109+ }
103110 is Event .OnMarkerClicked -> {
104111 if (viewPager.adapter != null ) {
105- viewPager.currentItem = event.markerIndex
112+ viewPager.setCurrentItem( event.markerIndex, false )
106113 } else {
107114 viewModel.showLocationViewPager(event.markerIndex)
108115 }
109116 }
110117 is Event .ShowRestaurantView -> {
111118 if (viewPager.adapter == null ) {
112- viewPager.adapter =
113- RestaurantAdapter (event.data, this , remoteConfigRepository, analyticsUtils)
119+ restaurantAdapter = RestaurantAdapter (event.data, this , remoteConfigRepository, analyticsUtils)
120+ viewPager.adapter = restaurantAdapter
114121 if (event.markerIndex != - 1 ) {
115- viewPager.currentItem = event.markerIndex
122+ viewPager.setCurrentItem( event.markerIndex, false )
116123 } else { }
117124 } else { }
118125 }
@@ -177,6 +184,9 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
177184 binding.naverMap.onResume()
178185
179186 viewModel.checkLatestAppVersion()
187+ if (viewPager != null && restaurantAdapter != null ) {
188+ viewModel.updateLocationInfo(viewPager.currentItem)
189+ }
180190 }
181191
182192 override fun onPause () {
@@ -211,28 +221,30 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
211221 viewPager.adapter = null
212222 viewModel.showLocationInfo(" 강남" )
213223
214- binding.locationGnBtn.background = applicationContext.getDrawable(R .drawable.color_button_background)
215- binding.locationYsBtn.background = applicationContext.getDrawable(R .drawable.white_button_background)
216- binding.locationGnBtn.setTextColor(applicationContext.getColor(R .color.white))
217- binding.locationYsBtn.setTextColor(applicationContext.getColor(R .color.gray600))
218-
219- binding.currentLocationBtn.background = resources.getDrawable(R .drawable.current_location_button)
220- binding.currentLocationTv.setTextColor(resources.getColor(R .color.colorPrimary))
221- binding.currentLocationIv.setColorFilter(resources.getColor(R .color.colorPrimary))
224+ binding.apply {
225+ locationGnBtn.background = applicationContext.getDrawable(R .drawable.color_button_background)
226+ locationYsBtn.background = applicationContext.getDrawable(R .drawable.white_button_background)
227+ locationGnBtn.setTextColor(applicationContext.getColor(R .color.white))
228+ locationYsBtn.setTextColor(applicationContext.getColor(R .color.gray600))
229+ currentLocationBtn.background = resources.getDrawable(R .drawable.current_location_button)
230+ currentLocationTv.setTextColor(resources.getColor(R .color.colorPrimary))
231+ currentLocationIv.setColorFilter(resources.getColor(R .color.colorPrimary))
232+ }
222233 }
223234 R .id.location_ys_btn -> {
224235 viewPager.invalidate()
225236 viewPager.adapter = null
226237 viewModel.showLocationInfo(" 역삼" )
227238
228- binding.locationYsBtn.background = applicationContext.getDrawable(R .drawable.color_button_background)
229- binding.locationGnBtn.background = applicationContext.getDrawable(R .drawable.white_button_background)
230- binding.locationYsBtn.setTextColor(applicationContext.getColor(R .color.white))
231- binding.locationGnBtn.setTextColor(applicationContext.getColor(R .color.gray600))
232-
233- binding.currentLocationBtn.background = resources.getDrawable(R .drawable.current_location_button)
234- binding.currentLocationTv.setTextColor(resources.getColor(R .color.colorPrimary))
235- binding.currentLocationIv.setColorFilter(resources.getColor(R .color.colorPrimary))
239+ binding.apply {
240+ locationYsBtn.background = applicationContext.getDrawable(R .drawable.color_button_background)
241+ locationGnBtn.background = applicationContext.getDrawable(R .drawable.white_button_background)
242+ locationYsBtn.setTextColor(applicationContext.getColor(R .color.white))
243+ locationGnBtn.setTextColor(applicationContext.getColor(R .color.gray600))
244+ currentLocationBtn.background = resources.getDrawable(R .drawable.current_location_button)
245+ currentLocationTv.setTextColor(resources.getColor(R .color.colorPrimary))
246+ currentLocationIv.setColorFilter(resources.getColor(R .color.colorPrimary))
247+ }
236248 }
237249 R .id.feedback_iv -> {
238250 val feedbackUrl = viewModel.getFeedbackUrl()
0 commit comments