package ai.pai.lensman.briefs;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher;

import com.android.common.utils.DeviceUtils;

import ai.pai.lensman.R;
import ai.pai.lensman.base.BaseActivity;
import ai.pai.lensman.bean.BriefsBean;
import ai.pai.lensman.settings.SettingsActivity;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class BriefsActivity extends BaseActivity implements BriefsContract.View{

    @BindView(R.id.tv_upload_photo_num)        TextView uploadPhotoNumText;
    @BindView(R.id.tv_today_capture_num)       TextView captureNumText;
    @BindView(R.id.tv_average_money_amount)    TextView averageMoneyText;
    @BindView(R.id.tv_today_incoming_account)  TextView todayIncomingText;
    @BindView(R.id.tv_total_incoming_account)  TextView totalIncomingText;
    @BindView(R.id.tv_today_capture_hours_account) TextView todayCaptureHoursText;
    @BindView(R.id.switcher_order_msg)         TextSwitcher orderMsgSwitch;
    @BindView(R.id.switcher_system_msg)         TextSwitcher systemMsgSwitch;

    private BriefsPresenter presenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_briefs);
        unbinder = ButterKnife.bind(this);

        ViewSwitcher.ViewFactory factory = new ViewSwitcher.ViewFactory() {

            public View makeView() {
                TextView myText = new TextView(BriefsActivity.this);
                myText.setGravity(Gravity.CENTER_VERTICAL);
                myText.setTextSize(18);
                myText.setTextColor(Color.parseColor("#333333"));
                return myText;
            }
        };
        orderMsgSwitch.setFactory(factory);
        systemMsgSwitch.setFactory(factory);
        presenter = new BriefsPresenter(this);
        presenter.start();
    }

    @OnClick(R.id.title_bar_back_layout)
    void back(){
        finish();
    }

    @OnClick(R.id.iv_settings)
    void goToSettingPage(){
        startActivity(new Intent(this, SettingsActivity.class));
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        presenter.stop();
    }

    @Override
    public void updateUserInfo(BriefsBean bean) {
        uploadPhotoNumText.setText(String.valueOf(bean.todayUpload));
        captureNumText.setText(String.valueOf(bean.todayUpload));
        averageMoneyText.setText(String.valueOf(bean.avgIncome));
        todayIncomingText.setText(String.valueOf(bean.todayIncome));
        totalIncomingText.setText(String.valueOf(bean.todayIncome));
        todayCaptureHoursText.setText(String.valueOf(bean.todayUpload));
    }

    @Override
    public void updateMessageBar(final String sysMsg, final String orderMsg) {
        systemMsgSwitch.post(new Runnable() {
            @Override
            public void run() {
                orderMsgSwitch.setText(TextUtils.isEmpty(orderMsg) ? getString(R.string.no_order_msg) : orderMsg);
                systemMsgSwitch.setText(TextUtils.isEmpty(sysMsg) ? getString(R.string.no_system_msg): sysMsg);
            }
        });

    }

}
