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