admin
2021-05-28 98cc34dbca6d6218ec5e72baffda2d3a1dd72a55
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
package com.tejia.lijin.app.ui.mine;
 
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.InputType;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
 
import com.alibaba.baichuan.trade.biz.login.AlibcLogin;
import com.alibaba.baichuan.trade.biz.login.AlibcLoginCallback;
import com.bumptech.glide.Glide;
import com.tejia.lijin.app.ShoppingApplication;
import com.wpc.library.RetainViewFragment;
import com.wpc.library.util.common.StringUtils;
import com.tejia.lijin.app.BasicTextHttpResponseHandler;
import com.tejia.lijin.app.R;
import com.tejia.lijin.app.ShoppingApi;
import com.tejia.lijin.app.ui.dialog.ShapeLoadingDialog;
import com.tejia.lijin.app.ui.invite.ShareBrowserActivity;
import com.tejia.lijin.app.util.OrderTransformationLink;
import com.tejia.lijin.app.util.user.UserUtil;
 
import org.apache.http.Header;
import org.json.JSONObject;
 
/**
 * 订单找回 fragment
 */
public class FragmentOrderAppeal extends RetainViewFragment implements View.OnClickListener {
    private TextView tv_refer_appeal, tv_order_appeal_doubt;
    private EditText et_orderId;
    private TextView tv_notice_content, iv_order_coursetxt;
    private LinearLayout ll_notice;
    private ImageView iv_close;
    private ScrollView sv_content;
    private TextView tv_order_appeal_aout;//自动找回
    private ImageView iv_order_course;//图片教程
 
    private int clickState = 0;
    private Bundle mBundle;//传递过来的值
    private String TYPE = "orderFind";//默认淘宝
 
    @Override
    public int getContentResource() {
        return R.layout.fragment_order_appeal;
    }
 
