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
# no-semi
# no-empty-class-body
# experimental:multiline-if-else

View file

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

View file

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

View file

@ -68,10 +68,11 @@ internal abstract class SASVerificationTransaction(
// older devices have limited support of emoji, so reply with decimal
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)
else
} else {
listOf(SasMode.DECIMAL)
}
}
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()
return if (isReply)
return if (isReply) {
TextContent(content.body, formattedText).removeInReplyFallbacks()
else
} else {
TextContent(content.body, formattedText)
}
}
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))

View file

@ -125,9 +125,9 @@ class BingRulePreference : VectorPreference {
*/
private fun refreshSummary() {
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
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)) {
when (index) {
NOTIFICATION_OFF_INDEX -> {
NOTIFICATION_OFF_INDEX -> {
rule.isEnabled = true
rule.setNotify(false)
}
@ -153,7 +153,7 @@ class BingRulePreference : VectorPreference {
rule.isEnabled = false
rule.setNotify(false)
}
NOTIFICATION_NOISY_INDEX -> {
NOTIFICATION_NOISY_INDEX -> {
rule.isEnabled = true
rule.setNotify(true)
rule.notificationSound = BingRule.ACTION_VALUE_DEFAULT
@ -177,10 +177,11 @@ class BingRulePreference : VectorPreference {
&& !TextUtils.equals(rule.ruleId, BingRule.RULE_ID_INVITE_ME)
&& 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
else
} else {
BingRule.ACTION_VALUE_DEFAULT
}
} else {
rule.removeNotificationSound()
}
@ -201,26 +202,26 @@ class BingRulePreference : VectorPreference {
radioGroup?.setOnCheckedChangeListener(null)
when (ruleStatusIndex) {
NOTIFICATION_OFF_INDEX -> {
NOTIFICATION_OFF_INDEX -> {
radioGroup?.check(R.id.bingPreferenceRadioBingRuleOff)
}
NOTIFICATION_SILENT_INDEX -> {
radioGroup?.check(R.id.bingPreferenceRadioBingRuleSilent)
}
else -> {
else -> {
radioGroup?.check(R.id.bingPreferenceRadioBingRuleNoisy)
}
}
radioGroup?.setOnCheckedChangeListener { _, checkedId ->
when (checkedId) {
R.id.bingPreferenceRadioBingRuleOff -> {
R.id.bingPreferenceRadioBingRuleOff -> {
onPreferenceChangeListener?.onPreferenceChange(this, NOTIFICATION_OFF_INDEX)
}
R.id.bingPreferenceRadioBingRuleSilent -> {
onPreferenceChangeListener?.onPreferenceChange(this, NOTIFICATION_SILENT_INDEX)
}
R.id.bingPreferenceRadioBingRuleNoisy -> {
R.id.bingPreferenceRadioBingRuleNoisy -> {
onPreferenceChangeListener?.onPreferenceChange(this, NOTIFICATION_NOISY_INDEX)
}
}

View file

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

View file

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

View file

@ -988,8 +988,9 @@ class RoomDetailFragment :
override fun onFinish() {}
override fun onSuccess(image: File?) {
if (image != null)
if (image != null) {
shareMedia(requireContext(), image, "image/*")
}
}
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)
if (circleStartColor != 0)
if (circleStartColor != 0) {
circleView.startColor = circleStartColor
}
circleEndColor = array.getColor(R.styleable.ReactionButton_circle_end_color, 0)
if (circleEndColor != 0)
if (circleEndColor != 0) {
circleView.endColor = circleEndColor
}
dotPrimaryColor = array.getColor(R.styleable.ReactionButton_dots_primary_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) {
if (!isEnabled)
if (!isEnabled) {
return
}
isChecked = !isChecked