Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

Multiple issues fixed and new features implemented #308

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "androidx.appcompat:appcompat:1.1.0"
implementation 'com.google.android.material:material:1.1.0'
implementation "androidx.appcompat:appcompat:1.2.0"
implementation 'com.google.android.material:material:1.2.1'
implementation 'com.jakewharton:butterknife:10.2.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.1'
implementation project(':singledateandtimepicker')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.single_date_picker_activity_main_double_picker);
ButterKnife.bind(this);

this.simpleDateFormat = new SimpleDateFormat("EEE d MMM HH:mm", Locale.getDefault());
this.simpleDateFormat = new SimpleDateFormat("EEE d MMM yyyy", Locale.getDefault());

this.simpleTimeFormat = new SimpleDateFormat("hh:mm aa", Locale.getDefault());

this.simpleDateOnlyFormat = new SimpleDateFormat("EEE d MMM", Locale.getDefault());
this.simpleDateOnlyFormat = new SimpleDateFormat("EEE d MMM yyyy", Locale.getDefault());

this.simpleDateLocaleFormat = new SimpleDateFormat("EEE d MMM", Locale.GERMAN);
this.simpleDateLocaleFormat = new SimpleDateFormat("EEE d MMM yyyy", Locale.GERMAN);
}

@Override
Expand Down Expand Up @@ -196,12 +196,11 @@ public void simpleClicked() {
.displayMonthNumbers(true)

//.mustBeOnFuture()

//.minutesStep(15)
//.mustBeOnFuture()
//.defaultDate(defaultDate)
// .minDateRange(minDate)
// .maxDateRange(maxDate)
//.minDateRange(minDate)
//.maxDateRange(maxDate)

.displayListener(new SingleDateAndTimePickerDialog.DisplayListener() {
@Override
Expand Down Expand Up @@ -233,6 +232,7 @@ public void doubleClicked() {
final Calendar calendarMax = Calendar.getInstance();

calendarMin.setTime(now); // Set min now
calendarMin.set(Calendar.DAY_OF_MONTH, calendarMin.get(Calendar.DAY_OF_MONTH) + 2);
calendarMax.setTime(new Date(now.getTime() + TimeUnit.DAYS.toMillis(150))); // Set max now + 150 days

final Date minDate = calendarMin.getTime();
Expand All @@ -243,8 +243,9 @@ public void doubleClicked() {
//.bottomSheet()
//.curved()

// .backgroundColor(Color.BLACK)
// .mainColor(Color.GREEN)
//.backgroundColor(Color.BLACK)
//.mainColor(Color.GREEN)

.minutesStep(15)
.mustBeOnFuture()

Expand All @@ -257,6 +258,7 @@ public void doubleClicked() {
.tab0Date(now)
.tab1Date(new Date(now.getTime() + TimeUnit.HOURS.toMillis(1)))

//.todayText("Today")
.title("Double")

.tab0Text("Depart")
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.2'
classpath 'com.android.tools.build:gradle:4.0.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
// NOTE: Do not place your application dependencies here; they belong
Expand All @@ -23,7 +23,7 @@ allprojects {
}

ext {
sdk = 28
sdk = 30
minSdk = 14

github = 'https://github.com/florent37/SingleDateAndTimePicker'
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
2 changes: 1 addition & 1 deletion singledateandtimepicker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ android {
}

dependencies {
implementation "androidx.appcompat:appcompat:1.1.0"
implementation "androidx.appcompat:appcompat:1.2.0"
}

ext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

public class DoubleDateAndTimePickerDialog extends BaseDialog {


private Listener listener;
private BottomSheetHelper bottomSheetHelper;
private TextView buttonTab0;
Expand Down Expand Up @@ -234,16 +233,6 @@ public void onClick(View view) {
pickerTab1.setSelectedTextColor(mainColor);
}

if (minDate != null) {
pickerTab0.setMinDate(minDate);
pickerTab1.setMinDate(minDate);
}

if (maxDate != null) {
pickerTab0.setMaxDate(maxDate);
pickerTab1.setMaxDate(maxDate);
}

if (defaultDate != null) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(defaultDate);
Expand All @@ -263,6 +252,16 @@ public void onClick(View view) {
pickerTab1.selectDate(calendar);
}

if (minDate != null) {
pickerTab0.setMinDate(minDate);
pickerTab1.setMinDate(minDate);
}

if (maxDate != null) {
pickerTab0.setMaxDate(maxDate);
pickerTab1.setMaxDate(maxDate);
}

if (dayFormatter != null) {
pickerTab0.setDayFormatter(dayFormatter);
pickerTab1.setDayFormatter(dayFormatter);
Expand All @@ -282,6 +281,9 @@ public void onDateChanged(String displayed, Date date) {
}
});
}

pickerTab0.checkPickersMinMax();
pickerTab1.checkPickersMinMax();
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ protected DateWithLabel initDefault() {
return new DateWithLabel(getTodayText(), new Date());
}

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

@Override
protected void onItemSelected(int position, DateWithLabel item) {
if (onDaySelectedListener != null) {
Expand Down Expand Up @@ -124,28 +119,14 @@ private SimpleDateFormat getDateFormat() {
}

private Date convertItemToDate(int itemPosition) {
Date date;
final String itemText = adapter.getItemText(itemPosition);
final Calendar todayCalendar = Calendar.getInstance();
todayCalendar.setTimeZone(dateHelper.getTimeZone());

int todayPosition = -1;
final List<DateWithLabel> data = adapter.getData();

for (int i = 0; i < data.size(); i++) {
if (data.get(i).label.equals(getTodayText())) {
todayPosition = i;
break;
}
}

if (getTodayText().equals(itemText)) {
date = todayCalendar.getTime();
} else {
todayCalendar.add(Calendar.DAY_OF_YEAR, (itemPosition - todayPosition));
date = todayCalendar.getTime();
if (!getTodayText().equals(itemText)) {
todayCalendar.add(Calendar.DAY_OF_YEAR, (itemPosition - getTodayItemPosition()));
}
return date;
return todayCalendar.getTime();
}

public void setTodayText(DateWithLabel today) {
Expand All @@ -154,6 +135,7 @@ public void setTodayText(DateWithLabel today) {
if (data.get(i).label.equals(getTodayText())) {
adapter.getData().set(i, today);
notifyDatasetChanged();
this.today = today;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public abstract class WheelPicker<V> extends View {
protected int lastScrollPosition;
protected Listener<WheelPicker, V> listener;
protected Adapter<V> adapter = new Adapter<>();
protected DateWithLabel today;
protected int todayItemPosition = -1;
private Locale customLocale;
private Paint paint;
private Scroller scroller;
Expand Down Expand Up @@ -664,7 +666,6 @@ protected void onItemSelected(int position, V item) {
}
}


protected void onItemCurrentScroll(int position, V item) {
if (lastScrollPosition != position) {
if (listener != null) {
Expand Down Expand Up @@ -733,16 +734,26 @@ public int getDefaultItemPosition() {
}

public int getTodayItemPosition() {
List<V> list = adapter.getData();
for (int i = 0; i < list.size(); i++) {
if (list.get(i) instanceof DateWithLabel) {
DateWithLabel dwl = (DateWithLabel) list.get(i);
if (dwl.label.equals(getLocalizedString(R.string.picker_today))) {
return i;
if (todayItemPosition == -1) {
todayItemPosition = 0;
List<V> list = adapter.getData();
String todayText = getTodayText();
for (int i = 0; i < list.size(); i++) {
if (list.get(i) instanceof DateWithLabel) {
DateWithLabel dwl = (DateWithLabel) list.get(i);
if (dwl.label.equals(todayText)) {
todayItemPosition = i;
break;
}
}
}
}
return 0;
return todayItemPosition;
}

@NonNull
public String getTodayText() {
return today == null || TextUtils.isEmpty(today.label) ? getLocalizedString(R.string.picker_today) : today.label;
}

public void setAdapter(Adapter adapter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ protected String initDefault() {
return getTodayText();
}

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

@Override
protected void onItemSelected(int position, String item) {
if (onYearSelectedListener != null) {
Expand Down
4 changes: 4 additions & 0 deletions singledateandtimepicker/src/main/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="picker_today">dzisiaj</string>
</resources>
4 changes: 4 additions & 0 deletions singledateandtimepicker/src/main/res/values-sk/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="picker_today">dnes</string>
</resources>