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) withNullableControllerViewBinding {
try { val itemTouchHelper = ItemTouchHelper(messageSwipeController)
itemTouchHelper.attachToRecyclerView(binding.messagesListView) 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.common.SmoothScrollLinearLayoutManager
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
import java.io.IOException import java.io.IOException
import java.util.ArrayList
@AutoInjector(NextcloudTalkApplication::class) @AutoInjector(NextcloudTalkApplication::class)
class RingtoneSelectionController(args: Bundle) : class RingtoneSelectionController(args: Bundle) :
@ -107,11 +106,11 @@ class RingtoneSelectionController(args: Bundle) :
private fun findSelectedSound() { private fun findSelectedSound() {
var foundDefault = false var foundDefault = false
var preferencesString: String? = null var preferencesString: String? = null
if (callNotificationSounds && val callsEnabledButNoRingtone = callNotificationSounds &&
TextUtils.isEmpty(appPreferences!!.callRingtoneUri.also { preferencesString = it }) || TextUtils.isEmpty(appPreferences.callRingtoneUri.also { preferencesString = it })
!callNotificationSounds && val noCallsAndNoMessageTone = !callNotificationSounds &&
TextUtils.isEmpty(appPreferences!!.messageRingtoneUri.also { preferencesString = it }) TextUtils.isEmpty(appPreferences.messageRingtoneUri.also { preferencesString = it })
) { if (callsEnabledButNoRingtone || noCallsAndNoMessageTone) {
adapter!!.toggleSelection(1) adapter!!.toggleSelection(1)
foundDefault = true foundDefault = true
} }

View File

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

View File

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

View File

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

View File

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

View File

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