package org.ccci.gto.android.common.support.v4.util;

import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

public final class FragmentUtils {
    private FragmentUtils() {}

    /**
     * @deprecated Since v3.7.0, use `findViewById` directly now that it supports a generic type.
     */
    @Nullable
    @Deprecated
    public static <T> T findView(@NonNull final Fragment fragment, @NonNull final Class<T> clazz, final int id) {
        final View root = fragment.getView();
        if (root != null) {
            final View view = root.findViewById(id);
            if (clazz.isInstance(view)) {
                return clazz.cast(view);
            }
        }
        return null;
    }

    @Nullable
    public static <T> T getAncestorFragment(@NonNull final Fragment fragment, @NonNull final Class<T> clazz) {
        Fragment parent = fragment.getParentFragment();
        while (parent != null) {
            if (clazz.isInstance(parent)) {
                return clazz.cast(parent);
            }
            parent = parent.getParentFragment();
        }
        return null;
    }

    @Nullable
    public static <T> T getListener(@NonNull final Fragment fragment, @NonNull final Class<T> clazz) {
        final Fragment frag = fragment.getParentFragment();
        if (clazz.isInstance(frag)) {
            return clazz.cast(frag);
        }

        final FragmentActivity activity = fragment.getActivity();
        if (clazz.isInstance(activity)) {
            return clazz.cast(activity);
        }

        return null;
    }
}

@@ -51,35 +51,8 @@
 l;%0A%0A
-import android.view.View;%0A%0A
 impo
@@ -278,528 +278,8 @@
 %7B%7D%0A%0A
-    /**%0A     * @deprecated Since v3.7.0, use %60findViewById%60 directly now that it supports a generic type.%0A     */%0A    @Nullable%0A    @Deprecated%0A    public static %3CT%3E T findView(@NonNull final Fragment fragment, @NonNull final Class%3CT%3E clazz, final int id) %7B%0A        final View root = fragment.getView();%0A        if (root != null) %7B%0A            final View view = root.findViewById(id);%0A            if (clazz.isInstance(view)) %7B%0A                return clazz.cast(view);%0A            %7D%0A        %7D%0A        return null;%0A    %7D%0A%0A
     

remove v3.7.0 deprecated findView method