admin
2021-04-16 7ff3a948e725053434fc8132947726ff89162c9e
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
package com.weikou.beibeivideo.util.goldcorn;
 
import android.content.Intent;
import android.view.View;
 
import com.weikou.beibeivideo.BasicTextHttpResponseHandler;
import com.weikou.beibeivideo.BeibeiVideoAPI;
import com.weikou.beibeivideo.BeibeiVideoApplication;
import com.weikou.beibeivideo.util.downutil.StringUtils;
import com.weikou.beibeivideo.util.ui.ToastUtil;
 
import org.apache.http.Header;
import org.json.JSONObject;
 
public class GoldCornUtil {
 
    /**
     * 是否为赚影视豆
     *
     * @param intent
     * @return
     */
    public static String getGoldCornCode(Intent intent) {
        if (intent == null)
            return null;
        if (!StringUtils.isNullOrEmpty(intent.getStringExtra("goldcorn")))
            return intent.getStringExtra("goldcorn");
        return null;
    }
 
    public static Runnable makeGoldCorn(Intent intent, View view, String param1, String param2, Integer delaySeconds, GetGoldCornListener goldCornListener) {
        if (view == null)
            return null;
 
        String code = getGoldCornCode(intent);
        if (code != null) {
            Runnable runnable = new Runnable() {
                @Override
                public void run() {
                    BeibeiVideoAPI.makeGoldCorn(BeibeiVideoApplication.application, code, param1, param2, new BasicTextHttpResponseHandler() {
                        @Override
                        public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                            if (jsonObject.optBoolean("IsPost")) {
                                JSONObject data = jsonObject.optJSONObject("Data");
                                if (data == null)
                                    return;
                                int goldCorn = data.optInt("goldCorn");
                                ToastUtil.showGetGoldGornToast(BeibeiVideoApplication.application, "+" + goldCorn);
                                if (goldCornListener != null)
                                    goldCornListener.onGetSuccess(code, goldCorn);
                            } else {
                                if (goldCornListener != null)
                                    goldCornListener.onGetFail(code, jsonObject.optString("Error"));
                            }
                        }
                    });
                }
            };
            if (view != null) {
                view.postDelayed(runnable, delaySeconds == null ? 4000 : delaySeconds * 1000);
                return runnable;
            }
        }
        return null;
    }
 
 
    public static void makeGoldCorn(String code, String param1, String param2, GetGoldCornListener goldCornListener) {
        if (code != null) {
            BeibeiVideoAPI.makeGoldCorn(BeibeiVideoApplication.application, code, param1, param2, new BasicTextHttpResponseHandler() {
                @Override
                public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                    if (jsonObject.optBoolean("IsPost")) {
                        JSONObject data = jsonObject.optJSONObject("Data");
                        if (data == null)
                            return;
                        int goldCorn = data.optInt("goldCorn");
                        ToastUtil.showGetGoldGornToast(BeibeiVideoApplication.application, "+" + goldCorn);
                        if (goldCornListener != null)
                            goldCornListener.onGetSuccess(code, goldCorn);
                    } else {
                        if (goldCornListener != null)
                            goldCornListener.onGetFail(code, jsonObject.optString("Error"));
                    }
                }
            });
        }
    }
 
    public static void removeCallbacks(View view, Runnable runnable) {
        if (view != null && runnable != null) {
            view.removeCallbacks(runnable);
        }
    }
 
    public interface GetGoldCornListener {
 
        public void onGetSuccess(String code, int goldCorn);
 
        public void onGetFail(String code, String msg);
 
    }
 
}