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

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.collectgoods.BulkCollectActivity;
import com.huaheng.wms.model.CommonActivity;
import com.huaheng.wms.util.SoundUtils;
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.onShellWnLayout)
    LineLayout onShellWnLayout;
    @BindView(R.id.onShellCnLayout)
    LineLayout onShellCnLayout;
    @BindView(R.id.onShellRecommandLayout)
    LineLayout onShellRecommandLayout;
    @BindView(R.id.onShellNumLayoutLayout)
    LineLayout onShellNumLayoutLayout;
    @BindView(R.id.onShellContentLayout)
    LinearLayout onShellContentLayout;
    @BindView(R.id.onShellEnsureBtn)
    Button onShellEnsureBtn;
    @BindView(R.id.onShellEnsureLayout)
    LinearLayout onShellEnsureLayout;
    private String cn;
    private String sn;
    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));
        initView();
        enableButton(false);
    }


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

    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);
        onShellWnLayout.setLineName(getString(R.string.commodity_barcode));
        onShellWnLayout.setLineContent("21063020000038");
        onShellCnLayout.setLineName(getString(R.string.commodity_name));
        onShellCnLayout.setLineContent(name);
        onShellRecommandLayout.setLineName(getString(R.string.recommended_library_position));
        onShellRecommandLayout.setLineContent(postion);
        onShellNumLayoutLayout.setLineName(getString(R.string.number_of_shelves));
        onShellNumLayoutLayout.setLineContent(number);
    }

    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() {
        SoundUtils.getInstance(this).dingSound();
        finish();
        WMSUtils.startActivity(this, OnshellActivity.class);
    }

}