fix: improve detekt score and threshold

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2024-08-17 20:41:18 +02:00
parent 69ed8207d0
commit 9d62a6f745
No known key found for this signature in database
GPG Key ID: 6CADC7E3523C308B
5 changed files with 30 additions and 16 deletions

View File

@ -504,12 +504,12 @@ class OfflineFirstChatRepository @Inject constructor(
chatBlock.newestMessageId chatBlock.newestMessageId
).first() ).first()
if (connectedChatBlocks.size == 1) { return if (connectedChatBlocks.size == 1) {
Log.d(TAG, "This chatBlock is not connected to others") Log.d(TAG, "This chatBlock is not connected to others")
val chatBlockFromDb = connectedChatBlocks[0] val chatBlockFromDb = connectedChatBlocks[0]
Log.d(TAG, "chatBlockFromDb.oldestMessageId: " + chatBlockFromDb.oldestMessageId) Log.d(TAG, "chatBlockFromDb.oldestMessageId: " + chatBlockFromDb.oldestMessageId)
Log.d(TAG, "chatBlockFromDb.newestMessageId: " + chatBlockFromDb.newestMessageId) Log.d(TAG, "chatBlockFromDb.newestMessageId: " + chatBlockFromDb.newestMessageId)
return chatBlockFromDb chatBlockFromDb
} else if (connectedChatBlocks.size > 1) { } else if (connectedChatBlocks.size > 1) {
Log.d(TAG, "Found " + connectedChatBlocks.size + " chat blocks that are connected") Log.d(TAG, "Found " + connectedChatBlocks.size + " chat blocks that are connected")
val oldestIdFromDbChatBlocks = val oldestIdFromDbChatBlocks =
@ -536,10 +536,10 @@ class OfflineFirstChatRepository @Inject constructor(
Log.d(TAG, "A new chat block was created that covers all the range of the found chatblocks") Log.d(TAG, "A new chat block was created that covers all the range of the found chatblocks")
Log.d(TAG, "new chatBlock - oldest MessageId: $oldestIdFromDbChatBlocks") Log.d(TAG, "new chatBlock - oldest MessageId: $oldestIdFromDbChatBlocks")
Log.d(TAG, "new chatBlock - newest MessageId: $newestIdFromDbChatBlocks") Log.d(TAG, "new chatBlock - newest MessageId: $newestIdFromDbChatBlocks")
return newChatBlock newChatBlock
} else { } else {
Log.d(TAG, "No chat block found ....") Log.d(TAG, "No chat block found ....")
return null null
} }
} }

View File

