Merge pull request #1973 from nextcloud/bugfix/noid/reduce-number-of-detekt-issues

Reduce number of Detekt issues
This commit is contained in:
Tim Krueger 2022-05-04 13:53:35 +02:00 committed by GitHub
commit 04abd84d52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 109 additions and 92 deletions

View File

@ -213,7 +213,7 @@ class LocationPickerController(args: Bundle) :
return true return true
} }
@Suppress("Detekt.TooGenericExceptionCaught") @Suppress("Detekt.TooGenericExceptionCaught", "Detekt.ComplexMethod")
private fun initMap() { private fun initMap() {
binding.map.setTileSource(TileSourceFactory.MAPNIK) binding.map.setTileSource(TileSourceFactory.MAPNIK)
binding.map.onResume() binding.map.onResume()
@ -223,43 +223,7 @@ class LocationPickerController(args: Bundle) :
if (!isLocationPermissionsGranted()) { if (!isLocationPermissionsGranted()) {
requestLocationPermissions() requestLocationPermissions()
} else { } else {
try { requestLocationUpdates()
when {
locationManager!!.isProviderEnabled(LocationManager.NETWORK_PROVIDER) -> {
locationManager!!.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_LOCATION_UPDATE_TIME,
MIN_LOCATION_UPDATE_DISTANCE,
this
)
}
locationManager!!.isProviderEnabled(LocationManager.GPS_PROVIDER) -> {
locationManager!!.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_LOCATION_UPDATE_TIME,
MIN_LOCATION_UPDATE_DISTANCE,
this
)
Log.d(TAG, "LocationManager.NETWORK_PROVIDER falling back to LocationManager.GPS_PROVIDER")
}
else -> {
Log.e(
TAG,
"Error requesting location updates. Probably this is a phone without google services" +
" and there is no alternative like UnifiedNlp installed. Furthermore no GPS is " +
"supported."
)
Toast.makeText(context, context?.getString(R.string.nc_location_unknown), Toast.LENGTH_LONG)
.show()
}
}
} catch (e: SecurityException) {
Log.e(TAG, "Error when requesting location updates. Permissions may be missing.", e)
Toast.makeText(context, context?.getString(R.string.nc_location_unknown), Toast.LENGTH_LONG).show()
} catch (e: Exception) {
Log.e(TAG, "Error when requesting location updates.", e)
Toast.makeText(context, context?.getString(R.string.nc_common_error_sorry), Toast.LENGTH_LONG).show()
}
} }
val copyrightOverlay = CopyrightOverlay(context) val copyrightOverlay = CopyrightOverlay(context)
@ -317,41 +281,84 @@ class LocationPickerController(args: Bundle) :
} }
binding.map.addMapListener( binding.map.addMapListener(
DelayedMapListener( delayedMapListener()
object : MapListener {
@Suppress("Detekt.TooGenericExceptionCaught")
override fun onScroll(paramScrollEvent: ScrollEvent): Boolean {
try {
when {
moveToCurrentLocationWasClicked -> {
setLocationDescription(isGpsLocation = true, isGeocodedResult = false)
moveToCurrentLocationWasClicked = false
}
receivedChosenGeocodingResult -> {
binding.shareLocation.isClickable = true
setLocationDescription(isGpsLocation = false, isGeocodedResult = true)
receivedChosenGeocodingResult = false
}
else -> {
binding.shareLocation.isClickable = true
setLocationDescription(isGpsLocation = false, isGeocodedResult = false)
}
}
} catch (e: NullPointerException) {
Log.d(TAG, "UI already closed")
}
readyToShareLocation = true
return true
}
override fun onZoom(event: ZoomEvent): Boolean {
return false
}
})
) )
} }
private fun delayedMapListener() = DelayedMapListener(
object : MapListener {
@Suppress("Detekt.TooGenericExceptionCaught")
override fun onScroll(paramScrollEvent: ScrollEvent): Boolean {
try {
when {
moveToCurrentLocationWasClicked -> {
setLocationDescription(isGpsLocation = true, isGeocodedResult = false)
moveToCurrentLocationWasClicked = false
}
receivedChosenGeocodingResult -> {
binding.shareLocation.isClickable = true
setLocationDescription(isGpsLocation = false, isGeocodedResult = true)
receivedChosenGeocodingResult = false
}
else -> {
binding.shareLocation.isClickable = true
setLocationDescription(isGpsLocation = false, isGeocodedResult = false)
}
}
} catch (e: NullPointerException) {
Log.d(TAG, "UI already closed")
}
readyToShareLocation = true
return true
}
override fun onZoom(event: ZoomEvent): Boolean {
return false
}
})
@Suppress("Detekt.TooGenericExceptionCaught")
private fun requestLocationUpdates() {
try {
when {
locationManager!!.isProviderEnabled(LocationManager.NETWORK_PROVIDER) -> {
locationManager!!.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_LOCATION_UPDATE_TIME,
MIN_LOCATION_UPDATE_DISTANCE,
this
)
}
locationManager!!.isProviderEnabled(LocationManager.GPS_PROVIDER) -> {
locationManager!!.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_LOCATION_UPDATE_TIME,
MIN_LOCATION_UPDATE_DISTANCE,
this
)
Log.d(TAG, "LocationManager.NETWORK_PROVIDER falling back to LocationManager.GPS_PROVIDER")
}
else -> {
Log.e(
TAG,
"Error requesting location updates. Probably this is a phone without google services" +
" and there is no alternative like UnifiedNlp installed. Furthermore no GPS is " +
"supported."
)
Toast.makeText(context, context?.getString(R.string.nc_location_unknown), Toast.LENGTH_LONG)
.show()
}
}
} catch (e: SecurityException) {
Log.e(TAG, "Error when requesting location updates. Permissions may be missing.", e)
Toast.makeText(context, context?.getString(R.string.nc_location_unknown), Toast.LENGTH_LONG).show()
} catch (e: Exception) {
Log.e(TAG, "Error when requesting location updates.", e)
Toast.makeText(context, context?.getString(R.string.nc_common_error_sorry), Toast.LENGTH_LONG).show()
}
}
private fun setLocationDescription(isGpsLocation: Boolean, isGeocodedResult: Boolean) { private fun setLocationDescription(isGpsLocation: Boolean, isGeocodedResult: Boolean) {
when { when {
isGpsLocation -> { isGpsLocation -> {
@ -467,11 +474,10 @@ class LocationPickerController(args: Bundle) :
grantResults: IntArray grantResults: IntArray
) { ) {
fun areAllGranted(grantResults: IntArray): Boolean { fun areAllGranted(grantResults: IntArray): Boolean {
if (grantResults.isEmpty()) return false
grantResults.forEach { grantResults.forEach {
if (it == PackageManager.PERMISSION_DENIED) return false if (it == PackageManager.PERMISSION_DENIED) return false
} }
return true return grantResults.isNotEmpty()
} }
if (requestCode == REQUEST_PERMISSIONS_REQUEST_CODE && areAllGranted(grantResults)) { if (requestCode == REQUEST_PERMISSIONS_REQUEST_CODE && areAllGranted(grantResults)) {

View File

@ -5,6 +5,8 @@
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com> * Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
* @author Marcel Hibbe * @author Marcel Hibbe
* Copyright (C) 2021 Marcel Hibbe <dev@mhibbe.de> * Copyright (C) 2021 Marcel Hibbe <dev@mhibbe.de>
* @author Tim Krüger
* Copyright (C) 2022 Tim Krüger <t@timkrueger.me>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -26,24 +28,32 @@ class ChatUtils {
companion object { companion object {
fun getParsedMessage(message: String?, messageParameters: HashMap<String?, HashMap<String?, String?>>?): fun getParsedMessage(message: String?, messageParameters: HashMap<String?, HashMap<String?, String?>>?):
String? { String? {
var resultMessage = message
if (messageParameters != null && messageParameters.size > 0) { if (messageParameters != null && messageParameters.size > 0) {
for (key in messageParameters.keys) { return parse(messageParameters, message)
val individualHashMap = messageParameters[key] }
val type = individualHashMap?.get("type") return message
if (type == "user" || type == "guest" || type == "call") { }
resultMessage = resultMessage?.replace("{$key}", "@" + individualHashMap["name"])
} else if (type == "geo-location") { private fun parse(
resultMessage = individualHashMap.get("name") messageParameters: HashMap<String?, HashMap<String?, String?>>,
} else if (individualHashMap?.containsKey("link") == true) { message: String?
resultMessage = if (type == "file") { ): String? {
resultMessage?.replace("{$key}", individualHashMap["name"].toString()) var resultMessage = message
} else { for (key in messageParameters.keys) {
individualHashMap["link"].toString() val individualHashMap = messageParameters[key]
} val type = individualHashMap?.get("type")
if (type == "user" || type == "guest" || type == "call") {
resultMessage = resultMessage?.replace("{$key}", "@" + individualHashMap["name"])
} else if (type == "geo-location") {
resultMessage = individualHashMap.get("name")
} else if (individualHashMap?.containsKey("link") == true) {
resultMessage = if (type == "file") {
resultMessage?.replace("{$key}", individualHashMap["name"].toString())
} else { } else {
resultMessage = individualHashMap?.get("name")?.let { resultMessage?.replace("{$key}", it) } individualHashMap["link"].toString()
} }
} else {
resultMessage = individualHashMap?.get("name")?.let { resultMessage?.replace("{$key}", it) }
} }
} }
return resultMessage return resultMessage

View File

@ -69,7 +69,8 @@ complexity:
excludes: ['**/androidTest/**'] excludes: ['**/androidTest/**']
LongParameterList: LongParameterList:
active: true active: true
threshold: 6 functionThreshold: 6
constructorThreshold: 7
ignoreDefaultParameters: false ignoreDefaultParameters: false
MethodOverloading: MethodOverloading:
active: false active: false
@ -333,7 +334,7 @@ potential-bugs:
active: false active: false
LateinitUsage: LateinitUsage:
active: false active: false
excludeAnnotatedProperties: "" ignoreAnnotated: []
ignoreOnClassesPattern: "" ignoreOnClassesPattern: ""
UnconditionalJumpStatementInLoop: UnconditionalJumpStatementInLoop:
active: false active: false
@ -439,10 +440,10 @@ style:
active: false active: false
UnderscoresInNumericLiterals: UnderscoresInNumericLiterals:
active: false active: false
acceptableDecimalLength: 5 acceptableLength: 5
UnnecessaryAbstractClass: UnnecessaryAbstractClass:
active: false active: false
excludeAnnotatedClasses: "dagger.Module" ignoreAnnotated: ["dagger.Module"]
UnnecessaryApply: UnnecessaryApply:
active: false active: false
UnnecessaryInheritance: UnnecessaryInheritance:
@ -462,7 +463,7 @@ style:
allowedNames: "(_|ignored|expected|serialVersionUID)" allowedNames: "(_|ignored|expected|serialVersionUID)"
UseDataClass: UseDataClass:
active: false active: false
excludeAnnotatedClasses: "" ignoreAnnotated: []
UtilityClassWithPublicConstructor: UtilityClassWithPublicConstructor:
active: false active: false
VarCouldBeVal: VarCouldBeVal: