hxb
2022-11-22 b3513b1713bb979d0a69c5a8c4ddcd038f184e6e
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
package com.mm.android.deviceaddmodule.p_typechoose;
 
 
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
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.TypeChooseConstract;
import com.mm.android.deviceaddmodule.event.DeviceAddEvent;
import com.mm.android.deviceaddmodule.mobilecommon.dialog.LCAlertDialog;
import com.mm.android.deviceaddmodule.mobilecommon.entity.deviceadd.DeviceAddInfo;
import com.mm.android.deviceaddmodule.mobilecommon.utils.UIUtils;
import com.mm.android.deviceaddmodule.mobilecommon.widget.ClearEditText;
import com.mm.android.deviceaddmodule.model.DeviceAddModel;
import com.mm.android.deviceaddmodule.presenter.TypeChoosePresenter;
import com.mm.android.deviceaddmodule.views.ChooseNetDialog;
 
import org.greenrobot.eventbus.EventBus;
 
/**
 * 设备类型选择页
 */
public class TypeChooseFragment extends BaseDevAddFragment implements TypeChooseConstract.View, View.OnClickListener {
    TypeChooseConstract.Presenter mPresenter;
    View mView;
    private ClearEditText mTvNameInput;
    private TextView mTvTip;
    private TextView mTvSure;
    private boolean isSelfInput = true;
    private ImageView ivSelfInput;
    private ImageView ivChooseOther;
 
