mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 20:06:51 +03:00
Add integration entry to settings
This commit is contained in:
parent
4b37ede8c2
commit
ba46f10e3f
3 changed files with 73 additions and 2 deletions
|
@ -69,7 +69,8 @@ class VectorPreferences @Inject constructor(private val context: Context) {
|
|||
const val SETTINGS_ENCRYPTION_IMPORT_E2E_ROOM_KEYS_PREFERENCE_KEY = "SETTINGS_ENCRYPTION_IMPORT_E2E_ROOM_KEYS_PREFERENCE_KEY"
|
||||
const val SETTINGS_ENCRYPTION_NEVER_SENT_TO_PREFERENCE_KEY = "SETTINGS_ENCRYPTION_NEVER_SENT_TO_PREFERENCE_KEY"
|
||||
const val SETTINGS_SHOW_DEVICES_LIST_PREFERENCE_KEY = "SETTINGS_SHOW_DEVICES_LIST_PREFERENCE_KEY"
|
||||
|
||||
const val SETTINGS_ALLOW_INTEGRATIONS_KEY = "SETTINGS_ALLOW_INTEGRATIONS_KEY"
|
||||
const val SETTINGS_INTEGRATION_MANAGER_UI_URL_KEY = "SETTINGS_INTEGRATION_MANAGER_UI_URL_KEY"
|
||||
const val SETTINGS_SECURE_MESSAGE_RECOVERY_PREFERENCE_KEY = "SETTINGS_SECURE_MESSAGE_RECOVERY_PREFERENCE_KEY"
|
||||
|
||||
// user
|
||||
|
|
|
@ -31,18 +31,23 @@ import androidx.core.view.isVisible
|
|||
import androidx.preference.EditTextPreference
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceCategory
|
||||
import androidx.preference.SwitchPreference
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.engine.cache.DiskCache
|
||||
import com.google.android.material.textfield.TextInputEditText
|
||||
import com.google.android.material.textfield.TextInputLayout
|
||||
import im.vector.matrix.android.api.MatrixCallback
|
||||
import im.vector.matrix.android.api.NoOpMatrixCallback
|
||||
import im.vector.matrix.android.api.failure.isInvalidPassword
|
||||
import im.vector.matrix.android.api.session.integrationmanager.IntegrationManagerConfig
|
||||
import im.vector.matrix.android.api.session.integrationmanager.IntegrationManagerService
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.extensions.hideKeyboard
|
||||
import im.vector.riotx.core.extensions.showPassword
|
||||
import im.vector.riotx.core.platform.SimpleTextWatcher
|
||||
import im.vector.riotx.core.preference.UserAvatarPreference
|
||||
import im.vector.riotx.core.preference.VectorPreference
|
||||
import im.vector.riotx.core.preference.VectorSwitchPreference
|
||||
import im.vector.riotx.core.utils.PERMISSION_REQUEST_CODE_LAUNCH_CAMERA
|
||||
import im.vector.riotx.core.utils.TextUtils
|
||||
import im.vector.riotx.core.utils.allGranted
|
||||
|
@ -92,6 +97,18 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() {
|
|||
findPreference<VectorPreference>(VectorPreferences.SETTINGS_CONTACTS_PHONEBOOK_COUNTRY_PREFERENCE_KEY)!!
|
||||
}
|
||||
|
||||
private val integrationServiceListener = object : IntegrationManagerService.Listener {
|
||||
override fun onConfigurationChanged(config: IntegrationManagerConfig) {
|
||||
super.onConfigurationChanged(config)
|
||||
refreshIntegrationManagerSettings()
|
||||
}
|
||||
|
||||
override fun onIsEnabledChanged(enabled: Boolean) {
|
||||
super.onIsEnabledChanged(enabled)
|
||||
refreshIntegrationManagerSettings()
|
||||
}
|
||||
}
|
||||
|
||||
override fun bindPref() {
|
||||
// Avatar
|
||||
mUserAvatarPreference.let {
|
||||
|
@ -196,6 +213,15 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
(findPreference(VectorPreferences.SETTINGS_ALLOW_INTEGRATIONS_KEY) as? VectorSwitchPreference)?.let {
|
||||
it.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
|
||||
//Disable it while updating the state, will be re-enabled by the account data listener.
|
||||
it.isEnabled = false
|
||||
session.integrationManagerService().setIntegrationEnabled(newValue as Boolean, NoOpMatrixCallback())
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
// clear medias cache
|
||||
findPreference<VectorPreference>(VectorPreferences.SETTINGS_CLEAR_MEDIA_CACHE_PREFERENCE_KEY)!!.let {
|
||||
val size = getSizeOfFiles(File(requireContext().cacheDir, DiskCache.Factory.DEFAULT_DISK_CACHE_DIR))
|
||||
|
@ -241,9 +267,15 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() {
|
|||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
// Refresh identity server summary
|
||||
mIdentityServerPreference.summary = session.identityService().getCurrentIdentityServerUrl() ?: getString(R.string.identity_server_not_defined)
|
||||
refreshIntegrationManagerSettings()
|
||||
session.integrationManagerService().addListener(integrationServiceListener)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
session.integrationManagerService().removeListener(integrationServiceListener)
|
||||
}
|
||||
|
||||
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
|
||||
|
@ -315,6 +347,25 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun refreshIntegrationManagerSettings() {
|
||||
val integrationAllowed = session.integrationManagerService().isIntegrationEnabled()
|
||||
(findPreference<SwitchPreference>(VectorPreferences.SETTINGS_ALLOW_INTEGRATIONS_KEY))!!.let {
|
||||
val savedListener = it.onPreferenceChangeListener
|
||||
it.onPreferenceChangeListener = null
|
||||
it.isChecked = integrationAllowed
|
||||
it.isEnabled = true
|
||||
it.onPreferenceChangeListener = savedListener
|
||||
}
|
||||
findPreference<VectorPreference>(VectorPreferences.SETTINGS_INTEGRATION_MANAGER_UI_URL_KEY)!!.let {
|
||||
if (integrationAllowed) {
|
||||
it.summary = session.integrationManagerService().getPreferredConfig().uiUrl
|
||||
it.isVisible = true
|
||||
} else {
|
||||
it.isVisible = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the avatar.
|
||||
*/
|
||||
|
|
|
@ -96,6 +96,25 @@
|
|||
|
||||
</im.vector.riotx.core.preference.VectorPreferenceCategory>
|
||||
|
||||
<im.vector.riotx.core.preference.VectorPreferenceCategory android:title="@string/settings_integrations">
|
||||
|
||||
<im.vector.riotx.core.preference.VectorPreference
|
||||
android:focusable="false"
|
||||
android:persistent="false"
|
||||
android:summary="@string/settings_integrations_summary" />
|
||||
|
||||
<im.vector.riotx.core.preference.VectorSwitchPreference
|
||||
android:key="SETTINGS_ALLOW_INTEGRATIONS_KEY"
|
||||
android:title="@string/settings_integration_allow" />
|
||||
|
||||
<im.vector.riotx.core.preference.VectorPreference
|
||||
android:dependency="SETTINGS_ALLOW_INTEGRATIONS_KEY"
|
||||
android:key="SETTINGS_INTEGRATION_MANAGER_UI_URL_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_integration_manager" />
|
||||
|
||||
</im.vector.riotx.core.preference.VectorPreferenceCategory>
|
||||
|
||||
<im.vector.riotx.core.preference.VectorPreferenceCategory android:title="@string/action_sign_out">
|
||||
|
||||
<im.vector.riotx.core.preference.VectorPreference
|
||||
|
|
Loading…
Reference in a new issue