1
0
Fork 0
mirror of https://git.sr.ht/~oppen/ariane synced 2024-12-27 02:10:30 +00:00

reestablish working history now tabs are removed

This commit is contained in:
Öppen 2020-09-03 20:45:43 +01:00
parent 55b0797612
commit 053935e879

View file

@ -10,11 +10,8 @@ class TvaViewModel: ViewModel() {
private lateinit var gemini: Datasource
private var onState: (state: TvaState) -> Unit = {}
private var activeTab = 0
val history = mutableListOf<URI>()
private val history = mutableListOf<URI>()
fun initialise(gemini: Datasource, onState: (state: TvaState) -> Unit){
this.gemini = gemini
@ -30,6 +27,11 @@ class TvaViewModel: ViewModel() {
fun request(uri: URI){
gemini.request(uri){ state ->
if(history.isEmpty()){
history.add(uri)
}else if(history.last().toString() != uri.toString()) {
history.add(uri)
}
onState(state)
}
}
@ -39,11 +41,22 @@ class TvaViewModel: ViewModel() {
@ExperimentalStdlibApi
fun goBack(){
when {
history.size >= 2 -> {
logHistory()
val previous = history[history.size - 2]
history.removeLast()
println("Requesting history item: $previous")
request(previous)
logHistory()
}
}
}
private fun logHistory(){
history.forEach { uri ->
println("History: $uri")
}
}
}