From 44acdbd2cbde3768c87ad120eed85dcba1582199 Mon Sep 17 00:00:00 2001 From: kosyak Date: Tue, 10 Dec 2024 23:40:54 +0100 Subject: [PATCH] fix message input initial focus loss --- .../conversations/ui/ConversationFragment.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 75628727a..84906ce04 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -3233,10 +3233,19 @@ public class ConversationFragment extends XmppFragment .setOpenConversation(this.conversation); if (commandAdapter != null && conversation != originalConversation) { + View currentFocus = null; + if (activity != null) { + currentFocus = activity.getCurrentFocus(); + } conversation.setupViewPager(binding.conversationViewPager, binding.tabLayout, originalConversation); refreshCommands(); + maybeRestoreMessageInputFocus(currentFocus); } if (commandAdapter == null && conversation != null) { + View currentFocus = null; + if (activity != null) { + currentFocus = activity.getCurrentFocus(); + } conversation.setupViewPager(binding.conversationViewPager, binding.tabLayout, null); commandAdapter = new CommandAdapter((XmppActivity) getActivity()); binding.commandsView.setAdapter(commandAdapter); @@ -3247,6 +3256,7 @@ public class ConversationFragment extends XmppFragment activity.startCommand(conversation.getAccount(), command.getAttributeAsJid("jid"), command.getAttribute("node")); }); refreshCommands(); + maybeRestoreMessageInputFocus(currentFocus); } previousClickedReply = null; @@ -3291,6 +3301,12 @@ public class ConversationFragment extends XmppFragment } } + private void maybeRestoreMessageInputFocus(View currentFocus) { + if (currentFocus == this.binding.textinput) { + this.binding.textinput.requestFocus(); + } + } + private void resetUnreadMessagesCount() { lastMessageUuid = null; hideUnreadMessagesCount();