543 lines
18 KiB
Java
543 lines
18 KiB
Java
package cn.shangyu.gdxzExpert.activity;
|
|
|
|
import static cn.shangyu.gdxzExpert.utils.UIUtils.getContext;
|
|
|
|
import android.Manifest;
|
|
import android.content.DialogInterface;
|
|
import android.content.Intent;
|
|
import android.os.Build;
|
|
import android.os.Environment;
|
|
import android.os.Handler;
|
|
import android.os.Message;
|
|
import android.util.Log;
|
|
import android.view.Gravity;
|
|
import android.view.View;
|
|
import android.widget.Button;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.RelativeLayout;
|
|
import android.widget.TextView;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import com.github.dfqin.grantor.PermissionListener;
|
|
import com.github.dfqin.grantor.PermissionsUtil;
|
|
import com.gyf.immersionbar.ImmersionBar;
|
|
import com.hjq.window.EasyWindow;
|
|
import com.lidroid.xutils.HttpUtils;
|
|
import com.lidroid.xutils.exception.HttpException;
|
|
import com.lidroid.xutils.http.HttpHandler;
|
|
import com.lidroid.xutils.http.RequestParams;
|
|
import com.lidroid.xutils.http.ResponseInfo;
|
|
import com.lidroid.xutils.http.callback.RequestCallBack;
|
|
|
|
import org.json.JSONException;
|
|
import org.json.JSONObject;
|
|
|
|
import java.io.File;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Timer;
|
|
import java.util.TimerTask;
|
|
|
|
import cn.shangyu.gdxzExpert.R;
|
|
import cn.shangyu.gdxzExpert.base.BaseActivity;
|
|
import cn.shangyu.gdxzExpert.bean.CourseOrderBean;
|
|
import cn.shangyu.gdxzExpert.ecdemo.storage.CoursewareBookDownloadSqlManager;
|
|
import cn.shangyu.gdxzExpert.ecdemo.ui.chatting.model.DownloadModel;
|
|
import cn.shangyu.gdxzExpert.http.OnCallBackFromNet;
|
|
import cn.shangyu.gdxzExpert.utils.AESUtil;
|
|
import cn.shangyu.gdxzExpert.utils.Constant;
|
|
import cn.shangyu.gdxzExpert.utils.GsonTools;
|
|
import cn.shangyu.gdxzExpert.utils.SharePrefUtil;
|
|
import cn.shangyu.gdxzExpert.utils.StringUtil;
|
|
import cn.shangyu.gdxzExpert.utils.ToastUtil;
|
|
import cn.shangyu.gdxzExpert.utils.UIUtils;
|
|
import cn.shangyu.gdxzExpert.utils.Url;
|
|
import cn.shangyu.gdxzExpert.widget.ECAlertDialog;
|
|
import cn.shangyu.gdxzExpert.widget.LoadingPage.ResultState;
|
|
|
|
public class CourseDetailOrderActivity extends BaseActivity implements
|
|
OnCallBackFromNet {
|
|
private View view;
|
|
private TextView mTv_course_num, mTv_pay_state, mTv_pay_to, mTv_pay_money,
|
|
mTv_creat_time, mTv_pay_mode, mTv_pay_time, mTv_cancel_time,
|
|
mTv_course_title;
|
|
private LinearLayout mLl_pay_mode, mLl_pay_time;
|
|
private RelativeLayout mRl_pay;
|
|
private Button mBt_cancel, mBt_pay;
|
|
private CourseDetailOrderActivity mActivity;
|
|
private String order_id;
|
|
private String order_status;
|
|
private String providername;
|
|
private String file_uuid;
|
|
String title;
|
|
private String type;
|
|
|
|
@Override
|
|
public void setTitle() {
|
|
// TODO Auto-generated method stub
|
|
top_title.setText("订单详情");
|
|
}
|
|
|
|
@Override
|
|
public View onCreateSuccessedView() {
|
|
// TODO Auto-generated method stub
|
|
ImmersionBar.with(this).keyboardEnable(true).statusBarDarkFont(true).titleBar(mToolbar).init();
|
|
view = UIUtils.inflate(R.layout.activity_course_order);
|
|
mActivity = this;
|
|
mTv_creat_time = (TextView) view
|
|
.findViewById(R.id.tv_course_creat_time);
|
|
mTv_pay_state = (TextView) view.findViewById(R.id.tv_course_state);
|
|
mTv_pay_to = (TextView) view.findViewById(R.id.tv_pay_to);
|
|
mTv_pay_money = (TextView) view.findViewById(R.id.tv_course_money);
|
|
mTv_course_num = (TextView) view.findViewById(R.id.tv_course_num);
|
|
mTv_pay_mode = (TextView) view.findViewById(R.id.tv_course_pay_mode);
|
|
mTv_pay_time = (TextView) view.findViewById(R.id.tv_course_pay_time);
|
|
mLl_pay_mode = (LinearLayout) view.findViewById(R.id.ll_pay_mode);
|
|
mLl_pay_time = (LinearLayout) view.findViewById(R.id.ll_pay_time);
|
|
mRl_pay = (RelativeLayout) view.findViewById(R.id.ll_to_pay);
|
|
mTv_cancel_time = (TextView) view.findViewById(R.id.textView1);
|
|
mTv_course_title = (TextView) view.findViewById(R.id.tv_course_title);
|
|
mBt_cancel = (Button) view.findViewById(R.id.cancel);
|
|
mBt_pay = (Button) view.findViewById(R.id.bt_pay);
|
|
initIntent();
|
|
mBt_cancel.setOnClickListener(this);
|
|
mBt_pay.setOnClickListener(this);
|
|
return view;
|
|
}
|
|
|
|
private void initIntent() {
|
|
// TODO Auto-generated method stub
|
|
order_id = getIntent().getStringExtra("order_id");
|
|
order_status = getIntent().getStringExtra("order_status");
|
|
providername = getIntent().getStringExtra("providername");
|
|
title = getIntent().getStringExtra("title");
|
|
type = getIntent().getStringExtra("type");
|
|
file_uuid = getIntent().getStringExtra("file_uuid");
|
|
mTv_course_title.setText(title);
|
|
mTv_pay_to.setText(providername);
|
|
mTv_course_num.setText(order_id);
|
|
showProgressDialog("加载中");
|
|
getDetailResult();
|
|
}
|
|
|
|
public void getDetailResult() {
|
|
Map<String, String> param = new HashMap<String, String>();
|
|
param.put("order_id", order_id);
|
|
sendJsonPostParamtoNetSignMD5(Url.getGanDanFileOrderDetial, param, 101,this);
|
|
|
|
}
|
|
|
|
public void getCancleResult() {
|
|
Map<String, String> param = new HashMap<String, String>();
|
|
param.put("order_id", order_id);
|
|
sendParamtoNet(Url.getCancelGanDanFileOrder, param, 102, mActivity,
|
|
true);
|
|
|
|
}
|
|
|
|
@Override
|
|
public ResultState onLoad() {
|
|
// TODO Auto-generated method stub
|
|
return ResultState.STATE_SUCCESSED;
|
|
}
|
|
|
|
@Override
|
|
protected void processClick(View v) {
|
|
// TODO Auto-generated method stub
|
|
// AGP 8.0+ R.id 不再是 final 常量,不能用于 switch,改用 if-else
|
|
int id = v.getId();
|
|
if (id == R.id.bt_pay) {
|
|
Intent intent = new Intent(mActivity, PayCourseActivity.class);
|
|
intent.putExtra("money",
|
|
(int) bean.data.getAccount() + "");
|
|
intent.putExtra("order_id", order_id);
|
|
intent.putExtra("providername", providername);
|
|
|
|
// intent.setType("detail");
|
|
startActivityForResult(intent, 201);
|
|
} else if (id == R.id.cancel) {
|
|
aaa();
|
|
}
|
|
}
|
|
|
|
private ECAlertDialog buildAlert;
|
|
|
|
public void aaa() {
|
|
buildAlert = ECAlertDialog.buildAlert(mActivity, "确定取消此次订单", "取消",
|
|
"确定", new DialogInterface.OnClickListener() {
|
|
@Override
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
// TODO Auto-generated method stub
|
|
buildAlert.dismiss();
|
|
}
|
|
}, new DialogInterface.OnClickListener() {
|
|
@Override
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
getCancleResult();
|
|
buildAlert.dismiss();
|
|
|
|
}
|
|
});
|
|
buildAlert.setTitle("温馨提示");
|
|
buildAlert.setTitleColor(mActivity.getResources().getColor(
|
|
R.color.top_title));
|
|
buildAlert.show();
|
|
}
|
|
|
|
private Timer timer;
|
|
int time;
|
|
|
|
public void WordLight(long times) {
|
|
time = (int) times;
|
|
final TimerTask tast = new TimerTask() {
|
|
@Override
|
|
public void run() {
|
|
Message message = Message.obtain();
|
|
handler.sendMessage(message);
|
|
}
|
|
};
|
|
timer = new Timer();
|
|
timer.schedule(tast, 0, 1000);
|
|
}
|
|
|
|
Handler handler = new Handler() {
|
|
@Override
|
|
public void handleMessage(Message msg) {
|
|
// TODO Auto-generated method stub
|
|
if (time == 0) {
|
|
timer.cancel();
|
|
// mTv_pay_state.setText("已取消");
|
|
mRl_pay.setVisibility(View.GONE);
|
|
// SEND_FRESH_RESULT = 203;
|
|
getDetailResult();
|
|
}
|
|
mTv_cancel_time.setText(secToTime(time));
|
|
time--;
|
|
}
|
|
};
|
|
|
|
public static String secToTime(int time) {
|
|
String timeStr = null;
|
|
int hour = 0;
|
|
int minute = 0;
|
|
int second = 0;
|
|
if (time <= 0)
|
|
return "00:00";
|
|
else {
|
|
minute = time / 60;
|
|
if (minute < 60) {
|
|
second = time % 60;
|
|
timeStr = unitFormat(minute) + ":" + unitFormat(second);
|
|
} else {
|
|
hour = minute / 60;
|
|
if (hour > 99)
|
|
return "99:59:59";
|
|
minute = minute % 60;
|
|
second = time - hour * 3600 - minute * 60;
|
|
timeStr = unitFormat(hour) + ":" + unitFormat(minute) + ":"
|
|
+ unitFormat(second);
|
|
}
|
|
}
|
|
return timeStr;
|
|
}
|
|
|
|
public static String unitFormat(int i) {
|
|
String retStr = null;
|
|
if (i >= 0 && i < 10)
|
|
retStr = "0" + Integer.toString(i);
|
|
else
|
|
retStr = "" + i;
|
|
return retStr;
|
|
}
|
|
|
|
/**
|
|
* 201 不刷新 202待支付变成已支付 203待支付变成已取消
|
|
*/
|
|
public int SEND_FRESH_RESULT = 201;
|
|
|
|
@Override
|
|
public void onCallbackFromThread(String resultJson) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
private String system_time;
|
|
|
|
@Override
|
|
public void onCallBackFromThread(String resultJson, int resultCode) {
|
|
Log.d("WXEntryActivity",resultCode+" "+resultJson);
|
|
// TODO Auto-generated method stub
|
|
switch (resultCode) {
|
|
case 101:
|
|
closeProgressDialog();
|
|
preaseData(resultJson);
|
|
break;
|
|
case 102:
|
|
if (resultJson.equals("\"SUCCEED\"")) {
|
|
SEND_FRESH_RESULT = 203;
|
|
timer.cancel();
|
|
mTv_pay_state.setText("已取消");
|
|
mRl_pay.setVisibility(View.GONE);
|
|
ToastUtil.showMessage("取消成功");
|
|
} else {
|
|
ToastUtil.showMessage("取消失败");
|
|
}
|
|
break;
|
|
case 104:
|
|
JSONObject objs2;
|
|
try {
|
|
objs2 = new JSONObject(resultJson);
|
|
system_time = objs2.getString("system_time");
|
|
} catch (JSONException e) {
|
|
// TODO Auto-generated catch block
|
|
|
|
}
|
|
|
|
// 文件保存到应用私有目录(getExternalFilesDir),Android 13+ 不需要存储权限
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
boolean needsPermission = Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU;
|
|
boolean hasPermission = true;
|
|
|
|
if (needsPermission) {
|
|
// Android 12及以下需要存储权限
|
|
hasPermission = PermissionsUtil.hasPermission(CourseDetailOrderActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
|
}
|
|
// Android 13+ 保存到应用私有目录不需要权限
|
|
|
|
if (hasPermission) {
|
|
getDownLoadResult();
|
|
} else {
|
|
EasyWindow.with(CourseDetailOrderActivity.this).setGravity(Gravity.TOP).setYOffset(200).setWidth(1000)
|
|
|
|
.setContentView(R.layout.float_top_dialog_download).show();
|
|
PermissionsUtil.requestPermission(CourseDetailOrderActivity.this, new PermissionListener() {
|
|
@Override
|
|
public void permissionGranted(@NonNull String[] permissions) {
|
|
EasyWindow.cancelAll();
|
|
getDownLoadResult();
|
|
|
|
}
|
|
|
|
@Override
|
|
public void permissionDenied(@NonNull String[] permissions) {
|
|
EasyWindow.cancelAll();
|
|
//用户拒绝了访问读写的申请
|
|
//
|
|
}
|
|
|
|
}, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE});
|
|
}
|
|
|
|
} else {
|
|
getDownLoadResult();
|
|
}
|
|
|
|
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
private HttpHandler<File> hand;
|
|
// private String filePath = Environment.getExternalStorageDirectory()
|
|
// .getAbsolutePath() + "/gdxzExpert/download/肝胆课件/";
|
|
private String filePath =getContext().getExternalFilesDir("").getAbsolutePath()+"/gdxzExpert/download/肝胆课件/";
|
|
public void getDownLoadResult() {
|
|
int a = StringUtil.getnum();
|
|
// 下载pdf
|
|
if (Environment.getExternalStorageState().equals(
|
|
Environment.MEDIA_MOUNTED)) {
|
|
// sdcard存在
|
|
HttpUtils http = new HttpUtils();
|
|
RequestParams params = new RequestParams();
|
|
params.addHeader("Cookie", "token=" + Constant.YKToken);
|
|
params.addHeader("Doc-Client", "medicool-android");
|
|
// params.addHeader("Content-Type", "application/json");
|
|
// + "bean.title===" + bean.getTitle());
|
|
// http.download(url, target, params, autoResume, callback)
|
|
final String path = filePath + file_uuid + "." + type.trim();
|
|
// 下载的路径,及app安装包的命名
|
|
// ***************************************************
|
|
hand = http.download(Url.getDownloadGanDanFile + "?gdf="
|
|
+ getGdf(a) + "&a=" + a, path, params, false, // 如果目标文件存在,接着未完成的部分继续下载。服务器不支持RANGE时将从新下载。
|
|
false, // 如果从请求返回信息中获取到文件名,下载完成后自动重命名。
|
|
new RequestCallBack<File>() {
|
|
|
|
private DownloadModel downloadModel;
|
|
|
|
/** 下载开始 **/
|
|
@Override
|
|
public void onStart() {
|
|
ToastUtil.showToast("开始下载");
|
|
|
|
// 插入下载数据库
|
|
downloadModel = new DownloadModel(file_uuid);
|
|
downloadModel.setTitle(title);// 设置标题
|
|
downloadModel.setCurrentProgress(providername);
|
|
downloadModel.setFilePath(path);// 设置文件下载路径
|
|
downloadModel.setFileFormat(type.trim());// 设置文件格式
|
|
downloadModel.setState(1);// 0未下载,1下载中,2已下载
|
|
CoursewareBookDownloadSqlManager
|
|
.insertDownload(downloadModel);
|
|
// 异步显示
|
|
ToastUtil.showMessage("下载中");
|
|
|
|
}
|
|
|
|
/** 下载中与进度 **/
|
|
@Override
|
|
public void onLoading(long total, long current,
|
|
boolean isUploading) {
|
|
}
|
|
|
|
/** 下载完成 **/
|
|
@Override
|
|
public void onSuccess(ResponseInfo<File> responseInfo) {
|
|
// 更新下载状态为完成
|
|
if (downloadModel == null) {
|
|
downloadModel = new DownloadModel(file_uuid);
|
|
}
|
|
downloadModel.setState(2);// 0未下载,1下载中,2已下载
|
|
CoursewareBookDownloadSqlManager
|
|
.updateDownloadState(downloadModel);
|
|
// 异步显示
|
|
ToastUtil.showToast("下载完成!");
|
|
// 查看
|
|
// getaddWanFangCount();
|
|
|
|
}
|
|
|
|
/** 下载失败 **/
|
|
@Override
|
|
public void onFailure(HttpException error, String msg) {
|
|
ToastUtil.showToast("下载失败!");
|
|
// 更新下载状态为未下载
|
|
if (downloadModel == null) {
|
|
downloadModel = new DownloadModel(file_uuid);
|
|
}
|
|
downloadModel.setState(0);// 0未下载,1下载中,2已下载
|
|
CoursewareBookDownloadSqlManager
|
|
.updateDownloadState(downloadModel);
|
|
}
|
|
});
|
|
} else {
|
|
ToastUtil.showToast("SD卡不存在,无法下载");
|
|
return;
|
|
}
|
|
}
|
|
public String getGdf(int a) {
|
|
String expert_uuid=SharePrefUtil.getString(mActivity, "uuid", "");
|
|
String mc = null;
|
|
try {
|
|
mc = StringUtil.getRandomString(a)
|
|
+ AESUtil.Encrypt(file_uuid + "|" + order_id + "|" + expert_uuid
|
|
+ "|" + system_time, "deoep09_klodLdAo");
|
|
} catch (Exception e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
}
|
|
return mc;
|
|
}
|
|
CourseOrderBean bean;
|
|
|
|
public void preaseData(String result) {
|
|
System.out.println(" result == "+result);
|
|
try {
|
|
bean = GsonTools.fromGsonToBean(result, CourseOrderBean.class);
|
|
} catch (Exception e) {
|
|
// TODO Auto-generated catch block
|
|
}
|
|
if (bean != null && bean.data != null) {
|
|
if (bean.data.getOrder_status().equals("created")) {
|
|
mTv_pay_state.setText("待付款");
|
|
SimpleDateFormat sdf = new SimpleDateFormat(
|
|
"yyyy-MM-dd HH:mm:ss");
|
|
//
|
|
// String sd = sdf.format(new Date(bean.pingGanDanFileOrder
|
|
// .getCreate_date() * 1000));
|
|
// mTv_creat_time.setText(sd);
|
|
mTv_pay_money.setText(String.format("%.2f",
|
|
bean.data.getAccount() / 100) + "元");
|
|
mRl_pay.setVisibility(View.VISIBLE);
|
|
WordLight(bean.data.getExpire_time()
|
|
- bean.data.getSystem_time());
|
|
|
|
}
|
|
if (bean.data.getOrder_status().equals("paid")) {
|
|
mTv_pay_state.setText("已支付");
|
|
SEND_FRESH_RESULT = 202;
|
|
// SimpleDateFormat sdf = new SimpleDateFormat(
|
|
// "yyyy-MM-dd HH:mm:ss");
|
|
//
|
|
// String CreatTime = sdf.format(new Date(bean.pingGanDanFileOrder
|
|
// .getCreate_date() * 1000));
|
|
mTv_creat_time.setText(bean.data
|
|
.getCreate_date());
|
|
// String PaytTime = sdf.format(new Date(bean.pingGanDanFileOrder
|
|
// .getPay_time() * 1000));
|
|
mTv_pay_time.setText(bean.data
|
|
.getPay_time());
|
|
if ("wx".equals(bean.data.getPay_channel())) {
|
|
|
|
mTv_pay_mode.setText("微信支付");
|
|
}
|
|
if ("balance".equals(bean.data.getPay_channel())) {
|
|
mTv_pay_mode.setText("余额支付");
|
|
}
|
|
if ("alipay".equals(bean.data.getPay_channel())) {
|
|
mTv_pay_mode.setText("支付宝支付");
|
|
}
|
|
if ("FREERECORD".equals(bean.data.getPay_channel())) {
|
|
mTv_pay_mode.setText("免费次数");
|
|
}
|
|
if ("FREE".equals(bean.data.getPay_channel())) {
|
|
mTv_pay_mode.setText("免费");
|
|
}
|
|
if (bean.data.getPay_channel()!=null&&bean.data.getPay_channel().contains("upacp")) {
|
|
mTv_pay_mode.setText("银联支付");
|
|
}
|
|
mTv_pay_money.setText(String.format("%.2f",
|
|
bean.data.getAccount() / 100) + "元");
|
|
mLl_pay_mode.setVisibility(View.VISIBLE);
|
|
mLl_pay_time.setVisibility(View.VISIBLE);
|
|
}
|
|
if (bean.data.getOrder_status().equals("canceled")) {
|
|
if (order_status != null && order_status.equals("created")) {
|
|
SEND_FRESH_RESULT = 203;
|
|
}
|
|
mTv_pay_state.setText("已取消");
|
|
SimpleDateFormat sdf = new SimpleDateFormat(
|
|
"yyyy-MM-dd HH:mm:ss");
|
|
//
|
|
// String sd = sdf.format(new Date(bean.pingGanDanFileOrder
|
|
// .getCreate_date() * 1000));
|
|
// mTv_creat_time.setText(sd);
|
|
mTv_pay_money.setText(String.format("%.2f",
|
|
bean.data.getAccount() / 100) + "元");
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
// TODO Auto-generated method stub
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
if (resultCode == 201) {
|
|
SEND_FRESH_RESULT = 202;
|
|
timer.cancel();
|
|
mRl_pay.setVisibility(View.GONE);
|
|
getDetailResult();
|
|
getSystemTime();
|
|
}
|
|
}
|
|
|
|
public void getSystemTime() {
|
|
Map<String, String> param = new HashMap<String, String>();
|
|
sendParamtoNet(Url.getSystemTime, param, 104, mActivity, true);
|
|
}
|
|
}
|