@@ -35,10 +35,9 @@ import com.github.code.gambit.utility.extention.show
3535import com.github.code.gambit.utility.extention.showDefaultMaterialAlert
3636import com.github.code.gambit.utility.extention.snackbar
3737import com.github.code.gambit.utility.sharedpreference.LastEvaluatedKeyManager
38+ import com.github.code.gambit.utility.sharedpreference.UserManager
3839import com.google.android.material.bottomsheet.BottomSheetBehavior
3940import com.google.android.material.bottomsheet.BottomSheetBehavior.BottomSheetCallback
40- import com.takusemba.spotlight.OnSpotlightListener
41- import com.takusemba.spotlight.OnTargetListener
4241import com.takusemba.spotlight.Spotlight
4342import com.takusemba.spotlight.Target
4443import com.takusemba.spotlight.shape.Circle
@@ -74,6 +73,9 @@ class HomeFragment : Fragment(R.layout.fragment_home), FileUrlClickCallback, Bot
7473 @Inject
7574 lateinit var lekManager: LastEvaluatedKeyManager
7675
76+ @Inject
77+ lateinit var userManager: UserManager
78+
7779 private lateinit var fileSearchComponent: FileSearchComponent
7880 private lateinit var filterComponent: FilterComponent
7981
@@ -125,7 +127,6 @@ class HomeFragment : Fragment(R.layout.fragment_home), FileUrlClickCallback, Bot
125127 setUpFileRecyclerView()
126128 registerEventCallbacks()
127129 viewModel.setEvent(HomeEvent .GetFiles )
128- // Handler().postDelayed({ spotlight() }, 6000)
129130 }
130131
131132 private fun registerEventCallbacks () {
@@ -206,7 +207,7 @@ class HomeFragment : Fragment(R.layout.fragment_home), FileUrlClickCallback, Bot
206207 }
207208
208209 private fun setUpFileRecyclerView () {
209- adapter.bindEmptyListView (binding.noFileIllustrationContainer)
210+ adapter.bindEmptyView (binding.noFileIllustrationContainer)
210211 val layoutManager = LinearLayoutManager (requireContext())
211212 binding.fileList.layoutManager = layoutManager
212213 binding.fileList.setHasFixedSize(false )
@@ -303,6 +304,7 @@ class HomeFragment : Fragment(R.layout.fragment_home), FileUrlClickCallback, Bot
303304 binding.topContainer.show()
304305 binding.swipeRefresh.show()
305306 binding.fileList.show()
307+ spotlight()
306308 }
307309
308310 private fun showShimmer () {
@@ -313,70 +315,64 @@ class HomeFragment : Fragment(R.layout.fragment_home), FileUrlClickCallback, Bot
313315 }
314316
315317 private fun spotlight () {
318+ if (userManager.isHomeOnBoarded()) {
319+ return
320+ }
316321 val targets = ArrayList <Target >()
317322
318323 val firstRoot = FrameLayout (requireContext())
319- val first = layoutInflater.inflate(R .layout.home_first_spot, firstRoot)
320- val firstTarget = Target .Builder ()
321- .setAnchor(requireMainActivity().getAddFab())
322- .setShape(Circle (120f ))
323- .setOverlay(first)
324- .setOnTargetListener(object : OnTargetListener {
325- override fun onEnded () {}
326- override fun onStarted () {}
327- })
328- .build()
324+ val first = layoutInflater.inflate(R .layout.home_add_file_spot, firstRoot)
325+ val firstTarget = getTarget(requireMainActivity().getAddFab(), first, 250 )
329326
330327 val secondRoot = FrameLayout (requireContext())
331- val second = layoutInflater.inflate(R .layout.home_second_spot, secondRoot)
332- val secondTarget = Target .Builder ()
333- .setAnchor(binding.searchButton)
334- .setShape(Circle (50f ))
335- .setOverlay(second)
336- .setOnTargetListener(object : OnTargetListener {
337- override fun onEnded () {}
338- override fun onStarted () {}
339- }).build()
340-
341- val thirdTarget = Target .Builder ()
342- .setAnchor(binding.filterButton)
343- .setShape(Circle (50f ))
344- .setOverlay(second)
345- .setOnTargetListener(object : OnTargetListener {
346- override fun onEnded () {}
347- override fun onStarted () {}
348- }).build()
328+ val second = layoutInflater.inflate(R .layout.home_drag_spot, secondRoot)
329+ val secondTarget = getTarget(requireMainActivity().getDragView(), second, 100 )
330+
331+ val thirdRoot = FrameLayout (requireContext())
332+ val third = layoutInflater.inflate(R .layout.home_search_filter_spot, thirdRoot)
333+ val thirdTarget = getTarget(binding.searchButton, third)
334+
335+ val fourthTarget = getTarget(binding.filterButton, third)
349336
350337 targets.add(firstTarget)
351338 targets.add(secondTarget)
352339 targets.add(thirdTarget)
340+ targets.add(fourthTarget)
353341
354342 val spotlight = Spotlight .Builder (requireActivity())
355343 .setTargets(targets)
356344 .setBackgroundColorRes(R .color.spotlightBackground)
357345 .setDuration(1000L )
358346 .setAnimation(DecelerateInterpolator (2f ))
359- .setOnSpotlightListener(object : OnSpotlightListener {
360- override fun onStarted () {}
361- override fun onEnded () {}
362- }).build()
347+ .build()
363348
364349 spotlight.start()
365350
366351 val nextTarget = View .OnClickListener { spotlight.next() }
367352
368- // val closeSpotlight = View.OnClickListener { spotlight.finish() }
353+ val closeSpotlight = View .OnClickListener {
354+ userManager.updateHomeOnBoardingState()
355+ spotlight.finish()
356+ }
369357
370358 first.findViewById<View >(R .id.next_button).setOnClickListener(nextTarget)
371- second.findViewById<View >(R .id.next_button).setOnClickListener {
359+ second.findViewById<View >(R .id.next_button).setOnClickListener(nextTarget)
360+ third.findViewById<View >(R .id.next_button).setOnClickListener {
372361 spotlight.next()
373- second .findViewById<TextView >(R .id.title_text).text = getString(R .string.use_filters)
374- second .findViewById<TextView >(R .id.info_text).text =
362+ third .findViewById<TextView >(R .id.title_text).text = getString(R .string.use_filters)
363+ third .findViewById<TextView >(R .id.info_text).text =
375364 getString(R .string.or_you_can_filter_files_based_on_dates_they_were_uploaded)
376- second.findViewById<View >(R .id.arrow).animate().rotation(105f ).setDuration(500 ).start()
365+ third.findViewById<View >(R .id.arrow).animate().rotation(105f ).setDuration(500 ).start()
366+ third.findViewById<View >(R .id.next_button).setOnClickListener(closeSpotlight)
377367 }
378368 }
379369
370+ private fun getTarget (anchorView : View , overlay : View , radius : Int = 50): Target {
371+ return Target .Builder ().setAnchor(anchorView).setShape(Circle (radius.toFloat()))
372+ .setOverlay(overlay)
373+ .build()
374+ }
375+
380376 private fun showFilter () {
381377 animateBottomNav(0f )
382378 binding.overlay.show()
@@ -399,6 +395,7 @@ class HomeFragment : Fragment(R.layout.fragment_home), FileUrlClickCallback, Bot
399395
400396 fun closeSearch () {
401397 hideKeyboard()
398+ adapter.bindEmptyView(binding.noFileIllustrationContainer)
402399 adapter.restore()
403400 searchBinding.root.hide()
404401 showBottomNav()
0 commit comments