package com.meiji.toutiao.module.base;

import android.os.Bundle;

/**
 * Created by Meiji on 2016/12/27.
 */

public abstract class LazyLoadFragment<T extends IBasePresenter> extends BaseFragment<T> {

    protected boolean isViewInitiated;
    protected boolean isVisibleToUser;
    protected boolean isDataInitiated;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        isViewInitiated = true;
        prepareFetchData();
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        this.isVisibleToUser = isVisibleToUser;
        prepareFetchData();
    }

    public abstract void fetchData();

    public boolean prepareFetchData() {
        return prepareFetchData(false);
    }

    public boolean prepareFetchData(boolean forceUpdate) {
        if (isVisibleToUser && isViewInitiated && (!isDataInitiated || forceUpdate)) {
            fetchData();
            isDataInitiated = true;
            return true;
        }
        return false;
    }

}
@@ -58,16 +58,60 @@
 .Bundle;
+%0Aimport android.support.annotation.Nullable;
 %0A%0A/**%0A *
@@ -240,16 +240,48 @@
 t%3CT%3E %7B%0A%0A
+    /**%0A     * %E6%98%AF%E5%90%A6%E5%88%9D%E5%A7%8B%E5%8C%96%E8%BF%87%E5%B8%83%E5%B1%80%0A     */%0A
     prot
@@ -311,16 +311,48 @@
 tiated;%0A
+    /**%0A     * %E5%BD%93%E5%89%8D%E7%95%8C%E9%9D%A2%E6%98%AF%E5%90%A6%E5%8F%AF%E8%A7%81%0A     */%0A
     prot
@@ -378,24 +378,55 @@
 ibleToUser;%0A
+    /**%0A     * %E6%98%AF%E5%90%A6%E5%8A%A0%E8%BD%BD%E8%BF%87%E6%95%B0%E6%8D%AE%0A     */%0A
     protecte
@@ -457,127 +457,8 @@
 d;%0A%0A
-    @Override%0A    public void onCreate(Bundle savedInstanceState) %7B%0A        super.onCreate(savedInstanceState);%0A    %7D%0A%0A
     
@@ -501,16 +501,26 @@
 Created(
+@Nullable 
 Bundle s
@@ -847,34 +847,106 @@
     
-prepareFetchData();%0A    %7D%0A
+if (isVisibleToUser) %7B%0A            prepareFetchData();%0A        %7D%0A    %7D%0A%0A    /**%0A     * %E6%87%92%E5%8A%A0%E8%BD%BD%0A     */
 %0A   
@@ -984,39 +984,36 @@
 ();%0A%0A    public 
-boolean
+void
  prepareFetchDat
@@ -1026,23 +1026,16 @@
         
-return 
 prepareF
@@ -1066,22 +1066,96 @@
     
-public boolean
+/**%0A     * %E5%88%A4%E6%96%AD%E6%87%92%E5%8A%A0%E8%BD%BD%E6%9D%A1%E4%BB%B6%0A     *%0A     * @param forceUpdate %E5%BC%BA%E5%88%B6%E6%9B%B4%E6%96%B0%EF%BC%8C%E5%A5%BD%E5%83%8F%E6%B2%A1%E4%BB%80%E4%B9%88%E7%94%A8%EF%BC%9F%0A     */%0A    public void
  pre
@@ -1351,61 +1351,13 @@
     
-    return true;%0A        %7D%0A        return false;%0A    %7D%0A
+%7D%0A    %7D
 %0A%7D

Update LazyLoadFragment