Skip to content

Commit a4281a6

Browse files
Auto hide bottom nav based on scrolling
1 parent 1f80313 commit a4281a6

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

apikey.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
API_KEY="replace this with your api key"
1+
API_KEY="buyTPvbuxa4HNCJQzDLUj5ndoZWFVZ8d46fsSBXi"

app/src/main/java/com/github/code/gambit/ui/fragment/home/HomeFragment.kt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import androidx.core.view.isVisible
99
import androidx.fragment.app.Fragment
1010
import androidx.fragment.app.viewModels
1111
import androidx.recyclerview.widget.LinearLayoutManager
12+
import androidx.recyclerview.widget.RecyclerView
1213
import com.github.code.gambit.R
1314
import com.github.code.gambit.data.model.File
1415
import com.github.code.gambit.data.model.Url
@@ -144,10 +145,30 @@ class HomeFragment : Fragment(R.layout.fragment_home), FileUrlClickCallback, Bot
144145
}
145146

146147
private fun setUpFileRecyclerView() {
147-
binding.fileList.layoutManager = LinearLayoutManager(requireContext())
148+
val layoutManager = LinearLayoutManager(requireContext())
149+
binding.fileList.layoutManager = layoutManager
148150
binding.fileList.setHasFixedSize(false)
149151
binding.fileList.adapter = adapter
150152
adapter.listener = this
153+
binding.fileList.addOnScrollListener(object : RecyclerView.OnScrollListener() {
154+
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
155+
if (searchBinding.root.isVisible) {
156+
super.onScrolled(recyclerView, dx, dy)
157+
return
158+
}
159+
if (dy > 0) {
160+
hideBottomNav()
161+
} else {
162+
showBottomNav()
163+
}
164+
if (!recyclerView.canScrollVertically(1) && layoutManager.findLastVisibleItemPosition() == layoutManager.itemCount - 1) {
165+
// shortToast("End of list")
166+
println()
167+
}
168+
Timber.tag("home").i("(dx: $dx, dy: $dy)")
169+
super.onScrolled(recyclerView, dx, dy)
170+
}
171+
})
151172
}
152173

153174
private fun registerUrlComponent() {

0 commit comments

Comments
 (0)