package ai.pai.lensman.base;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

import com.android.common.utils.NetworkUtil;
import com.android.views.swipebacklayout.SwipeBackActivityBase;
import com.android.views.swipebacklayout.SwipeBackActivityHelper;
import com.android.views.swipebacklayout.SwipeBackLayout;
import com.android.views.swipebacklayout.Utils;

import ai.pai.lensman.R;
import butterknife.Unbinder;

/**
 * Created by chengzhenyu on 2015/12/2.
 */
public class BaseActivity extends AppCompatActivity implements SwipeBackActivityBase {

    protected  String TAG ;

    private SwipeBackActivityHelper mHelper;

    protected Unbinder unbinder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TAG = getClass().getSimpleName();
        mHelper = new SwipeBackActivityHelper(this);
        mHelper.onActivityCreate();
        if(!NetworkUtil.isNetworkConnected(this)){
            Toast.makeText(this, R.string.network_disconnect,Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        mHelper.onPostCreate();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(unbinder!=null){
            unbinder.unbind();
        }
    }

    @Override
    public View findViewById(int id) {
        View v = super.findViewById(id);
        if (v == null && mHelper != null)
            return mHelper.findViewById(id);
        return v;
    }

    @Override
    public SwipeBackLayout getSwipeBackLayout() {
        return mHelper.getSwipeBackLayout();
    }

    @Override
    public void setSwipeBackEnable(boolean enable) {
        getSwipeBackLayout().setEnableGesture(enable);
    }

    @Override
    public void scrollToFinishActivity() {
        Utils.convertActivityToTranslucent(this);
        getSwipeBackLayout().scrollToFinishActivity();
    }


}
