From 935570ba63d4702a1d5bc060f4b76e2948a6ff95 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Thu, 23 Mar 2023 19:59:02 -0500 Subject: [PATCH] Delay showing command bar on refreshes To prevent flickering when the other side says it has commands but doesn't. --- .../conversations/ui/ConversationFragment.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 2585957e85ba73f7f9e0c5b4c68901fe8a3e42d7..762d8cdf5b384d12c7e829d02a7fc241f1411c31 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -1809,7 +1809,7 @@ public class ConversationFragment extends XmppFragment if (activity == null) return; activity.runOnUiThread(() -> { refresh(); - refreshCommands(); + refreshCommands(true); }); }); } @@ -2836,7 +2836,7 @@ public class ConversationFragment extends XmppFragment if (commandAdapter != null && conversation != originalConversation) { originalConversation.setupViewPager(null, null); conversation.setupViewPager(binding.conversationViewPager, binding.tabLayout); - refreshCommands(); + refreshCommands(false); } if (commandAdapter == null && conversation != null) { conversation.setupViewPager(binding.conversationViewPager, binding.tabLayout); @@ -2846,24 +2846,24 @@ public class ConversationFragment extends XmppFragment final Element command = commandAdapter.getItem(position); activity.startCommand(conversation.getAccount(), command.getAttributeAsJid("jid"), command.getAttribute("node")); }); - refreshCommands(); + refreshCommands(false); } return true; } public void refreshForNewCaps() { - refreshCommands(); + refreshCommands(true); } - protected void refreshCommands() { + protected void refreshCommands(boolean delayShow) { if (commandAdapter == null) return; Jid commandJid = conversation.getContact().resourceWhichSupport(Namespace.COMMANDS); if (commandJid == null) { conversation.hideViewPager(); } else { - conversation.showViewPager(); + if (!delayShow) conversation.showViewPager(); activity.xmppConnectionService.fetchCommands(conversation.getAccount(), commandJid, (a, iq) -> { if (activity == null) return; @@ -2877,7 +2877,11 @@ public class ConversationFragment extends XmppFragment } } - if (commandAdapter.getCount() < 1) conversation.hideViewPager(); + if (commandAdapter.getCount() < 1) { + conversation.hideViewPager(); + } else if (delayShow) { + conversation.showViewPager(); + } }); }); }