Skip to content

Commit

Permalink
数据加载优化
Browse files Browse the repository at this point in the history
  • Loading branch information
huangyong committed Aug 18, 2020
1 parent 7ddfbdb commit 0cfcc6d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 43 deletions.
27 changes: 10 additions & 17 deletions library/src/main/java/com/wheelpicker/DateWheelPicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* 修改描述:
* 修改日期
*/
public class DateWheelPicker extends LinearLayout implements OnWheelPickedListener, IPickerView {
public class DateWheelPicker extends LinearLayout implements OnWheelPickedListener<String>, IPickerView {
public final static int TYPE_YEAR = 1 << 1;
public final static int TYPE_MONTH = 1 << 2;
public final static int TYPE_DAY = 1 << 3;
Expand Down Expand Up @@ -437,7 +437,7 @@ public int getDateMode() {

@SuppressWarnings("rawtypes")
@Override
public void onWheelSelected(AbstractWheelPicker wheelPicker, int index, Object data) {
public void onWheelSelected(AbstractWheelPicker wheelPicker, int index, String data) {
switch (wheelPicker.getId()) {
case TYPE_YEAR:
int year = getCurrentDate(data, mYearStr);
Expand Down Expand Up @@ -720,24 +720,17 @@ private void updateMaxSecond(int maxSecond) {
}
}

private int getCurrentDate(Object data, String suffix) {
if (data instanceof String) {
int suffixLeg = suffix == null ? 0 : suffix.length();
String temp = (String) data;
return Integer.parseInt(temp.substring(0, temp.length() - suffixLeg));
}
private int getCurrentDate(String data, String suffix) {
int suffixLeg = suffix == null ? 0 : suffix.length();
String temp = data;
return Integer.parseInt(temp.substring(0, temp.length() - suffixLeg));

return -1;
}

private int getCurrentMonth(Object data, String suffix) {
if (data instanceof String) {
int suffixLeg = suffix == null ? 0 : suffix.length();
String temp = (String) data;
return Integer.parseInt(temp.substring(0, temp.length() - suffixLeg)) - 1;
}

return -1;
private int getCurrentMonth(String data, String suffix) {
int suffixLeg = suffix == null ? 0 : suffix.length();
String temp = data;
return Integer.parseInt(temp.substring(0, temp.length() - suffixLeg)) - 1;
}

private boolean isLeapYear(int year) {
Expand Down
31 changes: 13 additions & 18 deletions library/src/main/java/com/wheelpicker/FutureTimePicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* 修改描述:
* 修改日期
*/
public class FutureTimePicker extends LinearLayout implements OnWheelPickedListener, IPickerView {
public class FutureTimePicker extends LinearLayout implements OnWheelPickedListener<String>, IPickerView {
public final static int TYPE_DAY = 1 << 1;
public final static int TYPE_HOUR = 1 << 2;
public final static int TYPE_MINUTE = 1 << 3;
Expand Down Expand Up @@ -193,10 +193,10 @@ private void updateDate(int durationDays) {
mDayMap.put(mTomorrowStr, today + oneDay);
break;
//case 2:
//after tomorrow
//str = mAfterTomorrowStr;
//mDayMap.put(mAfterTomorrowStr, today + 2 * oneDay);
//break;
//after tomorrow
//str = mAfterTomorrowStr;
//mDayMap.put(mAfterTomorrowStr, today + 2 * oneDay);
//break;
default:
//xx year xx month xx day
calendar.setTimeInMillis(today + i * oneDay);
Expand All @@ -206,7 +206,7 @@ private void updateDate(int durationDays) {

if (year == mCurrYear) {
//do nothing, 当年只含月份
} else if (year == mCurrYear + 1){
} else if (year == mCurrYear + 1) {
sb.append(mNextYear);
} else {
sb.append(year);
Expand Down Expand Up @@ -264,7 +264,7 @@ public void setPickedTime(long pickedTime) {

c.set(y, month, d, 0, 0, 0);
long pickedDay = c.getTimeInMillis();
int dayIndex = Math.max(0, (int)((pickedDay - mStartDay) / ONE_DAY));
int dayIndex = Math.max(0, (int) ((pickedDay - mStartDay) / ONE_DAY));
dayIndex = Math.min(dayIndex, DURATION);

if (dayIndex > 0) {
Expand All @@ -283,7 +283,7 @@ public void setPickedTime(long pickedTime) {
mHourWheelPicker.setCurrentItem(hIndex);
mMinuteWheelPicker.setCurrentItem(mIndex);

mSelectedHour = getCurrentDate(mHourPickerAdapter.getItem(hIndex), mHourStr);
mSelectedHour = getCurrentDate(mHourPickerAdapter.getItemText(hIndex), mHourStr);
mSelectedMinute = getCurrentDate(mMinutePickerAdapter.getItemText(mIndex), mMinuteStr);

if (mOnFutureDatePickListener != null) {
Expand Down Expand Up @@ -366,7 +366,7 @@ public View asView() {
}

@Override
public void onWheelSelected(AbstractWheelPicker wheelPicker, int index, Object data) {
public void onWheelSelected(AbstractWheelPicker wheelPicker, int index, String data) {
Calendar calendar = Calendar.getInstance();
int hourIndex = 0;
int minuteIndex = 0;
Expand Down Expand Up @@ -431,17 +431,12 @@ public void notifyDataSetChanged() {
mDayPickerAdapter.notifyDataSetChanged();
}

private int getCurrentDate(Object data, String suffix) {
if (data instanceof String) {
int suffixLeg = suffix == null ? 0 : suffix.length();
String temp = (String) data;
return Integer.parseInt(temp.substring(0, temp.length() - suffixLeg));
}

return -1;
private int getCurrentDate(String data, String suffix) {
int suffixLeg = suffix == null ? 0 : suffix.length();
String temp = data;
return Integer.parseInt(temp.substring(0, temp.length() - suffixLeg));
}


public int getSelectedYear() {
return mSelectedYear;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* 修改日期
*/
public class MultipleTextWheelPicker<T extends MultiplePickerData> extends LinearLayout
implements OnWheelPickedListener, IPickerView {
implements OnWheelPickedListener<String>, IPickerView {
protected List<T> mData;
protected List<TextWheelPicker> mWheelPickers;
protected List<TextWheelPickerAdapter> mTextWheelPickerAdapters;
Expand Down Expand Up @@ -127,9 +127,9 @@ private void init(List<T> data) {
}

@Override
public void onWheelSelected(AbstractWheelPicker wheelPicker, int index, Object data) {
public void onWheelSelected(AbstractWheelPicker wheelPicker, int index, String data) {
//默认不联动
mPickedData.set(wheelPicker.getId(), (String) data);
mPickedData.set(wheelPicker.getId(), data);

if (mOnMultiPickListener != null) {
mOnMultiPickListener.onDataPicked(mPickedData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
* 修改描述:
* 修改日期
*/
public interface OnWheelPickedListener {

@SuppressWarnings("rawtypes")
public void onWheelSelected(AbstractWheelPicker wheelPicker, int index, Object data);
public interface OnWheelPickedListener<T> {

public void onWheelSelected(AbstractWheelPicker wheelPicker, int index, T data);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public String getItemText(int position) {
}

@Override
public Object getItem(int position) {
public String getItem(int position) {
return getItemText(position);
}
}

0 comments on commit 0cfcc6d

Please sign in to comment.