package com.joeracosta.library.activity;

import android.arch.lifecycle.LifecycleFragment;

/**
 * Created by Joe on 8/14/2017.
 * Simple Fragment. Must be used in a FragmentStackFragment/Activity or FragmentMapFragment/Activity
 */

public abstract class SimpleFragment extends LifecycleFragment {

    private boolean atForefront;

    public void setAtForefront(boolean atForefront){
        this.atForefront = atForefront;
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);

        if (hidden){
            atForefront = false;
            onHidden();
        } else {
            atForefront = true;
            onShown();
        }
    }

    @Override
    public void onStart() {
        super.onStart();

        if (atForefront) { //only use onStart for when app is coming back from background
            onShown();
        }
    }

    @Override
    public void onStop() {
        super.onStop();

        if (atForefront) { //only use onStop for when app is backgrounding
            onHidden();
        }
    }

    /**
     * Called when the fragment is shown on the screen
     */
    public void onShown(){
        System.out.print("");
    }

    /**
     * Called when the fragment is hidden on the screen
     */
    public void onHidden(){
        System.out.print("");
    }

    /**
     * Called when back is pressed when using this Fragment in a FragmentMapActivity or FragmentStackActivity
     * @return whether or not the backpress was handled
     */
    public boolean onSimpleBackPressed(){
        return false;
    }
}

@@ -83,16 +83,86 @@
 ragment;
+%0Aimport android.os.Bundle;%0Aimport android.support.annotation.Nullable;
 %0A%0A/**%0A *
@@ -363,16 +363,100 @@
 ment %7B%0A%0A
+    private static final String FOREFRONT_TAG = %22com.joeracosta.at_forefront_tag%22;%0A%0A
     priv
@@ -534,16 +534,16 @@
 front)%7B%0A
-
         
@@ -573,32 +573,1162 @@
 refront;%0A    %7D%0A%0A
+    @Override%0A    public void onCreate(@Nullable Bundle savedInstanceState) %7B%0A        super.onCreate(savedInstanceState);%0A%0A        if (savedInstanceState != null)%7B%0A            atForefront = savedInstanceState.getBoolean(FOREFRONT_TAG, false);%0A        %7D%0A%0A        if (getParentFragment() != null)%7B%0A            if (!(getParentFragment() instanceof FragmentStackFragment) &&%0A                    !(getParentFragment() instanceof FragmentMapFragment))%7B%0A                throw new RuntimeException(%22A SimpleFragment must have a FragmentStackFragment/Activity or FragmentMapFragment/Activity as a parent!%22);%0A            %7D%0A        %7D else %7B%0A            if (!(getActivity() instanceof FragmentMapActivity) &&%0A                    !(getActivity() instanceof FragmentStackActivity))%7B%0A                throw new RuntimeException(%22A SimpleFragment must have a FragmentStackFragment/Activity or FragmentMapFragment/Activity as a parent!%22);%0A            %7D%0A        %7D%0A    %7D%0A%0A    @Override%0A    public void onSaveInstanceState(Bundle outState) %7B%0A        outState.putBoolean(FOREFRONT_TAG, atForefront);%0A        super.onSaveInstanceState(outState);%0A    %7D%0A%0A
     @Override%0A  

fix bug