    public static TypeChooseFragment newInstance() {
        TypeChooseFragment fragment = new TypeChooseFragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }
 
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        isDestoryView = false;
        if (mView != null) {
            ViewGroup parent = (ViewGroup) mView.getParent();
            if (parent != null) {
                parent.removeView(mView);
            }
        } else {
            mView = inflater.inflate(R.layout.fragment_type_input, container, false);
            initView(mView);
            initData();
        }
        if (mPresenter != null) {
            mPresenter.resetDevPwdCache();
        }
        return mView;
    }
 
    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
 
    }
 
    protected void initView(View view) {
        mTvNameInput = view.findViewById(R.id.tv_name_input);
        view.findViewById(R.id.ll_choose_other).setOnClickListener(this);
        view.findViewById(R.id.ll_self_input).setOnClickListener(this);
        mTvTip = view.findViewById(R.id.tv_tip);
        ivSelfInput = view.findViewById(R.id.iv_self_input);
        ivChooseOther = view.findViewById(R.id.iv_choose_other);
        mTvSure = view.findViewById(R.id.tv_sure);
        mTvSure.setOnClickListener(this);
 
        String str1 = getResources().getString(R.string.add_device_choose_type_tip1);
        String str2 = getResources().getString(R.string.add_device_choose_type_tip2);
        String str3 = getResources().getString(R.string.add_device_choose_type_tip3);
        String str4 = getResources().getString(R.string.add_device_choose_type_tip4);
        String str5 = getResources().getString(R.string.add_device_choose_type_tip5);
        String str6 = getResources().getString(R.string.add_device_choose_type_tip6);
        SpannableString info = new SpannableString(str1 + str2 + str3 + str4 + str5 + str6);
        if (!TextUtils.isEmpty(str1)) {
            info.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.cf4)), 0, str1.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            info.setSpan(new StyleSpan(Typeface.BOLD), 0, str1.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        if (!TextUtils.isEmpty(str2)) {
            info.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.c40)), str1.length(), str1.length() + str2.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            info.setSpan(new StyleSpan(Typeface.BOLD), str1.length(), str1.length() + str2.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        if (!TextUtils.isEmpty(str3)) {
            info.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.c40)), str1.length() + str2.length(), str1.length() + str2.length() + str3.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        if (!TextUtils.isEmpty(str4)) {
            info.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.c40)), str1.length() + str2.length() + str3.length(), str1.length() + str2.length() + str3.length() + str4.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            info.setSpan(new StyleSpan(android.graphics.Typeface.BOLD),str1.length() + str2.length() + str3.length(), str1.length() + str2.length() + str3.length() + str4.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        if (!TextUtils.isEmpty(str5)) {
            info.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.c40)), str1.length() + str2.length() + str3.length() + str4.length(), str1.length() + str2.length() + str3.length() + str4.length() + str5.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        if (!TextUtils.isEmpty(str6)) {
            info.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.c40)), str1.length() + str2.length() + str3.length() + str4.length() + str5.length(), str1.length() + str2.length() + str3.length() + str4.length() + str5.length() + str6.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            info.setSpan(new StyleSpan(android.graphics.Typeface.BOLD),str1.length() + str2.length() + str3.length() + str4.length() + str5.length(), str1.length() + str2.length() + str3.length() + str4.length() + str5.length() + str6.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        mTvTip.setText(info);
    }
 
    protected void initData() {
        mPresenter = new TypeChoosePresenter(this);
    }
 
    @Override
    public void onDestroy() {
        super.onDestroy();
        mPresenter.resetDevPwdCache();
    }
 
    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.ll_choose_other) {
            isSelfInput = false;
            ivSelfInput.setImageResource(R.drawable.adddevice_box_checkbox);
            ivChooseOther.setImageResource(R.drawable.adddevice_box_checkbox_checked);
        } else if (id == R.id.ll_self_input) {
            isSelfInput = true;
            ivChooseOther.setImageResource(R.drawable.adddevice_box_checkbox);
            ivSelfInput.setImageResource(R.drawable.adddevice_box_checkbox_checked);
        } else if (id == R.id.tv_sure) {
            if (UIUtils.isFastDoubleClick()) {
                return;
            }
            if (isSelfInput) {
                //手动输入
                String name = mTvNameInput.getText().toString().trim();
                if (TextUtils.isEmpty(name)) {
                    toast(R.string.device_tip_content);
                    return;
                }
                mPresenter.getDeviceInfoSync(name);
            } else {
                //其他选择
                ChooseNetDialog chooseNetDialog = new ChooseNetDialog(getContext());
                chooseNetDialog.setOnChooseNetLisenter(new ChooseNetDialog.OnChooseNetLisenter() {
                    @Override
                    public void softap() {
                        EventBus.getDefault().post(new DeviceAddEvent(DeviceAddEvent.CHANGE_TO_SOFTAP_ACTION));
                        DeviceAddModel.newInstance().getDeviceInfoCache().setCurDeviceAddType(DeviceAddInfo.DeviceAddType.SOFTAP);
                    }
 
                    @Override
                    public void wlan() {
                        EventBus.getDefault().post(new DeviceAddEvent(DeviceAddEvent.CHANGE_TO_WIRELESS_ACTION));
                        DeviceAddModel.newInstance().getDeviceInfoCache().setCurDeviceAddType(DeviceAddInfo.DeviceAddType.WLAN);
                    }
 
                    @Override
                    public void lan() {
                        EventBus.getDefault().post(new DeviceAddEvent(DeviceAddEvent.CHANGE_TO_WIRED_ACTION));
                        DeviceAddModel.newInstance().getDeviceInfoCache().setCurDeviceAddType(DeviceAddInfo.DeviceAddType.LAN);
                    }
                });
                chooseNetDialog.show();
            }
        }
    }
 
    LCAlertDialog mLCAlertDialog;
    private final String searchError = "searchError";
 
    @Override
    public void showSearchError() {
        LCAlertDialog.Builder builder = new LCAlertDialog.Builder(getContext());
        builder.setTitle("");
        builder.setMessage(R.string.add_device_choose_type_error);
        builder.setCancelButton(R.string.common_cancel, null);
        builder.setConfirmButton(R.string.common_confirm,
                new LCAlertDialog.OnClickListener() {
                    @Override
                    public void onClick(LCAlertDialog dialog, int which, boolean isChecked) {
                        dismissLCAlertDialog();
                    }
                });
 
        mLCAlertDialog = builder.create();
        mLCAlertDialog.show(getActivity().getSupportFragmentManager(),
                searchError);
    }
 
    private void dismissLCAlertDialog() {
        if (mLCAlertDialog != null && mLCAlertDialog.isVisible()) {
            mLCAlertDialog.dismissAllowingStateLoss();
            mLCAlertDialog = null;
        }
    }
 
}