Skip to content

Commit

Permalink
Merge pull request roomorama#341 from sh0m1/refactor/optimizations
Browse files Browse the repository at this point in the history
Optimizations
  • Loading branch information
thomasdao committed Nov 30, 2015
2 parents ea2eb88 + 8f55e90 commit 6079a4c
Showing 1 changed file with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<DateTime, Integer> disableDatesMap = new HashMap<DateTime, Integer>();
protected HashMap<DateTime, Integer> selectedDatesMap = new HashMap<DateTime, Integer>();
protected HashMap<DateTime, Integer> disableDatesMap = new HashMap<>();
protected HashMap<DateTime, Integer> selectedDatesMap = new HashMap<>();

protected DateTime minDateTime;
protected DateTime maxDateTime;
Expand All @@ -59,6 +59,8 @@ public class CaldroidGridAdapter extends BaseAdapter {
*/
protected HashMap<String, Object> extraData;

protected LayoutInflater localInflater;

public void setAdapterDateTime(DateTime dateTime) {
this.month = dateTime.getMonth();
this.year = dateTime.getYear();
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -309,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);
Expand All @@ -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;
}

}

0 comments on commit 6079a4c

Please sign in to comment.