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 580bd508..d142fb9c 100644
--- a/app/src/main/java/com/futo/platformplayer/dialogs/CommentDialog.kt
+++ b/app/src/main/java/com/futo/platformplayer/dialogs/CommentDialog.kt
@@ -6,6 +6,7 @@ import android.graphics.Color
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
+import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.WindowManager
import android.view.inputmethod.InputMethodManager
@@ -57,12 +58,21 @@ class CommentDialog(context: Context?, val contextUrl: String, val ref: Protocol
_editComment = findViewById(R.id.edit_comment);
_textCharacterCount = findViewById(R.id.character_count);
_textCharacterCountMax = findViewById(R.id.character_count_max);
+ setCanceledOnTouchOutside(false)
+ setOnKeyListener { _, keyCode, event ->
+ if (keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_UP) {
+ handleCloseAttempt()
+ true
+ } else {
+ false
+ }
+ }
_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();
+ _textCharacterCount.text = (s?.length ?: 0).toString();
if (count > PolycentricPlatformComment.MAX_COMMENT_SIZE) {
_textCharacterCount.setTextColor(Color.RED);
@@ -79,10 +89,13 @@ class CommentDialog(context: Context?, val contextUrl: String, val ref: Protocol
_inputMethodManager = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager;
_buttonCancel.setOnClickListener {
- clearFocus();
- dismiss();
+ handleCloseAttempt()
};
+ setOnCancelListener {
+ handleCloseAttempt()
+ }
+
_buttonCreate.setOnClickListener {
clearFocus();
@@ -134,6 +147,22 @@ class CommentDialog(context: Context?, val contextUrl: String, val ref: Protocol
focus();
}
+ private fun handleCloseAttempt() {
+ if (_editComment.text.isEmpty()) {
+ clearFocus()
+ dismiss()
+ } else {
+ UIDialogs.showConfirmationDialog(
+ context,
+ context.resources.getString(R.string.not_empty_close),
+ action = {
+ clearFocus()
+ dismiss()
+ }
+ )
+ }
+ }
+
private fun focus() {
_editComment.requestFocus();
window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index ddf228b7..33ca1593 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -199,6 +199,7 @@
Previous
Next
Comment
+ Comment is not empty, close anyway?
Import
My Playlist Name
Do you want to import this store?