Merge pull request #2296 from nextcloud/chore/detekt-decrease

Fix some easy detekt issues and detekt.yml syntax
This commit is contained in:
Andy Scherzinger 2022-08-12 15:16:50 +02:00 committed by GitHub
commit 0a53814e65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 102 additions and 97 deletions

View File

@ -403,11 +403,9 @@ class ChatController(args: Bundle) :
}
)
val itemTouchHelper = ItemTouchHelper(messageSwipeController)
try {
withNullableControllerViewBinding {
val itemTouchHelper = ItemTouchHelper(messageSwipeController)
itemTouchHelper.attachToRecyclerView(binding.messagesListView)
} catch (npe: NullPointerException) {
Log.i(TAG, "UI already teared down", npe)
}
}
}

View File

@ -49,7 +49,6 @@ import eu.davidea.flexibleadapter.SelectableAdapter
import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
import java.io.IOException
import java.util.ArrayList
@AutoInjector(NextcloudTalkApplication::class)
class RingtoneSelectionController(args: Bundle) :
@ -107,11 +106,11 @@ class RingtoneSelectionController(args: Bundle) :
private fun findSelectedSound() {
var foundDefault = false
var preferencesString: String? = null
if (callNotificationSounds &&
TextUtils.isEmpty(appPreferences!!.callRingtoneUri.also { preferencesString = it }) ||
!callNotificationSounds &&
TextUtils.isEmpty(appPreferences!!.messageRingtoneUri.also { preferencesString = it })
) {
val callsEnabledButNoRingtone = callNotificationSounds &&
TextUtils.isEmpty(appPreferences.callRingtoneUri.also { preferencesString = it })
val noCallsAndNoMessageTone = !callNotificationSounds &&
TextUtils.isEmpty(appPreferences.messageRingtoneUri.also { preferencesString = it })
if (callsEnabledButNoRingtone || noCallsAndNoMessageTone) {
adapter!!.toggleSelection(1)
foundDefault = true
}

View File

@ -84,7 +84,7 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
)
}
try {
return try {
val currentUser = userManager.currentUser.blockingGet()
val sourcefiles = inputData.getStringArray(DEVICE_SOURCEFILES)
val ncTargetpath = inputData.getString(NC_TARGETPATH)
@ -111,14 +111,14 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
metaData
)
}
Result.success()
} catch (e: IllegalStateException) {
Log.e(javaClass.simpleName, "Something went wrong when trying to upload file", e)
return Result.failure()
Result.failure()
} catch (e: IllegalArgumentException) {
Log.e(javaClass.simpleName, "Something went wrong when trying to upload file", e)
return Result.failure()
Result.failure()
}
return Result.success()
}
@Suppress("Detekt.TooGenericExceptionCaught")
@ -196,7 +196,6 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
filename: String?,
metaData: String?
) {
val paths: MutableList<String> = ArrayList()
paths.add("$ncTargetpath/$filename")
@ -221,9 +220,9 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
const val META_DATA = "META_DATA"
fun isStoragePermissionGranted(context: Context): Boolean {
when {
return when {
Build.VERSION.SDK_INT > Build.VERSION_CODES.Q -> {
return if (PermissionChecker.checkSelfPermission(
if (PermissionChecker.checkSelfPermission(
context,
Manifest.permission.READ_EXTERNAL_STORAGE
) == PermissionChecker.PERMISSION_GRANTED
@ -236,7 +235,7 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
}
}
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M -> {
return if (PermissionChecker.checkSelfPermission(
if (PermissionChecker.checkSelfPermission(
context,
Manifest.permission.WRITE_EXTERNAL_STORAGE
) == PermissionChecker.PERMISSION_GRANTED
@ -250,13 +249,12 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
}
else -> { // permission is automatically granted on sdk<23 upon installation
Log.d(TAG, "Permission is granted")
return true
true
}
}
}
fun requestStoragePermission(controller: Controller) {
when {
Build.VERSION.SDK_INT > Build.VERSION_CODES.Q -> {
controller.requestPermissions(
@ -283,6 +281,6 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
private data class UploadItem(
val uri: Uri,
val fileName: String,
val requestBody: RequestBody?,
val requestBody: RequestBody?
)
}

View File

@ -177,60 +177,56 @@ class EnumSystemMessageTypeConverter : StringBasedTypeConverter<ChatMessage.Syst
@Suppress("Detekt.ComplexMethod")
override fun convertToString(`object`: ChatMessage.SystemMessageType?): String {
if (`object` == null) {
return ""
}
when (`object`) {
CONVERSATION_CREATED -> return "conversation_created"
CONVERSATION_RENAMED -> return "conversation_renamed"
DESCRIPTION_REMOVED -> return "description_removed"
DESCRIPTION_SET -> return "description_set"
CALL_STARTED -> return "call_started"
CALL_JOINED -> return "call_joined"
CALL_LEFT -> return "call_left"
CALL_ENDED -> return "call_ended"
CALL_ENDED_EVERYONE -> return "call_ended_everyone"
CALL_MISSED -> return "call_missed"
CALL_TRIED -> return "call_tried"
READ_ONLY_OFF -> return "read_only_off"
READ_ONLY -> return "read_only"
LISTABLE_NONE -> return "listable_none"
LISTABLE_USERS -> return "listable_users"
LISTABLE_ALL -> return "listable_all"
LOBBY_NONE -> return "lobby_none"
LOBBY_NON_MODERATORS -> return "lobby_non_moderators"
LOBBY_OPEN_TO_EVERYONE -> return "lobby_timer_reached"
GUESTS_ALLOWED -> return "guests_allowed"
GUESTS_DISALLOWED -> return "guests_disallowed"
PASSWORD_SET -> return "password_set"
PASSWORD_REMOVED -> return "password_removed"
USER_ADDED -> return "user_added"
USER_REMOVED -> return "user_removed"
GROUP_ADDED -> return "group_added"
GROUP_REMOVED -> return "group_removed"
CIRCLE_ADDED -> return "circle_added"
CIRCLE_REMOVED -> return "circle_removed"
MODERATOR_PROMOTED -> return "moderator_promoted"
MODERATOR_DEMOTED -> return "moderator_demoted"
GUEST_MODERATOR_PROMOTED -> return "guest_moderator_promoted"
GUEST_MODERATOR_DEMOTED -> return "guest_moderator_demoted"
MESSAGE_DELETED -> return "message_deleted"
FILE_SHARED -> return "file_shared"
OBJECT_SHARED -> return "object_shared"
MATTERBRIDGE_CONFIG_ADDED -> return "matterbridge_config_added"
MATTERBRIDGE_CONFIG_EDITED -> return "matterbridge_config_edited"
MATTERBRIDGE_CONFIG_REMOVED -> return "matterbridge_config_removed"
MATTERBRIDGE_CONFIG_ENABLED -> return "matterbridge_config_enabled"
MATTERBRIDGE_CONFIG_DISABLED -> return "matterbridge_config_disabled"
CLEARED_CHAT -> return "clear_history"
REACTION -> return "reaction"
REACTION_DELETED -> return "reaction_deleted"
REACTION_REVOKED -> return "reaction_revoked"
POLL_VOTED -> return "poll_voted"
POLL_CLOSED -> return "poll_closed"
else -> return ""
return when (`object`) {
null -> ""
CONVERSATION_CREATED -> "conversation_created"
CONVERSATION_RENAMED -> "conversation_renamed"
DESCRIPTION_REMOVED -> "description_removed"
DESCRIPTION_SET -> "description_set"
CALL_STARTED -> "call_started"
CALL_JOINED -> "call_joined"
CALL_LEFT -> "call_left"
CALL_ENDED -> "call_ended"
CALL_ENDED_EVERYONE -> "call_ended_everyone"
CALL_MISSED -> "call_missed"
CALL_TRIED -> "call_tried"
READ_ONLY_OFF -> "read_only_off"
READ_ONLY -> "read_only"
LISTABLE_NONE -> "listable_none"
LISTABLE_USERS -> "listable_users"
LISTABLE_ALL -> "listable_all"
LOBBY_NONE -> "lobby_none"
LOBBY_NON_MODERATORS -> "lobby_non_moderators"
LOBBY_OPEN_TO_EVERYONE -> "lobby_timer_reached"
GUESTS_ALLOWED -> "guests_allowed"
GUESTS_DISALLOWED -> "guests_disallowed"
PASSWORD_SET -> "password_set"
PASSWORD_REMOVED -> "password_removed"
USER_ADDED -> "user_added"
USER_REMOVED -> "user_removed"
GROUP_ADDED -> "group_added"
GROUP_REMOVED -> "group_removed"
CIRCLE_ADDED -> "circle_added"
CIRCLE_REMOVED -> "circle_removed"
MODERATOR_PROMOTED -> "moderator_promoted"
MODERATOR_DEMOTED -> "moderator_demoted"
GUEST_MODERATOR_PROMOTED -> "guest_moderator_promoted"
GUEST_MODERATOR_DEMOTED -> "guest_moderator_demoted"
MESSAGE_DELETED -> "message_deleted"
FILE_SHARED -> "file_shared"
OBJECT_SHARED -> "object_shared"
MATTERBRIDGE_CONFIG_ADDED -> "matterbridge_config_added"
MATTERBRIDGE_CONFIG_EDITED -> "matterbridge_config_edited"
MATTERBRIDGE_CONFIG_REMOVED -> "matterbridge_config_removed"
MATTERBRIDGE_CONFIG_ENABLED -> "matterbridge_config_enabled"
MATTERBRIDGE_CONFIG_DISABLED -> "matterbridge_config_disabled"
CLEARED_CHAT -> "clear_history"
REACTION -> "reaction"
REACTION_DELETED -> "reaction_deleted"
REACTION_REVOKED -> "reaction_revoked"
POLL_VOTED -> "poll_voted"
POLL_CLOSED -> "poll_closed"
else -> ""
}
}
}

View File

@ -318,7 +318,7 @@ class ShowReactionsDialog(
val reactionVote1Active = activeUser == actorId1
val reactionVote2Active = activeUser == actorId2
if (!reactionVote1Active && !reactionVote2Active || reactionVote1Active && reactionVote2Active) {
if (reactionVote1Active == reactionVote2Active) {
return 0
}

View File

@ -122,16 +122,12 @@ object AccountUtils {
PackageManager.GET_SIGNATURES
).signatures
if (Arrays.equals(ownSignatures, filesAppSignatures)) {
return if (Arrays.equals(ownSignatures, filesAppSignatures)) {
val accMgr = AccountManager.get(context)
val accounts = accMgr.getAccountsByType(context.getString(R.string.nc_import_account_type))
for (account in accounts) {
if (account.name == accountName) {
return true
}
}
accounts.any { it.name == accountName }
} else {
return true
true
}
}
} catch (appNotFoundException: PackageManager.NameNotFoundException) {

View File

@ -1,5 +1,5 @@
build:
maxIssues: 84
maxIssues: 77
weights:
# complexity: 2
# LongParameterList: 1
@ -8,7 +8,7 @@ build:
processors:
active: true
exclude:
exclude: []
# - 'FunctionCountProcessor'
# - 'PropertyCountProcessor'
# - 'ClassCountProcessor'
@ -17,7 +17,7 @@ processors:
console-reports:
active: true
exclude:
exclude: []
# - 'ProjectStatisticsReport'
# - 'ComplexityReport'
# - 'NotificationReport'
@ -59,7 +59,7 @@ complexity:
excludes: ['**/androidTest/**']
LabeledExpression:
active: false
ignoredLabels: ""
ignoredLabels: []
LargeClass:
active: true
threshold: 600
@ -132,7 +132,11 @@ exceptions:
active: true
ExceptionRaisedInUnexpectedLocation:
active: false
methodNames: 'toString,hashCode,equals,finalize'
methodNames:
- toString
- hashCode
- equals
- finalize
InstanceOfCheckForException:
active: false
NotImplementedDeclaration:
@ -145,14 +149,21 @@ exceptions:
active: false
SwallowedException:
active: false
ignoredExceptionTypes: 'InterruptedException,NumberFormatException,ParseException,MalformedURLException'
ignoredExceptionTypes:
- InterruptedException
- NumberFormatException
- ParseException
- MalformedURLException
ThrowingExceptionFromFinally:
active: false
ThrowingExceptionInMain:
active: false
ThrowingExceptionsWithoutMessageOrCause:
active: false
exceptions: 'IllegalArgumentException,IllegalStateException,IOException'
exceptions:
- IllegalArgumentException
- IllegalStateException
- IOException
ThrowingNewInstanceOfSameException:
active: false
TooGenericExceptionCaught:
@ -256,7 +267,7 @@ naming:
enumEntryPattern: '^[A-Z][_a-zA-Z0-9]*'
ForbiddenClassName:
active: false
forbiddenName: ''
forbiddenName: []
FunctionMaxLength:
active: false
maximumFunctionNameLength: 30
@ -268,7 +279,8 @@ naming:
functionPattern: '^([a-z$][a-zA-Z$0-9]*)|(`.*`)$'
excludeClassPattern: '$^'
ignoreOverridden: true
excludes: "**/*Test.kt"
excludes:
- "**/*Test.kt"
FunctionParameterNaming:
active: true
parameterPattern: '[a-z][A-Za-z0-9]*'
@ -367,10 +379,13 @@ style:
includeLineWrapping: false
ForbiddenComment:
active: true
values: 'TODO:,FIXME:,STOPSHIP:'
values:
- "TODO:"
- "FIXME:"
- "STOPSHIP:"
ForbiddenImport:
active: false
imports: ''
imports: []
ForbiddenVoid:
active: false
FunctionOnlyReturningConstant:
@ -382,7 +397,7 @@ style:
maxJumpCount: 1
MagicNumber:
active: true
ignoreNumbers: '-1,0,1,2'
ignoreNumbers: [ "-1","0","1","2" ]
ignoreHashCodeFunction: true
ignorePropertyDeclaration: false
ignoreConstantDeclaration: true
@ -390,7 +405,8 @@ style:
ignoreAnnotation: false
ignoreNamedArgument: true
ignoreEnums: false
excludes: "**/*Test.kt"
excludes:
- "**/*Test.kt"
MandatoryBracesIfStatements:
active: false
MaxLineLength:
@ -470,4 +486,6 @@ style:
active: false
WildcardImport:
active: true
excludeImports: 'java.util.*,kotlinx.android.synthetic.*'
excludeImports:
- 'java.util.*'
- 'kotlinx.android.synthetic.*'