@ -77,6 +77,8 @@ object DisplayUtils {
private const val TWITTER_HANDLE_PREFIX = "@" private const val TWITTER_HANDLE_PREFIX = "@"
private const val HTTP_PROTOCOL = "http://" private const val HTTP_PROTOCOL = "http://"
private const val HTTPS_PROTOCOL = "https://" private const val HTTPS_PROTOCOL = "https://"
private const val HTTP_MIN_LENGTH: Int = 7
private const val HTTPS_MIN_LENGTH: Int = 7
private const val DATE_TIME_PARTS_SIZE = 2 private const val DATE_TIME_PARTS_SIZE = 2
fun isDarkModeOn(context: Context): Boolean { fun isDarkModeOn(context: Context): Boolean {
val currentNightMode = context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK val currentNightMode = context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
@ -394,10 +396,14 @@ object DisplayUtils {
if (TextUtils.isEmpty(url)) { if (TextUtils.isEmpty(url)) {
return "" return ""
} }
if (url!!.length >= 7 && HTTP_PROTOCOL.equals(url.substring(0, 7), ignoreCase = true)) { if (url!!.length >= HTTP_MIN_LENGTH &&
HTTP_PROTOCOL.equals(url.substring(0, HTTP_MIN_LENGTH), ignoreCase = true)
) {
return url.substring(HTTP_PROTOCOL.length).trim { it <= ' ' } return url.substring(HTTP_PROTOCOL.length).trim { it <= ' ' }
} }
return if (url.length >= 8 && HTTPS_PROTOCOL.equals(url.substring(0, 8), ignoreCase = true)) { return if (url.length >= HTTPS_MIN_LENGTH &&
HTTPS_PROTOCOL.equals(url.substring(0, HTTPS_MIN_LENGTH), ignoreCase = true)
) {
url.substring(HTTPS_PROTOCOL.length).trim { it <= ' ' } url.substring(HTTPS_PROTOCOL.length).trim { it <= ' ' }
} else { } else {
url.trim { it <= ' ' } url.trim { it <= ' ' }

View File

@ -162,26 +162,26 @@ class PushUtils {
var keyGen: KeyPairGenerator? = null var keyGen: KeyPairGenerator? = null
try { try {
keyGen = KeyPairGenerator.getInstance("RSA") keyGen = KeyPairGenerator.getInstance("RSA")
keyGen.initialize(2048) keyGen.initialize(RSA_KEY_SIZE)
val pair = keyGen.generateKeyPair() val pair = keyGen.generateKeyPair()
val statusPrivate = saveKeyToFile(pair.private, privateKeyFile.absolutePath) val statusPrivate = saveKeyToFile(pair.private, privateKeyFile.absolutePath)
val statusPublic = saveKeyToFile(pair.public, publicKeyFile.absolutePath) val statusPublic = saveKeyToFile(pair.public, publicKeyFile.absolutePath)
return if (statusPrivate == 0 && statusPublic == 0) { return if (statusPrivate == 0 && statusPublic == 0) {
// all went well // all went well
0 RETURN_CODE_KEY_GENERATION_SUCCESSFUL
} else { } else {
-2 RETURN_CODE_KEY_GENERATION_FAILED
} }
} catch (e: NoSuchAlgorithmException) { } catch (e: NoSuchAlgorithmException) {
Log.d(TAG, "RSA algorithm not supported") Log.d(TAG, "RSA algorithm not supported")
} }
} else { } else {
// We already have the key // We already have the key
return -1 return RETURN_CODE_KEY_ALREADY_EXISTS
} }
// we failed to generate the key // we failed to generate the key
return -2 return RETURN_CODE_KEY_GENERATION_FAILED
} }
fun pushRegistrationToServer(ncApi: NcApi) { fun pushRegistrationToServer(ncApi: NcApi) {
@ -399,6 +399,10 @@ class PushUtils {
companion object { companion object {
private const val TAG = "PushUtils" private const val TAG = "PushUtils"
private const val RSA_KEY_SIZE: Int = 2048
private const val RETURN_CODE_KEY_GENERATION_SUCCESSFUL: Int = 0
private const val RETURN_CODE_KEY_ALREADY_EXISTS: Int = -1
private const val RETURN_CODE_KEY_GENERATION_FAILED: Int = -2
const val LATEST_PUSH_REGISTRATION_AT_SERVER: String = "LATEST_PUSH_REGISTRATION_AT_SERVER" const val LATEST_PUSH_REGISTRATION_AT_SERVER: String = "LATEST_PUSH_REGISTRATION_AT_SERVER"
const val LATEST_PUSH_REGISTRATION_AT_PUSH_PROXY: String = "LATEST_PUSH_REGISTRATION_AT_PUSH_PROXY" const val LATEST_PUSH_REGISTRATION_AT_PUSH_PROXY: String = "LATEST_PUSH_REGISTRATION_AT_PUSH_PROXY"
} }

View File

@ -503,10 +503,10 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
for (msgStr in queueStr.split("]")) { for (msgStr in queueStr.split("]")) {
try { try {
val msgArray = msgStr.replace("[", "").split(",") val msgArray = msgStr.replace("[", "").split(",")
val message = msgArray[0] val message = msgArray[MESSAGE_INDEX]
val replyTo = msgArray[1].toInt() val replyTo = msgArray[REPLY_TO_INDEX].toInt()
val displayName = msgArray[2] val displayName = msgArray[DISPLY_NAME_INDEX]
val silent = msgArray[3].toBoolean() val silent = msgArray[SILENT_INDEX].toBoolean()
val qMsg = MessageInputViewModel.QueuedMessage(message, displayName, replyTo, silent) val qMsg = MessageInputViewModel.QueuedMessage(message, displayName, replyTo, silent)
queue.add(qMsg) queue.add(qMsg)
@ -570,6 +570,10 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
@Suppress("UnusedPrivateProperty") @Suppress("UnusedPrivateProperty")
private val TAG = AppPreferencesImpl::class.simpleName private val TAG = AppPreferencesImpl::class.simpleName
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "settings") private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "settings")
private const val MESSAGE_INDEX: Int = 0
private const val REPLY_TO_INDEX: Int = 1
private const val DISPLY_NAME_INDEX: Int = 2
private const val SILENT_INDEX: Int = 3
const val PROXY_TYPE = "proxy_type" const val PROXY_TYPE = "proxy_type"
const val PROXY_SERVER = "proxy_server" const val PROXY_SERVER = "proxy_server"
const val PROXY_HOST = "proxy_host" const val PROXY_HOST = "proxy_host"

View File

@ -1,7 +1,7 @@
# SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors # SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
build: build:
maxIssues: 138 maxIssues: 166
weights: weights:
# complexity: 2 # complexity: 2
# LongParameterList: 1 # LongParameterList: 1