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);
|
|
}
|
|
}
|