save cursor position

Signed-off-by: Julius Linus <julius.linus@nextcloud.com>
This commit is contained in:
Julius Linus 2024-01-04 11:14:14 -06:00 committed by Marcel Hibbe
parent e559d159e3
commit 30c6ad5ab6
No known key found for this signature in database
GPG key ID: C793F8B59F43CE7B

View file

@ -525,7 +525,9 @@ class ChatActivity :
active = true
context.getSharedPreferences(localClassName, MODE_PRIVATE).apply {
val text = getString(roomToken, "")
val cursor = getInt(roomToken + CURSOR_KEY, 0)
binding.messageInputView.messageInput.setText(text)
binding.messageInputView.messageInput.setSelection(cursor)
}
this.lifecycle.addObserver(AudioUtils)
}
@ -544,10 +546,12 @@ class ChatActivity :
stopMediaPlayer(currentlyPlayedVoiceMessage!!)
}
val text = binding.messageInputView.messageInput.text.toString()
val cursor = binding.messageInputView.messageInput.selectionStart
val previous = context.getSharedPreferences(localClassName, MODE_PRIVATE).getString(roomToken, "null")
if (text != previous) {
context.getSharedPreferences(localClassName, MODE_PRIVATE).edit().apply {
putString(roomToken, text)
putInt(roomToken + CURSOR_KEY, cursor)
apply()
}
}
@ -4603,5 +4607,6 @@ class ChatActivity :
private const val CALL_STARTED_ID = -2
private const val MILISEC_15: Long = 15
private const val LINEBREAK = "\n"
private const val CURSOR_KEY = "_cursor"
}
}