MutilTitleDetailFragment.java
5.23 KB
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
package com.sunvote.xpadapp.fragments;
import com.sunvote.util.LogUtil;
import com.sunvote.xpadapp.MainActivity;
import com.sunvote.xpadapp.R;
import com.sunvote.xpadapp.base.SuperBaseFragment;
import com.sunvote.xpadapp.db.modal.BillInfo;
import com.sunvote.xpadapp.db.modal.MultiTitleItem;
import com.sunvote.xpadcomm.XPadApi;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
public class MutilTitleDetailFragment extends SuperBaseFragment {
private String TAG = "MutileTitleDetail";
private MultiTitleItem data;
private TextView tvTitle;
private TextView tvTips;
private TextView ivReuslt;
private Button btnA;
private Button btnB;
private Button btnC;
public String[] options;
public int modifyable;
public int secret;
public BillInfo bill;
boolean submited = false;
private TitleVoteOnBack ls;
public interface TitleVoteOnBack {
void onBack();
}
public void setInfo(MultiTitleItem item, TitleVoteOnBack listener) {
data = item;
ls = listener;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
LogUtil.d(TAG, "onCreateView");
View view = inflater.inflate(R.layout.fragment_multi_title_detail, container, false);
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
;
}
});
final MainActivity mact = (MainActivity) getActivity();
tvTitle = (TextView) view.findViewById(R.id.mutli_title_detail_content);
if (data.title != null) {
tvTitle.setText(data.title);
}
tvTips = (TextView) view.findViewById(R.id.mutli_title_detail_tv_tips);
ivReuslt = (TextView) view.findViewById(R.id.mutli_title_detail_tv_result);
ivReuslt.setVisibility(View.INVISIBLE);
btnA = (Button) view.findViewById(R.id.mutli_title_detail_btnA);
btnA.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
doVoteWithIndex(1);
}
});
btnB = (Button) view.findViewById(R.id.mutli_title_detail_btnB);
btnB.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
doVoteWithIndex(2);
}
});
btnC = (Button) view.findViewById(R.id.mutli_title_detail_btnC);
btnC.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (options.length == 2) {
doVoteWithIndex(2);
} else {
doVoteWithIndex(3);
}
}
});
ImageButton btnBack = (ImageButton) view.findViewById(R.id.mutli_title_detail_btnback);
btnBack.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
goBack();
}
});
if (options.length == 2) {
btnA.setText(options[0]);
btnB.setVisibility(View.INVISIBLE);
btnC.setText(options[1]);
} else if (options.length == 3) {
btnA.setText(options[0]);
btnB.setText(options[1]);
btnC.setText(options[2]);
}
if (data.startVote) {
showVote();
// if(!data.submited){
// showVote();
// }else{
// hideVote();
// }
} else {
hideVote();
}
showResult();
return view;
}
private void doVoteWithIndex(int index) {
data.result = index;
mMainActivity.presenter.submitVote(XPadApi.AnsType_BatchSingle, data.No + ":" + index);
showResult();
// new Thread(new Runnable() {
// public void run() {
// disableVote();
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// goBack();
// }
// }).start();
// if (modifyable == 1) {
// // showModify();
// } else {
disableVote();
// }
}
private void showResult(){
if(data.result>0){
if (secret == 0) {
if (bill.billType == BillInfo.BillType_Vote) {
ivReuslt.setText("");
ivReuslt.setBackgroundResource(getResultResourceByTitle(options[data.result-1]));
} else if (bill.billType == BillInfo.BillType_Evaluate) {
ivReuslt.setText(options[data.result-1]);
ivReuslt.setBackgroundResource(R.drawable.voted_empty);
}
} else {
ivReuslt.setText("");
ivReuslt.setBackgroundResource(R.drawable.voted);
}
ivReuslt.setVisibility(View.VISIBLE);
}else{
ivReuslt.setVisibility(View.INVISIBLE);
}
}
private void goBack() {
FragmentManager fm = getFragmentManager();
FragmentTransaction tx = fm.beginTransaction();
tx.remove(MutilTitleDetailFragment.this);
tx.commit();
ls.onBack();
}
public void hideVote() {
btnA.setVisibility(View.INVISIBLE);
btnB.setVisibility(View.INVISIBLE);
btnC.setVisibility(View.INVISIBLE);
ivReuslt.setVisibility(View.INVISIBLE);
tvTips.setVisibility(View.INVISIBLE);
}
public void showVote() {
btnA.setVisibility(View.VISIBLE);
if(options.length==3){
btnB.setVisibility(View.VISIBLE);
}else{
btnB.setVisibility(View.INVISIBLE);
}
btnC.setVisibility(View.VISIBLE);
tvTips.setVisibility(View.VISIBLE);
}
public void disableVote() {
btnA.setEnabled(false);
btnB.setEnabled(false);
btnC.setEnabled(false);
}
public void onVoteSubmitSuccess() {
goBack();
}
}