Allow ignoring network changes for autoreconnect

parent 26b2fdf7
......@@ -93,10 +93,9 @@ class QuasselService : DaggerLifecycleService(),
val connectionSettings = Settings.connection(this)
if (this.connectionSettings.showNotification != connectionSettings.showNotification) {
this.connectionSettings = connectionSettings
updateNotificationStatus(this.progress)
}
this.connectionSettings = connectionSettings
val (accountId, reconnect) = this.sharedPreferences(Keys.Status.NAME, Context.MODE_PRIVATE) {
Pair(
......@@ -415,13 +414,15 @@ class QuasselService : DaggerLifecycleService(),
.observeNetworkConnectivity(applicationContext)
.toLiveData()
.observe(this, Observer { connectivity ->
log(INFO, "QuasselService", "Connectivity changed: $connectivity")
handlerService.backend {
log(INFO, "QuasselService", "Reconnect triggered: Network changed")
sessionManager.autoConnect(
ignoreConnectionState = true,
ignoreSetting = true
)
if (!connectionSettings.ignoreNetworkChanges) {
log(INFO, "QuasselService", "Connectivity changed: $connectivity")
handlerService.backend {
log(INFO, "QuasselService", "Reconnect triggered: Network changed")
sessionManager.autoConnect(
ignoreConnectionState = true,
ignoreSetting = true
)
}
}
})
......
......@@ -20,7 +20,8 @@
package de.kuschku.quasseldroid.settings
data class ConnectionSettings(
val showNotification: Boolean = true
val showNotification: Boolean = true,
val ignoreNetworkChanges: Boolean = false
) {
companion object {
val DEFAULT = ConnectionSettings()
......
......@@ -263,6 +263,10 @@ object Settings {
showNotification = getBoolean(
context.getString(R.string.preference_show_notification_key),
ConnectionSettings.DEFAULT.showNotification
),
ignoreNetworkChanges = getBoolean(
context.getString(R.string.preference_ignore_network_changes_key),
ConnectionSettings.DEFAULT.ignoreNetworkChanges
)
)
}
......
......@@ -333,5 +333,9 @@
<string name="preference_show_notification_title">Show notification</string>
<string name="preference_show_notification_summary">Keeps Quasseldroid always connected by showing a persistent notification</string>
<string name="preference_ignore_network_changes_key" translatable="false">ignore_network_changes</string>
<string name="preference_ignore_network_changes_title">Ignore network changes</string>
<string name="preference_ignore_network_changes_summary">Stops Quasseldroid from reconnecting automatically if the network changes</string>
<string name="preference_notification_id_key" translatable="false">notification_id</string>
</resources>
......@@ -348,5 +348,10 @@
android:key="@string/preference_show_notification_key"
android:summary="@string/preference_show_notification_summary"
android:title="@string/preference_show_notification_title" />
<SwitchPreference
android:defaultValue="true"
android:key="@string/preference_ignore_network_changes_key"
android:summary="@string/preference_ignore_network_changes_summary"
android:title="@string/preference_ignore_network_changes_title" />
</PreferenceCategory>
</PreferenceScreen>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment