public ArrayList<String> getHeaders() { ArrayList<String> headers = new ArrayList<>(); for (Lesson lesson : arrayList) { if (!headers.contains(lesson.getDate())) { headers.add(lesson.getDate()); } } for (int i = 0; i < headers.size(); i++) { try { Date date = new SimpleDateFormat(CommonFunctions.FORMAT_YYYY_MM_DD, new Locale("ru")) .parse(headers.get(i)); String header = CommonFunctions.getDate(date, "E").toUpperCase() + " " + CommonFunctions.getDate(date, CommonFunctions.FORMAT_E_D_MMMM_YYYY); headers.set(i, header); } catch (ParseException e) { e.printStackTrace(); } } return headers; }
@Override public View getView(int position, View convertView, ViewGroup parent) { View customView = convertView; final SubjectMark mark = arrayList.get(position); final ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); customView = layoutInflater.inflate(R.layout.item_subject_mark, parent, false); holder.mMarkView = (ImageView) customView.findViewById(R.id.image_view); holder.mTypeTextView = (TextView) customView.findViewById(R.id.type); holder.mDateTextView = (TextView) customView.findViewById(R.id.date); customView.setTag(holder); } else { holder = (ViewHolder) customView.getTag(); } holder.mMarkView.setImageDrawable(null); TextDrawable drawable = TextDrawable.builder() .beginConfig() .bold() .useFont(Typeface.DEFAULT) .fontSize(30) .endConfig() .buildRoundRect( String.valueOf(mark.getValue()), CommonFunctions.setMarkColor(context, mark.getValue()), 8); holder.mMarkView.setImageDrawable(drawable); holder.mTypeTextView.setText(mark.getType()); holder.mDateTextView.setText( CommonFunctions.getDate( mark.getDate(), CommonFunctions.FORMAT_YYYY_MM_DD, CommonFunctions.FORMAT_DD_MM_YYYY)); return customView; }
public int addProgress(JSONArray progress) { if ((CommonFunctions.StringIsNullOrEmpty(progress.toString())) || (progress.length() == 0)) return 0; try { ArrayList<ContentValues> progressValues = new ArrayList<>(); for (int i = 0; i < progress.length(); i++) { JSONObject progressItem = progress.getJSONObject(i); JSONArray marks = progressItem.getJSONArray(context.getString(R.string.marks)); for (int j = 0; j < marks.length(); j++) { ContentValues cv = new ContentValues(); JSONObject mark = marks.getJSONObject(j); cv.put( PROGRESS_COLUMN_SUBJECTS_CLASS_ID, CommonFunctions.getFieldInt(progressItem, context.getString(R.string.subject_id))); cv.put( PROGRESS_COLUMN_ID, CommonFunctions.getFieldInt(mark, context.getString(R.string.id))); cv.put( PROGRESS_COLUMN_MARK, CommonFunctions.getFieldInt(mark, context.getString(R.string.mark))); cv.put( PROGRESS_COLUMN_PERIOD_ID, CommonFunctions.getFieldInt(mark, context.getString(R.string.period_id))); progressValues.add(cv); } } return insert(PROGRESS_TABLE_NAME, ADBWorker.REPLACE, progressValues); } catch (Exception e) { e.printStackTrace(); return 0; } }