package ai.pai.client.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

import com.android.common.utils.NetworkUtil;
import com.umeng.analytics.MobclickAgent;

import ai.pai.client.R;
import ai.pai.client.services.MyLocationService;
import ai.pai.client.swipelayout.SwipeBackActivityBase;
import ai.pai.client.swipelayout.SwipeBackActivityHelper;
import ai.pai.client.swipelayout.SwipeBackLayout;
import ai.pai.client.swipelayout.Utils;

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

    protected  String TAG ;

    private SwipeBackActivityHelper mHelper;

    @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 onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
        Intent intent = new Intent(this, MyLocationService.class);
        intent.putExtra("command",MyLocationService.COMMAND_START_LOCATION);
        startService(intent);
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }

    @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();
    }


}
