package com.sunzee.ui.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.hboxs.serialport.SerialPortSendQueue;
import com.hboxs.serialport.frame.WriteCommandFrame;
import com.hboxs.serialport.util.HexUtils;
import com.sunzee.R;
import com.sunzee.base.MvpFragment;
import com.sunzee.mvp.homepage.HomePagePresenter;
import com.sunzee.mvp.homepage.HomePageView;

/**
 * 首页界面 fragment
 */
public class HomepageFragment extends MvpFragment<HomePagePresenter> implements HomePageView {

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.fragment_home, container, false);
        initView(inflate);
        return inflate;
    }

    private void initView(View inflate) {
        LinearLayout startNumberClean = inflate.findViewById(R.id.start_number_clean);
        startNumberClean.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //可以写入成功。
                SerialPortSendQueue.sendCommand(new WriteCommandFrame("D120", HexUtils.hexStr2BinStr("0002")), 120, "D120");
            }
        });
    }

    @Override
    protected HomePagePresenter createPresenter() {
        return null;
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }
}
