Improve code
This commit is contained in:
parent
062a21e39a
commit
34cf9903dc
@ -160,46 +160,8 @@ class DiscoverySettingsController @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun buildEmail(pidInfo: PidInfo) {
|
private fun buildEmail(pidInfo: PidInfo) {
|
||||||
settingsTextButtonSingleLineItem {
|
buildThreePid(pidInfo)
|
||||||
id(pidInfo.threePid.value)
|
|
||||||
title(pidInfo.threePid.value)
|
|
||||||
colorProvider(colorProvider)
|
|
||||||
stringProvider(stringProvider)
|
|
||||||
when (pidInfo.isShared) {
|
|
||||||
is Loading -> {
|
|
||||||
buttonIndeterminate(true)
|
|
||||||
}
|
|
||||||
is Fail -> {
|
|
||||||
buttonType(ButtonType.NORMAL)
|
|
||||||
buttonStyle(ButtonStyle.DESTRUCTIVE)
|
|
||||||
buttonTitle(stringProvider.getString(R.string.global_retry))
|
|
||||||
iconMode(IconMode.ERROR)
|
|
||||||
buttonClickListener { listener?.onTapRetryToRetrieveBindings() }
|
|
||||||
}
|
|
||||||
is Success -> when (pidInfo.isShared()) {
|
|
||||||
SharedState.SHARED,
|
|
||||||
SharedState.NOT_SHARED -> {
|
|
||||||
buttonType(ButtonType.SWITCH)
|
|
||||||
checked(pidInfo.isShared() == SharedState.SHARED)
|
|
||||||
switchChangeListener { _, checked ->
|
|
||||||
if (checked) {
|
|
||||||
listener?.onTapShare(pidInfo.threePid)
|
|
||||||
} else {
|
|
||||||
listener?.onTapRevoke(pidInfo.threePid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SharedState.BINDING_IN_PROGRESS -> {
|
|
||||||
buttonType(ButtonType.NO_BUTTON)
|
|
||||||
when (pidInfo.finalRequest) {
|
|
||||||
is Incomplete -> iconMode(IconMode.INFO)
|
|
||||||
is Fail -> iconMode(IconMode.ERROR)
|
|
||||||
else -> iconMode(IconMode.NONE)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (pidInfo.isShared is Fail) {
|
if (pidInfo.isShared is Fail) {
|
||||||
buildSharedFail(pidInfo)
|
buildSharedFail(pidInfo)
|
||||||
buildContinueCancel(pidInfo.threePid)
|
buildContinueCancel(pidInfo.threePid)
|
||||||
@ -278,41 +240,8 @@ class DiscoverySettingsController @Inject constructor(
|
|||||||
}
|
}
|
||||||
?: pidInfo.threePid.value
|
?: pidInfo.threePid.value
|
||||||
|
|
||||||
settingsTextButtonSingleLineItem {
|
buildThreePid(pidInfo, phoneNumber)
|
||||||
id(pidInfo.threePid.value)
|
|
||||||
title(phoneNumber)
|
|
||||||
colorProvider(colorProvider)
|
|
||||||
stringProvider(stringProvider)
|
|
||||||
when (pidInfo.isShared) {
|
|
||||||
is Loading -> {
|
|
||||||
buttonIndeterminate(true)
|
|
||||||
}
|
|
||||||
is Fail -> {
|
|
||||||
buttonType(ButtonType.NORMAL)
|
|
||||||
buttonStyle(ButtonStyle.DESTRUCTIVE)
|
|
||||||
buttonTitle(stringProvider.getString(R.string.global_retry))
|
|
||||||
iconMode(IconMode.ERROR)
|
|
||||||
buttonClickListener { listener?.onTapRetryToRetrieveBindings() }
|
|
||||||
}
|
|
||||||
is Success -> when (pidInfo.isShared()) {
|
|
||||||
SharedState.SHARED,
|
|
||||||
SharedState.NOT_SHARED -> {
|
|
||||||
checked(pidInfo.isShared() == SharedState.SHARED)
|
|
||||||
buttonType(ButtonType.SWITCH)
|
|
||||||
switchChangeListener { _, checked ->
|
|
||||||
if (checked) {
|
|
||||||
listener?.onTapShare(pidInfo.threePid)
|
|
||||||
} else {
|
|
||||||
listener?.onTapRevoke(pidInfo.threePid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SharedState.BINDING_IN_PROGRESS -> {
|
|
||||||
buttonType(ButtonType.NO_BUTTON)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (pidInfo.isShared is Fail) {
|
if (pidInfo.isShared is Fail) {
|
||||||
buildSharedFail(pidInfo)
|
buildSharedFail(pidInfo)
|
||||||
}
|
}
|
||||||
@ -355,6 +284,49 @@ class DiscoverySettingsController @Inject constructor(
|
|||||||
}.exhaustive
|
}.exhaustive
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun buildThreePid(pidInfo: PidInfo, title: String = pidInfo.threePid.value) {
|
||||||
|
settingsTextButtonSingleLineItem {
|
||||||
|
id(pidInfo.threePid.value)
|
||||||
|
title(title)
|
||||||
|
colorProvider(colorProvider)
|
||||||
|
stringProvider(stringProvider)
|
||||||
|
when (pidInfo.isShared) {
|
||||||
|
is Loading -> {
|
||||||
|
buttonIndeterminate(true)
|
||||||
|
}
|
||||||
|
is Fail -> {
|
||||||
|
buttonType(ButtonType.NORMAL)
|
||||||
|
buttonStyle(ButtonStyle.DESTRUCTIVE)
|
||||||
|
buttonTitle(stringProvider.getString(R.string.global_retry))
|
||||||
|
iconMode(IconMode.ERROR)
|
||||||
|
buttonClickListener { listener?.onTapRetryToRetrieveBindings() }
|
||||||
|
}
|
||||||
|
is Success -> when (pidInfo.isShared()) {
|
||||||
|
SharedState.SHARED,
|
||||||
|
SharedState.NOT_SHARED -> {
|
||||||
|
buttonType(ButtonType.SWITCH)
|
||||||
|
checked(pidInfo.isShared() == SharedState.SHARED)
|
||||||
|
switchChangeListener { _, checked ->
|
||||||
|
if (checked) {
|
||||||
|
listener?.onTapShare(pidInfo.threePid)
|
||||||
|
} else {
|
||||||
|
listener?.onTapRevoke(pidInfo.threePid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SharedState.BINDING_IN_PROGRESS -> {
|
||||||
|
buttonType(ButtonType.NO_BUTTON)
|
||||||
|
when (pidInfo.finalRequest) {
|
||||||
|
is Incomplete -> iconMode(IconMode.INFO)
|
||||||
|
is Fail -> iconMode(IconMode.ERROR)
|
||||||
|
else -> iconMode(IconMode.NONE)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun buildSharedFail(pidInfo: PidInfo) {
|
private fun buildSharedFail(pidInfo: PidInfo) {
|
||||||
settingsInformationItem {
|
settingsInformationItem {
|
||||||
id("info${pidInfo.threePid.value}")
|
id("info${pidInfo.threePid.value}")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user