Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
The crash was caused when today's label was set using todayText() method. The WheelDayPicker was considering the label from resources for today position instead of the custom set label.
  • Loading branch information
Akhunzaada committed Jul 12, 2018
1 parent 54386c6 commit f8d09c5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.util.AttributeSet;

import com.github.florent37.singledateandtimepicker.DateHelper;
Expand All @@ -22,6 +23,8 @@ public class WheelDayPicker extends WheelPicker<String> {

private OnDaySelectedListener onDaySelectedListener;

private String todayText;

public WheelDayPicker(Context context) {
super(context);
}
Expand All @@ -40,11 +43,6 @@ protected String initDefault() {
return getTodayText();
}

@NonNull
private String getTodayText() {
return getResources().getString(R.string.picker_today);
}

public WheelDayPicker setDayFormatter(SimpleDateFormat simpleDateFormat){
this.simpleDateFormat = simpleDateFormat;
adapter.setData(generateAdapterValues());
Expand Down Expand Up @@ -126,11 +124,21 @@ private Date convertItemToDate(int itemPosition) {
return date;
}

public int getTodayTextPosition() {
return adapter.getData().indexOf(getTodayText());
}

@NonNull
private String getTodayText() {
return TextUtils.isEmpty(todayText) ? getResources().getString(R.string.picker_today) : todayText;
}

public void setTodayText(String todayText) {
int index = adapter.getData().indexOf(getTodayText());
int index = getTodayTextPosition();
if (index != -1) {
adapter.getData().set(index, todayText);
notifyDatasetChanged();
this.todayText = todayText;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ public int findIndexOfDate(@NonNull Date date) {
if (this instanceof WheelDayPicker) {
String today = getFormattedValue(new Date());
if (today.equals(formatItem)) {
return getDefaultItemPosition();
return ((WheelDayPicker)this).getTodayTextPosition();
}
}

Expand Down

0 comments on commit f8d09c5

Please sign in to comment.