Skip to content
This repository has been archived by the owner on Feb 6, 2025. It is now read-only.

Commit

Permalink
Remove debug code, use thread-safe list implementation (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzolnai authored Oct 18, 2024
1 parent 3f53e85 commit 0b885b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
23 changes: 10 additions & 13 deletions app/src/main/java/nl/eduvpn/app/service/HistoryService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import nl.eduvpn.app.entity.exception.CommonException
import nl.eduvpn.app.service.SerializerService.UnknownFormatException
import nl.eduvpn.app.utils.Listener
import nl.eduvpn.app.utils.Log
import java.util.LinkedList
import java.util.function.Consumer
import java.util.concurrent.CopyOnWriteArrayList

/**
* Service which stores previously used access token and profile names.
Expand All @@ -36,33 +35,31 @@ class HistoryService(private val backendService: BackendService) {
var addedServers: AddedServers? = null
private set

private val _listeners: MutableList<Listener> = LinkedList()
private val listeners = CopyOnWriteArrayList<Listener>()

/**
* Loads the state of the service.
*/
@kotlin.jvm.Throws(Exception::class)
fun load() {
try {
addedServers = backendService.getAddedServers()
notifyListeners()
} catch (e: Exception) {
throw RuntimeException(e)
}
addedServers = backendService.getAddedServers()
notifyListeners()
}

fun addListener(listener: Listener) {
if (!_listeners.contains(listener)) {
_listeners.add(listener)
if (!listeners.contains(listener)) {
listeners.add(listener)
}
}

fun removeListener(listener: Listener) {
_listeners.remove(listener)
listeners.remove(listener)
}

private fun notifyListeners() {
_listeners.forEach(Consumer { l: Listener -> l.update(this, null) })
listeners.forEach {
it.update(this, null)
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,18 @@ class ServerSelectionViewModel @Inject constructor(

private fun refresh() {
viewModelScope.launch(Dispatchers.IO) {
println("XXX Starting refresh")
try {
historyService.removeListener(this@ServerSelectionViewModel)
historyService.load()
historyService.addListener(this@ServerSelectionViewModel)

println("XXX Added server in SSM ${historyService.addedServers?.customServers}")
val needsServerList = historyService.addedServers?.secureInternetServer != null
if (needsServerList) {
refreshServerList()
} else {
refreshInstances()
}
} catch (ex: Exception) {
Log.w(TAG, "XXX Could not refresh server selection list", ex)
Log.w(TAG, "Could not refresh server selection list", ex)
_parentAction.postValue(ParentAction.DisplayError(R.string.error_dialog_title, ex.message ?: ex.toString()))
}
}
Expand Down

0 comments on commit 0b885b0

Please sign in to comment.