mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
creating dedicated discovery policy items and displaying within an expandable form item
This commit is contained in:
parent
3111d0b46d
commit
7e8ca29ca7
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2021 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.features.discovery
|
||||
|
||||
import android.widget.TextView
|
||||
import com.airbnb.epoxy.EpoxyAttribute
|
||||
import com.airbnb.epoxy.EpoxyModelClass
|
||||
import com.airbnb.epoxy.EpoxyModelWithHolder
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.epoxy.ClickListener
|
||||
import im.vector.app.core.epoxy.VectorEpoxyHolder
|
||||
import im.vector.app.core.epoxy.onClick
|
||||
|
||||
@EpoxyModelClass(layout = R.layout.item_discovery_policy)
|
||||
abstract class DiscoveryPolicyItem : EpoxyModelWithHolder<DiscoveryPolicyItem.Holder>() {
|
||||
|
||||
@EpoxyAttribute
|
||||
var name: String? = null
|
||||
|
||||
@EpoxyAttribute
|
||||
var url: String? = null
|
||||
|
||||
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
|
||||
var clickListener: ClickListener? = null
|
||||
|
||||
override fun bind(holder: Holder) {
|
||||
super.bind(holder)
|
||||
holder.title.text = name
|
||||
holder.url.text = url
|
||||
holder.view.onClick(clickListener)
|
||||
}
|
||||
|
||||
class Holder : VectorEpoxyHolder() {
|
||||
val title by bind<TextView>(R.id.discovery_policy_name)
|
||||
val url by bind<TextView>(R.id.discovery_policy_url)
|
||||
}
|
||||
}
|
@ -15,7 +15,6 @@
|
||||
*/
|
||||
package im.vector.app.features.discovery
|
||||
|
||||
import android.text.method.LinkMovementMethod
|
||||
import com.airbnb.epoxy.TypedEpoxyController
|
||||
import com.airbnb.mvrx.Async
|
||||
import com.airbnb.mvrx.Fail
|
||||
@ -27,14 +26,13 @@ import im.vector.app.R
|
||||
import im.vector.app.core.epoxy.attributes.ButtonStyle
|
||||
import im.vector.app.core.epoxy.attributes.ButtonType
|
||||
import im.vector.app.core.epoxy.attributes.IconMode
|
||||
import im.vector.app.core.epoxy.expandableTextItem
|
||||
import im.vector.app.core.epoxy.loadingItem
|
||||
import im.vector.app.core.error.ErrorFormatter
|
||||
import im.vector.app.core.extensions.getFormattedValue
|
||||
import im.vector.app.core.resources.ColorProvider
|
||||
import im.vector.app.core.resources.StringProvider
|
||||
import im.vector.app.core.utils.EvenBetterLinkMovementMethod
|
||||
import org.matrix.android.sdk.api.extensions.appendNl
|
||||
import im.vector.app.features.form.formAdvancedToggleItem
|
||||
import im.vector.app.features.terms.termItem
|
||||
import org.matrix.android.sdk.api.failure.Failure
|
||||
import org.matrix.android.sdk.api.session.identity.SharedState
|
||||
import org.matrix.android.sdk.api.session.identity.ThreePid
|
||||
@ -124,21 +122,24 @@ class DiscoverySettingsController @Inject constructor(
|
||||
title(identityServerUrl)
|
||||
}
|
||||
|
||||
val policyUrls = identityServer?.policyUrls?.joinToString(separator = "\n") { it }
|
||||
if (policyUrls != null) {
|
||||
val title = stringProvider.getString(R.string.settings_discovery_identity_server_policies_title)
|
||||
expandableTextItem {
|
||||
val terms = identityServer?.terms
|
||||
if (terms != null) {
|
||||
formAdvancedToggleItem {
|
||||
id("policy-urls")
|
||||
maxLines(1)
|
||||
enableScrollBar(false)
|
||||
content(buildString {
|
||||
append(title)
|
||||
appendNl(policyUrls)
|
||||
})
|
||||
movementMethod(LinkMovementMethod())
|
||||
title(host.stringProvider.getString(R.string.settings_discovery_identity_server_policies_title))
|
||||
expanded(data.isIdentityPolicyUrlsExpanded)
|
||||
onExpandClicked {
|
||||
host.listener?.onPolicyUrlsExpandedStateToggled()
|
||||
listener { host.listener?.onPolicyUrlsExpandedStateToggled() }
|
||||
}
|
||||
if (data.isIdentityPolicyUrlsExpanded) {
|
||||
terms.forEach { term ->
|
||||
discoveryPolicyItem {
|
||||
id(term.url)
|
||||
name(term.name)
|
||||
url(term.url)
|
||||
clickListener {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,5 +33,7 @@ data class DiscoverySettingsState(
|
||||
|
||||
data class IdentityServerWithTerms(
|
||||
val serverUrl: String,
|
||||
val policyUrls: List<String>
|
||||
val terms: List<IdentityServerTerms>
|
||||
)
|
||||
|
||||
data class IdentityServerTerms(val name: String, val url: String)
|
||||
|
@ -421,7 +421,15 @@ class DiscoverySettingsViewModel @AssistedInject constructor(
|
||||
val terms = termsService.getTerms(TermsService.ServiceType.IdentityService, identityServerUrl.ensureProtocol())
|
||||
.serverResponse
|
||||
.getLocalizedTerms(stringProvider.getString(R.string.resources_language))
|
||||
val policyUrls = terms.mapNotNull { it.localizedUrl }
|
||||
val policyUrls = terms.mapNotNull {
|
||||
val name = it.localizedName ?: it.policyName
|
||||
val url = it.localizedUrl
|
||||
if (name == null || url == null) {
|
||||
null
|
||||
} else {
|
||||
IdentityServerTerms(name = name, url = url)
|
||||
}
|
||||
}
|
||||
IdentityServerWithTerms(identityServerUrl, policyUrls)
|
||||
}
|
||||
}
|
||||
|
51
vector/src/main/res/layout/item_discovery_policy.xml
Normal file
51
vector/src/main/res/layout/item_discovery_policy.xml
Normal file
@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/discovery_policy_name"
|
||||
style="@style/Widget.Vector.TextView.Body"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="0dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:textColor="?vctr_content_primary"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintEnd_toStartOf="@id/term_policy_arrow"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="Integration manager" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/discovery_policy_url"
|
||||
style="@style/Widget.Vector.TextView.Body"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="0dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:textColor="?vctr_content_secondary"
|
||||
app:layout_constraintEnd_toStartOf="@id/term_policy_arrow"
|
||||
app:layout_constraintStart_toStartOf="@+id/discovery_policy_name"
|
||||
app:layout_constraintTop_toBottomOf="@+id/discovery_policy_name"
|
||||
tools:text="Use bots, bridges, widget and sticker packs." />
|
||||
|
||||
<!-- Do not use drawableEnd on the TextView because of RTL support -->
|
||||
<ImageView
|
||||
android:id="@+id/term_policy_arrow"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:importantForAccessibility="no"
|
||||
android:rotationY="@integer/rtl_mirror_flip"
|
||||
android:src="@drawable/ic_arrow_right"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:tint="?vctr_content_primary"
|
||||
tools:ignore="MissingPrefix" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in New Issue
Block a user