Material datetime pickers

pull/384/head
Alex Baker 9 years ago
parent 7590a075e6
commit efe6d5e91a

@ -90,7 +90,7 @@ dependencies {
compile ('org.scala-saddle:google-rfc-2445:20110304') {
transitive = false
}
compile ('com.github.flavienlaurent.datetimepicker:library:0.0.2') {
compile ('com.wdullaer:materialdatetimepicker:2.1.1') {
exclude group: 'com.android.support', module: 'support-v4'
}

@ -22,7 +22,6 @@ import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
import com.fourmob.datetimepicker.date.DatePickerDialog;
import com.google.ical.values.Frequency;
import com.google.ical.values.RRule;
import com.google.ical.values.Weekday;
@ -32,6 +31,7 @@ import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.ui.NumberPickerDialog;
import com.todoroo.astrid.ui.NumberPickerDialog.OnNumberPickedListener;
import com.todoroo.astrid.ui.PopupControlSet;
import com.wdullaer.materialdatetimepicker.date.DatePickerDialog;
import org.tasks.R;
import org.tasks.dialogs.DialogBuilder;
@ -134,14 +134,14 @@ public class RepeatControlSet extends PopupControlSet {
public void onDateSet(DatePickerDialog datePickerDialog, int year, int month, int day) {
setRepeatUntilValue(new DateTime(year, month + 1, day, 0, 0, 0, 0).getMillis());
}
}, initial.getYear(), initial.getMonthOfYear() - 1, initial.getDayOfMonth(), false);
}, initial.getYear(), initial.getMonthOfYear() - 1, initial.getDayOfMonth());
dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
setRepeatUntilValue(repeatUntilValue);
}
});
dialog.show(activity.getSupportFragmentManager(), FRAG_TAG_REPEAT_UNTIL);
dialog.show(activity.getFragmentManager(), FRAG_TAG_REPEAT_UNTIL);
}
public void addListener(RepeatChangedListener listener) {

@ -1,25 +1,30 @@
package org.tasks.activities;
import android.app.FragmentManager;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import com.fourmob.datetimepicker.date.DatePickerDialog;
import com.wdullaer.materialdatetimepicker.date.DatePickerDialog;
import org.tasks.time.DateTime;
import org.tasks.dialogs.MyDatePickerDialog;
import org.tasks.injection.InjectingAppCompatActivity;
import org.tasks.preferences.ActivityPreferences;
import org.tasks.time.DateTime;
import javax.inject.Inject;
import static org.tasks.time.DateTimeUtils.currentTimeMillis;
public class DateAndTimePickerActivity extends FragmentActivity implements DatePickerDialog.OnDateSetListener, DialogInterface.OnCancelListener {
public class DateAndTimePickerActivity extends InjectingAppCompatActivity implements DatePickerDialog.OnDateSetListener, DialogInterface.OnCancelListener {
private static final String FRAG_TAG_DATE_PICKER = "frag_tag_date_picker";
private static final String EXTRA_DATE_SELECTED = "extra_date_selected";
public static final String EXTRA_TIMESTAMP = "extra_timestamp";
@Inject ActivityPreferences preferences;
private DateTime initial;
private boolean dateSelected;
@ -27,6 +32,8 @@ public class DateAndTimePickerActivity extends FragmentActivity implements DateP
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
preferences.applyTheme();
initial = new DateTime(getIntent().getLongExtra(EXTRA_TIMESTAMP, currentTimeMillis()));
if (savedInstanceState != null) {
@ -36,12 +43,12 @@ public class DateAndTimePickerActivity extends FragmentActivity implements DateP
}
}
FragmentManager supportFragmentManager = getSupportFragmentManager();
MyDatePickerDialog datePickerDialog = (MyDatePickerDialog) supportFragmentManager.findFragmentByTag(FRAG_TAG_DATE_PICKER);
FragmentManager fragmentManager = getFragmentManager();
MyDatePickerDialog datePickerDialog = (MyDatePickerDialog) fragmentManager.findFragmentByTag(FRAG_TAG_DATE_PICKER);
if (datePickerDialog == null) {
datePickerDialog = new MyDatePickerDialog();
datePickerDialog.initialize(null, initial.getYear(), initial.getMonthOfYear() - 1, initial.getDayOfMonth(), false);
datePickerDialog.show(supportFragmentManager, FRAG_TAG_DATE_PICKER);
datePickerDialog.initialize(null, initial.getYear(), initial.getMonthOfYear() - 1, initial.getDayOfMonth());
datePickerDialog.show(fragmentManager, FRAG_TAG_DATE_PICKER);
}
datePickerDialog.setOnCancelListener(this);
datePickerDialog.setOnDateSetListener(this);

@ -1,27 +1,32 @@
package org.tasks.activities;
import android.app.FragmentManager;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.text.format.DateFormat;
import com.sleepbot.datetimepicker.time.RadialPickerLayout;
import com.sleepbot.datetimepicker.time.TimePickerDialog;
import com.wdullaer.materialdatetimepicker.time.RadialPickerLayout;
import com.wdullaer.materialdatetimepicker.time.TimePickerDialog;
import org.tasks.time.DateTime;
import org.tasks.dialogs.MyTimePickerDialog;
import org.tasks.injection.InjectingAppCompatActivity;
import org.tasks.preferences.ActivityPreferences;
import org.tasks.time.DateTime;
import javax.inject.Inject;
import static org.tasks.time.DateTimeUtils.currentTimeMillis;
public class TimePickerActivity extends FragmentActivity implements TimePickerDialog.OnTimeSetListener, DialogInterface.OnDismissListener {
public class TimePickerActivity extends InjectingAppCompatActivity implements TimePickerDialog.OnTimeSetListener, DialogInterface.OnDismissListener {
private static final String FRAG_TAG_TIME_PICKER = "frag_tag_time_picker";
public static final String EXTRA_TIMESTAMP = "extra_timestamp";
@Inject ActivityPreferences preferences;
private DateTime initial;
private boolean isChangingConfigurations;
@ -29,13 +34,15 @@ public class TimePickerActivity extends FragmentActivity implements TimePickerDi
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
preferences.applyTheme();
initial = new DateTime(getIntent().getLongExtra(EXTRA_TIMESTAMP, currentTimeMillis()));
FragmentManager supportFragmentManager = getSupportFragmentManager();
FragmentManager supportFragmentManager = getFragmentManager();
MyTimePickerDialog dialog = (MyTimePickerDialog) supportFragmentManager.findFragmentByTag(FRAG_TAG_TIME_PICKER);
if (dialog == null) {
dialog = new MyTimePickerDialog();
dialog.initialize(null, initial.getHourOfDay(), initial.getMinuteOfHour(), DateFormat.is24HourFormat(this), false);
dialog.initialize(null, initial.getHourOfDay(), initial.getMinuteOfHour(), 0, DateFormat.is24HourFormat(this));
dialog.show(supportFragmentManager, FRAG_TAG_TIME_PICKER);
}
dialog.setOnDismissListener(this);
@ -43,7 +50,7 @@ public class TimePickerActivity extends FragmentActivity implements TimePickerDi
}
@Override
public void onTimeSet(RadialPickerLayout radialPickerLayout, final int hours, final int minutes) {
public void onTimeSet(RadialPickerLayout radialPickerLayout, final int hours, final int minutes, int seconds) {
setResult(RESULT_OK, new Intent() {{
putExtra(EXTRA_TIMESTAMP, initial
.startOfDay()
@ -54,9 +61,9 @@ public class TimePickerActivity extends FragmentActivity implements TimePickerDi
}
@Override
public Object onRetainCustomNonConfigurationInstance() {
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
isChangingConfigurations = true;
return super.onRetainCustomNonConfigurationInstance();
}
@Override

@ -2,7 +2,7 @@ package org.tasks.dialogs;
import android.content.DialogInterface;
import com.fourmob.datetimepicker.date.DatePickerDialog;
import com.wdullaer.materialdatetimepicker.date.DatePickerDialog;
public class MyDatePickerDialog extends DatePickerDialog {

@ -2,7 +2,7 @@ package org.tasks.dialogs;
import android.content.DialogInterface;
import com.sleepbot.datetimepicker.time.TimePickerDialog;
import com.wdullaer.materialdatetimepicker.time.TimePickerDialog;
public class MyTimePickerDialog extends TimePickerDialog {

@ -28,6 +28,7 @@ import org.tasks.activities.CalendarSelectionActivity;
import org.tasks.activities.CameraActivity;
import org.tasks.activities.ClearAllDataActivity;
import org.tasks.activities.ClearGtaskDataActivity;
import org.tasks.activities.DateAndTimePickerActivity;
import org.tasks.activities.DeleteAllCalendarEventsActivity;
import org.tasks.activities.DeleteCompletedActivity;
import org.tasks.activities.DeleteCompletedEventsActivity;
@ -38,6 +39,7 @@ import org.tasks.activities.ImportTaskActivity;
import org.tasks.activities.PurgeDeletedActivity;
import org.tasks.activities.ResetPreferencesActivity;
import org.tasks.activities.SortActivity;
import org.tasks.activities.TimePickerActivity;
import org.tasks.preferences.AppearancePreferences;
import org.tasks.preferences.BackupPreferences;
import org.tasks.preferences.BasicPreferences;
@ -100,7 +102,9 @@ import dagger.Provides;
CalendarSelectionActivity.class,
AddAttachmentActivity.class,
ShortcutActivity.class,
CameraActivity.class
CameraActivity.class,
TimePickerActivity.class,
DateAndTimePickerActivity.class
})
public class ActivityModule {

@ -13,12 +13,12 @@ import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import com.fourmob.datetimepicker.date.DatePickerDialog;
import com.sleepbot.datetimepicker.time.RadialPickerLayout;
import com.sleepbot.datetimepicker.time.TimePickerDialog;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.helper.TaskEditControlSetBase;
import com.wdullaer.materialdatetimepicker.date.DatePickerDialog;
import com.wdullaer.materialdatetimepicker.time.RadialPickerLayout;
import com.wdullaer.materialdatetimepicker.time.TimePickerDialog;
import org.tasks.R;
import org.tasks.dialogs.MyDatePickerDialog;
@ -292,14 +292,14 @@ public class DeadlineControlSet extends TaskEditControlSetBase {
public void onDateSet(DatePickerDialog datePickerDialog, int year, int month, int day) {
setDate(new DateTime(year, month + 1, day, 0, 0, 0, 0).getMillis());
}
}, initial.getYear(), initial.getMonthOfYear() - 1, initial.getDayOfMonth(), false);
}, initial.getYear(), initial.getMonthOfYear() - 1, initial.getDayOfMonth());
dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
refreshDisplayView();
}
});
dialog.show(activity.getSupportFragmentManager(), FRAG_TAG_PICK_A_DATE);
dialog.show(activity.getFragmentManager(), FRAG_TAG_PICK_A_DATE);
break;
}
}
@ -342,17 +342,17 @@ public class DeadlineControlSet extends TaskEditControlSetBase {
}
dialog.initialize(new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(RadialPickerLayout radialPickerLayout, int hour, int minute) {
public void onTimeSet(RadialPickerLayout radialPickerLayout, int hour, int minute, int seconds) {
setTime((int) TimeUnit.HOURS.toMillis(hour) + (int) TimeUnit.MINUTES.toMillis(minute));
}
}, initialHours, initialMinutes, DateFormat.is24HourFormat(activity), false);
}, initialHours, initialMinutes, 0, DateFormat.is24HourFormat(activity));
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
refreshDisplayView();
}
});
dialog.show(activity.getSupportFragmentManager(), FRAG_TAG_PICK_A_TIME);
dialog.show(activity.getFragmentManager(), FRAG_TAG_PICK_A_TIME);
break;
}
}

Loading…
Cancel
Save