diff --git a/app/build.gradle b/app/build.gradle index dbfd17c10..56cc30c85 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -297,7 +297,7 @@ dependencies { implementation 'fr.dudie:nominatim-api:3.4' // 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 // Android comes with its own httpclient diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingLocationMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingLocationMessageViewHolder.kt index c2ce4615f..7d4cd3e07 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingLocationMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingLocationMessageViewHolder.kt @@ -58,9 +58,8 @@ import javax.inject.Inject @AutoInjector(NextcloudTalkApplication::class) class IncomingLocationMessageViewHolder(incomingView: View) : MessageHolders .IncomingTextMessageViewHolder(incomingView) { - private val binding: ItemCustomIncomingLocationMessageBinding = ItemCustomIncomingLocationMessageBinding.bind(itemView) - - private val TAG = "LocMessageView" + private val binding: ItemCustomIncomingLocationMessageBinding = + ItemCustomIncomingLocationMessageBinding.bind(itemView) var locationLon: String? = "" var locationLat: String? = "" @@ -79,6 +78,27 @@ class IncomingLocationMessageViewHolder(incomingView: View) : MessageHolders override fun onBind(message: ChatMessage) { super.onBind(message) 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 if (!TextUtils.isEmpty(author)) { binding.messageAuthor.text = author @@ -116,37 +136,31 @@ class IncomingLocationMessageViewHolder(incomingView: View) : MessageHolders } binding.messageAuthor.visibility = View.GONE } + } + private fun colorizeMessageBubble(message: ChatMessage) { 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 if (message.isGrouped) { 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( bgBubbleColor, resources.getColor(R.color.transparent), bgBubbleColor, bubbleResource ) ViewCompat.setBackground(bubble, bubbleDrawable) + } - 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 + private fun setParentMessageDataOnMessageItem(message: ChatMessage) { if (!message.isDeleted && message.parentMessage != null) { val parentChatMessage = message.parentMessage parentChatMessage.activeUser = message.activeUser @@ -178,9 +192,9 @@ class IncomingLocationMessageViewHolder(incomingView: View) : MessageHolders } else { binding.messageQuote.quotedChatMessageView.visibility = View.GONE } + } - // geo-location - + private fun setLocationDataOnMessageItem(message: ChatMessage) { if (message.messageParameters != null && message.messageParameters.size > 0) { for (key in message.messageParameters.keys) { val individualHashMap: Map = message.messageParameters[key]!! @@ -247,4 +261,8 @@ class IncomingLocationMessageViewHolder(incomingView: View) : MessageHolders private fun addMarkerToGeoLink(locationGeoLink: String): String { return locationGeoLink.replace("geo:", "geo:0,0?q=") } + + companion object { + private const val TAG = "LocInMessageView" + } } diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicOutcomingTextMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicOutcomingTextMessageViewHolder.kt index ca68228b8..520e20294 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicOutcomingTextMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicOutcomingTextMessageViewHolder.kt @@ -146,7 +146,9 @@ class MagicOutcomingTextMessageViewHolder(itemView: View) : OutcomingTextMessage binding.messageQuote.quotedMessageAuthor.text = parentChatMessage.actorDisplayName ?: context!!.getText(R.string.nc_nick_guest) 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.quoteColoredView.setBackgroundResource(R.color.white) diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingLocationMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingLocationMessageViewHolder.kt index 1b89ff88a..74b88a897 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingLocationMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingLocationMessageViewHolder.kt @@ -58,8 +58,6 @@ class OutcomingLocationMessageViewHolder(incomingView: View) : MessageHolders ItemCustomOutcomingLocationMessageBinding.bind(itemView) private val realView: View = itemView - private val TAG = "LocMessageView" - var locationLon: String? = "" var locationLat: String? = "" var locationName: String? = "" @@ -128,7 +126,9 @@ class OutcomingLocationMessageViewHolder(incomingView: View) : MessageHolders binding.messageQuote.quotedMessageAuthor.text = parentChatMessage.actorDisplayName ?: context!!.getText(R.string.nc_nick_guest) 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.quoteColoredView.setBackgroundResource(R.color.white) @@ -188,7 +188,9 @@ class OutcomingLocationMessageViewHolder(incomingView: View) : MessageHolders } 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( "&mapProviderAttribution=" + URLEncoder.encode( context!!.getString( @@ -230,4 +232,8 @@ class OutcomingLocationMessageViewHolder(incomingView: View) : MessageHolders private fun addMarkerToGeoLink(locationGeoLink: String): String { return locationGeoLink.replace("geo:", "geo:0,0?q=") } + + companion object { + private const val TAG = "LocOutMessageView" + } } diff --git a/app/src/main/java/com/nextcloud/talk/controllers/GeocodingController.kt b/app/src/main/java/com/nextcloud/talk/controllers/GeocodingController.kt index 0c7a5f10e..0373c212f 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/GeocodingController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/GeocodingController.kt @@ -179,7 +179,7 @@ class GeocodingController(args: Bundle) : private fun initGeocoder() { 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 httpClient: HttpClient = DefaultHttpClient(connexionManager, null) val baseUrl = context!!.getString(R.string.osm_geocoder_url) @@ -222,6 +222,7 @@ class GeocodingController(args: Bundle) : } companion object { - private val TAG = "GeocodingController" + private const val TAG = "GeocodingController" + private const val HTTPS_PORT: Int = 443 } } diff --git a/app/src/main/java/com/nextcloud/talk/controllers/LocationPickerController.kt b/app/src/main/java/com/nextcloud/talk/controllers/LocationPickerController.kt index b076c0345..b76724fa5 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/LocationPickerController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/LocationPickerController.kt @@ -227,6 +227,7 @@ class LocationPickerController(args: Bundle) : try { locationManager!!.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0L, 0f, this) } catch (ex: SecurityException) { + Log.w(TAG, "Error requesting location updates", ex) } val copyrightOverlay = CopyrightOverlay(context) @@ -237,7 +238,7 @@ class LocationPickerController(args: Bundle) : locationOverlay = MyLocationNewOverlay(GpsMyLocationProvider(context), binding.map) locationOverlay.enableMyLocation() - locationOverlay.setPersonHotspot(20.0F, 20.0F) + locationOverlay.setPersonHotspot(PERSON_HOT_SPOT_X, PERSON_HOT_SPOT_Y) locationOverlay.setPersonIcon( DisplayUtils.getBitmap( ResourcesCompat.getDrawable(resources!!, R.drawable.current_location_circle, null) @@ -248,9 +249,9 @@ class LocationPickerController(args: Bundle) : val mapController = binding.map.controller if (receivedChosenGeocodingResult) { - mapController?.setZoom(14.0) + mapController?.setZoom(ZOOM_LEVEL_RECEIVED_RESULT) } else { - mapController?.setZoom(12.0) + mapController?.setZoom(ZOOM_LEVEL_DEFAULT) } val zoomToCurrentPositionOnFirstFix = !receivedChosenGeocodingResult @@ -258,13 +259,13 @@ class LocationPickerController(args: Bundle) : myLocation = locationOverlay.myLocation if (zoomToCurrentPositionOnFirstFix) { activity!!.runOnUiThread { - mapController?.setZoom(12.0) + mapController?.setZoom(ZOOM_LEVEL_DEFAULT) mapController?.setCenter(myLocation) } } } - if (receivedChosenGeocodingResult && geocodedLat != 0.0 && geocodedLon != 0.0) { + if (receivedChosenGeocodingResult && geocodedLat != GEOCODE_ZERO && geocodedLon != GEOCODE_ZERO) { mapController?.setCenter(GeoPoint(geocodedLat, geocodedLon)) } @@ -353,6 +354,7 @@ class LocationPickerController(args: Bundle) : .observeOn(AndroidSchedulers.mainThread()) .subscribe(object : Observer { override fun onSubscribe(d: Disposable) { + // unused atm } override fun onNext(t: GenericOverall) { @@ -366,6 +368,7 @@ class LocationPickerController(args: Bundle) : } override fun onComplete() { + // unused atm } }) } @@ -398,8 +401,15 @@ class LocationPickerController(args: Bundle) : ) } - override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { - if (requestCode == REQUEST_PERMISSIONS_REQUEST_CODE && grantResults.size > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + override fun onRequestPermissionsResult( + requestCode: Int, + permissions: Array, + grantResults: IntArray + ) { + if (requestCode == REQUEST_PERMISSIONS_REQUEST_CODE && + grantResults.size > 0 && + grantResults[0] == PackageManager.PERMISSION_GRANTED + ) { initMap() } else { 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() { 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 httpClient: HttpClient = DefaultHttpClient(connexionManager, null) val baseUrl = context!!.getString(R.string.osm_geocoder_url) @@ -468,5 +478,11 @@ class LocationPickerController(args: Bundle) : companion object { private const val TAG = "LocPicker" 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 } }