/** * VenueBookingFragment.java[v 1.0.0] * class:com.bdyjy.fragment,VenueBookingFragment * �ܺ� create at 2016-4-5 ����2:50:41 */ package com.bdyjy.fragment; import java.util.HashMap; import java.util.List; import android.annotation.SuppressLint; import android.app.Fragment; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; import com.alibaba.fastjson.JSON; import com.bdyjy.R; import com.bdyjy.activity.MainActivity; import com.bdyjy.constants.HandlerOrder; import com.bdyjy.entity.venue.ListTime; import com.bdyjy.entity.venue.MyOrder; import com.bdyjy.entity.venue.MyOrderData; import com.bdyjy.entity.venue.MyOrderDataRow; import com.bdyjy.util.OkHttpUtils; import com.bdyjy.util.SPUtils; /** * com.bdyjy.fragment.VenueBookingFragment * * @author �ܺ�<br/> * create at 2016-4-5 ����2:50:41 */ @SuppressLint("NewApi") public class VenueBookingMyFragment extends Fragment { MainActivity ctx; private Handler handler = null; String toastMsg; private List<MyOrderDataRow> rows; View ll_all; View ll_to_pay; View ll_not_finish; View ll_finished; private void initHandler() { handler = new Handler(ctx.getMainLooper()) { @Override public void handleMessage(Message msg) { switch (msg.what) { case HandlerOrder.TOAST: Toast.makeText(ctx, toastMsg, Toast.LENGTH_LONG).show(); break; case HandlerOrder.PROCESSBAR_SHOW: ctx.showRoundProcessDialog(); break; case HandlerOrder.PROCESSBAR_HIDE: ctx.hideRoundProcessDialog(); break; case HandlerOrder.UPDATE_LISTVIEW: initTable(); break; } } }; } // // ��������� // private Dialog mDialog; // // public void showRoundProcessDialog() // { // mDialog = new AlertDialog.Builder(ctx).create(); // mDialog.setCancelable(false); // mDialog.show(); // // ע��˴�Ҫ����show֮�� ����ᱨ�쳣 // mDialog.setContentView(R.layout.loading_process_dialog_anim); // } // // public void hideRoundProcessDialog() // { // if (null != mDialog && mDialog.isShowing()) // mDialog.hide(); // } /** * */ public VenueBookingMyFragment(MainActivity ctx) { this.ctx = ctx; initHandler(); } private LayoutInflater inflater; private View viewMain; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { this.inflater = inflater; viewMain = inflater.inflate(R.layout.venue_booking_my, null); TextView tv = (TextView) viewMain.findViewById(R.id.tv_title); tv.setText("����Ԥ��-�ҵ�Ԥ��"); viewMain.findViewById(R.id.ll_my).setVisibility(View.INVISIBLE); // ���ذ�ť viewMain.findViewById(R.id.tv_back).setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { if ("psersonCenter".equals(MainActivity.orderFrom)) { ctx.jumpToPersonalCenterFragment(); MainActivity.orderFrom = ""; } else ctx.jumpToFirstPageFregment(); } }); ll_all = viewMain.findViewById(R.id.ll_all); ll_to_pay = viewMain.findViewById(R.id.ll_to_pay); ll_not_finish = viewMain.findViewById(R.id.ll_not_finish); ll_finished = viewMain.findViewById(R.id.ll_finished); // �����л�Ч�� // ȫ�� ll_all.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { initButton(); ll_all.setBackground(getResources().getDrawable( R.drawable.selected_item_bg)); // �������¼������� queryMyOrders(-1); } }); ll_to_pay.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { initButton(); ll_to_pay.setBackground(getResources().getDrawable( R.drawable.selected_item_bg)); queryMyOrders(0); } }); ll_not_finish.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { initButton(); ll_not_finish.setBackground(getResources().getDrawable( R.drawable.selected_item_bg)); queryMyOrders(2); } }); ll_finished.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { initButton(); ll_finished.setBackground(getResources().getDrawable( R.drawable.selected_item_bg)); queryMyOrders(1); } }); queryMyOrders(-1); return viewMain; } private void initButton() { ll_finished.setBackground(getResources().getDrawable( R.drawable.not_selected_item_bg)); ll_to_pay.setBackground(getResources().getDrawable( R.drawable.not_selected_item_bg)); ll_not_finish.setBackground(getResources().getDrawable( R.drawable.not_selected_item_bg)); ll_all.setBackground(getResources().getDrawable( R.drawable.not_selected_item_bg)); } /** * �̣߳������ҵĶ��� * * ������ȫ�� -1��0 δ֧��;1��֧��; 2 ��ȡ��; * * @param id */ private void queryMyOrders(final int status) { new Thread() { @Override public void run() { // ����get���� String res = null; // ��sharePreference��ȡ��֮ǰ�洢�IJ��� String token = (String) SPUtils.get(ctx, "token", ""); String singnature = (String) SPUtils.get(ctx, "singnature", ""); String st = (String) SPUtils.get(ctx, "st", ""); StringBuffer timeStr = new StringBuffer(); if (status != -1) { timeStr.append("&status=" + status); } String httpStr = "/admin/appointmenrecord/grid.do?" + "token=" + token + "&singnature=" + singnature + "&st=" + st + timeStr.toString(); System.out.println(httpStr); try { handler.sendEmptyMessage(HandlerOrder.PROCESSBAR_SHOW); res = OkHttpUtils.getInstance().doGet(ctx, httpStr); handler.sendEmptyMessage(HandlerOrder.PROCESSBAR_HIDE); System.out.println(res); MyOrder bean = JSON.parseObject(res, MyOrder.class); MyOrderData mod = bean.getData(); rows = mod.getRows(); handler.sendEmptyMessage(HandlerOrder.UPDATE_LISTVIEW); } catch (Exception e) { e.printStackTrace(); toastMsg = "��ȡ����ʧ��"; handler.sendEmptyMessage(HandlerOrder.TOAST); return; } } }.start(); } /** * �����ݼ��ص����� */ private void initTable() { LinearLayout ll_list = (LinearLayout) viewMain .findViewById(R.id.ll_list);// �����б� ll_list.removeAllViews(); // ����list for (MyOrderDataRow r : rows) { View item = inflater.inflate(R.layout.venue_order_item, null);// ÿһ��item r.getId();// ����id r.getRoomId();// ����id r.getAmount();// Ԥ������ r.getAppDate();// Ԥ������ r.getRoomName();// �������� r.getStatus();// ֧��״̬ TextView tv_venue_name = (TextView) item .findViewById(R.id.tv_venue_name); tv_venue_name.setText(r.getRoomName()); tv_venue_name.setTag(r.getRoomId()); TextView tv_app_date = (TextView) item .findViewById(R.id.tv_app_date); tv_app_date.setText(r.getAppDate()); List<ListTime> list = r.getListTime();// ʱ�䰲��id TextView tv_amount = (TextView) item.findViewById(R.id.tv_amount); tv_amount.setText("��" + Double.parseDouble(r.getAmount()) * list.size()); TextView tv_time_1 = (TextView) item.findViewById(R.id.tv_time_1); TextView tv_time_2 = (TextView) item.findViewById(R.id.tv_time_2); int i = 1; for (ListTime lt : list) { if (i == 1) { tv_time_1.setText(lt.getStartTime() + " - " + lt.getEndTime()); tv_time_1.setTag(lt.getId()); } else if (i == 2) { tv_time_2.setText(lt.getStartTime() + " - " + lt.getEndTime()); tv_time_2.setTag(lt.getId()); } lt.getId(); lt.getStartTime(); lt.getEndTime(); System.out.println(lt.getId()); System.out.println(lt.getStartTime()); System.out.println(lt.getEndTime()); i++; } View v = item.findViewById(R.id.tv_to_pay); TextView tv_status_name = (TextView) item .findViewById(R.id.tv_status_name); if ("1".equals(r.getStatus())) { v.setVisibility(View.INVISIBLE); tv_status_name.setText("��֧��"); } else if ("2".equals(r.getStatus())) { v.setVisibility(View.INVISIBLE); tv_status_name.setText("��ȡ��"); } else // if ("0".equals(r.getStatus()))// 0 ��δ֧�� { v.setVisibility(View.VISIBLE); v.setOnClickListener(new MyOnClickListener(item)); tv_status_name.setText("δ֧��"); } // else // { // v.setVisibility(View.INVISIBLE); // tv_status_name.setText("δ֪״ֵ̬"); // } System.out.println("====================================="); ll_list.addView(item); } } private class MyOnClickListener implements OnClickListener { View item; MyOnClickListener(View item) { this.item = item; } @Override public void onClick(View v) { // ��ת֮ǰ��������һ������ // 2016-04-06&1834B71BABF74EA9ABC72647CC185DE4&20:30 - 21:00 // �����_3&30.00&A77387170AC340DF9EF81D493B54DD40 // TODO ��һ������������������������ // MainActivity.venueBookingResultMap = map; TextView tv_app_date = (TextView) item .findViewById(R.id.tv_app_date);// app_date String app_date = tv_app_date.getText().toString(); TextView tv_time_1 = (TextView) item.findViewById(R.id.tv_time_1);// tv_time_1 TextView tv_time_2 = (TextView) item.findViewById(R.id.tv_time_2);// tv_time_2 String time_1_id = tv_time_1.getTag().toString(); String time_2_id = null; if (tv_time_2.getTag() != null) { time_2_id = tv_time_2.getTag().toString(); } else { time_2_id = ""; } String time_1 = tv_time_1.getText().toString(); String time_2 = tv_time_2.getText().toString(); TextView tv_venue_name = (TextView) item .findViewById(R.id.tv_venue_name); String venue_name = tv_venue_name.getText().toString(); String venue_id = tv_venue_name.getTag().toString(); TextView tv_amount = (TextView) item.findViewById(R.id.tv_amount); String amount = tv_amount.getText().toString().substring(1); HashMap<String, String> map = new HashMap<String, String>(); if (time_1_id.trim().length() > 0) { map.put(app_date + "&" + time_1_id + "&" + time_1, venue_name + "&" + amount + "&" + venue_id); } if (time_2_id.trim().length() > 0) { map.put(app_date + "&" + time_2_id + "&" + time_2, venue_name + "&" + amount + "&" + venue_id); } for (String key : map.keySet()) { System.out.println(key + " --------- " + map.get(key)); } MainActivity.venueBookingResultMap = map; MainActivity.order_data_from = "VenueBookingMyFragment"; ctx.jumpToVenueBookingPayMyFregment(); } } }