MultiTitleFragment.java 25.7 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 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732
package com.sunvote.xpadapp.fragments;

import android.annotation.SuppressLint;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.AbsoluteSizeSpan;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnScrollChangeListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sunvote.util.LogUtil;
import com.sunvote.xpadapp.MainActivity;
import com.sunvote.xpadapp.R;
import com.sunvote.xpadapp.base.BaseFragment;
import com.sunvote.xpadapp.db.modal.BillInfo;
import com.sunvote.xpadapp.db.modal.MultiTitleItem;
import com.sunvote.xpadapp.dialog.ToastAlertDialog;
import com.sunvote.xpadapp.fragments.MutilTitleDetailFragment.TitleVoteOnBack;
import com.sunvote.xpadapp.utils.SharedPreferencesUtil;
import com.sunvote.xpadcomm.XPadApi;
import com.sunvote.xpadcomm.XPadApiInterface.VoteInfo;

import java.util.ArrayList;

import static com.sunvote.xpadapp.utils.MyStringUtil.replaceBlank;

public class MultiTitleFragment extends BaseFragment implements TitleVoteOnBack {
    private String TAG = "MultiTitleFragment";
    private ArrayList<MultiTitleItem> aryContent = null;
    BillInfo bill;
    private TextView tvTitle;
    private ListView listview;
    private View tvInfoLayout;
    private TextView tvInfo;
    private TextView tvPage;
    private Button btnConfirm;
    private Button btnModify;

    MutilTitleDetailFragment fDetail;

    private RelativeLayout bottomLayout;
    private RelativeLayout confirmLayout;
    private TextView tvConfirmText;
    private int currIndex;
    private MyAdapter mAdapter;
    private int page = 1;
    private int totalPage;
    private int votedCount;

    // private int modifyable;
    // private int secret;
    // private int less;// 1 不可缺选
    private String[] options;
    private TextView btnAgreeAll;
    private TextView btnOpposeAll;
    private TextView btnAbstainAll;
    public VoteInfo voteInfo;
    private String voteValues;
    private Handler handler;

    public void setInfo(BillInfo info, VoteInfo vtInfo, ArrayList<MultiTitleItem> subInfo) {
        voteInfo = vtInfo;
        bill = info;
        if (bill.billOptions != null) {
            options = bill.billOptions.split("/");
            for (int i = 0; i < options.length; i++) {
                options[i] = replaceBlank(options[i]);
            }
        }
        aryContent = subInfo;
        votedCount = 0;
        totalPage = aryContent.size() / 3;
        if (aryContent.size() % 3 > 0) {
            totalPage++;
        }

    }

