Задать вопрос
@Chesterfield25

Почему постоянно переходит только в первую группу?

Пытаюсь создать постер в фейсбуке, но столкнулся с проблемой что постоянно переходит в первую группу и публикует только в ней
@Override
    public void onAccessibilityEvent(AccessibilityEvent event) {
     @Override
    public void onAccessibilityEvent(AccessibilityEvent event) {
        final AccessibilityNodeInfo root = getRootInActiveWindow();
        if (root == null) return;

        if (!searchIconClicked) {
            if (clickSearchIcon(root)) {
                searchIconClicked = true;
                Log.d(TAG, " Клік по іконці пошуку");
            }
            return;
        }

        if (searchIconClicked && !textInserted) {
            AccessibilityNodeInfo input = findFirstEditable(root);
            if (input != null) {
                pasteTextFromClipboard(input, queryText);
                textInserted = true;
                Log.d(TAG, " Вставлено текст: " + queryText);
            }
            return;
        }

        if (textInserted && !groupsTabClicked) {
            if (clickGroupsTab(root)) {
                groupsTabClicked = true;
                Log.d(TAG, " Клік по вкладці 'Групи'");
            }
            return;
        }

        if (groupsTabClicked && !imageClicked && !isPostingInProgress) {
            // Завжди оновлюємо список груп перед кліком
            List<AccessibilityNodeInfo> updatedGroups = findAllGroupImages(root);
            if (updatedGroups.isEmpty()) {
                showToast("⚠️ Не знайдено жодної групи");
                Log.d(TAG, "⚠️ Не знайдено жодної групи");
                return;
            }

            // Перевірка: чи індекс не вийшов за межі
            if (currentGroupIndex >= updatedGroups.size()) {
                showToast("✅ Усі групи пройдені");
                Log.d(TAG, "✅ Усі групи пройдені");
                return;
            }

            groupImages = updatedGroups;

            Log.d(TAG, "clickNextGroup currentGroupIndex = " + currentGroupIndex + ", total groups = " + groupImages.size());
            clickNextGroup();
            return;
        }


        if (imageClicked && !postFieldClicked && !isPostingInProgress) {
            postFieldClicked = true;
            isPostingInProgress = true;
            checkForPostField();
        }
    }

private List<AccessibilityNodeInfo> findAllGroupImages(AccessibilityNodeInfo root) {
        List<AccessibilityNodeInfo> results = new ArrayList<>();
        findAllImagesRecursive(root, results);
        return results;
    }

    private void findAllImagesRecursive(AccessibilityNodeInfo node, List<AccessibilityNodeInfo> list) {
        if (node == null) return;

        if ("android.widget.ImageView".contentEquals(node.getClassName()) && node.isVisibleToUser()) {
            if (isInsideTargetContainer(node, "android.view.ViewGroup")) {
                list.add(node);
            }
        }

        for (int i = 0; i < node.getChildCount(); i++) {
            findAllImagesRecursive(node.getChild(i), list);
        }
    }

    private boolean clickGroupContainer(AccessibilityNodeInfo node) {
        if (node == null) return false;

        AccessibilityNodeInfo current = node;
        while (current != null) {
            if (current.isClickable()) {
                Log.d(TAG, "Клікаємо по клікабельному вузлу: " + current.getClassName() +
                        ", desc=" + current.getContentDescription());
                boolean clicked = current.performAction(AccessibilityNodeInfo.ACTION_CLICK);
                if (clicked) return true;
                else Log.w(TAG, "Спроба клікнути не вдалася");
            }
            current = current.getParent();
        }

        Log.w(TAG, "Не знайдено клікабельний батьківський вузол для кліку");
        return false;
    }

    private boolean isInsideTargetContainer(AccessibilityNodeInfo node, String containerClassName) {
        AccessibilityNodeInfo parent = node.getParent();
        while (parent != null) {
            if (containerClassName.equals(parent.getClassName())) {
                return true;
            }
            parent = parent.getParent();
        }
        return false;
    }

    private void clickNextGroup() {
        if (currentGroupIndex >= groupImages.size()) {
            showToast("✅ Усі групи пройдено");
            Log.d(TAG, "✅ Усі групи пройдено");
            return;
        }

        AccessibilityNodeInfo groupImage = groupImages.get(currentGroupIndex);
        boolean clicked = clickGroupContainer(groupImage);

        if (clicked) {
            imageClicked = true;
            showToast("✅ Клік по групі #" + (currentGroupIndex + 1));
            Log.d(TAG, "✅ Клік по групі #" + (currentGroupIndex + 1));

            // Збільшуємо індекс після успішного кліку
            currentGroupIndex++;
        } else {
            Log.w(TAG, "Не вдалося клікнути по групі #" + (currentGroupIndex + 1));
            currentGroupIndex++;
            clickNextGroup();
        }
    }
   private void resetStateAndContinue() {
        handler.postDelayed(() -> {
            AccessibilityNodeInfo root = getRootInActiveWindow();
            if (root == null) {
                showToast("⚠️ Не вдалося оновити інтерфейс");
                return;
            }

            imageClicked = false;
            postFieldClicked = false;
            isPostingInProgress = false;
            postTextCheckAttempts = 0;

            // НЕ оновлюємо groupImages тут!
            Log.d(TAG, "Поточний індекс групи: " + currentGroupIndex + " з " + groupImages.size());

            if (currentGroupIndex >= groupImages.size()) {
                showToast("✅ Усі групи пройдено");
                Log.d(TAG, "✅ Усі групи пройдено");
                return;
            }

            clickNextGroup();
        }, 3000);
    }
  • Вопрос задан
  • 42 просмотра
Подписаться 1 Простой Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы