improve codacy score

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2021-06-10 21:33:14 +02:00
parent a5923de582
commit a8368e626e
No known key found for this signature in database
GPG Key ID: 6CADC7E3523C308B
6 changed files with 79 additions and 36 deletions

View File

@ -297,7 +297,7 @@ dependencies {
implementation 'fr.dudie:nominatim-api:3.4' implementation 'fr.dudie:nominatim-api:3.4'
// noinspection DuplicatePlatformClasses // noinspection DuplicatePlatformClasses
api 'org.apache.httpcomponents:httpclient:4.5.9' api group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.9'
// nominatim-api uses httpclient // nominatim-api uses httpclient
// Android comes with its own httpclient // Android comes with its own httpclient

View File

@ -58,9 +58,8 @@ import javax.inject.Inject
@AutoInjector(NextcloudTalkApplication::class) @AutoInjector(NextcloudTalkApplication::class)
class IncomingLocationMessageViewHolder(incomingView: View) : MessageHolders class IncomingLocationMessageViewHolder(incomingView: View) : MessageHolders
.IncomingTextMessageViewHolder<ChatMessage>(incomingView) { .IncomingTextMessageViewHolder<ChatMessage>(incomingView) {
private val binding: ItemCustomIncomingLocationMessageBinding = ItemCustomIncomingLocationMessageBinding.bind(itemView) private val binding: ItemCustomIncomingLocationMessageBinding =
ItemCustomIncomingLocationMessageBinding.bind(itemView)
private val TAG = "LocMessageView"
var locationLon: String? = "" var locationLon: String? = ""
var locationLat: String? = "" var locationLat: String? = ""
@ -79,6 +78,27 @@ class IncomingLocationMessageViewHolder(incomingView: View) : MessageHolders
override fun onBind(message: ChatMessage) { override fun onBind(message: ChatMessage) {
super.onBind(message) super.onBind(message)
sharedApplication!!.componentApplication.inject(this) sharedApplication!!.componentApplication.inject(this)
setAvatarAndAuthorOnMessageItem(message)
colorizeMessageBubble(message)
itemView.isSelected = false
binding.messageTime.setTextColor(context?.resources!!.getColor(R.color.warm_grey_four))
val textSize = context?.resources!!.getDimension(R.dimen.chat_text_size)
binding.messageText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize)
binding.messageText.text = message.text
binding.messageText.isEnabled = false
// parent message handling
setParentMessageDataOnMessageItem(message)
// geo-location
setLocationDataOnMessageItem(message)
}
private fun setAvatarAndAuthorOnMessageItem(message: ChatMessage) {
val author: String = message.actorDisplayName val author: String = message.actorDisplayName
if (!TextUtils.isEmpty(author)) { if (!TextUtils.isEmpty(author)) {
binding.messageAuthor.text = author binding.messageAuthor.text = author
@ -116,37 +136,31 @@ class IncomingLocationMessageViewHolder(incomingView: View) : MessageHolders
} }
binding.messageAuthor.visibility = View.GONE binding.messageAuthor.visibility = View.GONE
} }
}
private fun colorizeMessageBubble(message: ChatMessage) {
val resources = itemView.resources val resources = itemView.resources
val bgBubbleColor = if (message.isDeleted) {
resources.getColor(R.color.bg_message_list_incoming_bubble_deleted)
} else {
resources.getColor(R.color.bg_message_list_incoming_bubble)
}
var bubbleResource = R.drawable.shape_incoming_message var bubbleResource = R.drawable.shape_incoming_message
if (message.isGrouped) { if (message.isGrouped) {
bubbleResource = R.drawable.shape_grouped_incoming_message bubbleResource = R.drawable.shape_grouped_incoming_message
} }
val bgBubbleColor = if (message.isDeleted) {
resources.getColor(R.color.bg_message_list_incoming_bubble_deleted)
} else {
resources.getColor(R.color.bg_message_list_incoming_bubble)
}
val bubbleDrawable = DisplayUtils.getMessageSelector( val bubbleDrawable = DisplayUtils.getMessageSelector(
bgBubbleColor, bgBubbleColor,
resources.getColor(R.color.transparent), resources.getColor(R.color.transparent),
bgBubbleColor, bubbleResource bgBubbleColor, bubbleResource
) )
ViewCompat.setBackground(bubble, bubbleDrawable) ViewCompat.setBackground(bubble, bubbleDrawable)
}
itemView.isSelected = false private fun setParentMessageDataOnMessageItem(message: ChatMessage) {
binding.messageTime.setTextColor(context?.resources!!.getColor(R.color.warm_grey_four))
val textSize = context?.resources!!.getDimension(R.dimen.chat_text_size)
binding.messageText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize)
binding.messageText.text = message.text
binding.messageText.isEnabled = false
// parent message handling
if (!message.isDeleted && message.parentMessage != null) { if (!message.isDeleted && message.parentMessage != null) {
val parentChatMessage = message.parentMessage val parentChatMessage = message.parentMessage
parentChatMessage.activeUser = message.activeUser parentChatMessage.activeUser = message.activeUser
@ -178,9 +192,9 @@ class IncomingLocationMessageViewHolder(incomingView: View) : MessageHolders
} else { } else {
binding.messageQuote.quotedChatMessageView.visibility = View.GONE binding.messageQuote.quotedChatMessageView.visibility = View.GONE
} }
}
// geo-location private fun setLocationDataOnMessageItem(message: ChatMessage) {
if (message.messageParameters != null && message.messageParameters.size > 0) { if (message.messageParameters != null && message.messageParameters.size > 0) {
for (key in message.messageParameters.keys) { for (key in message.messageParameters.keys) {
val individualHashMap: Map<String, String> = message.messageParameters[key]!! val individualHashMap: Map<String, String> = message.messageParameters[key]!!
@ -247,4 +261,8 @@ class IncomingLocationMessageViewHolder(incomingView: View) : MessageHolders
private fun addMarkerToGeoLink(locationGeoLink: String): String { private fun addMarkerToGeoLink(locationGeoLink: String): String {
return locationGeoLink.replace("geo:", "geo:0,0?q=") return locationGeoLink.replace("geo:", "geo:0,0?q=")
} }
companion object {
private const val TAG = "LocInMessageView"
}
} }

View File

@ -146,7 +146,9 @@ class MagicOutcomingTextMessageViewHolder(itemView: View) : OutcomingTextMessage
binding.messageQuote.quotedMessageAuthor.text = parentChatMessage.actorDisplayName binding.messageQuote.quotedMessageAuthor.text = parentChatMessage.actorDisplayName
?: context!!.getText(R.string.nc_nick_guest) ?: context!!.getText(R.string.nc_nick_guest)
binding.messageQuote.quotedMessage.text = parentChatMessage.text binding.messageQuote.quotedMessage.text = parentChatMessage.text
binding.messageQuote.quotedMessage.setTextColor(context!!.resources.getColor(R.color.nc_outcoming_text_default)) binding.messageQuote.quotedMessage.setTextColor(
context!!.resources.getColor(R.color.nc_outcoming_text_default)
)
binding.messageQuote.quotedMessageAuthor.setTextColor(context!!.resources.getColor(R.color.nc_grey)) binding.messageQuote.quotedMessageAuthor.setTextColor(context!!.resources.getColor(R.color.nc_grey))
binding.messageQuote.quoteColoredView.setBackgroundResource(R.color.white) binding.messageQuote.quoteColoredView.setBackgroundResource(R.color.white)

View File

@ -58,8 +58,6 @@ class OutcomingLocationMessageViewHolder(incomingView: View) : MessageHolders
ItemCustomOutcomingLocationMessageBinding.bind(itemView) ItemCustomOutcomingLocationMessageBinding.bind(itemView)
private val realView: View = itemView private val realView: View = itemView
private val TAG = "LocMessageView"
var locationLon: String? = "" var locationLon: String? = ""
var locationLat: String? = "" var locationLat: String? = ""
var locationName: String? = "" var locationName: String? = ""
@ -128,7 +126,9 @@ class OutcomingLocationMessageViewHolder(incomingView: View) : MessageHolders
binding.messageQuote.quotedMessageAuthor.text = parentChatMessage.actorDisplayName binding.messageQuote.quotedMessageAuthor.text = parentChatMessage.actorDisplayName
?: context!!.getText(R.string.nc_nick_guest) ?: context!!.getText(R.string.nc_nick_guest)
binding.messageQuote.quotedMessage.text = parentChatMessage.text binding.messageQuote.quotedMessage.text = parentChatMessage.text
binding.messageQuote.quotedMessage.setTextColor(context!!.resources.getColor(R.color.nc_outcoming_text_default)) binding.messageQuote.quotedMessage.setTextColor(
context!!.resources.getColor(R.color.nc_outcoming_text_default)
)
binding.messageQuote.quotedMessageAuthor.setTextColor(context!!.resources.getColor(R.color.nc_grey)) binding.messageQuote.quotedMessageAuthor.setTextColor(context!!.resources.getColor(R.color.nc_grey))
binding.messageQuote.quoteColoredView.setBackgroundResource(R.color.white) binding.messageQuote.quoteColoredView.setBackgroundResource(R.color.white)
@ -188,7 +188,9 @@ class OutcomingLocationMessageViewHolder(incomingView: View) : MessageHolders
} }
val urlStringBuffer = StringBuffer("file:///android_asset/leafletMapMessagePreview.html") val urlStringBuffer = StringBuffer("file:///android_asset/leafletMapMessagePreview.html")
urlStringBuffer.append("?mapProviderUrl=" + URLEncoder.encode(context!!.getString(R.string.osm_tile_server_url))) urlStringBuffer.append(
"?mapProviderUrl=" + URLEncoder.encode(context!!.getString(R.string.osm_tile_server_url))
)
urlStringBuffer.append( urlStringBuffer.append(
"&mapProviderAttribution=" + URLEncoder.encode( "&mapProviderAttribution=" + URLEncoder.encode(
context!!.getString( context!!.getString(
@ -230,4 +232,8 @@ class OutcomingLocationMessageViewHolder(incomingView: View) : MessageHolders
private fun addMarkerToGeoLink(locationGeoLink: String): String { private fun addMarkerToGeoLink(locationGeoLink: String): String {
return locationGeoLink.replace("geo:", "geo:0,0?q=") return locationGeoLink.replace("geo:", "geo:0,0?q=")
} }
companion object {
private const val TAG = "LocOutMessageView"
}
} }

View File

@ -179,7 +179,7 @@ class GeocodingController(args: Bundle) :
private fun initGeocoder() { private fun initGeocoder() {
val registry = SchemeRegistry() val registry = SchemeRegistry()
registry.register(Scheme("https", SSLSocketFactory.getSocketFactory(), 443)) registry.register(Scheme("https", SSLSocketFactory.getSocketFactory(), HTTPS_PORT))
val connexionManager: ClientConnectionManager = SingleClientConnManager(null, registry) val connexionManager: ClientConnectionManager = SingleClientConnManager(null, registry)
val httpClient: HttpClient = DefaultHttpClient(connexionManager, null) val httpClient: HttpClient = DefaultHttpClient(connexionManager, null)
val baseUrl = context!!.getString(R.string.osm_geocoder_url) val baseUrl = context!!.getString(R.string.osm_geocoder_url)
@ -222,6 +222,7 @@ class GeocodingController(args: Bundle) :
} }
companion object { companion object {
private val TAG = "GeocodingController" private const val TAG = "GeocodingController"
private const val HTTPS_PORT: Int = 443
} }
} }

View File

@ -227,6 +227,7 @@ class LocationPickerController(args: Bundle) :
try { try {
locationManager!!.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0L, 0f, this) locationManager!!.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0L, 0f, this)
} catch (ex: SecurityException) { } catch (ex: SecurityException) {
Log.w(TAG, "Error requesting location updates", ex)
} }
val copyrightOverlay = CopyrightOverlay(context) val copyrightOverlay = CopyrightOverlay(context)
@ -237,7 +238,7 @@ class LocationPickerController(args: Bundle) :
locationOverlay = MyLocationNewOverlay(GpsMyLocationProvider(context), binding.map) locationOverlay = MyLocationNewOverlay(GpsMyLocationProvider(context), binding.map)
locationOverlay.enableMyLocation() locationOverlay.enableMyLocation()
locationOverlay.setPersonHotspot(20.0F, 20.0F) locationOverlay.setPersonHotspot(PERSON_HOT_SPOT_X, PERSON_HOT_SPOT_Y)
locationOverlay.setPersonIcon( locationOverlay.setPersonIcon(
DisplayUtils.getBitmap( DisplayUtils.getBitmap(
ResourcesCompat.getDrawable(resources!!, R.drawable.current_location_circle, null) ResourcesCompat.getDrawable(resources!!, R.drawable.current_location_circle, null)
@ -248,9 +249,9 @@ class LocationPickerController(args: Bundle) :
val mapController = binding.map.controller val mapController = binding.map.controller
if (receivedChosenGeocodingResult) { if (receivedChosenGeocodingResult) {
mapController?.setZoom(14.0) mapController?.setZoom(ZOOM_LEVEL_RECEIVED_RESULT)
} else { } else {
mapController?.setZoom(12.0) mapController?.setZoom(ZOOM_LEVEL_DEFAULT)
} }
val zoomToCurrentPositionOnFirstFix = !receivedChosenGeocodingResult val zoomToCurrentPositionOnFirstFix = !receivedChosenGeocodingResult
@ -258,13 +259,13 @@ class LocationPickerController(args: Bundle) :
myLocation = locationOverlay.myLocation myLocation = locationOverlay.myLocation
if (zoomToCurrentPositionOnFirstFix) { if (zoomToCurrentPositionOnFirstFix) {
activity!!.runOnUiThread { activity!!.runOnUiThread {
mapController?.setZoom(12.0) mapController?.setZoom(ZOOM_LEVEL_DEFAULT)
mapController?.setCenter(myLocation) mapController?.setCenter(myLocation)
} }
} }
} }
if (receivedChosenGeocodingResult && geocodedLat != 0.0 && geocodedLon != 0.0) { if (receivedChosenGeocodingResult && geocodedLat != GEOCODE_ZERO && geocodedLon != GEOCODE_ZERO) {
mapController?.setCenter(GeoPoint(geocodedLat, geocodedLon)) mapController?.setCenter(GeoPoint(geocodedLat, geocodedLon))
} }
@ -353,6 +354,7 @@ class LocationPickerController(args: Bundle) :
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Observer<GenericOverall> { .subscribe(object : Observer<GenericOverall> {
override fun onSubscribe(d: Disposable) { override fun onSubscribe(d: Disposable) {
// unused atm
} }
override fun onNext(t: GenericOverall) { override fun onNext(t: GenericOverall) {
@ -366,6 +368,7 @@ class LocationPickerController(args: Bundle) :
} }
override fun onComplete() { override fun onComplete() {
// unused atm
} }
}) })
} }
@ -398,8 +401,15 @@ class LocationPickerController(args: Bundle) :
) )
} }
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) { override fun onRequestPermissionsResult(
if (requestCode == REQUEST_PERMISSIONS_REQUEST_CODE && grantResults.size > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
if (requestCode == REQUEST_PERMISSIONS_REQUEST_CODE &&
grantResults.size > 0 &&
grantResults[0] == PackageManager.PERMISSION_GRANTED
) {
initMap() initMap()
} else { } else {
Toast.makeText(context, context!!.getString(R.string.nc_location_permission_required), Toast.LENGTH_LONG) Toast.makeText(context, context!!.getString(R.string.nc_location_permission_required), Toast.LENGTH_LONG)
@ -416,7 +426,7 @@ class LocationPickerController(args: Bundle) :
private fun initGeocoder() { private fun initGeocoder() {
val registry = SchemeRegistry() val registry = SchemeRegistry()
registry.register(Scheme("https", SSLSocketFactory.getSocketFactory(), 443)) registry.register(Scheme("https", SSLSocketFactory.getSocketFactory(), HTTPS_PORT))
val connexionManager: ClientConnectionManager = SingleClientConnManager(null, registry) val connexionManager: ClientConnectionManager = SingleClientConnManager(null, registry)
val httpClient: HttpClient = DefaultHttpClient(connexionManager, null) val httpClient: HttpClient = DefaultHttpClient(connexionManager, null)
val baseUrl = context!!.getString(R.string.osm_geocoder_url) val baseUrl = context!!.getString(R.string.osm_geocoder_url)
@ -468,5 +478,11 @@ class LocationPickerController(args: Bundle) :
companion object { companion object {
private const val TAG = "LocPicker" private const val TAG = "LocPicker"
private const val REQUEST_PERMISSIONS_REQUEST_CODE = 1 private const val REQUEST_PERMISSIONS_REQUEST_CODE = 1
private const val PERSON_HOT_SPOT_X: Float = 20.0F
private const val PERSON_HOT_SPOT_Y: Float = 20.0F
private const val ZOOM_LEVEL_RECEIVED_RESULT: Double = 14.0
private const val ZOOM_LEVEL_DEFAULT: Double = 14.0
private const val GEOCODE_ZERO : Double = 0.0
private const val HTTPS_PORT: Int = 443
} }
} }