Make force reconnect work
This commit is contained in:
parent
1dcd77287c
commit
ee29bdfc46
4 changed files with 18 additions and 2 deletions
|
|
@ -27,6 +27,7 @@ class Repository(private val sharedPrefs: SharedPreferences, database: Database)
|
|||
|
||||
private val connectionDetails = ConcurrentHashMap<String, ConnectionDetails>()
|
||||
private val connectionDetailsLiveData = MutableLiveData<Map<String, ConnectionDetails>>(connectionDetails)
|
||||
private val reconnectVersions = ConcurrentHashMap<String, Long>()
|
||||
|
||||
// TODO Move these into an ApplicationState singleton
|
||||
val detailViewSubscriptionId = AtomicLong(0L) // Omg, what a hack ...
|
||||
|
|
@ -572,6 +573,15 @@ class Repository(private val sharedPrefs: SharedPreferences, database: Database)
|
|||
return connectionDetails[baseUrl]
|
||||
}
|
||||
|
||||
fun getReconnectVersion(baseUrl: String): Long {
|
||||
return reconnectVersions[baseUrl] ?: 0L
|
||||
}
|
||||
|
||||
fun incrementReconnectVersion(baseUrl: String) {
|
||||
reconnectVersions.compute(baseUrl) { _, current -> (current ?: 0L) + 1 }
|
||||
Log.d(TAG, "Reconnect version incremented for $baseUrl: ${reconnectVersions[baseUrl]}")
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val SHARED_PREFS_ID = "MainPreferences"
|
||||
const val SHARED_PREFS_POLL_WORKER_VERSION = "PollWorkerVersion"
|
||||
|
|
|
|||
|
|
@ -17,5 +17,6 @@ data class ConnectionId(
|
|||
val credentialsHash: Int, // Hash of "username:password" or 0 if no user
|
||||
val headersHash: Int, // Hash of sorted headers or 0 if none
|
||||
val trustedCertsHash: Int, // Hash of trusted certificates or 0 if none
|
||||
val clientCertHash: Int // Hash of client certificate or 0 if none
|
||||
val clientCertHash: Int, // Hash of client certificate or 0 if none
|
||||
val reconnectVersion: Long // Incremented to force reconnection for this baseUrl
|
||||
)
|
||||
|
|
|
|||
|
|
@ -220,6 +220,7 @@ class SubscriberService : Service() {
|
|||
.hashCode()
|
||||
val trustedCertsHash = repository.getTrustedCertificate(baseUrl)?.hashCode() ?: 0
|
||||
val clientCertHash = repository.getClientCertificate(baseUrl)?.hashCode() ?: 0
|
||||
val reconnectVersion = repository.getReconnectVersion(baseUrl)
|
||||
ConnectionId(
|
||||
baseUrl = baseUrl,
|
||||
topicsToSubscriptionIds = subs.associate { s -> s.topic to s.id },
|
||||
|
|
@ -227,7 +228,8 @@ class SubscriberService : Service() {
|
|||
credentialsHash = credentialsHash,
|
||||
headersHash = headersHash,
|
||||
trustedCertsHash = trustedCertsHash,
|
||||
clientCertHash = clientCertHash
|
||||
clientCertHash = clientCertHash,
|
||||
reconnectVersion = reconnectVersion
|
||||
)
|
||||
}
|
||||
.toSet()
|
||||
|
|
|
|||
|
|
@ -72,6 +72,9 @@ class ConnectionErrorFragment : DialogFragment() {
|
|||
toolbar.setOnMenuItemClickListener { menuItem ->
|
||||
when (menuItem.itemId) {
|
||||
R.id.connection_error_dialog_action_retry -> {
|
||||
selectedBaseUrl?.let { baseUrl ->
|
||||
repository.incrementReconnectVersion(baseUrl)
|
||||
}
|
||||
SubscriberServiceManager.refresh(requireContext())
|
||||
dismiss()
|
||||
true
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue