package me.xdj.multistateview;

import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import me.xdj.view.MultiStateView;

/**
 * Created by xdj on 16/2/5.
 */
public class MultiStateFragment extends Fragment {
    private Handler mHandler;
    private MultiStateView mMultiStateView;

    private int other_status = 1111;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_content, container, false);

        mMultiStateView = (MultiStateView) view.findViewById(R.id.multi_state_view);
        mMultiStateView.addViewForStatus(other_status, R.layout.view_other_status);
//        mMultiStateView.addViewForStatus(BaseMultiStateView.STATE_LOADING, R.layout.msv_view_state_loading);
//        mMultiStateView.addViewForStatus(BaseMultiStateView.STATE_FAIL, R.layout.msv_view_state_fail);
//        mMultiStateView.addViewForStatus(BaseMultiStateView.STATE_EMPTY, R.layout.msv_view_state_empty);

        mMultiStateView.getView(MultiStateView.STATE_FAIL).findViewById(R.id.retry)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mMultiStateView.setViewState(MultiStateView.STATE_LOADING);
                        mHandler.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                mMultiStateView.setViewState(MultiStateView.STATE_EMPTY);
                            }
                        }, 2000);
                    }
                });
        mMultiStateView.getView(MultiStateView.STATE_EMPTY).findViewById(R.id.retry)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mMultiStateView.setViewState(MultiStateView.STATE_LOADING);
                        mHandler.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                mMultiStateView.setViewState(MultiStateView.STATE_CONTENT);
                            }
                        }, 2000);
                    }
                });
        mMultiStateView.getView(MultiStateView.STATE_CONTENT)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mMultiStateView.setViewState(MultiStateView.STATE_LOADING);
                        mHandler.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                mMultiStateView.setViewState(other_status);
                            }
                        }, 2000);
                    }
                });

        mHandler = new Handler();
        mMultiStateView.setViewState(MultiStateView.STATE_LOADING);
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                mMultiStateView.setViewState(MultiStateView.STATE_FAIL);
            }
        }, 2000);
        Log.d("xdj", "onCreateView:" + this);
        return view;
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        Log.d("xdj", "setUserVisibleHint:" + isVisibleToUser + this);
        if (isVisibleToUser) {

        }
    }

    public static MultiStateFragment newInstance() {
        return new MultiStateFragment();
    }

    public void refresh() {
        mMultiStateView.setViewState(MultiStateView.STATE_LOADING);
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                mMultiStateView.setViewState(MultiStateView.STATE_FAIL);
            }
        }, 1000);
    }
}

@@ -405,16 +405,148 @@
 gment %7B%0A
+%0A    private static final String TAG = MultiStateFragment.class.getSimpleName();%0A%0A    public static final int OTHER_STATUS = 1111;%0A%0A
     priv
@@ -616,46 +616,8 @@
 w;%0A%0A
-    private int other_status = 1111;%0A%0A
     
@@ -974,28 +974,28 @@
 rStatus(
-other_status
+OTHER_STATUS
 , R.layo
@@ -3158,28 +3158,28 @@
 ewState(
-other_status
+OTHER_STATUS
 );%0A     
@@ -3601,21 +3601,19 @@
   Log.d(
-%22xdj%22
+TAG
 , %22onCre
@@ -3663,254 +3663,8 @@
  %7D%0A%0A
-    @Override%0A    public void setUserVisibleHint(boolean isVisibleToUser) %7B%0A        super.setUserVisibleHint(isVisibleToUser);%0A        Log.d(%22xdj%22, %22setUserVisibleHint:%22 + isVisibleToUser + this);%0A        if (isVisibleToUser) %7B%0A%0A        %7D%0A    %7D%0A%0A
     

Update App