diff --git a/app/src/main/java/oppen/tva/ui/TvaViewModel.kt b/app/src/main/java/oppen/tva/ui/TvaViewModel.kt index a04c336..c7103a1 100644 --- a/app/src/main/java/oppen/tva/ui/TvaViewModel.kt +++ b/app/src/main/java/oppen/tva/ui/TvaViewModel.kt @@ -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() - + private val history = mutableListOf() 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") + } + } } \ No newline at end of file