diff --git a/CHANGES.md b/CHANGES.md
index 78cea417aa..62bd92006e 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -13,6 +13,7 @@ Improvements 🙌:
- Add Setting Item to Change PIN (#2462)
- Improve room history visibility setting UX (#1579)
- Matrix.to deeplink custom scheme support
+ - Homeserver history (#1933)
Bugfix 🐛:
- Fix cancellation of sending event (#2438)
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/raw/RawModule.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/raw/RawModule.kt
index 6ed14ddb3c..50721b809a 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/raw/RawModule.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/raw/RawModule.kt
@@ -24,9 +24,7 @@ import dagger.Module
import dagger.Provides
import io.realm.RealmConfiguration
import okhttp3.OkHttpClient
-import org.matrix.android.sdk.api.auth.HomeServerHistoryService
import org.matrix.android.sdk.api.raw.RawService
-import org.matrix.android.sdk.internal.auth.DefaultHomeServerHistoryService
import org.matrix.android.sdk.internal.database.RealmKeysUtils
import org.matrix.android.sdk.internal.di.GlobalDatabase
import org.matrix.android.sdk.internal.di.MatrixScope
@@ -61,6 +59,7 @@ internal abstract class RawModule {
.name("matrix-sdk-global.realm")
.schemaVersion(GlobalRealmMigration.SCHEMA_VERSION)
.migration(GlobalRealmMigration)
+ .allowWritesOnUiThread(true)
.modules(GlobalRealmModule())
.build()
}
diff --git a/vector/src/main/java/im/vector/app/features/login/LoginAction.kt b/vector/src/main/java/im/vector/app/features/login/LoginAction.kt
index 9ab02711b5..2b4e3d6be0 100644
--- a/vector/src/main/java/im/vector/app/features/login/LoginAction.kt
+++ b/vector/src/main/java/im/vector/app/features/login/LoginAction.kt
@@ -60,6 +60,9 @@ sealed class LoginAction : VectorViewModelAction {
object ResetLogin : ResetAction()
object ResetResetPassword : ResetAction()
+ // Homeserver history
+ object ClearHomeServerHistory : LoginAction()
+
// For the soft logout case
data class SetupSsoForSessionRecovery(val homeServerUrl: String,
val deviceId: String,
diff --git a/vector/src/main/java/im/vector/app/features/login/LoginServerUrlFormFragment.kt b/vector/src/main/java/im/vector/app/features/login/LoginServerUrlFormFragment.kt
index 716c1cda88..1915cdd204 100644
--- a/vector/src/main/java/im/vector/app/features/login/LoginServerUrlFormFragment.kt
+++ b/vector/src/main/java/im/vector/app/features/login/LoginServerUrlFormFragment.kt
@@ -21,10 +21,12 @@ import android.os.Bundle
import android.view.View
import android.view.inputmethod.EditorInfo
import android.widget.ArrayAdapter
+import androidx.core.view.isInvisible
import androidx.core.view.isVisible
import butterknife.OnClick
import com.google.android.material.textfield.TextInputLayout
import com.jakewharton.rxbinding3.widget.textChanges
+import im.vector.app.BuildConfig
import im.vector.app.R
import im.vector.app.core.extensions.hideKeyboard
import im.vector.app.core.utils.ensureProtocol
@@ -84,7 +86,7 @@ class LoginServerUrlFormFragment @Inject constructor() : AbstractLoginFragment()
loginServerUrlFormNotice.text = getString(R.string.login_server_url_form_common_notice)
}
}
- val completions = state.knownCustomHomeServersUrls
+ val completions = state.knownCustomHomeServersUrls + if (BuildConfig.DEBUG) listOf("http://10.0.2.2:8080") else emptyList()
loginServerUrlFormHomeServerUrl.setAdapter(ArrayAdapter(
requireContext(),
R.layout.item_completion_homeserver,
@@ -100,6 +102,11 @@ class LoginServerUrlFormFragment @Inject constructor() : AbstractLoginFragment()
openUrlInChromeCustomTab(requireActivity(), null, EMS_LINK)
}
+ @OnClick(R.id.loginServerUrlFormClearHistory)
+ fun clearHistory() {
+ loginViewModel.handle(LoginAction.ClearHomeServerHistory)
+ }
+
override fun resetViewModel() {
loginViewModel.handle(LoginAction.ResetHomeServerUrl)
}
@@ -141,6 +148,8 @@ class LoginServerUrlFormFragment @Inject constructor() : AbstractLoginFragment()
override fun updateWithState(state: LoginViewState) {
setupUi(state)
+ loginServerUrlFormClearHistory.isInvisible = state.knownCustomHomeServersUrls.isEmpty()
+
if (state.loginMode != LoginMode.Unknown) {
// The home server url is valid
loginViewModel.handle(LoginAction.PostViewEvent(LoginViewEvents.OnLoginFlowRetrieved))
diff --git a/vector/src/main/java/im/vector/app/features/login/LoginViewModel.kt b/vector/src/main/java/im/vector/app/features/login/LoginViewModel.kt
index 2f84c3081d..0a6dbcaae2 100644
--- a/vector/src/main/java/im/vector/app/features/login/LoginViewModel.kt
+++ b/vector/src/main/java/im/vector/app/features/login/LoginViewModel.kt
@@ -28,7 +28,6 @@ import com.airbnb.mvrx.Uninitialized
import com.airbnb.mvrx.ViewModelContext
import com.squareup.inject.assisted.Assisted
import com.squareup.inject.assisted.AssistedInject
-import im.vector.app.BuildConfig
import im.vector.app.R
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.extensions.configureAndStart
@@ -80,10 +79,7 @@ class LoginViewModel @AssistedInject constructor(
private fun getKnownCustomHomeServersUrls() {
setState {
- copy(
- knownCustomHomeServersUrls = homeServerHistoryService.getKnownServersUrls()
- + if (BuildConfig.DEBUG) listOf("http://10.0.2.2:8080") else emptyList()
- )
+ copy(knownCustomHomeServersUrls = homeServerHistoryService.getKnownServersUrls())
}
}
@@ -137,6 +133,7 @@ class LoginViewModel @AssistedInject constructor(
is LoginAction.ResetAction -> handleResetAction(action)
is LoginAction.SetupSsoForSessionRecovery -> handleSetupSsoForSessionRecovery(action)
is LoginAction.UserAcceptCertificate -> handleUserAcceptCertificate(action)
+ LoginAction.ClearHomeServerHistory -> handleClearHomeServerHistory()
is LoginAction.PostViewEvent -> _viewEvents.post(action.viewEvent)
}.exhaustive
}
@@ -167,6 +164,11 @@ class LoginViewModel @AssistedInject constructor(
getKnownCustomHomeServersUrls()
}
+ private fun handleClearHomeServerHistory() {
+ homeServerHistoryService.clearHistory()
+ getKnownCustomHomeServersUrls()
+ }
+
private fun handleLoginWithToken(action: LoginAction.LoginWithToken) {
val safeLoginWizard = loginWizard
diff --git a/vector/src/main/res/layout/fragment_login_server_url_form.xml b/vector/src/main/res/layout/fragment_login_server_url_form.xml
index 3c223f19cc..a441fee3be 100644
--- a/vector/src/main/res/layout/fragment_login_server_url_form.xml
+++ b/vector/src/main/res/layout/fragment_login_server_url_form.xml
@@ -70,6 +70,17 @@
+
+
Sign Up
Sign In
Continue with SSO
+ Clear history
Element Matrix Services Address
Address