1
0
Fork 0
mirror of https://github.com/Corewala/Buran synced 2024-12-22 07:42:43 +00:00

Previous scroll position is cached to reduce unnecessary re-scrolling

This commit is contained in:
Corewala 2022-07-08 12:28:17 -04:00
parent 9d4386939a
commit aa6dcdad91

View file

@ -81,8 +81,12 @@ class GemActivity : AppCompatActivity() {
private var certPassword: String? = null
private var previousPosition: Int = 0
private var initialised: Boolean = false
private var goingBack: Boolean = false
lateinit var adapter: AbstractGemtextAdapter
private lateinit var home: String
@ -103,6 +107,7 @@ class GemActivity : AppCompatActivity() {
startActivity(Intent.createChooser(this, null))
}
}else{
previousPosition = (binding.gemtextRecycler.layoutManager as LinearLayoutManager).findLastVisibleItemPosition()
//Reset input text hint after user has been searching
if(inSearch) {
binding.addressEdit.hint = getString(R.string.main_input_hint)
@ -696,10 +701,17 @@ class GemActivity : AppCompatActivity() {
adapter.render(state.lines)
//Scroll to top
//Scroll to correct position
if(goingBack){
println("Returning to previous position: $previousPosition")
binding.gemtextRecycler.scrollToPosition(previousPosition)
previousPosition = 0
goingBack = false
}else{
binding.gemtextRecycler.post {
binding.gemtextRecycler.scrollToPosition(0)
}
}
focusEnd()
}
@ -921,6 +933,7 @@ class GemActivity : AppCompatActivity() {
model.cancel()
loadingView(false)
}else if(omniTerm.canGoBack()){
goingBack = true
gemRequest(omniTerm.goBack())
}else{
println("Buran history is empty - exiting")