Fix connection error dialog bug

This commit is contained in:
Philipp Heckel 2026-01-19 18:04:41 -05:00
parent 52d0d74d11
commit 18ba443da6
7 changed files with 13 additions and 21 deletions

View file

@ -17,8 +17,8 @@ android {
minSdkVersion 26
targetSdkVersion 36
versionCode 56
versionName "1.22.0"
versionCode 57
versionName "1.22.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

View file

@ -28,7 +28,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 connectionForceReconnectVersions = ConcurrentHashMap<String, Long>()
private val connectionForceReconnectVersions = ConcurrentHashMap<String, Long>() // Base URL -> Number of times "Retry" was pressed
// TODO Move these into an ApplicationState singleton
val detailViewSubscriptionId = AtomicLong(0L) // Omg, what a hack ...
@ -94,8 +94,10 @@ class Repository(private val sharedPrefs: SharedPreferences, database: Database)
@Suppress("RedundantSuspendModifier")
@WorkerThread
suspend fun removeSubscription(subscriptionId: Long) {
subscriptionDao.remove(subscriptionId)
suspend fun removeSubscription(subscription: Subscription) {
notificationDao.removeAll(subscription.id)
subscriptionDao.remove(subscription.id)
updateConnectionDetails(subscription.baseUrl, ConnectionState.NOT_APPLICABLE)
}
suspend fun getNotifications(): List<Notification> {
@ -174,10 +176,6 @@ class Repository(private val sharedPrefs: SharedPreferences, database: Database)
notificationDao.removeIfOlderThan(subscriptionId, olderThanTimestamp)
}
fun removeAllNotifications(subscriptionId: Long) {
notificationDao.removeAll(subscriptionId)
}
suspend fun getUsers(): List<User> {
return userDao.list()
}
@ -577,10 +575,6 @@ class Repository(private val sharedPrefs: SharedPreferences, database: Database)
return connectionDetails.toMap()
}
fun getConnectionDetailsForBaseUrl(baseUrl: String): ConnectionDetails? {
return connectionDetails[baseUrl]
}
fun getConnectionForceReconnectVersion(baseUrl: String): Long {
return connectionForceReconnectVersions[baseUrl] ?: 0L
}

View file

@ -231,9 +231,8 @@ class ConnectionErrorFragment : DialogFragment() {
private fun updateCountdown() {
val details = selectedBaseUrl?.let { connectionDetails[it] }
if (details != null && details.nextRetryTime > 0) {
val remainingMillis = details.nextRetryTime - System.currentTimeMillis()
if (remainingMillis > 0) {
val remainingSeconds = (remainingMillis / 1000).toInt()
val remainingSeconds = ((details.nextRetryTime - System.currentTimeMillis()) / 1000).toInt()
if (remainingSeconds > 0) {
countdownTextView.text = getString(R.string.connection_error_dialog_retry_countdown, remainingSeconds)
countdownTextView.visibility = View.VISIBLE
} else {

View file

@ -872,8 +872,8 @@ class DetailActivity : AppCompatActivity(), NotificationFragment.NotificationSet
.setPositiveButton(R.string.detail_delete_dialog_permanently_delete) { _, _ ->
Log.d(TAG, "Deleting subscription with subscription ID $subscriptionId (topic: $subscriptionTopic)")
GlobalScope.launch(Dispatchers.IO) {
repository.removeAllNotifications(subscriptionId)
repository.removeSubscription(subscriptionId)
val subscription = repository.getSubscription(subscriptionId) ?: return@launch
repository.removeSubscription(subscription)
if (subscriptionBaseUrl == appBaseUrl) {
messenger.unsubscribe(subscriptionTopic)
}

View file

@ -32,8 +32,7 @@ class SubscriptionsViewModel(private val repository: Repository) : ViewModel() {
val distributor = Distributor(context)
distributor.sendUnregistered(subscription.upAppId, subscription.upConnectorToken)
}
repository.removeAllNotifications(subscriptionId)
repository.removeSubscription(subscriptionId)
repository.removeSubscription(subscription)
if (subscription.icon != null) {
val resolver = context.applicationContext.contentResolver
try {

View file

@ -209,7 +209,7 @@ class BroadcastReceiver : android.content.BroadcastReceiver() {
// Remove subscription
Log.d(TAG, "Removing subscription ${existingSubscription.id} with connectorToken $connectorToken")
repository.removeSubscription(existingSubscription.id)
repository.removeSubscription(existingSubscription)
existingSubscription.upAppId?.let { appId -> distributor.sendUnregistered(appId, connectorToken) }
// Refresh (and maybe stop) foreground service