Add labs setting to use UP endpoint as gateway directly

Change-Id: I8117a4bd15d67703d15be20023146dec8ceec07f
This commit is contained in:
SpiritCroc 2021-09-14 09:56:19 +02:00
parent c38ece586e
commit b96f150dd0
5 changed files with 33 additions and 0 deletions

View File

@ -22,6 +22,7 @@ import androidx.core.content.edit
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import im.vector.app.R
import im.vector.app.core.di.DefaultSharedPreferences
import im.vector.app.features.settings.VectorPreferences
import im.vector.app.push.fcm.FcmHelper
import org.unifiedpush.android.connector.Registration
import timber.log.Timber
@ -158,6 +159,10 @@ object UPHelper {
* if GET custom returns """{"unifiedpush":{"gateway":"matrix"}}"""
* return custom
*/
val vectorPreferences = VectorPreferences(context)
if (vectorPreferences.forceUsCustomUpGateway()) {
return custom
}
}
return default
}

View File

@ -205,6 +205,7 @@ class VectorPreferences @Inject constructor(private val context: Context) {
private const val SETTINGS_USER_COLOR_MODE_PUBLIC_ROOM = "SETTINGS_USER_COLOR_MODE_PUBLIC_ROOM"
private const val SETTINGS_OPEN_CHATS_AT_FIRST_UNREAD = "SETTINGS_OPEN_CHATS_AT_FIRST_UNREAD"
const val SETTINGS_VOICE_MESSAGE = "SETTINGS_VOICE_MESSAGE"
const val SETTINGS_UNIFIED_PUSH_FORCE_CUSTOM_GATEWAY = "SETTINGS_UNIFIED_PUSH_FORCE_CUSTOM_GATEWAY"
private const val DID_ASK_TO_ENABLE_SESSION_PUSH = "DID_ASK_TO_ENABLE_SESSION_PUSH"
private const val DID_PROMOTE_NEW_RESTRICTED_JOIN_RULE = "DID_PROMOTE_NEW_RESTRICTED_JOIN_RULE"
@ -1021,6 +1022,10 @@ class VectorPreferences @Inject constructor(private val context: Context) {
return Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP && defaultPrefs.getBoolean(SETTINGS_VOICE_MESSAGE, true)
}
fun forceUsCustomUpGateway(): Boolean {
return defaultPrefs.getBoolean(SETTINGS_UNIFIED_PUSH_FORCE_CUSTOM_GATEWAY, false)
}
/**
* I likely do more fresh installs of the app than anyone else, so a shortcut to change some of the default settings to
* my preferred values can safe me some time
@ -1041,6 +1046,7 @@ class VectorPreferences @Inject constructor(private val context: Context) {
.putBoolean(SETTINGS_LABS_ENABLE_SWIPE_TO_REPLY, false)
.putBoolean(SETTINGS_VOICE_MESSAGE, false)
.putBoolean(SETTINGS_USE_RAGE_SHAKE_KEY, true)
.putBoolean(SETTINGS_UNIFIED_PUSH_FORCE_CUSTOM_GATEWAY, true)
.apply()
}

View File

@ -17,9 +17,12 @@
package im.vector.app.features.settings
import android.os.Build
import android.os.Handler
import android.os.Looper
import androidx.preference.Preference
import im.vector.app.R
import im.vector.app.core.preference.VectorSwitchPreference
import im.vector.app.core.pushers.UPHelper
import im.vector.app.features.themes.ThemeUtils
import im.vector.app.features.MainActivity
import im.vector.app.features.MainActivityArgs
@ -58,5 +61,10 @@ class VectorSettingsLabsFragment @Inject constructor(
findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_ALLOW_URL_PREVIEW_IN_ENCRYPTED_ROOM_KEY)?.isEnabled = vectorPreferences.showUrlPreviews()
findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_VOICE_MESSAGE)?.isEnabled = Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP
findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_UNIFIED_PUSH_FORCE_CUSTOM_GATEWAY)?.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, _ ->
Handler(Looper.getMainLooper()).postDelayed({ context?.let { UPHelper.registerUnifiedPush(it)} } , 1000)
true
}
}
}

View File

@ -132,4 +132,8 @@
<string name="settings_apply_sc_default_settings_dialog_title">Mess up settings</string>
<string name="settings_apply_sc_default_settings_dialog_summary">If you continue, this will mess with your app settings!</string>
<string name="settings_unifiedpush">UnifiedPush</string>
<string name="settings_unifiedpush_force_custom_gateway">Force custom push gateway</string>
<string name="settings_unifiedpush_force_custom_gateway_summary">Only enable this if your push endpoint does not require an external gateway.</string>
</resources>

View File

@ -82,5 +82,15 @@
android:summary="@string/labs_use_restricted_join_rule_desc"/>
<!--</im.vector.app.core.preference.VectorPreferenceCategory>-->
<im.vector.app.core.preference.VectorPreferenceCategory
android:title="@string/settings_unifiedpush">
<im.vector.app.core.preference.VectorSwitchPreference
android:key="SETTINGS_UNIFIED_PUSH_FORCE_CUSTOM_GATEWAY"
android:title="@string/settings_unifiedpush_force_custom_gateway"
android:summary="@string/settings_unifiedpush_force_custom_gateway_summary"
android:defaultValue="false" />
</im.vector.app.core.preference.VectorPreferenceCategory>
</androidx.preference.PreferenceScreen>