Rename some classes

This commit is contained in:
Benoit Marty 2021-12-08 21:57:45 +01:00 committed by Benoit Marty
parent 411fd31d4c
commit e1fc7cfaba
12 changed files with 32 additions and 33 deletions

View File

@ -23,7 +23,7 @@ import android.webkit.WebViewClient
import android.widget.TextView
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import im.vector.app.R
import im.vector.app.features.discovery.IdentityServerWithTerms
import im.vector.app.features.discovery.ServerAndPolicies
import me.gujun.android.span.link
import me.gujun.android.span.span
@ -45,7 +45,7 @@ fun Context.displayInWebView(url: String) {
.show()
}
fun Context.showIdentityServerConsentDialog(identityServerWithTerms: IdentityServerWithTerms?,
fun Context.showIdentityServerConsentDialog(identityServerWithTerms: ServerAndPolicies?,
consentCallBack: (() -> Unit)) {
// Build the message
val content = span {

View File

@ -17,9 +17,9 @@
package im.vector.app.features.contactsbook
import im.vector.app.core.platform.VectorViewEvents
import im.vector.app.features.discovery.IdentityServerWithTerms
import im.vector.app.features.discovery.ServerAndPolicies
sealed class ContactsBookViewEvents : VectorViewEvents {
data class Failure(val throwable: Throwable) : ContactsBookViewEvents()
data class OnPoliciesRetrieved(val identityServerWithTerms: IdentityServerWithTerms?) : ContactsBookViewEvents()
data class OnPoliciesRetrieved(val identityServerWithTerms: ServerAndPolicies?) : ContactsBookViewEvents()
}

View File

@ -433,6 +433,6 @@ class DiscoverySettingsController @Inject constructor(
fun onTapUpdateUserConsent(newValue: Boolean)
fun onTapRetryToRetrieveBindings()
fun onPolicyUrlsExpandedStateToggled(newExpandedState: Boolean)
fun onPolicyTapped(policy: IdentityServerPolicy)
fun onPolicyTapped(policy: ServerPolicy)
}
}

View File

@ -204,7 +204,7 @@ class DiscoverySettingsFragment @Inject constructor(
viewModel.handle(DiscoverySettingsAction.SetPoliciesExpandState(expanded = newExpandedState))
}
override fun onPolicyTapped(policy: IdentityServerPolicy) {
override fun onPolicyTapped(policy: ServerPolicy) {
openUrlInChromeCustomTab(requireContext(), null, policy.url)
}

View File

@ -21,7 +21,7 @@ import com.airbnb.mvrx.MavericksState
import com.airbnb.mvrx.Uninitialized
data class DiscoverySettingsState(
val identityServer: Async<IdentityServerWithTerms?> = Uninitialized,
val identityServer: Async<ServerAndPolicies?> = Uninitialized,
val emailList: Async<List<PidInfo>> = Uninitialized,
val phoneNumbersList: Async<List<PidInfo>> = Uninitialized,
// Can be true if terms are updated

View File

@ -78,7 +78,7 @@ class DiscoverySettingsViewModel @AssistedInject constructor(
init {
setState {
copy(
identityServer = Success(identityService.getCurrentIdentityServerUrl()?.let { IdentityServerWithTerms(it, emptyList()) }),
identityServer = Success(identityService.getCurrentIdentityServerUrl()?.let { ServerAndPolicies(it, emptyList()) }),
userConsent = identityService.getUserConsent()
)
}
@ -151,7 +151,7 @@ class DiscoverySettingsViewModel @AssistedInject constructor(
val data = session.identityService().setNewIdentityServer(action.url)
setState {
copy(
identityServer = Success(IdentityServerWithTerms(data, emptyList())),
identityServer = Success(ServerAndPolicies(data, emptyList())),
userConsent = false
)
}
@ -401,7 +401,7 @@ class DiscoverySettingsViewModel @AssistedInject constructor(
}
}
private suspend fun fetchIdentityServerWithTerms(): IdentityServerWithTerms? {
private suspend fun fetchIdentityServerWithTerms(): ServerAndPolicies? {
return session.fetchIdentityServerWithTerms(stringProvider.getString(R.string.resources_language))
}
}

View File

@ -20,21 +20,21 @@ import im.vector.app.core.utils.ensureProtocol
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.terms.TermsService
suspend fun Session.fetchIdentityServerWithTerms(userLanguage: String): IdentityServerWithTerms? {
suspend fun Session.fetchIdentityServerWithTerms(userLanguage: String): ServerAndPolicies? {
val identityServerUrl = identityService().getCurrentIdentityServerUrl()
return identityServerUrl?.let {
fetchTerms(it, TermsService.ServiceType.IdentityService, userLanguage)
}
}
suspend fun Session.fetchHomeserverWithTerms(userLanguage: String): IdentityServerWithTerms {
suspend fun Session.fetchHomeserverWithTerms(userLanguage: String): ServerAndPolicies {
val homeserverUrl = sessionParams.homeServerUrl
return fetchTerms(homeserverUrl, TermsService.ServiceType.Homeserver, userLanguage)
}
private suspend fun Session.fetchTerms(serviceUrl: String,
serviceType: TermsService.ServiceType,
userLanguage: String): IdentityServerWithTerms {
userLanguage: String): ServerAndPolicies {
val terms = getTerms(serviceType, serviceUrl.ensureProtocol())
.serverResponse
.getLocalizedTerms(userLanguage)
@ -44,8 +44,8 @@ private suspend fun Session.fetchTerms(serviceUrl: String,
if (name == null || url == null) {
null
} else {
IdentityServerPolicy(name = name, url = url)
ServerPolicy(name = name, url = url)
}
}
return IdentityServerWithTerms(serviceUrl, policyUrls)
return ServerAndPolicies(serviceUrl, policyUrls)
}

View File

@ -16,13 +16,12 @@
package im.vector.app.features.discovery
// TODO Rename for more generic name
data class IdentityServerWithTerms(
data class ServerAndPolicies(
val serverUrl: String,
val policies: List<IdentityServerPolicy>
val policies: List<ServerPolicy>
)
data class IdentityServerPolicy(
data class ServerPolicy(
val name: String,
val url: String
)

View File

@ -26,8 +26,8 @@ import im.vector.app.core.epoxy.errorWithRetryItem
import im.vector.app.core.epoxy.loadingItem
import im.vector.app.core.error.ErrorFormatter
import im.vector.app.core.resources.StringProvider
import im.vector.app.features.discovery.IdentityServerPolicy
import im.vector.app.features.discovery.IdentityServerWithTerms
import im.vector.app.features.discovery.ServerPolicy
import im.vector.app.features.discovery.ServerAndPolicies
import im.vector.app.features.discovery.discoveryPolicyItem
import im.vector.app.features.discovery.settingsInfoItem
import im.vector.app.features.discovery.settingsSectionTitleItem
@ -75,16 +75,16 @@ class LegalsController @Inject constructor(
}
}
private fun buildPolicy(tag: String, serverWithTerms: Async<IdentityServerWithTerms?>) {
private fun buildPolicy(tag: String, serverAndPolicies: Async<ServerAndPolicies?>) {
val host = this
when (serverWithTerms) {
when (serverAndPolicies) {
Uninitialized,
is Loading -> loadingItem {
id("loading_$tag")
}
is Success -> {
val policies = serverWithTerms()?.policies
val policies = serverAndPolicies()?.policies
if (policies.isNullOrEmpty()) {
settingsInfoItem {
id("emptyPolicy")
@ -104,7 +104,7 @@ class LegalsController @Inject constructor(
is Fail -> {
errorWithRetryItem {
id("errorRetry_$tag")
text(host.errorFormatter.toHumanReadable(serverWithTerms.error))
text(host.errorFormatter.toHumanReadable(serverAndPolicies.error))
listener { host.listener?.onTapRetry() }
}
}
@ -113,6 +113,6 @@ class LegalsController @Inject constructor(
interface Listener {
fun onTapRetry()
fun openPolicy(policy: IdentityServerPolicy)
fun openPolicy(policy: ServerPolicy)
}
}

View File

@ -29,7 +29,7 @@ import im.vector.app.core.extensions.exhaustive
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.utils.openUrlInChromeCustomTab
import im.vector.app.databinding.FragmentGenericRecyclerBinding
import im.vector.app.features.discovery.IdentityServerPolicy
import im.vector.app.features.discovery.ServerPolicy
import javax.inject.Inject
class LegalsFragment @Inject constructor(
@ -78,7 +78,7 @@ class LegalsFragment @Inject constructor(
viewModel.handle(LegalsAction.Refresh)
}
override fun openPolicy(policy: IdentityServerPolicy) {
override fun openPolicy(policy: ServerPolicy) {
openUrlInChromeCustomTab(requireContext(), null, policy.url)
}
}

View File

@ -19,10 +19,10 @@ package im.vector.app.features.settings.legals
import com.airbnb.mvrx.Async
import com.airbnb.mvrx.MavericksState
import com.airbnb.mvrx.Uninitialized
import im.vector.app.features.discovery.IdentityServerWithTerms
import im.vector.app.features.discovery.ServerAndPolicies
data class LegalsState(
val homeServer: Async<IdentityServerWithTerms?> = Uninitialized,
val homeServer: Async<ServerAndPolicies?> = Uninitialized,
val hasIdentityServer: Boolean = false,
val identityServer: Async<IdentityServerWithTerms?> = Uninitialized
val identityServer: Async<ServerAndPolicies?> = Uninitialized
) : MavericksState

View File

@ -17,13 +17,13 @@
package im.vector.app.features.userdirectory
import im.vector.app.core.platform.VectorViewEvents
import im.vector.app.features.discovery.IdentityServerWithTerms
import im.vector.app.features.discovery.ServerAndPolicies
/**
* Transient events for invite users to room screen
*/
sealed class UserListViewEvents : VectorViewEvents {
data class Failure(val throwable: Throwable) : UserListViewEvents()
data class OnPoliciesRetrieved(val identityServerWithTerms: IdentityServerWithTerms?) : UserListViewEvents()
data class OnPoliciesRetrieved(val identityServerWithTerms: ServerAndPolicies?) : UserListViewEvents()
data class OpenShareMatrixToLink(val link: String) : UserListViewEvents()
}