ktlint: fix (experimental:multiline-if-else) issues

This commit is contained in:
Benoit Marty 2019-10-09 16:40:19 +02:00
parent 99d9704a50
commit e5779d425a
10 changed files with 49 additions and 37 deletions

View file

@ -28,3 +28,4 @@ disabled_rules=no-wildcard-imports,no-multi-spaces,colon-spacing,chain-wrapping,
# curly-spacing # curly-spacing
# no-semi # no-semi
# no-empty-class-body # no-empty-class-body
# experimental:multiline-if-else

View file

@ -38,8 +38,9 @@ object ContentUtils {
fun extractUsefulTextFromHtmlReply(repliedBody: String): String { fun extractUsefulTextFromHtmlReply(repliedBody: String): String {
if (repliedBody.startsWith("<mx-reply>")) { if (repliedBody.startsWith("<mx-reply>")) {
val closingTagIndex = repliedBody.lastIndexOf("</mx-reply>") val closingTagIndex = repliedBody.lastIndexOf("</mx-reply>")
if (closingTagIndex != -1) if (closingTagIndex != -1) {
return repliedBody.substring(closingTagIndex + "</mx-reply>".length).trim() return repliedBody.substring(closingTagIndex + "</mx-reply>".length).trim()
}
} }
return repliedBody return repliedBody
} }

View file

@ -52,10 +52,11 @@ fun base58encode(input: ByteArray): String {
s.insert(0, ALPHABET[bi.toInt()]) s.insert(0, ALPHABET[bi.toInt()])
// Convert leading zeros too. // Convert leading zeros too.
for (anInput in input) { for (anInput in input) {
if (anInput.toInt() == 0) if (anInput.toInt() == 0) {
s.insert(0, ALPHABET[0]) s.insert(0, ALPHABET[0])
else } else {
break break
}
} }
return s.toString() return s.toString()
} }

View file

@ -68,10 +68,11 @@ internal abstract class SASVerificationTransaction(
// older devices have limited support of emoji, so reply with decimal // older devices have limited support of emoji, so reply with decimal
val KNOWN_SHORT_CODES = val KNOWN_SHORT_CODES =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
listOf(SasMode.EMOJI, SasMode.DECIMAL) listOf(SasMode.EMOJI, SasMode.DECIMAL)
else } else {
listOf(SasMode.DECIMAL) listOf(SasMode.DECIMAL)
}
} }
override var state by Delegates.observable(SasVerificationTxState.None) { _, _, new -> override var state by Delegates.observable(SasVerificationTxState.None) { _, _, new ->

View file

@ -352,10 +352,11 @@ internal class LocalEchoEventFactory @Inject constructor(@UserId private val use
} }
} }
val isReply = content.isReply() || originalContent.isReply() val isReply = content.isReply() || originalContent.isReply()
return if (isReply) return if (isReply) {
TextContent(content.body, formattedText).removeInReplyFallbacks() TextContent(content.body, formattedText).removeInReplyFallbacks()
else } else {
TextContent(content.body, formattedText) TextContent(content.body, formattedText)
}
} }
MessageType.MSGTYPE_FILE -> return TextContent(stringProvider.getString(R.string.reply_to_a_file)) MessageType.MSGTYPE_FILE -> return TextContent(stringProvider.getString(R.string.reply_to_a_file))
MessageType.MSGTYPE_AUDIO -> return TextContent(stringProvider.getString(R.string.reply_to_an_audio_file)) MessageType.MSGTYPE_AUDIO -> return TextContent(stringProvider.getString(R.string.reply_to_an_audio_file))

View file