    @SuppressLint("NewApi")
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        LogUtil.d(TAG, "onCreateView");
        View view = inflater.inflate(R.layout.fragment_multi_title, container, false);
        view.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ;// 屏蔽点击到上层fragment
            }
        });
        final MainActivity mact = (MainActivity) getActivity();
        handler = new Handler();
        listview = (ListView) view.findViewById(R.id.multivote_listview);
        listview.setFastScrollAlwaysVisible(false);
        mAdapter = new MyAdapter(getActivity());
        listview.setAdapter(mAdapter);
        listview.setFastScrollAlwaysVisible(false);
        tvTitle = (TextView) view.findViewById(R.id.multivote_title);
        tvTitle.setText(replaceBlank(bill.title));

        tvInfoLayout =  view.findViewById(R.id.multivote_info_layout);
        tvInfo = (TextView) view.findViewById(R.id.multivote_info);
        tvInfo.setText("");
        tvInfo.setBackgroundResource(0);
        tvInfoLayout.setVisibility(View.GONE);
        tvInfoLayout.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        bottomLayout = (RelativeLayout) view.findViewById(R.id.multivote_pannal_bottom);
        confirmLayout = (RelativeLayout) view.findViewById(R.id.multivote_confirm_panel);
        tvConfirmText = (TextView) view.findViewById(R.id.multivote_confirm_text);

        // tvPage = (TextView) view.findViewById(R.id.multivote_page);


        btnConfirm = (Button) view.findViewById(R.id.multivote_btn_submit);
        btnConfirm.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                int remain = aryContent.size() - votedCount;
                if (voteInfo.less == 1) {// 不可缺选
                    if (remain > 0) {
                        ToastAlertDialog.makeText(mMainActivity, "您还有" + remain + "项未表决").show();
                        return;
                    }
                    if (voteInfo.mode2_modify == 1) {
                        doSubmitAllOk();
                    } else {
                        tvConfirmText.setText("投票后不可修改,确定提交吗?");
                        confirmLayout.setVisibility(View.VISIBLE);
                    }

                } else {
                    if (remain > 0) {
                        tvConfirmText.setText("您还有" + remain + "项未表决,确定提交吗?");
                        confirmLayout.setVisibility(View.VISIBLE);
                    } else {
                        if (voteInfo.mode2_modify == 1) {
                            doSubmitAllOk();
                        } else {
                            tvConfirmText.setText("投票后不可修改,确定提交吗?");
                            confirmLayout.setVisibility(View.VISIBLE);
                        }
                    }
                }

            }


        });

        btnModify = (Button) view.findViewById(R.id.multivote_btn_modify);
        btnModify.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // mMainActivity.presenter.cancelSubmitVoteAllOK();
                showVote(true);
                tvInfoLayout.setVisibility(View.GONE);
            }
        });

        Button btnConfirmOk = (Button) view.findViewById(R.id.multivote_confirm_btn_ok);
        btnConfirmOk.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                doSubmitAllOk();
                confirmLayout.setVisibility(View.GONE);
            }
        });

        Button btnConfirmCancel = (Button) view.findViewById(R.id.multivote_confirm_btn_cancel);
        btnConfirmCancel.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                confirmLayout.setVisibility(View.GONE);
            }
        });

        btnAgreeAll = (TextView) view.findViewById(R.id.multi_title_btn_agree_all);
        btnOpposeAll = (TextView) view.findViewById(R.id.multi_title_btn_oppose_all);
        btnAbstainAll = (TextView) view.findViewById(R.id.multi_title_btn_abstain_all);
        btnAgreeAll.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                selectAllWithValue(1);
            }
        });
        btnOpposeAll.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                selectAllWithValue(2);
            }
        });
        btnAbstainAll.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                selectAllWithValue(3);
            }
        });

        listview.setOnScrollChangeListener(new OnScrollChangeListener() {

            @Override
            public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
                // TODO Auto-generated method stub
                // int index = listview.getFirstVisiblePosition();
                // page = index / 3 + 1;
                // if ((index + 3) >= aryContent.size()) {
                // page = totalPage;
                // }
                // tvPage.setText(page + "/" + totalPage);

            }
        });

        // tvPage.setText(page + "/" + totalPage);
        tvInfo.setText("");
        tvInfoLayout.setVisibility(View.GONE);
        showVote(false);
        checkIsVoted();
        return view;
    }

    @Override
    public void onResume() {
        LogUtil.d(TAG, "onResume");
        super.onResume();
    }

    @Override
    public void onStart() {
        LogUtil.d(TAG, "onStart");
        super.onStart();
    }

    @Override
    public void onPause() {
        LogUtil.d(TAG, "onStart");
        super.onPause();
    }

    private void doSubmitAllOk() {
		tvInfo.setText(getString(R.string.submiting));
		tvInfo.setBackgroundResource(0);
        btnConfirm.setEnabled(false);
        disableVote();
        mMainActivity.presenter.submitVoteAllOK();
    }

    private void selectAllWithValue(final int val) {
        mMainActivity.presenter.submitVote(XPadApi.AnsType_BatchSingle, 65534 + ":" + val);// 0xfffe 表示全操作
        for (int i = 0; i < aryContent.size(); i++) {
            MultiTitleItem it = aryContent.get(i);
            it.result = 0;
        }
        mAdapter.notifyDataSetChanged();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < aryContent.size(); i++) {
                    MultiTitleItem it = aryContent.get(i);
                    if (it.result != val) {
                        it.result = val;
                    }
                }
                mAdapter.notifyDataSetChanged();
                checkVoted();
            }
        },200);

    }

    private void hideVote() {
        btnAgreeAll.setVisibility(View.GONE);
        btnOpposeAll.setVisibility(View.GONE);
        btnAbstainAll.setVisibility(View.GONE);
        btnConfirm.setVisibility(View.INVISIBLE);
        for (int i = 0; i < aryContent.size(); i++) {
            MultiTitleItem it = aryContent.get(i);
            it.startVote = false;
        }
        mAdapter.notifyDataSetChanged();
        if (fDetail != null) {
            fDetail.hideVote();
        }
    }

    private void disableVote() {
        btnAgreeAll.setVisibility(View.INVISIBLE);
        btnOpposeAll.setVisibility(View.INVISIBLE);
        btnAbstainAll.setVisibility(View.GONE);
        if (fDetail != null) {
            fDetail.disableVote();
        }
        for (int i = 0; i < aryContent.size(); i++) {
            MultiTitleItem it = aryContent.get(i);
            it.startVote = false;
        }
        mAdapter.notifyDataSetChanged();
        btnConfirm.setEnabled(false);
    }

    private void showVote() {

        if (options != null && options.length > 0) {
            btnAgreeAll.setVisibility(View.VISIBLE);
            btnAgreeAll.setText(getString(R.string.all) + options[0]);
        }
        if (options != null && options.length > 1) {
            btnOpposeAll.setVisibility(View.VISIBLE);
            btnOpposeAll.setText(getString(R.string.all) + options[1]);
        }
        if (options != null && options.length == 3) {
            btnAbstainAll.setText(getString(R.string.all) + options[2]);
            btnAbstainAll.setVisibility(View.VISIBLE);
        } else {
            btnAbstainAll.setVisibility(View.GONE);
        }
        btnConfirm.setEnabled(true);
        btnConfirm.setVisibility(View.VISIBLE);

        btnModify.setVisibility(View.INVISIBLE);
        if (fDetail != null) {
            fDetail.showVote();
        }
        SpannableStringBuilder text1= new SpannableStringBuilder(replaceBlank(bill.title));
        text1.setSpan(new AbsoluteSizeSpan(70), 0, text1.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        if (voteInfo.less == 1) {// 迫选
            SpannableStringBuilder text= new SpannableStringBuilder( "(总共" + aryContent.size() + "项, 不可缺选)");
            text.setSpan(new AbsoluteSizeSpan(45), 0, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            tvTitle.setText(text1.append(text));
        } else {
            SpannableStringBuilder text= new SpannableStringBuilder( "(总共" + aryContent.size() + "项)");
            text.setSpan(new AbsoluteSizeSpan(45), 0, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            tvTitle.setText(text1.append(text));
        }
    }

    private void showVote(boolean isModify) {

        if (options != null && options.length > 0) {
            btnAgreeAll.setVisibility(View.VISIBLE);
            btnAgreeAll.setText(getString(R.string.all) + options[0]);
        }
        if (options != null && options.length > 1) {
            btnOpposeAll.setVisibility(View.VISIBLE);
            btnOpposeAll.setText(getString(R.string.all) + options[1]);
        }
        if (options != null && options.length == 3) {
            btnAbstainAll.setText(getString(R.string.all) + options[2]);
            btnAbstainAll.setVisibility(View.VISIBLE);
        } else {
            btnAbstainAll.setVisibility(View.GONE);
        }
        btnConfirm.setEnabled(true);
        btnConfirm.setVisibility(View.VISIBLE);

        btnModify.setVisibility(View.INVISIBLE);
        for (int i = 0; i < aryContent.size(); i++) {
            MultiTitleItem it = aryContent.get(i);
            if (!isModify) {
                it.result = 0;
            }
            it.startVote = true;
        }
        if (fDetail != null) {
            fDetail.showVote();
        }
        mAdapter.notifyDataSetChanged();
        SpannableStringBuilder text1= new SpannableStringBuilder(replaceBlank(bill.title));
        text1.setSpan(new AbsoluteSizeSpan(70), 0, text1.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        if (voteInfo.less == 1) {// 迫选
            SpannableStringBuilder text= new SpannableStringBuilder( "(总共" + aryContent.size() + "项, 不可缺选)");
            text.setSpan(new AbsoluteSizeSpan(45), 0, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            tvTitle.setText(text1.append(text));
        } else {
            SpannableStringBuilder text= new SpannableStringBuilder( "(总共" + aryContent.size() + "项)");
            text.setSpan(new AbsoluteSizeSpan(45), 0, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            tvTitle.setText(text1.append(text));
        }
        checkVoted();
    }

    private void showModifyOrDisable() {
        if (voteInfo.mode2_modify == 1) {
            btnModify.setVisibility(View.VISIBLE);
//            tvInfo.setText(getString(R.string.submited));
            tvInfo.setBackgroundResource(R.drawable.voted);
            tvInfoLayout.setVisibility(View.VISIBLE);
        } else {
            disableVote();
//            tvInfo.setText(getString(R.string.submited));
            tvInfo.setBackgroundResource(R.drawable.voted);
            tvInfoLayout.setVisibility(View.VISIBLE);
//            tvInfo.setText(getString(R.string.submited_no_modify));
        }
        if(voteInfo.mode3_secret != 0){
            for (int i = 0; i < aryContent.size(); i++) {
                try {
                    MultiTitleItem it = aryContent.get(i);
                    it.result = 0;
                } catch (Exception ex) {
                }
            }
            mAdapter.notifyDataSetChanged();

        }
    }

    /*
        @Override
        public void onVoteEvent(VoteInfo info) {
            voteInfo = info;
            if (info.mode == XPadApi.VoteType_BatchVote) {

                showVote(false);

            } else if (info.mode == XPadApi.VoteType_Stop) {
                hideVote();
                btnModify.setVisibility(View.INVISIBLE);
            }

        }
    */
    @Override
    public void onVoteSubmitSuccess() {

        if (fDetail != null) {
            fDetail.onVoteSubmitSuccess();
        }

    }

    @Override
    public void onVoteSubmitAllOkSuccess() {
        //tvInfo.setText("已提交");

        hideVote();
        showModifyOrDisable();
        saveVoteInfo();

    }

    @Override
    public void onVoteSubmitError(XPadApi.VoteResultItem item) {
        super.onVoteSubmitError();
        if (item != null) {
            if (item.retBack.contains(65534 + ":")) {
                for (int i = 0; i < aryContent.size(); i++) {
                    aryContent.get(i).result = 0;
                    aryContent.get(i).submited = false;
                    aryContent.get(i).startVote = true;
                }
            } else {
                for (int i = 0; i < aryContent.size(); i++) {
                    String str = aryContent.get(i).No + ":" + aryContent.get(i).result;
                    if (str.equals(item.retBack)) {
                        aryContent.get(i).result = 0;
                        aryContent.get(i).submited = false;
                        aryContent.get(i).startVote = true;
                    }
                }
            }
        }
        mAdapter.notifyDataSetChanged();
        checkVoted();
        showVote();
    }

    @Override
    public void onVoteSubmitSuccess(XPadApi.VoteResultItem item) {
        super.onVoteSubmitSuccess(item);
        if (item != null) {
            if (item.retBack.contains(65534 + ":")) {
                for (int i = 0; i < aryContent.size(); i++) {
                    aryContent.get(i).submited = true;
                }
            } else {
                for (int i = 0; i < aryContent.size(); i++) {
                    String str = aryContent.get(i).No + ":" + aryContent.get(i).result;
                    if (str.equals(item.retBack)) {
                        aryContent.get(i).submited = true;
                    }
                }
            }
        }
    }

    private void saveVoteInfo() {
        StringBuilder values = new StringBuilder("");
        for (int i = 0; i < aryContent.size(); i++) {
            MultiTitleItem it = aryContent.get(i);
            values.append(it.result).append(",");
        }
        if (values != null && values.length() > 1) {
            values.deleteCharAt(values.length() - 1);
        }
        voteValues = values.toString();
        SharedPreferencesUtil.saveData(getActivity(), DATAPOS, Integer.valueOf(voteInfo.dataPos));
        SharedPreferencesUtil.saveData(getActivity(), VOTEMODE, Integer.valueOf(voteInfo.mode));
        SharedPreferencesUtil.saveData(getActivity(), VOTEVALUES, voteValues);
    }

    private void checkIsVoted() {
        LogUtil.i(TAG, "checkIsVoted: ");
        Integer datapos = (Integer) SharedPreferencesUtil.getData(getActivity(), DATAPOS, Integer.valueOf(-1));
        Integer votemode = (Integer) SharedPreferencesUtil.getData(getActivity(), VOTEMODE, Integer.valueOf(-1));
        String voteValues = (String) SharedPreferencesUtil.getData(getActivity(), VOTEVALUES, "");

        LogUtil.i(TAG, "checkIsVoted: datapos:" + datapos.intValue() + " voteMode:" + votemode.intValue() + " val:" + voteValues);
        if (datapos.intValue() == voteInfo.dataPos && votemode.intValue() == voteInfo.mode && voteValues.length() > 0) {

            String[] ary = voteValues.split(",");
            for (int i = 0; i < aryContent.size(); i++) {
                try {
                    MultiTitleItem it = aryContent.get(i);
                    it.result = Integer.parseInt(ary[i]);
                } catch (Exception ex) {
                }
            }
            hideVote();
            showModifyOrDisable();


            mAdapter.notifyDataSetChanged();
            checkVoted();


        }
    }

    /*
     * MyAdapter
     *
     */
    private class MyAdapter extends BaseAdapter {

        private LayoutInflater mInflater; //

        public MyAdapter(Context context) {
            this.mInflater = LayoutInflater.from(context);
        }

        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return aryContent.size();
        }

        @Override
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return aryContent.get(position);
        }

        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return position;
        }

        @Override
        public boolean isEnabled(int position) {
            // TODO Auto-generated method stub

            return super.isEnabled(position);
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            ViewHolder holder;
            LogUtil.v("BaseAdapterTest", "getView " + position + " " + convertView);

            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.list_multi_title_item, null);
                holder = new ViewHolder();

                holder.tvNum = (TextView) convertView.findViewById(R.id.list_multivote_item_num);
                holder.tvContent = (TextView) convertView.findViewById(R.id.list_multivote_item_content);
                holder.btnVote1 = (TextView) convertView.findViewById(R.id.list_multivote_item_btnvote1);
                holder.btnVote2 = (TextView) convertView.findViewById(R.id.list_multivote_item_btnvote2);// to
                holder.btnVote3 = (TextView) convertView.findViewById(R.id.list_multivote_item_btnvote3);
                holder.ivResult = (TextView) convertView.findViewById(R.id.list_multivote_item_tv_result);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }


            MultiTitleItem it = aryContent.get(position);
            holder.tvNum.setText(String.valueOf(it.No));
            holder.tvContent.setText(it.title);
            if (it.result > 0) {
                holder.ivResult.setVisibility(View.VISIBLE);
                if (voteInfo.mode3_secret == 0) {

                    holder.ivResult.setText(options[it.result - 1]);
                    holder.ivResult.setBackgroundResource(R.drawable.voted_empty);

                } else {
                    holder.ivResult.setText("");
                    holder.ivResult.setBackgroundResource(R.drawable.voted);
                }
            } else {
                holder.ivResult.setVisibility(View.INVISIBLE);
            }

            if (it.startVote) {
                holder.btnVote1.setText(options[0]);
                holder.btnVote2.setText(options[1]);
                holder.btnVote1.setVisibility(View.VISIBLE);
                holder.btnVote2.setVisibility(View.VISIBLE);

                if (options.length == 3) {
                    holder.btnVote3.setText(options[2]);
                    holder.btnVote3.setVisibility(View.VISIBLE);
                } else {
                    holder.btnVote3.setVisibility(View.GONE);
                }

            } else {
                holder.btnVote1.setVisibility(View.INVISIBLE);
                holder.btnVote2.setVisibility(View.INVISIBLE);
                holder.btnVote3.setVisibility(View.GONE);
            }


            holder.btnVote1.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    currIndex = position;
                    voteWithValue(position, 1);
                }
            });

            holder.btnVote2.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    currIndex = position;
                    voteWithValue(position, 2);
                }
            });
            holder.btnVote3.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    currIndex = position;
                    voteWithValue(position, 3);
                }
            });

            return convertView;
        }

        private void voteWithValue(int pos,final int val) {
            final MultiTitleItem it = aryContent.get(pos);
            if (it.result != val || !it.submited) {
                it.result = 0;
                mAdapter.notifyDataSetChanged();
            }
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    if (it.result != val || !it.submited) {
                        it.result = val;
                        mMainActivity.presenter.submitVote(XPadApi.AnsType_BatchSingle, it.No + ":" + val);
                        mAdapter.notifyDataSetChanged();
                    }
                    checkVoted();
                }
            },500);

        }

        private void showDetail(MultiTitleItem item) {
            FragmentManager fm = getFragmentManager();
            FragmentTransaction tx = fm.beginTransaction();
            fDetail = new MutilTitleDetailFragment();
            fDetail.setInfo(item, MultiTitleFragment.this);
            fDetail.options = options;
            fDetail.bill = bill;
            tx.add(R.id.frame_content, fDetail, "fDetail");
            tx.addToBackStack(null);
            tx.commit();
        }


        public final class ViewHolder {
            public TextView tvNum;
            public TextView tvContent;
            public TextView btnVote1;
            public TextView btnVote2;
            public TextView btnVote3;
            public TextView ivResult;
        }
    }

    private void checkVoted() {
        votedCount = 0;
        for (int i = 0; i < aryContent.size(); i++) {
            MultiTitleItem it = aryContent.get(i);
            if (it.result > 0) {
                votedCount++;
            }
        }

    }

    @Override
    public void onBack() {
        mAdapter.notifyDataSetChanged();
        checkVoted();
    }


}