OnshellActivity.java 4.56 KB
package com.huaheng.wms.onshell;

import android.content.Context;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

import com.huaheng.wms.R;
import com.huaheng.wms.WMSLog;
import com.huaheng.wms.model.CommonActivity;
import com.huaheng.wms.util.SpeechUtil;
import com.huaheng.wms.util.WMSUtils;
import com.huaheng.wms.views.LineLayout;

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

/*
 ** 上架
 */
public class OnshellActivity extends CommonActivity {

    @BindView(R.id.onShellEdit)
    EditText onShellEdit;
    @BindView(R.id.onShellRecommandLayout)
    LineLayout onShellRecommandLayout;
    @BindView(R.id.onShellContentLayout)
    LinearLayout onShellContentLayout;
    @BindView(R.id.onShellEnsureBtn)
    Button onShellEnsureBtn;
    @BindView(R.id.onShellEnsureLayout)
    LinearLayout onShellEnsureLayout;
    @BindView(R.id.onshell_linear)
    LinearLayout onshellLinear;
    private String cn;
    private String sn;
    private Context mContext;
    private boolean isEnterCN = true;

    @Override
    protected void initActivityOnCreate(Bundle savedInstanceState) {
        super.initActivityOnCreate(savedInstanceState);
        setContentView(R.layout.activity_on_shell);
        ButterKnife.bind(this);
        setTitle(getString(R.string.on_the_shelf));
        mContext = this;
        initView();
        enableButton(false);
    }


    @OnClick({R.id.onShellEnsureLayout})
    public void onViewClicked(View view) {
        WMSLog.d("onViewClicked @@");
        if (isEnterCN) {
            onShellEdit.setText("");
            onShellEdit.requestFocus();
            onShellEdit.setHint(R.string.enter_warehouse_number);
            isEnterCN = false;
            showLayout();
        } else {
            submit();
        }
    }

    private void initView() {
        onShellEdit.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                String number = editable.toString();
                if (number != null && number.length() > 0) {
                    if (isEnterCN) {
                        cn = number;
                    } else {
                        sn = number;
                    }
                    enableButton(true);
                } else {
                    enableButton(false);
                }
            }
        });
    }

    private void showLayout() {
        String name = "MYR930S-X 立式饮水机 白色 S2平台网销机";
        String postion = "A-01-02";
        String number = "629";
        onShellContentLayout.setVisibility(View.VISIBLE);
        onShellRecommandLayout.setLineName(getString(R.string.recommended_library_position));
        onShellRecommandLayout.setLineContent(postion);
        addGoodsInfo();
    }

    private void addGoodsInfo() {
        LineLayout lineLayout = new LineLayout(mContext);
        lineLayout.setLineName("商品名称");
        lineLayout.setLineContent("矿泉水");
        onshellLinear.addView(lineLayout);
        View view = new View(mContext);
        view.setMinimumHeight(1);
        view.setMinimumWidth(-1);
        view.setBackgroundResource(R.color.lightgray);
        onshellLinear.addView(view);
        LineLayout lineLayout2 = new LineLayout(mContext);
        lineLayout2.setLineName("商品条码");
        lineLayout2.setLineContent("2106302000038");
        onshellLinear.addView(lineLayout2);
        View view2 = new View(mContext);
        view.setMinimumHeight(1);
        view.setMinimumWidth(-1);
        view.setBackgroundResource(R.color.lightgray);
        onshellLinear.addView(view2);
    }

    private void enableButton(boolean enable) {
        if (enable) {
            onShellEnsureBtn.setBackgroundResource(R.drawable.blue_button_bg);
            onShellEnsureLayout.setClickable(true);
        } else {
            onShellEnsureBtn.setBackgroundResource(R.drawable.gray_button_bg);
            onShellEnsureLayout.setClickable(false);
        }
    }

    private void submit() {
        SpeechUtil.getInstance(this).speech(this.getString(R.string.onshell_success));
        finish();
        WMSUtils.startActivity(this, OnshellActivity.class);
    }

}