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
package com.mm.android.deviceaddmodule.p_errortip;
 
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.mm.android.deviceaddmodule.R;
import com.mm.android.deviceaddmodule.base.BaseDevAddFragment;
import com.mm.android.deviceaddmodule.contract.ErrorTipConstract;
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.PermissionHelper;
import com.mm.android.deviceaddmodule.mobilecommon.utils.UIUtils;
import com.mm.android.deviceaddmodule.presenter.ErrorTipPresenter;
import com.nostra13.universalimageloader.core.ImageLoader;
 
/**
 * 设备添加错误提示页
 */
public class ErrorTipFragment extends BaseDevAddFragment implements ErrorTipConstract.View, View.OnClickListener {
    ErrorTipConstract.Presenter mPresenter;
    public static String ERROR_PARAMS = "error_params";
    ImageView mTipImage;
    TextView mTipTxt, mTipTxt2, mHelpLinkTxt, mHelpPhoneTv;
    View mHelpLayout;
 
    private PermissionHelper mPermissionHelper;
 
    public static ErrorTipFragment newInstance(int errorCode) {
        ErrorTipFragment fragment = new ErrorTipFragment();
        Bundle args = new Bundle();
        args.putInt(ERROR_PARAMS, errorCode);
        fragment.setArguments(args);
        return fragment;
    }
 
 
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_error_tip, container, false);
    }
 
    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        if (mPresenter.isUserBindTipPage()) {
            DeviceAddHelper.updateTile(DeviceAddHelper.TitleMode.BLANK);
        } else {
            DeviceAddHelper.updateTile(DeviceAddHelper.TitleMode.MORE);
        }
    }
 
    protected void initView(View view) {
        mTipImage = view.findViewById(R.id.tip_img);
        mTipTxt = view.findViewById(R.id.tip_txt);
        mTipTxt2 = view.findViewById(R.id.tip_txt2);
        mHelpLinkTxt = view.findViewById(R.id.help_link);
        mHelpLinkTxt.setOnClickListener(this);
        mHelpLayout = view.findViewById(R.id.ll_help);
        mHelpPhoneTv = view.findViewById(R.id.tv_help_phone);
        mHelpLayout.setVisibility(View.GONE);
 
    }
 
    protected void initData() {
        mPresenter = new ErrorTipPresenter(this);
        if (getArguments() != null) {
            int errorcode = getArguments().getInt(ERROR_PARAMS);
            mPresenter.dispatchError(errorcode);
        }
    }
 
    @Override
    public Fragment getParent() {
        return this;
    }
 
    @Override
    public boolean onBackPressed() {
        if (mPresenter.isUserBindTipPageByBind()) {
            if(getActivity() != null) getActivity().finish();
        } else if (mPresenter.isResetPage()) {
            if(getActivity() != null) getActivity().getSupportFragmentManager().popBackStack();          //退回到上个界面
        }
        return mPresenter.isResetPage();
    }
 
    @Override
    public void updateInfo(String info, String img, boolean isNeedMatch) {
        if (isNeedMatch) {
            setImageMatchScreen();
        }
        if (!TextUtils.isEmpty(img)) {
            ImageLoader.getInstance().displayImage(img, mTipImage,
                    DeviceAddImageLoaderHelper.getCommonOptions());
        }
        if (!TextUtils.isEmpty(info)) {
            mTipTxt.setText(info);
        }
    }
 
    @Override
    public void updateInfo(int infoId, int tip2Id, String img, boolean isNeedMatch) {
        updateInfo(infoId, img, isNeedMatch);
        if(tip2Id!=0)
            mTipTxt2.setText(tip2Id);
    }
 
    @Override
    public void updateInfo(int infoId, String img, boolean isNeedMatch) {
        if (isNeedMatch) {
            setImageMatchScreen();
        }
        if (!TextUtils.isEmpty(img)) {
            ImageLoader.getInstance().displayImage(img, mTipImage,
                    DeviceAddImageLoaderHelper.getCommonOptions());
        }
        mTipTxt.setText(infoId);
    }
 
    @Override
    public void hideTipTxt() {
        mTipTxt.setVisibility(View.GONE);
        mTipTxt2.setVisibility(View.GONE);
    }
 
    @Override
    public void hideHelp() {
        mHelpLayout.setVisibility(View.GONE);
    }
 
    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.help_link) {
            ProviderManager.getDeviceAddCustomProvider().goFAQWebview(getActivity());
        }
    }
 
    private void setImageMatchScreen() {
        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mTipImage.getLayoutParams();
        layoutParams.height = /*LinearLayout.LayoutParams.WRAP_CONTENT*/UIUtils.dp2px(getContextInfo(), 300);
        layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
        layoutParams.topMargin=0;
        mTipImage.setLayoutParams(layoutParams);
        mTipImage.setScaleType(ImageView.ScaleType.FIT_CENTER);
    }
}