From 26c2c0065bec46104e8b671ef6fd0740807f367f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Kr=C3=BCger?= Date: Wed, 1 Jun 2022 12:12:38 +0200 Subject: [PATCH] Migrate Java parts to Kotlin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also fixing some detekt issues. Signed-off-by: Tim Krüger --- .../OutcomingTextMessageViewHolder.kt | 38 ++++++++++--------- .../talk/controllers/ChatController.kt | 28 +++++++------- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingTextMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingTextMessageViewHolder.kt index 754dec287..2cf4e0f86 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingTextMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingTextMessageViewHolder.kt @@ -102,23 +102,7 @@ class OutcomingTextMessageViewHolder(itemView: View) : OutcomingTextMessageViewH binding.messageQuote.quotedChatMessageView.visibility = View.GONE } - val readStatusDrawableInt = when (message.readStatus) { - ReadStatus.READ -> R.drawable.ic_check_all - ReadStatus.SENT -> R.drawable.ic_check - ReadStatus.SENDING -> R.drawable.ic_sending - ReadStatus.FAILED -> R.drawable.ic_warning_white - else -> null - } - - val readStatusContentDescriptionString = when (message.readStatus) { - ReadStatus.READ -> context?.resources?.getString(R.string.nc_message_read) - ReadStatus.SENT -> context?.resources?.getString(R.string.nc_message_sent) - ReadStatus.SENDING -> context?.resources?.getString(R.string.nc_message_sending) - ReadStatus.FAILED -> context?.resources?.getString(R.string.nc_message_send_error) - else -> null - } - - readStatusDrawableInt?.let { drawableInt -> + readStatusDrawableInt(message)?.let { drawableInt -> ResourcesCompat.getDrawable(context!!.resources, drawableInt, null)?.let { binding.checkMark.setImageDrawable(it) binding.checkMark.setColorFilter( @@ -127,7 +111,7 @@ class OutcomingTextMessageViewHolder(itemView: View) : OutcomingTextMessageViewH } } - binding.checkMark.setContentDescription(readStatusContentDescriptionString) + binding.checkMark.setContentDescription(readStatusContentDescriptionString(message)) itemView.setTag(MessageSwipeCallback.REPLYABLE_VIEW_TAG, message.replyable) @@ -150,6 +134,24 @@ class OutcomingTextMessageViewHolder(itemView: View) : OutcomingTextMessageViewH commonMessageInterface.onClickReaction(chatMessage, emoji) } + private fun readStatusContentDescriptionString(message: ChatMessage) = + when (message.readStatus) { + ReadStatus.READ -> context?.resources?.getString(R.string.nc_message_read) + ReadStatus.SENT -> context?.resources?.getString(R.string.nc_message_sent) + ReadStatus.SENDING -> context?.resources?.getString(R.string.nc_message_sending) + ReadStatus.FAILED -> context?.resources?.getString(R.string.nc_message_send_error) + else -> null + } + + private fun readStatusDrawableInt(message: ChatMessage) = + when (message.readStatus) { + ReadStatus.READ -> R.drawable.ic_check_all + ReadStatus.SENT -> R.drawable.ic_check + ReadStatus.SENDING -> R.drawable.ic_sending + ReadStatus.FAILED -> R.drawable.ic_warning_white + else -> null + } + private fun processParentMessage(message: ChatMessage) { val parentChatMessage = message.parentMessage val textColor = viewThemeUtils.getScheme(binding.messageQuote.quotedMessage.context).onSurfaceVariant diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index f0881a40f..1ff8219a8 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -2128,7 +2128,6 @@ class ChatController(args: Bundle) : messObj.timestamp = tsLong messObj.jsonMessageId = 0 - tsLong.toInt() - messObj.readStatus = ReadStatus.SENDING if (conversationUser!!.userId != "?") { @@ -3046,11 +3045,12 @@ class ChatController(args: Bundle) : fun replyPrivately(message: IMessage?) { val apiVersion = ApiUtils.getConversationApiVersion( - conversationUser, intArrayOf( - ApiUtils.APIv4, - 1 - ) - ) + conversationUser, + intArrayOf( + ApiUtils.APIv4, + 1 + ) + ) val retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom( apiVersion, conversationUser?.baseUrl, @@ -3108,20 +3108,20 @@ class ChatController(args: Bundle) : ) } - override fun onError(e: Throwable) { - Log.e(TAG, e.message, e) - } + override fun onError(e: Throwable) { + Log.e(TAG, e.message, e) + } - override fun onComplete() {// unused atm + override fun onComplete() { // unused atm } }) } - override fun onError(e: Throwable) { - Log.e(TAG, e.message, e) - } + override fun onError(e: Throwable) { + Log.e(TAG, e.message, e) + } - override fun onComplete() { + override fun onComplete() { // unused atm } })