mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 21:48:50 +03:00
Identity: Extract enum for Epoxy Items
This commit is contained in:
parent
bdfcf5c67c
commit
7822660ce7
6 changed files with 77 additions and 36 deletions
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 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.riotx.core.epoxy.attributes
|
||||||
|
|
||||||
|
enum class ButtonStyle {
|
||||||
|
POSITIVE,
|
||||||
|
DESTRUCTIVE
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 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.riotx.core.epoxy.attributes
|
||||||
|
|
||||||
|
enum class ButtonType {
|
||||||
|
NO_BUTTON,
|
||||||
|
NORMAL,
|
||||||
|
SWITCH
|
||||||
|
}
|
|
@ -14,10 +14,10 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package im.vector.riotx.features.discovery
|
package im.vector.riotx.core.epoxy.attributes
|
||||||
|
|
||||||
enum class IconMode {
|
enum class IconMode {
|
||||||
None,
|
NONE,
|
||||||
Info,
|
INFO,
|
||||||
Error
|
ERROR
|
||||||
}
|
}
|
|
@ -27,6 +27,9 @@ import im.vector.matrix.android.api.failure.Failure
|
||||||
import im.vector.matrix.android.api.session.identity.SharedState
|
import im.vector.matrix.android.api.session.identity.SharedState
|
||||||
import im.vector.matrix.android.api.session.identity.ThreePid
|
import im.vector.matrix.android.api.session.identity.ThreePid
|
||||||
import im.vector.riotx.R
|
import im.vector.riotx.R
|
||||||
|
import im.vector.riotx.core.epoxy.attributes.ButtonStyle
|
||||||
|
import im.vector.riotx.core.epoxy.attributes.ButtonType
|
||||||
|
import im.vector.riotx.core.epoxy.attributes.IconMode
|
||||||
import im.vector.riotx.core.epoxy.loadingItem
|
import im.vector.riotx.core.epoxy.loadingItem
|
||||||
import im.vector.riotx.core.error.ErrorFormatter
|
import im.vector.riotx.core.error.ErrorFormatter
|
||||||
import im.vector.riotx.core.extensions.exhaustive
|
import im.vector.riotx.core.extensions.exhaustive
|
||||||
|
@ -107,7 +110,7 @@ class DiscoverySettingsController @Inject constructor(
|
||||||
} else {
|
} else {
|
||||||
buttonTitleId(R.string.add_identity_server)
|
buttonTitleId(R.string.add_identity_server)
|
||||||
}
|
}
|
||||||
buttonStyle(SettingsTextButtonSingleLineItem.ButtonStyle.POSITIVE)
|
buttonStyle(ButtonStyle.POSITIVE)
|
||||||
buttonClickListener(View.OnClickListener {
|
buttonClickListener(View.OnClickListener {
|
||||||
listener?.onTapChangeIdentityServer()
|
listener?.onTapChangeIdentityServer()
|
||||||
})
|
})
|
||||||
|
@ -122,7 +125,7 @@ class DiscoverySettingsController @Inject constructor(
|
||||||
id("remove")
|
id("remove")
|
||||||
colorProvider(colorProvider)
|
colorProvider(colorProvider)
|
||||||
buttonTitleId(R.string.disconnect_identity_server)
|
buttonTitleId(R.string.disconnect_identity_server)
|
||||||
buttonStyle(SettingsTextButtonSingleLineItem.ButtonStyle.DESTRUCTIVE)
|
buttonStyle(ButtonStyle.DESTRUCTIVE)
|
||||||
buttonClickListener(View.OnClickListener {
|
buttonClickListener(View.OnClickListener {
|
||||||
listener?.onTapDisconnectIdentityServer()
|
listener?.onTapDisconnectIdentityServer()
|
||||||
})
|
})
|
||||||
|
@ -172,16 +175,16 @@ class DiscoverySettingsController @Inject constructor(
|
||||||
buttonIndeterminate(true)
|
buttonIndeterminate(true)
|
||||||
}
|
}
|
||||||
is Fail -> {
|
is Fail -> {
|
||||||
buttonStyle(SettingsTextButtonSingleLineItem.ButtonStyle.DESTRUCTIVE)
|
buttonStyle(ButtonStyle.DESTRUCTIVE)
|
||||||
buttonTitle(stringProvider.getString(R.string.global_retry))
|
buttonTitle(stringProvider.getString(R.string.global_retry))
|
||||||
iconMode(IconMode.Error)
|
iconMode(IconMode.ERROR)
|
||||||
buttonClickListener { listener?.onTapRetryToRetrieveBindings() }
|
buttonClickListener { listener?.onTapRetryToRetrieveBindings() }
|
||||||
}
|
}
|
||||||
is Success -> when (pidInfo.isShared()) {
|
is Success -> when (pidInfo.isShared()) {
|
||||||
SharedState.SHARED,
|
SharedState.SHARED,
|
||||||
SharedState.NOT_SHARED -> {
|
SharedState.NOT_SHARED -> {
|
||||||
checked(pidInfo.isShared() == SharedState.SHARED)
|
checked(pidInfo.isShared() == SharedState.SHARED)
|
||||||
buttonType(SettingsTextButtonSingleLineItem.ButtonType.SWITCH)
|
buttonType(ButtonType.SWITCH)
|
||||||
switchChangeListener { _, checked ->
|
switchChangeListener { _, checked ->
|
||||||
if (checked) {
|
if (checked) {
|
||||||
listener?.onTapShare(pidInfo.threePid)
|
listener?.onTapShare(pidInfo.threePid)
|
||||||
|
@ -191,11 +194,11 @@ class DiscoverySettingsController @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SharedState.BINDING_IN_PROGRESS -> {
|
SharedState.BINDING_IN_PROGRESS -> {
|
||||||
buttonType(SettingsTextButtonSingleLineItem.ButtonType.NO_BUTTON)
|
buttonType(ButtonType.NO_BUTTON)
|
||||||
when (pidInfo.finalRequest) {
|
when (pidInfo.finalRequest) {
|
||||||
is Incomplete -> iconMode(IconMode.Info)
|
is Incomplete -> iconMode(IconMode.INFO)
|
||||||
is Fail -> iconMode(IconMode.Error)
|
is Fail -> iconMode(IconMode.ERROR)
|
||||||
else -> iconMode(IconMode.None)
|
else -> iconMode(IconMode.NONE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -300,17 +303,17 @@ class DiscoverySettingsController @Inject constructor(
|
||||||
buttonIndeterminate(true)
|
buttonIndeterminate(true)
|
||||||
}
|
}
|
||||||
is Fail -> {
|
is Fail -> {
|
||||||
buttonType(SettingsTextButtonSingleLineItem.ButtonType.NORMAL)
|
buttonType(ButtonType.NORMAL)
|
||||||
buttonStyle(SettingsTextButtonSingleLineItem.ButtonStyle.DESTRUCTIVE)
|
buttonStyle(ButtonStyle.DESTRUCTIVE)
|
||||||
buttonTitle(stringProvider.getString(R.string.global_retry))
|
buttonTitle(stringProvider.getString(R.string.global_retry))
|
||||||
iconMode(IconMode.Error)
|
iconMode(IconMode.ERROR)
|
||||||
buttonClickListener { listener?.onTapRetryToRetrieveBindings() }
|
buttonClickListener { listener?.onTapRetryToRetrieveBindings() }
|
||||||
}
|
}
|
||||||
is Success -> when (pidInfo.isShared()) {
|
is Success -> when (pidInfo.isShared()) {
|
||||||
SharedState.SHARED,
|
SharedState.SHARED,
|
||||||
SharedState.NOT_SHARED -> {
|
SharedState.NOT_SHARED -> {
|
||||||
checked(pidInfo.isShared() == SharedState.SHARED)
|
checked(pidInfo.isShared() == SharedState.SHARED)
|
||||||
buttonType(SettingsTextButtonSingleLineItem.ButtonType.SWITCH)
|
buttonType(ButtonType.SWITCH)
|
||||||
switchChangeListener { _, checked ->
|
switchChangeListener { _, checked ->
|
||||||
if (checked) {
|
if (checked) {
|
||||||
listener?.onTapShare(pidInfo.threePid)
|
listener?.onTapShare(pidInfo.threePid)
|
||||||
|
@ -320,7 +323,7 @@ class DiscoverySettingsController @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SharedState.BINDING_IN_PROGRESS -> {
|
SharedState.BINDING_IN_PROGRESS -> {
|
||||||
buttonType(SettingsTextButtonSingleLineItem.ButtonType.NO_BUTTON)
|
buttonType(ButtonType.NO_BUTTON)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import com.airbnb.epoxy.EpoxyModelClass
|
||||||
import com.airbnb.epoxy.EpoxyModelWithHolder
|
import com.airbnb.epoxy.EpoxyModelWithHolder
|
||||||
import im.vector.riotx.R
|
import im.vector.riotx.R
|
||||||
import im.vector.riotx.core.epoxy.VectorEpoxyHolder
|
import im.vector.riotx.core.epoxy.VectorEpoxyHolder
|
||||||
|
import im.vector.riotx.core.epoxy.attributes.ButtonStyle
|
||||||
import im.vector.riotx.core.extensions.setTextOrHide
|
import im.vector.riotx.core.extensions.setTextOrHide
|
||||||
import im.vector.riotx.core.resources.ColorProvider
|
import im.vector.riotx.core.resources.ColorProvider
|
||||||
|
|
||||||
|
@ -40,7 +41,7 @@ abstract class SettingsButtonItem : EpoxyModelWithHolder<SettingsButtonItem.Hold
|
||||||
var buttonTitleId: Int? = null
|
var buttonTitleId: Int? = null
|
||||||
|
|
||||||
@EpoxyAttribute
|
@EpoxyAttribute
|
||||||
var buttonStyle: SettingsTextButtonSingleLineItem.ButtonStyle = SettingsTextButtonSingleLineItem.ButtonStyle.POSITIVE
|
var buttonStyle: ButtonStyle = ButtonStyle.POSITIVE
|
||||||
|
|
||||||
@EpoxyAttribute
|
@EpoxyAttribute
|
||||||
var buttonClickListener: View.OnClickListener? = null
|
var buttonClickListener: View.OnClickListener? = null
|
||||||
|
@ -54,10 +55,10 @@ abstract class SettingsButtonItem : EpoxyModelWithHolder<SettingsButtonItem.Hold
|
||||||
}
|
}
|
||||||
|
|
||||||
when (buttonStyle) {
|
when (buttonStyle) {
|
||||||
SettingsTextButtonSingleLineItem.ButtonStyle.POSITIVE -> {
|
ButtonStyle.POSITIVE -> {
|
||||||
holder.button.setTextColor(colorProvider.getColor(R.color.riotx_accent))
|
holder.button.setTextColor(colorProvider.getColor(R.color.riotx_accent))
|
||||||
}
|
}
|
||||||
SettingsTextButtonSingleLineItem.ButtonStyle.DESTRUCTIVE -> {
|
ButtonStyle.DESTRUCTIVE -> {
|
||||||
holder.button.setTextColor(colorProvider.getColor(R.color.riotx_destructive_accent))
|
holder.button.setTextColor(colorProvider.getColor(R.color.riotx_destructive_accent))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,9 @@ import com.airbnb.epoxy.EpoxyModelWithHolder
|
||||||
import im.vector.riotx.R
|
import im.vector.riotx.R
|
||||||
import im.vector.riotx.core.epoxy.ClickListener
|
import im.vector.riotx.core.epoxy.ClickListener
|
||||||
import im.vector.riotx.core.epoxy.VectorEpoxyHolder
|
import im.vector.riotx.core.epoxy.VectorEpoxyHolder
|
||||||
|
import im.vector.riotx.core.epoxy.attributes.ButtonStyle
|
||||||
|
import im.vector.riotx.core.epoxy.attributes.ButtonType
|
||||||
|
import im.vector.riotx.core.epoxy.attributes.IconMode
|
||||||
import im.vector.riotx.core.epoxy.onClick
|
import im.vector.riotx.core.epoxy.onClick
|
||||||
import im.vector.riotx.core.extensions.exhaustive
|
import im.vector.riotx.core.extensions.exhaustive
|
||||||
import im.vector.riotx.core.extensions.setTextOrHide
|
import im.vector.riotx.core.extensions.setTextOrHide
|
||||||
|
@ -40,17 +43,6 @@ import im.vector.riotx.features.themes.ThemeUtils
|
||||||
@EpoxyModelClass(layout = R.layout.item_settings_button_single_line)
|
@EpoxyModelClass(layout = R.layout.item_settings_button_single_line)
|
||||||
abstract class SettingsTextButtonSingleLineItem : EpoxyModelWithHolder<SettingsTextButtonSingleLineItem.Holder>() {
|
abstract class SettingsTextButtonSingleLineItem : EpoxyModelWithHolder<SettingsTextButtonSingleLineItem.Holder>() {
|
||||||
|
|
||||||
enum class ButtonStyle {
|
|
||||||
POSITIVE,
|
|
||||||
DESTRUCTIVE
|
|
||||||
}
|
|
||||||
|
|
||||||
enum class ButtonType {
|
|
||||||
NO_BUTTON,
|
|
||||||
NORMAL,
|
|
||||||
SWITCH
|
|
||||||
}
|
|
||||||
|
|
||||||
@EpoxyAttribute
|
@EpoxyAttribute
|
||||||
lateinit var colorProvider: ColorProvider
|
lateinit var colorProvider: ColorProvider
|
||||||
|
|
||||||
|
@ -65,7 +57,7 @@ abstract class SettingsTextButtonSingleLineItem : EpoxyModelWithHolder<SettingsT
|
||||||
var titleResId: Int? = null
|
var titleResId: Int? = null
|
||||||
|
|
||||||
@EpoxyAttribute
|
@EpoxyAttribute
|
||||||
var iconMode: IconMode = IconMode.None
|
var iconMode: IconMode = IconMode.NONE
|
||||||
|
|
||||||
@EpoxyAttribute
|
@EpoxyAttribute
|
||||||
var buttonTitle: String? = null
|
var buttonTitle: String? = null
|
||||||
|
@ -146,17 +138,17 @@ abstract class SettingsTextButtonSingleLineItem : EpoxyModelWithHolder<SettingsT
|
||||||
|
|
||||||
|
|
||||||
when (iconMode) {
|
when (iconMode) {
|
||||||
IconMode.None -> {
|
IconMode.NONE -> {
|
||||||
holder.textView.setCompoundDrawables(null, null, null, null)
|
holder.textView.setCompoundDrawables(null, null, null, null)
|
||||||
}
|
}
|
||||||
IconMode.Info -> {
|
IconMode.INFO -> {
|
||||||
val errorColor = colorProvider.getColor(R.color.notification_accent_color)
|
val errorColor = colorProvider.getColor(R.color.notification_accent_color)
|
||||||
ContextCompat.getDrawable(holder.view.context, R.drawable.ic_notification_privacy_warning)?.apply {
|
ContextCompat.getDrawable(holder.view.context, R.drawable.ic_notification_privacy_warning)?.apply {
|
||||||
ThemeUtils.tintDrawableWithColor(this, errorColor)
|
ThemeUtils.tintDrawableWithColor(this, errorColor)
|
||||||
holder.textView.setCompoundDrawablesWithIntrinsicBounds(this, null, null, null)
|
holder.textView.setCompoundDrawablesWithIntrinsicBounds(this, null, null, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
IconMode.Error -> {
|
IconMode.ERROR -> {
|
||||||
val errorColor = colorProvider.getColor(R.color.vector_error_color)
|
val errorColor = colorProvider.getColor(R.color.vector_error_color)
|
||||||
ContextCompat.getDrawable(holder.view.context, R.drawable.ic_notification_privacy_warning)?.apply {
|
ContextCompat.getDrawable(holder.view.context, R.drawable.ic_notification_privacy_warning)?.apply {
|
||||||
ThemeUtils.tintDrawableWithColor(this, errorColor)
|
ThemeUtils.tintDrawableWithColor(this, errorColor)
|
||||||
|
|
Loading…
Reference in a new issue