/*
 * Copyright (C) 2016-2018 Samuel Wall
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package uk.co.samuelwall.materialtaptargetprompt;

import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.View;
import android.view.ViewGroup;

/**
 * {@link ResourceFinder} implementation for {@link Fragment}.
 */
public class SupportFragmentResourceFinder implements ResourceFinder
{
    /**
     * The fragment to get the resources from.
     */
    @NonNull
    private final Fragment fragment;

    /**
     * Constructor.
     *
     * @param fragment Fragment to get the resources from.
     */
    public SupportFragmentResourceFinder(@NonNull final Fragment fragment)
    {
        this.fragment = fragment;
    }

    @Nullable
    @Override
    public View findViewById(int resId)
    {
        return this.fragment.getView().findViewById(resId);
    }

    @NonNull
    @Override
    public ViewGroup getPromptParentView()
    {
        //noinspection ConstantConditions
        return (ViewGroup) this.fragment.getView().getParent();
    }

    @NonNull
    @Override
    public Context getContext()
    {
        return this.fragment.requireContext();
    }

    @NonNull
    @Override
    public Resources getResources()
    {
        return this.fragment.getResources();
    }

    @NonNull
    @Override
    public Resources.Theme getTheme()
    {
        return this.fragment.requireActivity().getTheme();
    }

    @NonNull
    @Override
    public String getString(int resId)
    {
        return this.fragment.getString(resId);
    }

    @NonNull
    @Override
    public TypedArray obtainStyledAttributes(int resId, int[] attrs)
    {
        return this.fragment.requireActivity().obtainStyledAttributes(resId, attrs);
    }

    @Nullable
    @Override
    public Drawable getDrawable(int resId)
    {
        return this.fragment.getResources().getDrawable(resId);
    }
}

@@ -1238,16 +1238,96 @@
 gment;%0A%0A
+    /**%0A     * The fragment view parent.%0A     */%0A    private ViewGroup parent;%0A%0A
     /**%0A
@@ -1751,32 +1751,79 @@
 entView()%0A    %7B%0A
+        if (this.parent == null)%0A        %7B%0A    
         //noinsp
@@ -1856,22 +1856,33 @@
         
-return
+    this.parent =
  (ViewGr
@@ -1919,24 +1919,62 @@
 etParent();%0A
+        %7D%0A        return this.parent;%0A
     %7D%0A%0A    @

fix fragment view npe #137