-
Notifications
You must be signed in to change notification settings - Fork 1
/
OrderDetailActivity.java
187 lines (163 loc) · 6.21 KB
/
OrderDetailActivity.java
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package com.tudaidai.tuantrip;
import com.tudaidai.tuantrip.app.TuanTripApp;
import com.tudaidai.tuantrip.types.BaseResult;
import com.tudaidai.tuantrip.types.Order;
import com.tudaidai.tuantrip.util.NotificationsUtil;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class OrderDetailActivity extends Activity {
static final boolean DEBUG = TuanTripSettings.DEBUG;
public static final String EXTRA_ORDER = "com.tudaidai.tuantrip.OrderDetailActivity.ORDER";
static final String TAG = "OrderDetailActivity";
private Order order;
private ProgressDialog mProgressDialog;
private void dismissProgressDialog() {
mProgressDialog.dismiss();
}
private void startProgressBar(String title, String content) {
mProgressDialog = ProgressDialog.show(this, title, content);
mProgressDialog.show();
}
private void ensureUi() {
TextView travelDate = (TextView) findViewById(R.id.travelDateText);
travelDate.setText(order.getTravelDate());
TextView titleView = (TextView) findViewById(R.id.titleText);
titleView.setText(order.getShortTitle());
// TextView codeText = (TextView)findViewById(R.id.codeText);
// codeText.setText(order.getCode());
TextView cityText = (TextView) findViewById(R.id.cityText);
cityText.setText(order.getCityName());
TextView numText = (TextView) findViewById(R.id.numText);
numText.setText(order.getQuantity());
TextView priceText = (TextView) findViewById(R.id.priceText);
priceText.setText(order.getPrice());
TextView stateText = (TextView) findViewById(R.id.stateText);
if (order.getOrderStatus().equals("unpay")) {
stateText.setText("未付款");
} else if (order.getOrderStatus().equals("pay")) {
stateText.setText("已付款");
} else if (order.getOrderStatus().equals("end")) {
stateText.setText("过期");
} else if (order.getOrderStatus().equals("refunded")) {
stateText.setText("已退款");
}
TextView orderTimeText = (TextView) findViewById(R.id.orderTimeText);
orderTimeText.setText(order.getOrderTime());
if (order.getOrderStatus().equals("unpay")) {
LinearLayout layout = (LinearLayout) findViewById(R.id.unpaidLayout);
layout.setVisibility(View.VISIBLE);
Button unpay = (Button) findViewById(R.id.payButton);
unpay.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Dialog dialog = new AlertDialog.Builder(
OrderDetailActivity.this)
.setTitle("提交订单")
.setMessage("确认用余额进行支付吗?")
.setPositiveButton("确定",
new DialogInterface.OnClickListener() {
@Override
public void onClick(
DialogInterface dialog,
int which) {
String[] as = new String[1];
as[0] = order.getOid();
new SubmitOrderTask().execute(as);
}
})
.setNegativeButton("取消",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int whichButton) {
}
}).create();
dialog.show();
}
});
}
}
protected void onCreate(Bundle paramBundle) {
super.onCreate(paramBundle);
setContentView(R.layout.order_detail_activity);
order = (Order) getIntent().getExtras().getParcelable(EXTRA_ORDER);
ensureUi();
}
private void onSubmitTaskComplete(BaseResult baseResult, Exception exception) {
if (baseResult == null) {
NotificationsUtil.ToastReasonForFailure(this, exception);
} else if (baseResult.mHttpResult.getStat() == TuanTripSettings.POSTSUCCESS) {
Toast.makeText(this, baseResult.mHttpResult.getMessage(),
Toast.LENGTH_SHORT).show();
finish();
} else if (baseResult.mHttpResult.getStat() == TuanTripSettings.POSTFAILED) {
Toast.makeText(this, baseResult.mHttpResult.getMessage(),
Toast.LENGTH_SHORT).show();
} else if (baseResult.mHttpResult.getStat() == TuanTripSettings.ISBUY) {
Toast.makeText(this, baseResult.mHttpResult.getMessage(),
Toast.LENGTH_SHORT).show();
} else if (baseResult.mHttpResult.getStat() == TuanTripSettings.LOGINFAILED) {
Toast.makeText(this, baseResult.mHttpResult.getMessage(),
Toast.LENGTH_SHORT).show();
((TuanTrip) getApplication()).loginOut();
Intent localIntent4 = new Intent(this, LoginActivity.class);
localIntent4.putExtra(LoginActivity.EXTRA_OPTION,
LoginActivity.OPTION_SUBMIT_ORDER);
startActivity(localIntent4);
} else {
NotificationsUtil.ToastReasonForFailure(this, exception);
}
dismissProgressDialog();
}
class SubmitOrderTask extends AsyncTask<String, Void, BaseResult> {
private static final boolean DEBUG = TuanTripSettings.DEBUG;
private static final String TAG = "SubmitOrderTask";
private Exception mReason = null;
private SubmitOrderTask() {
}
protected BaseResult doInBackground(String... paramArray) {
if (DEBUG)
Log.d(TAG, "doInBackground()");
BaseResult baseResult = null;
try {
TuanTrip tuanTrip = (TuanTrip) OrderDetailActivity.this
.getApplication();
TuanTripApp tuanTripApp = tuanTrip.getTuanTripApp();
baseResult = tuanTripApp.submitOrder(paramArray[0]);
} catch (Exception localException) {
if (DEBUG)
Log.d(TAG, "Caught Exception.", localException);
this.mReason = localException;
baseResult = null;
}
return baseResult;
}
protected void onCancelled() {
super.onCancelled();
dismissProgressDialog();
}
protected void onPostExecute(BaseResult baseResult) {
if (DEBUG)
Log.d(TAG, "onPostExecute(): ");
onSubmitTaskComplete(baseResult, this.mReason);
}
protected void onPreExecute() {
if (DEBUG)
Log.d(TAG, "onPreExecute()");
startProgressBar("提交订单", "提交订单中...");
}
}
}