package com.littlesparkle.growler.raptor.driver.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.AppCompatButton;

import com.amap.api.maps2d.model.LatLng;
import com.littlesparkle.growler.library.activity.BaseActivity;
import com.littlesparkle.growler.library.dialog.DialogHelper;
import com.littlesparkle.growler.library.log.Logger;
import com.littlesparkle.growler.raptor.driver.R;
import com.littlesparkle.growler.raptor.driver.activity.event.SignOutEvent;
import com.littlesparkle.growler.raptor.driver.fragment.CurrentFragment;
import com.littlesparkle.growler.raptor.driver.fragment.MeFragment;
import com.ogaclejapan.smarttablayout.SmartTabLayout;
import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItemAdapter;
import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItems;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class MainActivity extends BaseActivity {
    @BindView(R.id.view_pager)
    ViewPager mViewPager;

    @BindView(R.id.tab_host)
    SmartTabLayout mSmartTabLayout;

    @BindView(R.id.map_mode)
    AppCompatButton mMapMode;

    @OnClick(R.id.map_mode)
    public void onMapModeClick(AppCompatButton button) {
        Intent intent = new Intent(this, MapActivity.class);
        intent.putExtra("passenger", new LatLng(39.979004, 116.508715));
        startActivity(intent);
    }

    @BindView(R.id.order_mode)
    AppCompatButton mOrderMode;

    @OnClick(R.id.order_mode)
    public void onOrderModeClick(AppCompatButton button) {
        DialogHelper.showDialogWithMessage(this, getString(R.string.order_mode));
    }

    @BindView(R.id.shutdown_mode)
    AppCompatButton mShutdownMode;

    @OnClick(R.id.shutdown_mode)
    public void onShutDownModeClick(AppCompatButton button) {
        DialogHelper.showDialogWithMessage(this, getString(R.string.shutdown_mode));
    }

    ViewPager.OnPageChangeListener mOnPageChangeListener = new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EventBus.getDefault().register(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Subscribe
    public void onSignOutEvent(SignOutEvent event) {
        Logger.log("received signout event");
        finish();
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView() {
        super.initView();
        ButterKnife.bind(this);

        mIsDoubleClickToQuit = true;

        FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(
                getSupportFragmentManager(), FragmentPagerItems.with(this)
                .add(R.string.tab_item_current, CurrentFragment.class)
                .add(R.string.tab_item_me, MeFragment.class)
                .create());

        mViewPager.setAdapter(adapter);
        mSmartTabLayout.setViewPager(mViewPager);
        mSmartTabLayout.setOnPageChangeListener(mOnPageChangeListener);
    }

    @Override
    protected void initData() {
        super.initData();
    }
}

@@ -352,80 +352,267 @@
 ary.
-dialog.DialogHelper;%0Aimport com.littlesparkle.growler.library.log.Logger
+bean.User;%0Aimport com.littlesparkle.growler.library.http.BaseHttpSubscriber;%0Aimport com.littlesparkle.growler.library.http.DefaultResponse;%0Aimport com.littlesparkle.growler.library.log.Logger;%0Aimport com.littlesparkle.growler.library.user.driver.DriverRequest
 ;%0Aim
@@ -1901,336 +1901,632 @@
     
-DialogHelper.showDialogWithMessage(this, getString(R.string.order_mode));%0A    %7D%0A%0A    @BindView(R.id.shutdown_mode)%0A    AppCompatButton mShutdownMode;%0A%0A    @OnClick(R.id.shutdown_mode)%0A    public void onShutDownModeClick(AppCompatButton button) %7B%0A        DialogHelper.showDialogWithMessage(this, getString(R.string.shutdown_mode)
+new DriverRequest().online(new BaseHttpSubscriber%3CDefaultResponse%3E(this, this) %7B%0A            @Override%0A            public void onNext(DefaultResponse defaultResponse) %7B%0A            %7D%0A        %7D, mUser.user_id, mUser.token);%0A    %7D%0A%0A    @BindView(R.id.shutdown_mode)%0A    AppCompatButton mShutdownMode;%0A%0A    @OnClick(R.id.shutdown_mode)%0A    public void onShutDownModeClick(AppCompatButton button) %7B%0A        new DriverRequest().offline(new BaseHttpSubscriber%3CDefaultResponse%3E(this, this) %7B%0A            @Override%0A            public void onNext(DefaultResponse defaultResponse) %7B%0A            %7D%0A        %7D, mUser.user_id, mUser.token
 );%0A 
@@ -4077,32 +4077,57 @@
 stener);%0A    %7D%0A%0A
+    private User mUser;%0A%0A
     @Override%0A  
@@ -4181,16 +4181,254 @@
 tData();
+%0A%0A        Intent it = getIntent();%0A        if (it != null) %7B%0A            mUser = it.getParcelableExtra(%22user%22);%0A            if (mUser == null) %7B%0A                mUser = new User();%0A                mUser.load(this);%0A            %7D%0A        %7D
 %0A    %7D%0A%7D

add online&offline