~singpolyma/cheogram-android

a4fac750ee4b4c42d57286f7504a1c6cf73d81f6 — Stephen Paul Weber a month ago b2e4a00
Only setup the command pager when not already set up

Otherwise it gets confused and blanks itself out.
1 files changed, 23 insertions(+), 21 deletions(-)

M src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
M src/main/java/eu/siacs/conversations/ui/ConversationFragment.java => src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +23 -21
@@ 2166,28 2166,30 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
        //TODO if we only do this when this fragment is running on main it won't *bing* in tablet layout which might be unnecessary since we can *see* it
        activity.xmppConnectionService.getNotificationService().setOpenConversation(this.conversation);

        conversation.setupViewPager(binding.conversationViewPager, binding.tabLayout);
        commandAdapter = new CommandAdapter((XmppActivity) getActivity());
        binding.commandsView.setAdapter(commandAdapter);
        binding.commandsView.setOnItemClickListener((parent, view, position, id) -> {
            conversation.startCommand(commandAdapter.getItem(position), activity.xmppConnectionService);
        });
        Jid commandJid = conversation.getContact().resourceWhichSupport(Namespace.COMMANDS);
        if (commandJid != null) {
            binding.tabLayout.setVisibility(View.VISIBLE);
            activity.xmppConnectionService.fetchCommands(conversation.getAccount(), commandJid, (a, iq) -> {
                if (iq.getType() == IqPacket.TYPE.RESULT) {
                    activity.runOnUiThread(() -> {
                        for (Element child : iq.query().getChildren()) {
                            if (!"item".equals(child.getName()) || !Namespace.DISCO_ITEMS.equals(child.getNamespace())) continue;
                            commandAdapter.add(child);
                        }
                    });
                } else {
                    binding.tabLayout.setVisibility(View.GONE);
                    binding.conversationViewPager.setCurrentItem(0);
                }
        if (commandAdapter == null) {
            conversation.setupViewPager(binding.conversationViewPager, binding.tabLayout);
            commandAdapter = new CommandAdapter((XmppActivity) getActivity());
            binding.commandsView.setAdapter(commandAdapter);
            binding.commandsView.setOnItemClickListener((parent, view, position, id) -> {
                conversation.startCommand(commandAdapter.getItem(position), activity.xmppConnectionService);
            });
            Jid commandJid = conversation.getContact().resourceWhichSupport(Namespace.COMMANDS);
            if (commandJid != null) {
                binding.tabLayout.setVisibility(View.VISIBLE);
                activity.xmppConnectionService.fetchCommands(conversation.getAccount(), commandJid, (a, iq) -> {
                    if (iq.getType() == IqPacket.TYPE.RESULT) {
                        activity.runOnUiThread(() -> {
                            for (Element child : iq.query().getChildren()) {
                                if (!"item".equals(child.getName()) || !Namespace.DISCO_ITEMS.equals(child.getNamespace())) continue;
                                commandAdapter.add(child);
                            }
                        });
                    } else {
                        binding.tabLayout.setVisibility(View.GONE);
                        binding.conversationViewPager.setCurrentItem(0);
                    }
                });
            }
        }

        return true;