Skip to content

Commit

Permalink
fix: #284
Browse files Browse the repository at this point in the history
  • Loading branch information
liyujiang-gzu committed Dec 21, 2021
1 parent 3a3e896 commit 9fe37e9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 25 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ requests 贡献您的代码,大家共同学习【[AndroidPicker 交流群 6042

## 接入指引

最新版本:[![jitpack](https://jitpack.io/v/gzu-liyujiang/AndroidPicker.svg)](https://jitpack.io/#gzu-liyujiang/AndroidPicker)
具体历史版本号参见 [更新日志](/ChangeLog.md)
**最新版本** [![jitpack](https://jitpack.io/v/gzu-liyujiang/AndroidPicker.svg)](https://jitpack.io/#gzu-liyujiang/AndroidPicker)
具体**历史版本号**参见 [更新日志](/ChangeLog.md)

### 注意事项

Expand All @@ -25,7 +25,7 @@ requests 贡献您的代码,大家共同学习【[AndroidPicker 交流群 6042

### 依赖配置

#### 在项目根目录下的build.gradle中
#### 在项目根目录下的`build.gradle`

```groovy
allprojects {
Expand All @@ -35,7 +35,7 @@ allprojects {
}
```

#### 在项目模块下的build.gradle中(以下依赖性都是独立的,不必全部引入,请按需来)
#### 在项目模块下的`build.gradle`中(以下依赖项不必全部引入,请按需来)

所有选择器的基础窗体(用于自定义弹窗):

Expand Down Expand Up @@ -101,7 +101,7 @@ dependencies {
}
```

旧版本 **AndroidX 稳定版本**
旧版本 **AndroidX 稳定版本** (不推荐)

```groovy
dependencies {
Expand All @@ -112,7 +112,7 @@ dependencies {
}
```

旧版本 **Support 稳定版本**
旧版本 **Support 稳定版本** (不推荐)

```groovy
dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class TimeWheelLayout extends BaseWheelLayout {
private WheelView meridiemWheelView;
private TimeEntity startValue;
private TimeEntity endValue;
private TimeEntity defaultValue;
private Integer selectedHour;
private Integer selectedMinute;
private Integer selectedSecond;
Expand Down Expand Up @@ -149,6 +150,11 @@ public void onWheelSelected(WheelView view, int position) {
if (id == R.id.wheel_picker_time_second_wheel) {
selectedSecond = secondWheelView.getItem(position);
timeSelectedCallback();
return;
}
if (id == R.id.wheel_picker_time_meridiem_wheel) {
isAnteMeridiem = "AM".equalsIgnoreCase(meridiemWheelView.getItem(position));
timeSelectedCallback();
}
}

Expand Down Expand Up @@ -247,17 +253,14 @@ public void setRange(TimeEntity startValue, TimeEntity endValue, TimeEntity defa
}
this.startValue = startValue;
this.endValue = endValue;
if (defaultValue != null) {
isAnteMeridiem = defaultValue.getHour() <= 12;
defaultValue.setHour(wrapHour(defaultValue.getHour()));
selectedHour = defaultValue.getHour();
selectedMinute = defaultValue.getMinute();
selectedSecond = defaultValue.getSecond();
} else {
selectedHour = null;
selectedMinute = null;
selectedSecond = null;
if (defaultValue == null) {
defaultValue = startValue;
}
this.defaultValue = defaultValue;
isAnteMeridiem = defaultValue.getHour() < 12 || defaultValue.getHour() == 24;
selectedHour = fixHour(defaultValue.getHour());
selectedMinute = defaultValue.getMinute();
selectedSecond = defaultValue.getSecond();
changeHour();
changeAnteMeridiem();
}
Expand Down Expand Up @@ -313,11 +316,11 @@ public void setTimeStep(int hourStep, int minuteStep, int secondStep) {
this.minuteStep = minuteStep;
this.secondStep = secondStep;
if (isDataAlready()) {
setRange(startValue, endValue, TimeEntity.target(selectedHour, selectedMinute, selectedSecond));
setRange(startValue, endValue, defaultValue);
}
}

public boolean isDataAlready() {
protected boolean isDataAlready() {
return startValue != null && endValue != null;
}

Expand Down Expand Up @@ -364,12 +367,17 @@ public final TextView getMeridiemLabelView() {

public final int getSelectedHour() {
int hour = hourWheelView.getCurrentItem();
return wrapHour(hour);
return fixHour(hour);
}

private int wrapHour(int hour) {
if (isHour12Mode() && hour > 12) {
hour = hour - 12;
private int fixHour(int hour) {
if (isHour12Mode()) {
if (hour == 0) {
hour = 24;
}
if (hour > 12) {
hour = hour - 12;
}
}
return hour;
}
Expand All @@ -387,7 +395,11 @@ public final int getSelectedSecond() {
}

public final boolean isAnteMeridiem() {
return meridiemWheelView.getCurrentItem().toString().equalsIgnoreCase("AM");
Object currentItem = meridiemWheelView.getCurrentItem();
if (currentItem == null) {
return isAnteMeridiem;
}
return "AM".equalsIgnoreCase(currentItem.toString());
}

private void changeHour() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ public void onTime12(View view) {
TimePicker picker = new TimePicker(this);
picker.setBodyWidth(140);
TimeWheelLayout wheelLayout = picker.getWheelLayout();
wheelLayout.setRange(TimeEntity.target(1, 0, 0), TimeEntity.target(12, 59, 59));
wheelLayout.setRange(TimeEntity.target(0, 0, 0), TimeEntity.target(24, 59, 59));
wheelLayout.setTimeMode(TimeMode.HOUR_12_NO_SECOND);
wheelLayout.setTimeLabel(":", " ", "");
wheelLayout.setDefaultValue(TimeEntity.now());
wheelLayout.setDefaultValue(TimeEntity.target(24, 0, 0));
wheelLayout.setTimeStep(1, 10, 1);
picker.setOnTimeMeridiemPickedListener(new OnTimeMeridiemPickedListener() {
@Override
Expand Down

0 comments on commit 9fe37e9

Please sign in to comment.