Improve code

This commit is contained in:
Benoit Marty 2020-05-11 00:00:24 +02:00
parent 062a21e39a
commit 34cf9903dc
1 changed files with 47 additions and 75 deletions

View File

@ -160,46 +160,8 @@ class DiscoverySettingsController @Inject constructor(
}
private fun buildEmail(pidInfo: PidInfo) {
settingsTextButtonSingleLineItem {
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)
}
}
}
}
}
buildThreePid(pidInfo)
if (pidInfo.isShared is Fail) {
buildSharedFail(pidInfo)
buildContinueCancel(pidInfo.threePid)
@ -278,41 +240,8 @@ class DiscoverySettingsController @Inject constructor(
}
?: pidInfo.threePid.value
settingsTextButtonSingleLineItem {
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)
}
}
}
}
buildThreePid(pidInfo, phoneNumber)
if (pidInfo.isShared is Fail) {
buildSharedFail(pidInfo)
}
@ -355,6 +284,49 @@ class DiscoverySettingsController @Inject constructor(
}.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) {
settingsInformationItem {
id("info${pidInfo.threePid.value}")