~singpolyma/cheogram-android

8a2f18574b7d9d86ac594116b3f6c8e106a70e80 — Stephen Paul Weber a month ago a4fac75
Hide pager when there are no commands

And really hide it, even swipe should not work to get to the blank page
M src/main/java/eu/siacs/conversations/entities/Conversation.java => src/main/java/eu/siacs/conversations/entities/Conversation.java +17 -0
@@ 1174,6 1174,10 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
        pagerAdapter.setupViewPager(pager, tabs);
    }

    public void hideViewPager() {
        pagerAdapter.hide();
    }

    public interface OnMessageFound {
        void onMessageFound(final Message message);
    }


@@ 1204,6 1208,10 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
        public void setupViewPager(ViewPager pager, TabLayout tabs) {
            mPager = pager;
            mTabs = tabs;
            if (sessions == null) {
                sessions = new ArrayList<>();
                notifyDataSetChanged();
            }
            pager.setAdapter(this);
            tabs.setupWithViewPager(mPager);
            pager.setCurrentItem(getCurrentTab());


@@ 1218,6 1226,13 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
            });
        }

        public void hide() {
            mPager.setCurrentItem(0);
            mTabs.setVisibility(View.GONE);
            sessions = null;
            notifyDataSetChanged();
        }

        public void startCommand(Element command, XmppConnectionService xmppConnectionService) {
            CommandSession session = new CommandSession(command.getAttribute("name"), xmppConnectionService);



@@ 1275,6 1290,8 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl

        @Override
        public int getCount() {
            if (sessions == null) return 1;

            int count = 2 + sessions.size();
            if (count > 2) {
                mTabs.setTabMode(TabLayout.MODE_SCROLLABLE);

M src/main/java/eu/siacs/conversations/ui/ConversationFragment.java => src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +11 -8
@@ 2174,20 2174,23 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
                conversation.startCommand(commandAdapter.getItem(position), activity.xmppConnectionService);
            });
            Jid commandJid = conversation.getContact().resourceWhichSupport(Namespace.COMMANDS);
            if (commandJid != null) {
            if (commandJid == null) {
                conversation.hideViewPager();
            } else {
                binding.tabLayout.setVisibility(View.VISIBLE);
                activity.xmppConnectionService.fetchCommands(conversation.getAccount(), commandJid, (a, iq) -> {
                    if (iq.getType() == IqPacket.TYPE.RESULT) {
                        activity.runOnUiThread(() -> {
                    if (activity == null) return;

                    activity.runOnUiThread(() -> {
                        if (iq.getType() == IqPacket.TYPE.RESULT) {
                            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.getCount() < 1) conversation.hideViewPager();
                    });
                });
            }
        }