    @Override
    public void onCreateView(View contentView, Bundle savedInstanceState) {
        tv_refer_appeal = contentView.findViewById(R.id.tv_refer_appeal);
        tv_order_appeal_doubt = contentView.findViewById(R.id.tv_order_appeal_doubt);
        et_orderId = contentView.findViewById(R.id.et_order_id);
        tv_order_appeal_aout = contentView.findViewById(R.id.tv_order_appeal_aout);
        tv_notice_content = contentView.findViewById(R.id.tv_notice_content);
        ll_notice = contentView.findViewById(R.id.ll_notice);
        iv_close = contentView.findViewById(R.id.iv_close);
        sv_content = contentView.findViewById(R.id.sv_content);
        iv_order_coursetxt = contentView.findViewById(R.id.iv_order_coursetxt);
        iv_order_course = contentView.findViewById(R.id.iv_order_course);
 
        et_orderId.setCursorVisible(true);
        et_orderId.setOnClickListener(this);
        tv_refer_appeal.setOnClickListener(this);
        tv_order_appeal_doubt.setOnClickListener(this);
        tv_order_appeal_aout.setOnClickListener(this);
        mBundle = getArguments();//传递过来的 值 做淘宝-京东-拼多多判断
        getOrderParseConfig();
        et_orderId.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                showSoftInputFromWindow(getActivity(), et_orderId);
                return false;
            }
        });
        setcourse(mBundle.getInt("id"));
    }
 
    /**
     * 设置图片教程
     *
     * @param id
     */
    private void setcourse(int id) {
        int uir;
        if (id == 1) {//淘宝
            uir = R.drawable.ic_order_appeal_buttom;
            iv_order_coursetxt.setText("手机淘宝中复制订单号教程");
            et_orderId.setHint("请输入或粘贴淘宝订单号");
            TYPE = "orderFind";//默认淘宝
        } else if (id == 2) {//京东
            uir = R.drawable.ic_order_appeal_buttomjd;
            iv_order_coursetxt.setText("京东中复制订单号教程");
            et_orderId.setHint("请输入或粘贴京东订单号");
            TYPE = "orderFindJD";
        } else if (id == 4) {//唯品会
            uir = R.drawable.ic_order_appeal_buttomvip;
            iv_order_coursetxt.setText("唯品会中复制订单号教程");
            et_orderId.setHint("请输入或粘贴唯品会订单号");
            TYPE = "orderFindVIP";
        } else if (id == 5) {//苏宁
            uir = R.drawable.ic_order_appeal_buttomsuning;
            iv_order_coursetxt.setText("苏宁中复制订单号教程");
            et_orderId.setHint("请输入或粘贴苏宁订单号");
            TYPE = "orderFindSuning";
        } else {//拼多多
            uir = R.drawable.ic_order_appeal_buttompdd;
            iv_order_coursetxt.setText("拼多多中复制订单号教程");
            et_orderId.setHint("请输入或粘贴拼多多订单号");
            TYPE = "orderFindPDD";
        }
        Glide.with(this)
                .load(uir)
                .into(iv_order_course);
        getAppPageNotification();//小黄条
    }
 
    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (isVisibleToUser && (getActivity()) != null) {
            //TODO now it's visible to user对用户可见
        } else {
            //TODO now it's invisible to user对用户不可见
            if ((getActivity()) != null) {
                et_orderId.setFocusable(false);
                et_orderId.setFocusableInTouchMode(false);
                InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(et_orderId.getWindowToken(), 0);//  s强制隐藏键盘
            }
        }
    }
 
    /**
     * EditText获取焦点并显示软键盘
     */
    public void showSoftInputFromWindow(Activity activity, EditText editText) {
        editText.setFocusable(true);
        editText.setFocusableInTouchMode(true);
        editText.requestFocus();
        //显示软键盘
        activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        //如果上面的代码没有弹出软键盘 可以使用下面另一种方式
        //InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        // imm.showSoftInput(editText, 0);
        sv_content.fullScroll(ScrollView.FOCUS_DOWN);
    }
 
    private int showCount = 0;
 
    @Override
    public void onResume() {
        super.onResume();
        if (clickState == 1) {
            clickState = 0;
            Intent intent = new Intent(getActivity(), OrderAppealHistoryActivity.class);
            startActivity(intent);
        }
//        final View activityRootView = getActivity().getWindow().getDecorView().findViewById(android.R.id.content);
//        if (getActivity() != null) {
//            getActivity().getWindow().getDecorView().addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
//                @Override
//                public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
//                    if (showCount > 1) {
//                        //获取View可见区域的bottom
//                        if (getActivity() != null) {
//                            int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
//                            if (heightDiff > 100) { // 99% of the time the height diff will be due to a keyboard.
//                                if (isOpened == false) {
//                                    //Do two things, make the view top visible and the editText smaller
//                                    isOpened = true;
//                                }
//                                sv_content.fullScroll(ScrollView.FOCUS_DOWN);
//                                Toast.makeText(getContext(), "Gotcha!!! softKeyboardup", Toast.LENGTH_SHORT).show();
//                            } else if (isOpened == true) {
//                                isOpened = false;
//                                sv_content.fullScroll(ScrollView.FOCUS_UP);
//                                Toast.makeText(getContext(), "softkeyborad Down!!!", Toast.LENGTH_SHORT).show();
//                            } else {
//                                isOpened = true;
//                            }
//                        }
//                    }
//                    showCount++;
//                }
//            });
//        }
    }
 
    boolean isOpened = false;
 
    /**
     * 小黄条
     */
    private void getAppPageNotification() {
        ShoppingApi.getAppPageNotification(getContext(), TYPE, new BasicTextHttpResponseHandler() {
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                if (jsonObject.optInt("code") == 0) {
                    boolean isClose = jsonObject.optJSONObject("data").optBoolean("canClose");
                    String content = jsonObject.optJSONObject("data").optString("content");
                    final String contentUrl = jsonObject.optJSONObject("data").optString("contentUrl");
                    final String md5 = jsonObject.optJSONObject("data").optString("md5");
 
                    tv_notice_content.setText(content);
                    final SharedPreferences sp = getContext().getSharedPreferences("notice", Context.MODE_PRIVATE);
                    if (!sp.getBoolean(md5, false)) {//false 展示,true不展示
                        ll_notice.setVisibility(View.VISIBLE);
                    } else {
                        ll_notice.setVisibility(View.GONE);
                    }
 
                    if (isClose) {
                        iv_close.setImageDrawable(getResources().getDrawable(R.drawable.ic_notice_close));
                        iv_close.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                ll_notice.setVisibility(View.GONE);
                                SharedPreferences.Editor editor = sp.edit();
                                editor.putBoolean(md5, true);
                                editor.commit();
                            }
                        });
                    } else {
                        iv_close.setImageDrawable(getResources().getDrawable(R.drawable.ic_notice_input));
                    }
                    ll_notice.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (StringUtils.isEmpty(contentUrl))
                                return;
                            Intent intent = new Intent(getContext(), ShareBrowserActivity.class);
                            intent.putExtra("url", contentUrl);
                            startActivity(intent);
                        }
                    });
                }
            }
        });
    }
 
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
 
 
            case R.id.tv_refer_appeal:
                if (StringUtils.isEmpty(et_orderId.getText().toString())) {
//                    SingleToast.showToast(OrderAppealActivity.this, "订单号不能为空");
                    Toast.makeText(getContext(), "订单号不能为空", Toast.LENGTH_SHORT).show();
                    break;
                }
                referAppeal();
                break;
            case R.id.tv_order_appeal_doubt://进入订单申诉的网页解释界面
            {
                SharedPreferences sp = getContext().getSharedPreferences("lostOrder", Context.MODE_PRIVATE);
                String what = sp.getString("what", "");
                Intent intent = new Intent(getContext(), ShareBrowserActivity.class);
                intent.putExtra("url", what);
                startActivity(intent);
            }
            case R.id.et_order_id: {
//                et_orderId.setCursorVisible(true);
//                 <!--android:focusable = "true"-- >
//        <!--android:focusableInTouchMode = "true"-- >
                et_orderId.setFocusable(true);
                et_orderId.setFocusableInTouchMode(true);
                et_orderId.setInputType(InputType.TYPE_CLASS_PHONE);
            }
            break;
            case R.id.tv_order_appeal_aout://自动找回
                SharedPreferences sp = getContext().getSharedPreferences("user", Context.MODE_PRIVATE);
                boolean isLogin = UserUtil.isLogin(getContext());
                if (isLogin) {
                    if (!btimer) {
                        if (AlibcLogin.getInstance().isLogin()) {
                            bindInfo();
                        } else {
                            tbLogin();
                        }
                    }
                } else {
                    UserUtil.jumpLogin(getContext());
                }
 
                break;
        }
    }
 
    String title = "找回提示";
 
    /**
     * 解密 淘宝找回订单
     */
    private void bindInfo() {
        waitinquire();//缓冲
        OrderTransformationLink order = new OrderTransformationLink(getActivity(), orderJS, orderUrl, "findOrder");
        btimer = true;
        timer();//开启线程
 
        order.setOnOrderListener(new OrderTransformationLink.onListener() {
            @Override
            public void onOrder(String reruen) {//找回成功
                if (btimer) {
                    btimer = false;
                    String content2;
                    if (reruen != null && reruen.equals("成功")) {
                        content2 = "订单找回成功, 请到“我的-订单”中查看";
                    } else {
                        content2 = reruen;
                    }
                    Dialog_explain(title, content2);
                }
                btimer = false;
                if (thread != null) {
                    thread.interrupt();
                }
            }
 
            @Override
            public void onIOrderError(String reruen) {//找回失败
                if (btimer) {
                    btimer = false;
                    String content1;
                    if (reruen != null && reruen.equals("失败")) {
                        content1 = "系统没有找到丢失订单,请确认是否满足找回条件或手动输入订单号找回";
                    } else {
                        content1 = reruen;
                    }
                    Dialog_explain(title, content1);
                }
                btimer = false;
                if (thread != null) {
                    thread.interrupt();
                }
            }
        });
        order.showOrder();
    }
 
    private Thread thread;//线程
    private boolean btimer = false;//开启线程
 
    /**
     * 主要是用于 点击自动找回 10秒超时
     */
    private void timer() {
        thread = new Thread(new Runnable() {
            @Override
            public void run() {
                int timer = 10;
                while (btimer && timer >= 1) {
                    //暂停一秒
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                        btimer = false;
                    }
                    timer--;
                    if (timer <= 1) {//结束线程
                        btimer = false;
                        Message message = new Message();
                        message.what = 1;
                        //发送信息给handler
                        handler.sendMessage(message);
                    }
                }
            }
        });
        thread.start();
    }
 
    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 1:
                    btimer = false;
                    if (thread != null) {
                        thread.interrupt();//线程中断
                    }
                    String content1 = "系统没有找到丢失订单,请确认是否满足找回条件或手动输入订单号找回";
                    Dialog_explain(title, content1);
                    break;
            }
        }
    };
 
    /**
     * 登陆淘宝
     */
    private void tbLogin() {
        final AlibcLogin alibcLogin = AlibcLogin.getInstance();
        alibcLogin.showLogin(new AlibcLoginCallback() {
 
            @Override
            public void onSuccess(int i, String s, String s1) {
                bindInfo();
            }
 
            @Override
            public void onFailure(int code, String msg) {
                Toast.makeText(getContext(), "登录失败,请稍候再试",
                        Toast.LENGTH_LONG).show();
            }
        });
 
    }
 
    ShapeLoadingDialog pd = null;
 
    public void waitinquire() {
        if (pd == null) {
            pd = new ShapeLoadingDialog.Builder(getContext()).build();
        }
        pd.show();
    }
 
 
    AlertDialog.Builder alterDiaglog;
    AlertDialog dialog;
 
    /**
     * dialog 弹窗说明
     *
     * @param title
     * @param str1
     */
    private void Dialog_explain(String title, String str1) {
        if (pd != null && pd.isShowing())
            pd.dismiss();
        alterDiaglog = new AlertDialog.Builder(getContext(), R.style.dialog_activationinvitecode2);
        View view = View.inflate(getContext(), R.layout.dialog_activationinvite3, null);
        alterDiaglog.setView(view);//加载进去
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }
        dialog = alterDiaglog.create();
        //显示
        dialog.show();
        //设置宽高
        WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
        params.width = getActivity().getWindowManager().getDefaultDisplay().getWidth();
        params.height = com.app.hubert.guide.util.ScreenUtils.dp2px(getContext(), 290);
        params.width = com.app.hubert.guide.util.ScreenUtils.dp2px(getContext(), 260);
        dialog.getWindow().setAttributes(params);
        TextView textitle = dialog.findViewById(R.id.dialog_activationinvitetxt_title);
        TextView textcontent1 = dialog.findViewById(R.id.dialog_activationinvitetxt_content1);
        FrameLayout fl_close = dialog.findViewById(R.id.dialog_activationinvitetxt_close);
        textitle.setText(title);
        textcontent1.setText(str1);
        fl_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (dialog != null && dialog.isShowing()) {
                    dialog.dismiss();
                    dialog.cancel();
                }
            }
        });
    }
 
    private void referAppeal() {
        Long uid = UserUtil.getUid(ShoppingApplication.application);
//        String uid = "323922";
        if (uid == null) {
//            SingleToast.showToast(OrderAppealActivity.this, "登录后才能申诉");
            Toast.makeText(getContext(), "登录后才能找回", Toast.LENGTH_SHORT).show();
            return;
        }
 
        ShoppingApi.setOrderAppeal(getContext(), et_orderId.getText().toString(), uid, mBundle.getInt("id") + "", new BasicTextHttpResponseHandler() {
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                if (jsonObject.optString("code").equalsIgnoreCase("0")) {
                    et_orderId.setText("");
//                    SingleToast.showToast(OrderAppealActivity.this, jsonObject.optJSONObject("data").optString("info"));
                    Toast.makeText(getContext(), jsonObject.optJSONObject("data").optString("info"), Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(getContext(), "找回失败", Toast.LENGTH_SHORT).show();
//                    SingleToast.showToast(OrderAppealActivity.this, "申诉失败!");
                }
            }
 
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
//                SingleToast.showToast(OrderAppealActivity.this, "提交失败!");
                Toast.makeText(getContext(), "提交失败", Toast.LENGTH_SHORT).show();
            }
        });
    }
 
 
    /**
     * 淘宝订单配置
     *
     * @param source
     */
    String orderJS;
    String orderUrl;
 
    /**
     * 淘宝订单解析配置
     */
    private void getOrderParseConfig() {
        //只有淘宝 才做自动找回
        if (mBundle.getInt("id") != 1) {
            return;
        }
        ShoppingApi.getOrderParseConfig(getContext(), new BasicTextHttpResponseHandler() {
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                if (jsonObject.optInt("code") == 0) {
                    tv_order_appeal_aout.setVisibility(View.VISIBLE);
                    orderJS = jsonObject.optJSONObject("data").getString("orderJS");
                    orderUrl = jsonObject.optJSONObject("data").getString("orderUrl");
                } else {//隐藏订单找回
                    tv_order_appeal_aout.setVisibility(View.GONE);
                }
            }
        });
    }
 
    @Override
    public void onPause() {
        super.onPause();
        btimer = false;
        if (thread != null) {
            thread.interrupt();
        }
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
            dialog.cancel();
        }
        if (pd != null && pd.isShowing())
            pd.dismiss();
        et_orderId.setFocusable(false);
        et_orderId.setFocusableInTouchMode(false);
//        et_orderId.requestFocus();
    }
 
 
    @Override
    public void onDestroy() {
        super.onDestroy();
        btimer = false;
        if (thread != null) {
            thread.interrupt();
        }
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
            dialog.cancel();
        }
        if (pd != null && pd.isShowing())
            pd.dismiss();
    }
}