package com.yeshi.ec.rebate.myapplication.util;
|
|
import android.app.Dialog;
|
import android.content.Context;
|
import android.content.DialogInterface;
|
import android.content.Intent;
|
import android.widget.Toast;
|
|
import com.yeshi.ec.rebate.myapplication.BasicTextHttpResponseHandler;
|
import com.yeshi.ec.rebate.myapplication.ShoppingApi;
|
import com.yeshi.ec.rebate.myapplication.entity.GiftCoupon;
|
import com.yeshi.ec.rebate.myapplication.ui.dialog.CopyGiftDialog;
|
import com.yeshi.ec.rebate.myapplication.ui.mine.PromotionRedenvelopeActivity;
|
import com.yeshi.ec.rebate.myapplication.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 String 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, String 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();
|
}
|
});
|
}
|
|
}
|