admin
2021-06-11 ae4dc86b64bd8ef85bc832106741fb98e8d516da
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
package com.tejia.lijin.app.util;
 
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.widget.Toast;
 
import com.tejia.lijin.app.BasicTextHttpResponseHandler;
import com.tejia.lijin.app.ShoppingApi;
import com.tejia.lijin.app.entity.GiftCoupon;
import com.tejia.lijin.app.ui.dialog.CopyGiftDialog;
import com.tejia.lijin.app.ui.mine.PromotionRedenvelopeActivity;
import com.tejia.lijin.app.ui.mine.WelfareCenterActivity;
 
import org.apache.http.Header;
import org.json.JSONObject;
 
/**
 * 10 // 类型:10-免单券   11-奖励券   12-红包
 */
public class CopyGiftDialogUtils {
    private Context mContext;
 
    public CopyGiftDialogUtils(Context mContext) {
        this.mContext = mContext;
    }
 
    /**
     * 奖励券 领取
     *
     * @param giftCoupon
     * @param uid
     * @param dialog
     * @param type
     */
    public void showCopyGiftDialog(final GiftCoupon giftCoupon, final Long uid, Dialog dialog, final String type) {
        CopyGiftDialog.Builder builder = new CopyGiftDialog.Builder(mContext);
        builder.setMessage(giftCoupon);
        builder.setPositiveButton("", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (giftCoupon.state) {
//                    Intent intent = new Intent(mContext, WelfareCenterActivity.class);
//                    mContext.startActivity(intent);
                    gettokenReceive(giftCoupon.token, uid, type);
                }
                if (dialog != null) {
                    dialog.dismiss();
                }
            }
        });
        builder.setNegativeButton("", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (dialog != null) {
                    dialog.dismiss();
                }
            }
        });
        dialog = builder.create();
        dialog.show();
    }
 
    /**
     * 智能搜索-口令领取
     *
     * @param token
     * @param uid
     */
    private void gettokenReceive(String token, Long uid, final String type) {
        ShoppingApi.getTokenReceive(mContext, uid, token, new BasicTextHttpResponseHandler() {
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                if (jsonObject.optInt("code") == 0) {
                    Intent intent = null;
                    if (type.equals("13")) {//推广红包
                        intent = new Intent(mContext, PromotionRedenvelopeActivity.class);
                    } else {//福利中心
                        intent = new Intent(mContext, WelfareCenterActivity.class);
                    }
                    mContext.startActivity(intent);
                } else {
                    Toast.makeText(mContext, jsonObject.optString("msg"), Toast.LENGTH_SHORT).show();
                }
            }
 
            @Override
            public void onFailure(int statusCode, Header[] headers, String jsonObject, Throwable e) {
                Toast.makeText(mContext, "领取失败", Toast.LENGTH_SHORT).show();
            }
        });
    }
 
}