From 22515113ca8f2370b3d0080c69f75d1ad270fbba Mon Sep 17 00:00:00 2001 From: Milos Milanovic Date: Sun, 29 Nov 2015 14:55:50 +0100 Subject: [PATCH 1/3] Optimize getView() callback in CaldroidGridAdapter Avoid creating ContextThemeWrapper on each getView() callback; Remove redundancy; Correct way for cellView inflation; --- .../caldroid/CaldroidGridAdapter.java | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/caldroid/src/main/java/com/roomorama/caldroid/CaldroidGridAdapter.java b/caldroid/src/main/java/com/roomorama/caldroid/CaldroidGridAdapter.java index 8a6aae4..1ef192b 100644 --- a/caldroid/src/main/java/com/roomorama/caldroid/CaldroidGridAdapter.java +++ b/caldroid/src/main/java/com/roomorama/caldroid/CaldroidGridAdapter.java @@ -59,6 +59,8 @@ public class CaldroidGridAdapter extends BaseAdapter { */ protected HashMap extraData; + protected LayoutInflater localInflater; + public void setAdapterDateTime(DateTime dateTime) { this.month = dateTime.getMonth(); this.year = dateTime.getYear(); @@ -148,6 +150,10 @@ public CaldroidGridAdapter(Context context, int month, int year, // Get data from caldroidData populateFromCaldroidData(); + + LayoutInflater inflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + localInflater = CaldroidFragment.getLayoutInflater(context, inflater, themeResource); } /** @@ -336,26 +342,21 @@ public long getItemId(int arg0) { return 0; } - @Override - public View getView(int position, View convertView, ViewGroup parent) { - LayoutInflater inflater = (LayoutInflater) context - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - CellView cellView = (CellView) convertView; - - LayoutInflater localInflater = CaldroidFragment.getLayoutInflater(context, inflater, themeResource); - - // For reuse - if (convertView == null) { - if (squareTextViewCell) { - cellView = (CellView) localInflater.inflate(R.layout.square_date_cell, null); - } else { - cellView = (CellView) localInflater.inflate(R.layout.normal_date_cell, null); - } - } + @Override + public View getView(int position, View convertView, ViewGroup parent) { + CellView cellView; - customizeTextView(position, cellView); + // For reuse + if (convertView == null) { + final int squareDateCellResource = squareTextViewCell ? R.layout.square_date_cell : R.layout.normal_date_cell; + cellView = (CellView) localInflater.inflate(squareDateCellResource, parent, false); + } else { + cellView = (CellView) convertView; + } - return cellView; - } + customizeTextView(position, cellView); + + return cellView; + } } From 9d4507f160e711fc2c4eea9fde2d8ea2b0d78829 Mon Sep 17 00:00:00 2001 From: Milos Milanovic Date: Sun, 29 Nov 2015 15:30:37 +0100 Subject: [PATCH 2/3] Remove string concatination in setText() method of cellview in CaldroidGridAdapter --- .../main/java/com/roomorama/caldroid/CaldroidGridAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/caldroid/src/main/java/com/roomorama/caldroid/CaldroidGridAdapter.java b/caldroid/src/main/java/com/roomorama/caldroid/CaldroidGridAdapter.java index 1ef192b..9a0d71a 100644 --- a/caldroid/src/main/java/com/roomorama/caldroid/CaldroidGridAdapter.java +++ b/caldroid/src/main/java/com/roomorama/caldroid/CaldroidGridAdapter.java @@ -315,7 +315,7 @@ protected void customizeTextView(int position, CellView cellView) { cellView.refreshDrawableState(); // Set text - cellView.setText("" + dateTime.getDay()); + cellView.setText(String.valueOf(dateTime.getDay())); // Set custom color if required setCustomResources(dateTime, cellView, cellView); From 8f55e905bde7151cd6fdd513acc1ae5750b622c4 Mon Sep 17 00:00:00 2001 From: Milos Milanovic Date: Sun, 29 Nov 2015 15:40:13 +0100 Subject: [PATCH 3/3] Use diamong notation for disableDatesMap and selectedDatesMap in CaldroidGridAdapter.java --- .../main/java/com/roomorama/caldroid/CaldroidGridAdapter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/caldroid/src/main/java/com/roomorama/caldroid/CaldroidGridAdapter.java b/caldroid/src/main/java/com/roomorama/caldroid/CaldroidGridAdapter.java index 9a0d71a..63c4b4e 100644 --- a/caldroid/src/main/java/com/roomorama/caldroid/CaldroidGridAdapter.java +++ b/caldroid/src/main/java/com/roomorama/caldroid/CaldroidGridAdapter.java @@ -35,8 +35,8 @@ public class CaldroidGridAdapter extends BaseAdapter { // Use internally, to make the search for date faster instead of using // indexOf methods on ArrayList - protected HashMap disableDatesMap = new HashMap(); - protected HashMap selectedDatesMap = new HashMap(); + protected HashMap disableDatesMap = new HashMap<>(); + protected HashMap selectedDatesMap = new HashMap<>(); protected DateTime minDateTime; protected DateTime maxDateTime;