@Override public void onClick(View v) { int id = v.getId(); switch (id) { case R.id.back_arrow_iv: onBackPressed(); break; case R.id.done_tv: if (doneTV.getText().toString().equals(getString(R.string.done_caps))) { CommonUtils.getLogs("DOne"); doneClicked(); } else if (doneTV.getText().toString().equals(getString(R.string.start_caps))) { adapter.selectAll(); CommonUtils.getLogs("start"); } /*else if (doneTV.getText().toString().equals("edit")) { Toast.makeText(this, "edit", Toast.LENGTH_LONG).show(); View vi=adapter.getView(1,null,studentsListview); vi.setBackgroundColor(getResources().getColor(R.color.Darkgreen)); }*/ break; // case R.id.logoutIV: // SharedPreferences clearSharedPreferenceForLogout; // clearSharedPreferenceForLogout = // getSharedPreferences("MyChild_Preferences", 0); // SharedPreferences.Editor editor = clearSharedPreferenceForLogout.edit(); // editor.clear(); // editor.commit(); // finish(); // startActivity(new Intent(this, LoginActivity.class)); case R.id.edit: editTV.setVisibility(View.GONE); doneTV.setVisibility(View.VISIBLE); studentsListabsent = teacherModel.getGradeModels().get(0).getAbsentStudentsModels(); adapter = new StudentsListAdapter( this, R.layout.select_student_list_item, studentsList, studentsListabsent, true, true); studentsListview.setAdapter(adapter); break; default: } }
private void doneClicked() { JSONObject jsonObject = new JSONObject(); try { if (adapter.mSelectedItemsIds.size() == studentsList.size()) { jsonObject.put("present_flag", "P"); } else { jsonObject.put("present_flag", "A"); JSONArray array = new JSONArray(); for (StudentDTO dto : studentsList) { if (!adapter.mSelectedItemsIds.get(dto.getStudentId())) { array.put(dto.getStudentId() + ""); } } jsonObject.put("studentList", array); } GradeModel gradeModel = teacherModel.getGradeModels().get(0); jsonObject.put("grade", gradeModel.getGradeName()); jsonObject.put("date", mselectedDate); // 06-04-2015 jsonObject.put("section", gradeModel.getSection()); CommonUtils.getLogs("POST Obj : " + jsonObject); if (CommonUtils.isNetworkAvailable(this)) { type = RequestType.GET_POST; // httpConnectThread = new HttpConnectThread(this, jsonObject, this); WebServiceCall call = new WebServiceCall(this); call.postToServer( jsonObject, (getString(R.string.base_url) + getString(R.string.url_save_attendence))); // httpConnectThread.execute(getString(R.string.base_url) + // getString(R.string.url_save_attendence)); } else { CommonUtils.getToastMessage(this, getString(R.string.network_error)); } } catch (JSONException e) { e.printStackTrace(); } }
@Override public void onRequestCompletion(JSONObject responseJson, JSONArray responseArray) { CommonUtils.getLogs("Response::::" + responseJson); if (responseJson != null && responseArray == null) { responseArray = new JSONArray(); responseArray.put(responseJson); } JSONObject obj = null; if (responseArray != null) { switch (type) { case TYPE_GET: boolean hasClassList = false; try { JSONObject jsonObject = responseArray.getJSONObject(0); if (jsonObject.has("message")) { hasClassList = jsonObject.getString("message").equals("No Class assigned as Class Teacher"); } } catch (JSONException e) { e.printStackTrace(); } if (!hasClassList) { teacherModel = AttendaceJsonParser.getInstance().getTeacherModel(responseArray); studentsList = teacherModel.getGradeModels().get(0).getStudentsModels(); studentsSize = studentsList.size(); if (AttendenceUpdateActivity.hasattendancedone) { studentsListabsent = teacherModel.getGradeModels().get(0).getAbsentStudentsModels(); adapter = new StudentsListAdapter( this, R.layout.select_student_list_item, studentsList, studentsListabsent, true, false); studentsListview.setAdapter(adapter); editTV.setVisibility(View.VISIBLE); doneTV.setVisibility(View.GONE); } else { adapter = new StudentsListAdapter(this, R.layout.select_student_list_item, studentsList); studentsListview.setAdapter(adapter); editTV.setVisibility(View.GONE); doneTV.setVisibility(View.VISIBLE); } Constants.stopProgress(this); try { obj = (JSONObject) responseArray.get(0); if (obj.has("message")) { CommonUtils.getToastMessage(this, obj.getString("message")); } } catch (JSONException e) { e.printStackTrace(); } } else { Constants.stopProgress(this); onBackPressed(); Toast.makeText(this, "No Class assigned as Class Teacher", Toast.LENGTH_LONG).show(); } break; case GET_POST: try { obj = responseJson; if (obj.has("message")) { CommonUtils.getToastMessage(this, obj.getString("message")); } } catch (JSONException e) { e.printStackTrace(); } } } else { Constants.stopProgress(this); try { obj = responseJson; obj = responseJson; if (obj.has("message")) { CommonUtils.getToastMessage(this, obj.getString("message")); } } catch (JSONException e) { e.printStackTrace(); } } }