@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { RequestManager.sharedInstance().setActivity(this.getActivity()); LoginFragment.flagLogin2Home = true; View view = inflater.inflate(R.layout.fragment_home, container, false); btn_workplan = (Button) view.findViewById(R.id.btn_workplan); txt_dataOff = (TextView) view.findViewById(R.id.txt_dataOff); // Log.d("INFO", PriceListProducts.getAllInMaps(getActivity()).toString()); btn_workplan.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); FragmentWorkPlan fragment = new FragmentWorkPlan(); fragment.tag = FRAGMENT_TAG.FRAG_WORKPLAN.toString(); fragment.section_index = NavigationDrawerFragment.WORK_PLAN; fragmentTransaction.addToBackStack(null); fragmentTransaction.replace( R.id.container, fragment, FRAGMENT_TAG.FRAG_WORKPLAN.toString()); fragmentTransaction.commit(); ((MainActivity) getActivity()).depthCounter = 1; } }); new OfflineManager(getActivity()); return view; }
@Override public void decodeResponse(String stringResponse) { Log.d(LOG_VISIT_FRAGMENT, stringResponse); try { JSONObject resp = new JSONObject(stringResponse); if (resp.getString("method").equalsIgnoreCase(METHOD.SEND_START_VISIT.toString())) { RequestManager.dismissProgressDialog(); if (resp.getString("success").equalsIgnoreCase("true")) { Toast.makeText(getActivity(), "Visita iniciada satisfactoriamente", Toast.LENGTH_SHORT) .show(); setCheckIn2DB(true, resp.getString("id_visit_session")); } else if (resp.getString("success").equalsIgnoreCase("nointernet")) { RequestManager.sharedInstance() .showConfirmationDialogWithListener( "No fue posible enviar el Check In, se registrara en modo OFFLINE", getActivity(), this); setCheckIn2DB(false, "no_id_visit_session"); } else { if (resp.getString("error").contains("started")) { Toast.makeText(getActivity(), "La visita ya habia sido iniciada", Toast.LENGTH_SHORT) .show(); } else { Toast.makeText(getActivity(), "Error en el servicio", Toast.LENGTH_LONG).show(); RequestManager.sharedInstance() .showConfirmationDialogWithListener("Error en el servicio", getActivity(), this); } } // WorkPlan.updateCheckIn(getActivity(), visit_id, "checkin"); // Log.e("CHECKINS ", CheckIn.getAllInMaps(getActivity()).toString()); } else if (resp.getString("method").equalsIgnoreCase(METHOD.END_VISIT.toString())) { RequestManager.dismissProgressDialog(); if (resp.getString("success").equalsIgnoreCase("true")) { Toast.makeText(getActivity(), "Visita finalizada satisfactoriamente", Toast.LENGTH_SHORT) .show(); setCheckOut2DB(true); getActivity().onBackPressed(); } else if (resp.getString("success").equalsIgnoreCase("nointernet")) { RequestManager.sharedInstance() .showConfirmationDialogWithListener( "No fue posible enviar el Check Out, se registrara en modo OFFLINE", getActivity(), this); setCheckOut2DB(false); getActivity().onBackPressed(); } else { if (resp.getString("error").contains("ended")) { Toast.makeText(getActivity(), "La visita ya habia sido finalizada", Toast.LENGTH_SHORT) .show(); } else { RequestManager.sharedInstance() .showConfirmationDialogWithListener("Error en el servicio", getActivity(), this); } } } } catch (JSONException e) { e.printStackTrace(); } super.decodeResponse(stringResponse); }
@Override public void clickFromList(int position) { Log.d(LOG_VISIT_FRAGMENT, "Position: " + position); Map<String, String> params = new HashMap<String, String>(); currentCheckin = CheckIn.getActiveMap(getActivity(), visit_id); if (currentCheckin.size() > 0) checkin = "active"; else checkin = "noactive"; Log.e("CHECKIN CLICK", checkin); if (position == 0) { // if(checkin.equalsIgnoreCase("no_checkin")) { if (!checkin.equalsIgnoreCase("active")) { params.put("latitude", String.valueOf(latitude)); params.put("longitude", String.valueOf(longitude)); params.put("visit_id", visit_id); params.put("date_time", "" + DatesHelper.getStringDateDays(new Date())); prepareRequest(METHOD.SEND_START_VISIT, params, true, true); } else if (checkin.equalsIgnoreCase("active")) { Toast.makeText(getActivity(), "La visita ya fue iniciada", Toast.LENGTH_SHORT).show(); } } else if (position == 1) { if (checkin.equalsIgnoreCase("active")) { // prepareRequest(METHOD.GET_PRODUCT,params,true); FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); FragmentOrder fragment = new FragmentOrder(); fragment.tag = FRAGMENT_TAG.FRAG_ORDERS.toString(); fragment.section_index = NavigationDrawerFragment.WORK_PLAN; fragment.setArguments(bundle); fragmentTransaction.addToBackStack(null); // fragmentTransaction.replace(R.id.container, fragment, // TrackerFragment.FRAGMENT_TAG.FRAG_HOME.toString()); fragmentTransaction.replace(R.id.container, fragment, FRAGMENT_TAG.FRAG_ORDERS.toString()); fragmentTransaction.commit(); ((MainActivity) getActivity()).depthCounter = 3; } else if (!checkin.equalsIgnoreCase("active")) { Toast.makeText(getActivity(), "Primero haz Check In", Toast.LENGTH_SHORT).show(); } } else if (position == 2) { FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); FragmentPromotions fragment = new FragmentPromotions(); fragment.tag = FRAGMENT_TAG.FRAG_SALES.toString(); fragment.section_index = NavigationDrawerFragment.WORK_PLAN; fragment.setArguments(bundle); fragmentTransaction.addToBackStack(null); fragmentTransaction.replace(R.id.container, fragment, FRAGMENT_TAG.FRAG_SALES.toString()); fragmentTransaction.commit(); ((MainActivity) getActivity()).depthCounter = 3; } else if (position == 3) { if (checkin.equalsIgnoreCase("active")) { FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); FragmentCashing fragment = new FragmentCashing(); fragment.tag = FRAGMENT_TAG.FRAG_PAYMENT.toString(); fragment.section_index = NavigationDrawerFragment.WORK_PLAN; fragment.setArguments(bundle); fragmentTransaction.addToBackStack(null); fragmentTransaction.replace(R.id.container, fragment, FRAGMENT_TAG.FRAG_PAYMENT.toString()); fragmentTransaction.commit(); ((MainActivity) getActivity()).depthCounter = 3; } else if (!checkin.equalsIgnoreCase("active")) { Toast.makeText(getActivity(), "Primero haz Check In", Toast.LENGTH_SHORT).show(); } } else if (position == 4) { if (checkin.equalsIgnoreCase("active")) { // if (WorkPlan.getAnswersandDatetimeByVisit(context, visit_id).get("answers").equals("")) { if (FormAnswers.getAnswers(context, visit_id).equals("")) { try { id_Form = Form.getAllInMaps(context) .get(0) .get("id_form"); // Si no hay formulario se puede causar una excepcion // por el ".get("id_form")" bundle.putString("id_form", id_Form); FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); FragmentForms fragment = new FragmentForms(); fragment.tag = FRAGMENT_TAG.FRAG_FORMS.toString(); fragment.section_index = NavigationDrawerFragment.WORK_PLAN; fragment.setArguments(bundle); fragmentTransaction.addToBackStack(null); fragmentTransaction.replace( R.id.container, fragment, FRAGMENT_TAG.FRAG_FORMS.toString()); fragmentTransaction.commit(); ((MainActivity) getActivity()).depthCounter = 3; } catch (Exception e) { // No hay formularios para esta visita Toast.makeText(getActivity(), "No hay formulario para este cliente", Toast.LENGTH_LONG) .show(); } } else { Toast.makeText( getActivity(), "Ya se envio un formulario para esta visita", Toast.LENGTH_LONG) .show(); } } else if (!checkin.equalsIgnoreCase("active")) { Toast.makeText(getActivity(), "Primero haz Check In", Toast.LENGTH_SHORT).show(); } } else if (position == 5) { if (!checkin.equalsIgnoreCase("active")) { Toast.makeText(getActivity(), "Primero haz Check In", Toast.LENGTH_SHORT).show(); } else { String id_visit_session = CheckIn.getIdVisitSession(getActivity(), currentCheckin.get("id_checkin")); checkoutFlag = true; if (!id_visit_session.equalsIgnoreCase("no_id_visit_session")) { params.put("visit_id", visit_id); params.put("date_time", "" + DatesHelper.getStringDateDays(new Date())); params.put("id_visit_session", "" + id_visit_session); prepareRequest(METHOD.END_VISIT, params, true, true); } else if (id_visit_session.equalsIgnoreCase("no_id_visit_session")) { RequestManager.sharedInstance() .showConfirmationDialogWithListener( "No fue posible enviar el Check Out, se registrara en modo OFFLINE", getActivity(), this); setCheckOut2DB(false); getActivity().onBackPressed(); } } } }