wxr
2022-11-23 1e7b3abd15d37f6c6bc97ac14922457b9604c275
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package com.mm.android.deviceaddmodule.p_ap;
 
 
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
 
import com.mm.android.deviceaddmodule.R;
import com.mm.android.deviceaddmodule.base.BaseDevAddFragment;
import com.mm.android.deviceaddmodule.contract.ApBindSuccessConstract;
import com.mm.android.deviceaddmodule.event.DeviceAddEvent;
import com.mm.android.deviceaddmodule.helper.DeviceAddHelper;
import com.mm.android.deviceaddmodule.helper.DeviceAddImageLoaderHelper;
import com.mm.android.deviceaddmodule.mobilecommon.AppConsume.ProviderManager;
import com.mm.android.deviceaddmodule.mobilecommon.common.LCConfiguration;
import com.mm.android.deviceaddmodule.mobilecommon.entity.AddApResult;
import com.mm.android.deviceaddmodule.mobilecommon.entity.deviceadd.DeviceAddInfo;
import com.mm.android.deviceaddmodule.mobilecommon.eventbus.event.CommonEvent;
import com.mm.android.deviceaddmodule.mobilecommon.utils.NameLengthFilter;
import com.mm.android.deviceaddmodule.mobilecommon.utils.WordInputFilter;
import com.mm.android.deviceaddmodule.mobilecommon.widget.ClearEditText;
import com.mm.android.deviceaddmodule.model.DeviceAddModel;
import com.mm.android.deviceaddmodule.presenter.ApBindSuccessPresenter;
import com.nostra13.universalimageloader.core.ImageLoader;
 
import org.greenrobot.eventbus.EventBus;
 
/**
 * 配件绑定成功页
 **/
public class ApBindSuccessFragment extends BaseDevAddFragment implements ApBindSuccessConstract.View,
        View.OnClickListener {
    private static String AP_RESULT_PARAM = "ap_result_param";
    private final int MAXLETHER = 20;
 
    ApBindSuccessConstract.Presenter mPresenter;
    ClearEditText mApNameEdit;
    TextView mNextBtn;
    ImageView mDevImg;
 
    public static ApBindSuccessFragment newInstance(AddApResult addApResult) {
        ApBindSuccessFragment fragment = new ApBindSuccessFragment();
        Bundle args = new Bundle();
        args.putSerializable(AP_RESULT_PARAM, addApResult);
        fragment.setArguments(args);
        return fragment;
    }
 
    private final TextWatcher mTextWatcher = new TextWatcher() {
 
        @Override
        public void onTextChanged(CharSequence s, int arg1, int arg2, int arg3) {
            String devName=s.toString().trim();
            if(!TextUtils.isEmpty(devName)){
                mNextBtn.setEnabled(true);
                mApNameEdit.removeTextChangedListener(mTextWatcher);
                String filterDevName = DeviceAddHelper.strDeviceNameFilter(devName);
                if (!filterDevName.equals(devName)) {
                    mApNameEdit.setText(filterDevName);
                    mApNameEdit.setSelection(filterDevName.length());
                }
                mApNameEdit.addTextChangedListener(mTextWatcher);
            }else{
                mNextBtn.setEnabled(false);
            }
        }
 
        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
        }
 
        @Override
        public void afterTextChanged(Editable arg0) {
        }
    };
 
 
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_ap_bind_success, container, false);
    }
 
    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        DeviceAddHelper.updateTile(DeviceAddHelper.TitleMode.BLANK);
    }
 
    @Override
    protected void initView(View view) {
        mApNameEdit = view.findViewById(R.id.ap_name_input);
        mNextBtn = view.findViewById(R.id.tv_next);
        mNextBtn.setOnClickListener(this);
 
        mApNameEdit.setFilters(new InputFilter[] {new WordInputFilter(WordInputFilter.REX_NAME) , new NameLengthFilter(MAXLETHER)});
        mApNameEdit.addTextChangedListener(mTextWatcher);
        mDevImg = view.findViewById(R.id.dev_img);
    }
 
    @Override
    protected void initData() {
        mPresenter = new ApBindSuccessPresenter(this);
        if (getArguments() != null) {
            AddApResult addApResult = (AddApResult) getArguments().getSerializable(AP_RESULT_PARAM);
            mPresenter.setData(addApResult);
        }
    }
 
    @Override
    public String getApName() {
        return mApNameEdit.getText().toString().trim();
    }
 
    @Override
    public void setApName(String name) {
        mApNameEdit.setText(name);
    }
 
    @Override
    public void setApImg(String img) {
        if (!TextUtils.isEmpty(img)) {
            ImageLoader.getInstance().displayImage(img, mDevImg,
                    DeviceAddImageLoaderHelper.getCommonOptions4success());
        }
    }
 
    @Override
    public void completeAction() {
        DeviceAddInfo deviceAddInfo = DeviceAddModel.newInstance().getDeviceInfoCache();
        boolean isDeviceDetail = deviceAddInfo.isDeviceDetail();
        String deviceId = deviceAddInfo.getGatewayInfo().getSn();
        String apId = deviceAddInfo.getDeviceSn();
 
        if (getActivity() != null) getActivity().finish();
 
        String code = CommonEvent.AP_PAIR_SUCCEED_2_MID_ACTION;
        if(!isDeviceDetail) {
            //添加结束跳转到首页设备列表
            code = CommonEvent.AP_PAIR_SUCCEED_2_MAIN_ACTION;
            ProviderManager.getDeviceAddCustomProvider().goHomePage(getContext());
        }
 
        Bundle bundle = new Bundle();
        bundle.putString(LCConfiguration.Device_ID, deviceId);
        bundle.putString(LCConfiguration.AP_ID, apId);
        CommonEvent commonEvent = new CommonEvent(code);
        commonEvent.setBundle(bundle);
        EventBus.getDefault().post(commonEvent);
 
        EventBus.getDefault().post(new DeviceAddEvent(DeviceAddEvent.DESTROY_ACTION));
    }
 
    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.tv_next) {
            mPresenter.modifyApName();
        }
    }
 
 
 
}