@ -125,9 +125,9 @@ class BingRulePreference : VectorPreference {
*/ */
private fun refreshSummary() { private fun refreshSummary() {
summary = context.getString(when (ruleStatusIndex) { summary = context.getString(when (ruleStatusIndex) {
NOTIFICATION_OFF_INDEX -> R.string.notification_off NOTIFICATION_OFF_INDEX -> R.string.notification_off
NOTIFICATION_SILENT_INDEX -> R.string.notification_silent NOTIFICATION_SILENT_INDEX -> R.string.notification_silent
else -> R.string.notification_noisy else -> R.string.notification_noisy
}) })
} }
@ -145,7 +145,7 @@ class BingRulePreference : VectorPreference {
if (TextUtils.equals(rule.ruleId, BingRule.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS)) { if (TextUtils.equals(rule.ruleId, BingRule.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS)) {
when (index) { when (index) {
NOTIFICATION_OFF_INDEX -> { NOTIFICATION_OFF_INDEX -> {
rule.isEnabled = true rule.isEnabled = true
rule.setNotify(false) rule.setNotify(false)
} }
@ -153,7 +153,7 @@ class BingRulePreference : VectorPreference {
rule.isEnabled = false rule.isEnabled = false
rule.setNotify(false) rule.setNotify(false)
} }
NOTIFICATION_NOISY_INDEX -> { NOTIFICATION_NOISY_INDEX -> {
rule.isEnabled = true rule.isEnabled = true
rule.setNotify(true) rule.setNotify(true)
rule.notificationSound = BingRule.ACTION_VALUE_DEFAULT rule.notificationSound = BingRule.ACTION_VALUE_DEFAULT
@ -177,10 +177,11 @@ class BingRulePreference : VectorPreference {
&& !TextUtils.equals(rule.ruleId, BingRule.RULE_ID_INVITE_ME) && !TextUtils.equals(rule.ruleId, BingRule.RULE_ID_INVITE_ME)
&& NOTIFICATION_NOISY_INDEX == index) && NOTIFICATION_NOISY_INDEX == index)
if (NOTIFICATION_NOISY_INDEX == index) { if (NOTIFICATION_NOISY_INDEX == index) {
rule.notificationSound = if (TextUtils.equals(rule.ruleId, BingRule.RULE_ID_CALL)) rule.notificationSound = if (TextUtils.equals(rule.ruleId, BingRule.RULE_ID_CALL)) {
BingRule.ACTION_VALUE_RING BingRule.ACTION_VALUE_RING
else } else {
BingRule.ACTION_VALUE_DEFAULT BingRule.ACTION_VALUE_DEFAULT
}
} else { } else {
rule.removeNotificationSound() rule.removeNotificationSound()
} }
@ -201,26 +202,26 @@ class BingRulePreference : VectorPreference {
radioGroup?.setOnCheckedChangeListener(null) radioGroup?.setOnCheckedChangeListener(null)
when (ruleStatusIndex) { when (ruleStatusIndex) {
NOTIFICATION_OFF_INDEX -> { NOTIFICATION_OFF_INDEX -> {
radioGroup?.check(R.id.bingPreferenceRadioBingRuleOff) radioGroup?.check(R.id.bingPreferenceRadioBingRuleOff)
} }
NOTIFICATION_SILENT_INDEX -> { NOTIFICATION_SILENT_INDEX -> {
radioGroup?.check(R.id.bingPreferenceRadioBingRuleSilent) radioGroup?.check(R.id.bingPreferenceRadioBingRuleSilent)
} }
else -> { else -> {
radioGroup?.check(R.id.bingPreferenceRadioBingRuleNoisy) radioGroup?.check(R.id.bingPreferenceRadioBingRuleNoisy)
} }
} }
radioGroup?.setOnCheckedChangeListener { _, checkedId -> radioGroup?.setOnCheckedChangeListener { _, checkedId ->
when (checkedId) { when (checkedId) {
R.id.bingPreferenceRadioBingRuleOff -> { R.id.bingPreferenceRadioBingRuleOff -> {
onPreferenceChangeListener?.onPreferenceChange(this, NOTIFICATION_OFF_INDEX) onPreferenceChangeListener?.onPreferenceChange(this, NOTIFICATION_OFF_INDEX)
} }
R.id.bingPreferenceRadioBingRuleSilent -> { R.id.bingPreferenceRadioBingRuleSilent -> {
onPreferenceChangeListener?.onPreferenceChange(this, NOTIFICATION_SILENT_INDEX) onPreferenceChangeListener?.onPreferenceChange(this, NOTIFICATION_SILENT_INDEX)
} }
R.id.bingPreferenceRadioBingRuleNoisy -> { R.id.bingPreferenceRadioBingRuleNoisy -> {
onPreferenceChangeListener?.onPreferenceChange(this, NOTIFICATION_NOISY_INDEX) onPreferenceChangeListener?.onPreferenceChange(this, NOTIFICATION_NOISY_INDEX)
} }
} }

View file

@ -82,10 +82,11 @@ fun logPermissionStatuses(context: Context) {
for (permission in permissions) { for (permission in permissions) {
Timber.v(("Status of [$permission] : " + Timber.v(("Status of [$permission] : " +
if (PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(context, permission)) if (PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(context, permission)) {
"PERMISSION_GRANTED" "PERMISSION_GRANTED"
else } else {
"PERMISSION_DENIED")) "PERMISSION_DENIED"
}))
} }
} }
} }
@ -147,13 +148,13 @@ private fun checkPermissions(permissionsToBeGrantedBitMap: Int,
} else if (PERMISSIONS_EMPTY == permissionsToBeGrantedBitMap) { } else if (PERMISSIONS_EMPTY == permissionsToBeGrantedBitMap) {
isPermissionGranted = true isPermissionGranted = true
} else if (PERMISSIONS_FOR_AUDIO_IP_CALL != permissionsToBeGrantedBitMap } else if (PERMISSIONS_FOR_AUDIO_IP_CALL != permissionsToBeGrantedBitMap
&& PERMISSIONS_FOR_VIDEO_IP_CALL != permissionsToBeGrantedBitMap && PERMISSIONS_FOR_VIDEO_IP_CALL != permissionsToBeGrantedBitMap
&& PERMISSIONS_FOR_TAKING_PHOTO != permissionsToBeGrantedBitMap && PERMISSIONS_FOR_TAKING_PHOTO != permissionsToBeGrantedBitMap
&& PERMISSIONS_FOR_MEMBERS_SEARCH != permissionsToBeGrantedBitMap && PERMISSIONS_FOR_MEMBERS_SEARCH != permissionsToBeGrantedBitMap
&& PERMISSIONS_FOR_MEMBER_DETAILS != permissionsToBeGrantedBitMap && PERMISSIONS_FOR_MEMBER_DETAILS != permissionsToBeGrantedBitMap
&& PERMISSIONS_FOR_ROOM_AVATAR != permissionsToBeGrantedBitMap && PERMISSIONS_FOR_ROOM_AVATAR != permissionsToBeGrantedBitMap
&& PERMISSIONS_FOR_VIDEO_RECORDING != permissionsToBeGrantedBitMap && PERMISSIONS_FOR_VIDEO_RECORDING != permissionsToBeGrantedBitMap
&& PERMISSIONS_FOR_WRITING_FILES != permissionsToBeGrantedBitMap) { && PERMISSIONS_FOR_WRITING_FILES != permissionsToBeGrantedBitMap) {
Timber.w("## checkPermissions(): permissions to be granted are not supported") Timber.w("## checkPermissions(): permissions to be granted are not supported")
isPermissionGranted = false isPermissionGranted = false
} else { } else {
@ -204,7 +205,7 @@ private fun checkPermissions(permissionsToBeGrantedBitMap: Int,
if (permissionsToBeGrantedBitMap == PERMISSIONS_FOR_VIDEO_IP_CALL || permissionsToBeGrantedBitMap == PERMISSIONS_FOR_AUDIO_IP_CALL) { if (permissionsToBeGrantedBitMap == PERMISSIONS_FOR_VIDEO_IP_CALL || permissionsToBeGrantedBitMap == PERMISSIONS_FOR_AUDIO_IP_CALL) {
// Permission request for VOIP call // Permission request for VOIP call
if (permissionListAlreadyDenied.contains(Manifest.permission.CAMERA) if (permissionListAlreadyDenied.contains(Manifest.permission.CAMERA)
&& permissionListAlreadyDenied.contains(Manifest.permission.RECORD_AUDIO)) { && permissionListAlreadyDenied.contains(Manifest.permission.RECORD_AUDIO)) {
// Both missing // Both missing
explanationMessage += activity.getString(R.string.permissions_rationale_msg_camera_and_audio) explanationMessage += activity.getString(R.string.permissions_rationale_msg_camera_and_audio)
} else if (permissionListAlreadyDenied.contains(Manifest.permission.RECORD_AUDIO)) { } else if (permissionListAlreadyDenied.contains(Manifest.permission.RECORD_AUDIO)) {
@ -256,9 +257,9 @@ private fun checkPermissions(permissionsToBeGrantedBitMap: Int,
.setPositiveButton(R.string.ok) { _, _ -> .setPositiveButton(R.string.ok) { _, _ ->
if (!permissionsListToBeGranted.isEmpty()) { if (!permissionsListToBeGranted.isEmpty()) {
fragment?.requestPermissions(permissionsListToBeGranted.toTypedArray(), requestCode) fragment?.requestPermissions(permissionsListToBeGranted.toTypedArray(), requestCode)
?: run { ?: run {
ActivityCompat.requestPermissions(activity, permissionsListToBeGranted.toTypedArray(), requestCode) ActivityCompat.requestPermissions(activity, permissionsListToBeGranted.toTypedArray(), requestCode)
} }
} }
} }
.show() .show()

View file

@ -90,11 +90,12 @@ class CreateDirectRoomActivity : SimpleFragmentActivity() {
hideWaitingView() hideWaitingView()
if (error is CreateRoomFailure.CreatedWithTimeout) { if (error is CreateRoomFailure.CreatedWithTimeout) {
finish() finish()
} else } else {
AlertDialog.Builder(this) AlertDialog.Builder(this)
.setMessage(errorFormatter.toHumanReadable(error)) .setMessage(errorFormatter.toHumanReadable(error))
.setPositiveButton(R.string.ok, null) .setPositiveButton(R.string.ok, null)
.show() .show()
}
} }
private fun renderCreationSuccess(roomId: String?) { private fun renderCreationSuccess(roomId: String?) {

View file

@ -988,8 +988,9 @@ class RoomDetailFragment :
override fun onFinish() {} override fun onFinish() {}
override fun onSuccess(image: File?) { override fun onSuccess(image: File?) {
if (image != null) if (image != null) {
shareMedia(requireContext(), image, "image/*") shareMedia(requireContext(), image, "image/*")
}
} }
override fun onFail(error: Exception?) {} override fun onFail(error: Exception?) {}

View file

@ -117,13 +117,15 @@ class ReactionButton @JvmOverloads constructor(context: Context, attrs: Attribut
circleStartColor = array.getColor(R.styleable.ReactionButton_circle_start_color, 0) circleStartColor = array.getColor(R.styleable.ReactionButton_circle_start_color, 0)
if (circleStartColor != 0) if (circleStartColor != 0) {
circleView.startColor = circleStartColor circleView.startColor = circleStartColor
}
circleEndColor = array.getColor(R.styleable.ReactionButton_circle_end_color, 0) circleEndColor = array.getColor(R.styleable.ReactionButton_circle_end_color, 0)
if (circleEndColor != 0) if (circleEndColor != 0) {
circleView.endColor = circleEndColor circleView.endColor = circleEndColor
}
dotPrimaryColor = array.getColor(R.styleable.ReactionButton_dots_primary_color, 0) dotPrimaryColor = array.getColor(R.styleable.ReactionButton_dots_primary_color, 0)
dotSecondaryColor = array.getColor(R.styleable.ReactionButton_dots_secondary_color, 0) dotSecondaryColor = array.getColor(R.styleable.ReactionButton_dots_secondary_color, 0)
@ -159,8 +161,9 @@ class ReactionButton @JvmOverloads constructor(context: Context, attrs: Attribut
*/ */
override fun onClick(v: View) { override fun onClick(v: View) {
if (!isEnabled) if (!isEnabled) {
return return
}
isChecked = !isChecked isChecked = !isChecked