diff --git a/app/src/main/java/com/futo/platformplayer/dialogs/CommentDialog.kt b/app/src/main/java/com/futo/platformplayer/dialogs/CommentDialog.kt index f3a981be..cce0a9f3 100644 --- a/app/src/main/java/com/futo/platformplayer/dialogs/CommentDialog.kt +++ b/app/src/main/java/com/futo/platformplayer/dialogs/CommentDialog.kt @@ -2,12 +2,16 @@ package com.futo.platformplayer.dialogs import android.app.AlertDialog import android.content.Context +import android.graphics.Color import android.os.Bundle +import android.text.Editable +import android.text.TextWatcher import android.view.LayoutInflater import android.view.WindowManager import android.view.inputmethod.InputMethodManager import android.widget.* import com.futo.platformplayer.R +import com.futo.platformplayer.UIDialogs import com.futo.platformplayer.api.media.PlatformID import com.futo.platformplayer.api.media.models.PlatformAuthorLink import com.futo.platformplayer.api.media.models.comments.IPlatformComment @@ -32,6 +36,8 @@ class CommentDialog(context: Context?, val contextUrl: String, val ref: Protocol private lateinit var _buttonCancel: MaterialButton; private lateinit var _editComment: EditText; private lateinit var _inputMethodManager: InputMethodManager; + private lateinit var _textCharacterCount: TextView; + private lateinit var _textCharacterCountMax: TextView; val onCommentAdded = Event1(); @@ -42,6 +48,26 @@ class CommentDialog(context: Context?, val contextUrl: String, val ref: Protocol _buttonCancel = findViewById(R.id.button_cancel); _buttonCreate = findViewById(R.id.button_create); _editComment = findViewById(R.id.edit_comment); + _textCharacterCount = findViewById(R.id.character_count); + _textCharacterCountMax = findViewById(R.id.character_count_max); + + _editComment.addTextChangedListener(object : TextWatcher { + override fun afterTextChanged(s: Editable?) = Unit + override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) = Unit + override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { + _textCharacterCount.text = count.toString(); + + if (count > MAX_COMMENT_SIZE) { + _textCharacterCount.setTextColor(Color.RED); + _textCharacterCountMax.setTextColor(Color.RED); + _buttonCreate.alpha = 0.4f; + } else { + _textCharacterCount.setTextColor(Color.WHITE); + _textCharacterCountMax.setTextColor(Color.WHITE); + _buttonCreate.alpha = 1.0f; + } + } + }); _inputMethodManager = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager; @@ -53,6 +79,11 @@ class CommentDialog(context: Context?, val contextUrl: String, val ref: Protocol _buttonCreate.setOnClickListener { clearFocus(); + if (_editComment.text.count() > MAX_COMMENT_SIZE) { + UIDialogs.toast(context, "Comment should be less than 5000 characters"); + return@setOnClickListener; + } + val comment = _editComment.text.toString(); val processHandle = StatePolycentric.instance.processHandle!! val eventPointer = processHandle.post(comment, null, ref) @@ -100,5 +131,6 @@ class CommentDialog(context: Context?, val contextUrl: String, val ref: Protocol companion object { private val TAG = "CommentDialog"; + private val MAX_COMMENT_SIZE = 5000; } } \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_comment.xml b/app/src/main/res/layout/dialog_comment.xml index 1c84ce23..e454379a 100644 --- a/app/src/main/res/layout/dialog_comment.xml +++ b/app/src/main/res/layout/dialog_comment.xml @@ -35,6 +35,25 @@ android:gravity="center" android:layout_marginTop="12dp"> + + + +