From 9e7ae94979cb54f7809b9d6deea349f15b4a4e81 Mon Sep 17 00:00:00 2001 From: Phillip Thelen Date: Tue, 10 Jul 2018 17:01:30 +0200 Subject: [PATCH] Implement chat message limit. Fixes #993 --- .../res/layout/tavern_chat_new_entry_item.xml | 45 ++++++++++++++----- .../habitica/ui/activities/MainActivity.java | 2 +- .../habitica/ui/views/social/ChatBarView.kt | 27 +++++++++-- 3 files changed, 59 insertions(+), 15 deletions(-) diff --git a/Habitica/res/layout/tavern_chat_new_entry_item.xml b/Habitica/res/layout/tavern_chat_new_entry_item.xml index b585466fc..2192a483d 100644 --- a/Habitica/res/layout/tavern_chat_new_entry_item.xml +++ b/Habitica/res/layout/tavern_chat_new_entry_item.xml @@ -1,6 +1,7 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools"> + android:paddingBottom="4dp" + tools:height="200dp"/> - + + + + + Unit)? = null constructor(context: Context) : super(context) { @@ -47,7 +50,8 @@ class ChatBarView : FrameLayout { override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { - setSendButtonEnabled(chatEditText.text.isNotEmpty()) + setSendButtonEnabled(chatEditText.text.isNotEmpty() && chatEditText.text.length <= maxChatLength) + updateTextIndicator(chatEditText.text.toString()) } }) @@ -56,6 +60,23 @@ class ChatBarView : FrameLayout { resizeForDrawingUnderNavbar() } + private fun updateTextIndicator(text: String) { + if (chatEditText.lineCount >= 3) { + textIndicator.visibility = View.VISIBLE + indicatorSpacing.visibility = View.VISIBLE + textIndicator.text = "${text.length}/${maxChatLength}" + val color = when { + text.length > maxChatLength -> R.color.red_50 + text.length > (maxChatLength * 0.95) -> R.color.yellow_5 + else -> R.color.gray_400 + } + textIndicator.setTextColor(ContextCompat.getColor(context, color)) + } else { + textIndicator.visibility = View.GONE + indicatorSpacing.visibility = View.GONE + } + } + override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) { super.onLayout(changed, left, top, right, bottom) if (changed) {