Remove TimePickerActivity

pull/935/head
Alex Baker 5 years ago
parent 2e23257d98
commit abc9e7bfd0

@ -141,10 +141,6 @@
android:name=".activities.DatePickerActivity"
android:theme="@style/TranslucentDialog"/>
<activity
android:name=".activities.TimePickerActivity"
android:theme="@style/TranslucentDialog"/>
<activity
android:name=".activities.DateAndTimePickerActivity"
android:taskAffinity=""

@ -38,7 +38,7 @@ import java.util.List;
import javax.inject.Inject;
import org.tasks.R;
import org.tasks.activities.DateAndTimePickerActivity;
import org.tasks.activities.TimePickerActivity;
import org.tasks.dialogs.MyTimePickerDialog;
import org.tasks.injection.ForActivity;
import org.tasks.injection.FragmentComponent;
import org.tasks.preferences.Preferences;
@ -195,7 +195,7 @@ public class HideUntilControlSet extends TaskEditControlFragment implements OnIt
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_HIDE_UNTIL) {
if (resultCode == Activity.RESULT_OK) {
setCustomDate(data.getLongExtra(TimePickerActivity.EXTRA_TIMESTAMP, 0L));
setCustomDate(data.getLongExtra(MyTimePickerDialog.EXTRA_TIMESTAMP, 0L));
}
} else {
super.onActivityResult(requestCode, resultCode, data);

@ -41,8 +41,8 @@ import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import org.tasks.R;
import org.tasks.activities.DateAndTimePickerActivity;
import org.tasks.activities.TimePickerActivity;
import org.tasks.data.Alarm;
import org.tasks.dialogs.MyTimePickerDialog;
import org.tasks.injection.ForActivity;
import org.tasks.injection.FragmentComponent;
import org.tasks.ui.HiddenTopArrayAdapter;
@ -222,7 +222,7 @@ public class ReminderControlSet extends TaskEditControlFragment {
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_NEW_ALARM) {
if (resultCode == Activity.RESULT_OK) {
addAlarmRow(data.getLongExtra(TimePickerActivity.EXTRA_TIMESTAMP, 0L));
addAlarmRow(data.getLongExtra(MyTimePickerDialog.EXTRA_TIMESTAMP, 0L));
}
} else {
super.onActivityResult(requestCode, resultCode, data);

@ -1,5 +1,6 @@
package org.tasks.activities;
import static org.tasks.dialogs.MyTimePickerDialog.newTimePicker;
import static org.tasks.time.DateTimeUtils.currentTimeMillis;
import android.content.DialogInterface;
@ -7,22 +8,23 @@ import android.content.Intent;
import android.os.Bundle;
import com.wdullaer.materialdatetimepicker.date.DatePickerDialog;
import javax.inject.Inject;
import org.tasks.R;
import org.tasks.dialogs.MyDatePickerDialog;
import org.tasks.dialogs.MyTimePickerDialog;
import org.tasks.injection.ActivityComponent;
import org.tasks.injection.InjectingAppCompatActivity;
import org.tasks.preferences.Preferences;
import org.tasks.themes.ThemeAccent;
import org.tasks.themes.ThemeBase;
import org.tasks.time.DateTime;
public class DateAndTimePickerActivity extends InjectingAppCompatActivity
implements DatePickerDialog.OnDateSetListener,
DialogInterface.OnCancelListener {
DialogInterface.OnCancelListener, MyTimePickerDialog.TimePickerCallback {
public static final String EXTRA_TIMESTAMP = "extra_timestamp";
private static final String FRAG_TAG_DATE_PICKER = "frag_tag_date_picker";
private static final String FRAG_TAG_TIME_PICKER = "frag_tag_time_picker";
private static final String EXTRA_DATE_SELECTED = "extra_date_selected";
@Inject ThemeBase themeBase;
@Inject ThemeAccent themeAccent;
@Inject Preferences preferences;
@ -42,6 +44,8 @@ public class DateAndTimePickerActivity extends InjectingAppCompatActivity
}
}
themeAccent.applyStyle(getTheme());
androidx.fragment.app.FragmentManager fragmentManager = getSupportFragmentManager();
MyDatePickerDialog datePickerDialog =
(MyDatePickerDialog) fragmentManager.findFragmentByTag(FRAG_TAG_DATE_PICKER);
@ -49,8 +53,7 @@ public class DateAndTimePickerActivity extends InjectingAppCompatActivity
datePickerDialog = new MyDatePickerDialog();
datePickerDialog.initialize(
null, initial.getYear(), initial.getMonthOfYear() - 1, initial.getDayOfMonth());
datePickerDialog.setThemeDark(themeBase.isDarkTheme(this));
datePickerDialog.setAccentColor(themeAccent.getAccentColor());
datePickerDialog.setThemeDark(getResources().getBoolean(R.bool.is_dark));
int firstDayOfWeek = preferences.getFirstDayOfWeek();
if (firstDayOfWeek >= 1 && firstDayOfWeek <= 7) {
datePickerDialog.setFirstDayOfWeek(firstDayOfWeek);
@ -78,11 +81,8 @@ public class DateAndTimePickerActivity extends InjectingAppCompatActivity
dateSelected = true;
final long timestamp =
new DateTime(year, month + 1, day).withMillisOfDay(initial.getMillisOfDay()).getMillis();
Intent intent = new Intent(this, TimePickerActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
intent.putExtra(TimePickerActivity.EXTRA_TIMESTAMP, timestamp);
startActivity(intent);
finish();
newTimePicker(null, 0, timestamp)
.show(getSupportFragmentManager(), FRAG_TAG_TIME_PICKER);
}
@Override
@ -90,4 +90,13 @@ public class DateAndTimePickerActivity extends InjectingAppCompatActivity
finish();
}
@Override
public void onTimePicked(long timestamp) {
if (timestamp != MyTimePickerDialog.NO_TIME) {
Intent data = new Intent();
data.putExtra(MyTimePickerDialog.EXTRA_TIMESTAMP, timestamp);
setResult(RESULT_OK, data);
}
finish();
}
}

@ -1,67 +0,0 @@
package org.tasks.activities;
import static org.tasks.time.DateTimeUtils.currentTimeMillis;
import android.content.Intent;
import android.os.Bundle;
import android.text.format.DateFormat;
import com.wdullaer.materialdatetimepicker.time.TimePickerDialog;
import javax.inject.Inject;
import org.tasks.dialogs.MyTimePickerDialog;
import org.tasks.injection.ActivityComponent;
import org.tasks.injection.InjectingAppCompatActivity;
import org.tasks.themes.ThemeAccent;
import org.tasks.themes.ThemeBase;
import org.tasks.time.DateTime;
public class TimePickerActivity extends InjectingAppCompatActivity
implements TimePickerDialog.OnTimeSetListener {
public static final String EXTRA_TIMESTAMP = "extra_timestamp";
private static final String FRAG_TAG_TIME_PICKER = "frag_tag_time_picker";
@Inject ThemeBase themeBase;
@Inject ThemeAccent themeAccent;
private DateTime initial;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initial = new DateTime(getIntent().getLongExtra(EXTRA_TIMESTAMP, currentTimeMillis()));
androidx.fragment.app.FragmentManager fragmentManager = getSupportFragmentManager();
MyTimePickerDialog dialog =
(MyTimePickerDialog) fragmentManager.findFragmentByTag(FRAG_TAG_TIME_PICKER);
if (dialog == null) {
dialog = new MyTimePickerDialog();
dialog.initialize(
null,
initial.getHourOfDay(),
initial.getMinuteOfHour(),
0,
DateFormat.is24HourFormat(this));
dialog.setThemeDark(themeBase.isDarkTheme(this));
dialog.setAccentColor(themeAccent.getAccentColor());
dialog.show(fragmentManager, FRAG_TAG_TIME_PICKER);
}
dialog.setOnCancelListener(dialogInterface -> finish());
dialog.setOnTimeSetListener(this);
}
@Override
public void inject(ActivityComponent component) {
component.inject(this);
}
@Override
public void onTimeSet(
TimePickerDialog timePickerDialog, final int hours, final int minutes, int seconds) {
Intent data = new Intent();
data.putExtra(
EXTRA_TIMESTAMP,
initial.startOfDay().withHourOfDay(hours).withMinuteOfHour(minutes).getMillis());
setResult(RESULT_OK, data);
finish();
}
}

@ -1,23 +1,88 @@
package org.tasks.dialogs;
import static android.app.Activity.RESULT_OK;
import static org.tasks.date.DateTimeUtils.newDateTime;
import static org.tasks.time.DateTimeUtils.currentTimeMillis;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.format.DateFormat;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import com.wdullaer.materialdatetimepicker.time.TimePickerDialog;
import com.wdullaer.materialdatetimepicker.time.TimePickerDialog.OnTimeSetListener;
import org.tasks.R;
import org.tasks.time.DateTime;
public class MyTimePickerDialog extends TimePickerDialog implements OnTimeSetListener {
public static final String EXTRA_TIMESTAMP = "extra_timestamp";
public static final int NO_TIME = -1;
public static MyTimePickerDialog newTimePicker(Fragment target, int rc, long initial) {
Bundle arguments = new Bundle();
arguments.putLong(EXTRA_TIMESTAMP, initial);
MyTimePickerDialog dialog = new MyTimePickerDialog();
dialog.setArguments(arguments);
dialog.setTargetFragment(target, rc);
return dialog;
}
public class MyTimePickerDialog extends TimePickerDialog {
public interface TimePickerCallback { // TODO: remove this after removing DateAndTimePickerActivity
void onTimePicked(long timestamp);
}
private DialogInterface.OnDismissListener listener;
private DateTime initial;
private TimePickerCallback callback;
@Override
public void setOnDismissListener(DialogInterface.OnDismissListener listener) {
this.listener = listener;
public void onCreate(Bundle savedInstanceState) {
initial = newDateTime(getArguments().getLong(EXTRA_TIMESTAMP, currentTimeMillis()));
if (savedInstanceState == null) {
initialize(
null,
initial.getHourOfDay(),
initial.getMinuteOfHour(),
0,
DateFormat.is24HourFormat(getContext()));
setThemeDark(getResources().getBoolean(R.bool.is_dark)); // TODO: remove this after removing DateAndTimePickerActivity
}
setOnTimeSetListener(this);
super.onCreate(savedInstanceState);
}
@Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
public void onAttach(@NonNull Context context) {
super.onAttach(context);
if (listener != null) {
listener.onDismiss(dialog);
if (context instanceof TimePickerCallback) {
callback = (TimePickerCallback) context;
}
}
@Override
public void onCancel(DialogInterface dialog) {
super.onCancel(dialog);
if (getTargetFragment() == null) {
callback.onTimePicked(NO_TIME);
}
}
@Override
public void onTimeSet(TimePickerDialog view, int hours, int minutes, int second) {
long result = initial.startOfDay().withHourOfDay(hours).withMinuteOfHour(minutes).getMillis();
if (getTargetFragment() == null) {
callback.onTimePicked(result);
} else {
Intent data = new Intent();
data.putExtra(EXTRA_TIMESTAMP, result);
getTargetFragment().onActivityResult(getTargetRequestCode(), RESULT_OK, data);
}
}
}

@ -15,7 +15,6 @@ import org.tasks.activities.FilterSelectionActivity;
import org.tasks.activities.FilterSettingsActivity;
import org.tasks.activities.GoogleTaskListSettingsActivity;
import org.tasks.activities.TagSettingsActivity;
import org.tasks.activities.TimePickerActivity;
import org.tasks.billing.PurchaseActivity;
import org.tasks.caldav.CaldavAccountSettingsActivity;
import org.tasks.caldav.CaldavCalendarSettingsActivity;
@ -90,8 +89,6 @@ public interface ActivityComponent {
void inject(CameraActivity cameraActivity);
void inject(TimePickerActivity timePickerActivity);
void inject(VoiceCommandActivity voiceCommandActivity);
void inject(WidgetConfigActivity widgetConfigActivity);

@ -25,6 +25,8 @@ import javax.inject.Inject
abstract class InjectingPreferenceFragment : PreferenceFragmentCompat() {
companion object {
const val FRAG_TAG_TIME_PICKER = "frag_tag_time_picker"
fun tintIcons(pref: Preference, color: Int) {
if (pref is PreferenceGroup) {
for (i in 0 until pref.preferenceCount) {

@ -19,14 +19,14 @@ import org.tasks.BuildConfig
import org.tasks.LocalBroadcastManager
import org.tasks.R
import org.tasks.activities.FilterSelectionActivity
import org.tasks.activities.TimePickerActivity
import org.tasks.billing.Inventory
import org.tasks.billing.PurchaseActivity
import org.tasks.dialogs.ColorWheelPicker
import org.tasks.dialogs.ColorWheelPicker.Companion.newColorWheel
import org.tasks.dialogs.ColorPalettePicker
import org.tasks.dialogs.ColorPalettePicker.Companion.newColorPalette
import org.tasks.dialogs.ColorPickerAdapter
import org.tasks.dialogs.ColorWheelPicker
import org.tasks.dialogs.ColorWheelPicker.Companion.newColorWheel
import org.tasks.dialogs.MyTimePickerDialog.newTimePicker
import org.tasks.dialogs.ThemePickerDialog
import org.tasks.dialogs.ThemePickerDialog.Companion.newThemePickerDialog
import org.tasks.gtasks.PlayServices
@ -403,10 +403,9 @@ class LookAndFeel : InjectingPreferenceFragment(), Preference.OnPreferenceChange
preference.onPreferenceChangeListener = this
preference.onPreferenceClickListener = Preference.OnPreferenceClickListener {
val current = DateTime().withMillisOfDay(preference.millisOfDay)
val intent = Intent(context, TimePickerActivity::class.java)
intent.putExtra(TimePickerActivity.EXTRA_TIMESTAMP, current.millis)
startActivityForResult(intent, requestCode)
true
newTimePicker(this, requestCode, current.millis)
.show(parentFragmentManager, FRAG_TAG_TIME_PICKER)
false
}
}

@ -18,7 +18,7 @@ import com.todoroo.astrid.voice.VoiceOutputAssistant
import org.tasks.LocalBroadcastManager
import org.tasks.R
import org.tasks.activities.FilterSelectionActivity
import org.tasks.activities.TimePickerActivity
import org.tasks.dialogs.MyTimePickerDialog.newTimePicker
import org.tasks.injection.FragmentComponent
import org.tasks.injection.InjectingPreferenceFragment
import org.tasks.preferences.DefaultFilterProvider
@ -226,10 +226,9 @@ class Notifications : InjectingPreferenceFragment() {
private fun initializeTimePreference(preference: TimePreference, requestCode: Int) {
preference.onPreferenceClickListener = Preference.OnPreferenceClickListener {
val current = DateTime().withMillisOfDay(preference.millisOfDay)
val intent = Intent(context, TimePickerActivity::class.java)
intent.putExtra(TimePickerActivity.EXTRA_TIMESTAMP, current.millis)
startActivityForResult(intent, requestCode)
true
newTimePicker(this, requestCode, current.millis)
.show(parentFragmentManager, FRAG_TAG_TIME_PICKER)
false
}
}

@ -10,7 +10,7 @@ import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import org.tasks.activities.DateAndTimePickerActivity;
import org.tasks.activities.TimePickerActivity;
import org.tasks.dialogs.MyTimePickerDialog;
import org.tasks.injection.ActivityComponent;
import org.tasks.injection.InjectingAppCompatActivity;
import org.tasks.notifications.NotificationManager;
@ -114,7 +114,7 @@ public class SnoozeActivity extends InjectingAppCompatActivity
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_DATE_TIME) {
if (resultCode == RESULT_OK && data != null) {
long timestamp = data.getLongExtra(TimePickerActivity.EXTRA_TIMESTAMP, 0L);
long timestamp = data.getLongExtra(MyTimePickerDialog.EXTRA_TIMESTAMP, 0L);
snoozeForTime(new DateTime(timestamp));
} else {
finish();

@ -56,7 +56,7 @@ public class ThemeAccent implements Pickable {
accentColor = source.readInt();
}
void applyStyle(Resources.Theme theme) {
public void applyStyle(Resources.Theme theme) {
theme.applyStyle(style, true);
}

@ -4,6 +4,7 @@ import static androidx.core.content.ContextCompat.getColor;
import static com.google.common.collect.Lists.newArrayList;
import static java.util.Arrays.asList;
import static org.tasks.date.DateTimeUtils.newDateTime;
import static org.tasks.dialogs.MyTimePickerDialog.newTimePicker;
import android.app.Activity;
import android.content.Context;
@ -33,7 +34,7 @@ import java.util.List;
import javax.inject.Inject;
import org.tasks.R;
import org.tasks.activities.DatePickerActivity;
import org.tasks.activities.TimePickerActivity;
import org.tasks.dialogs.MyTimePickerDialog;
import org.tasks.injection.ForActivity;
import org.tasks.injection.FragmentComponent;
import org.tasks.preferences.Preferences;
@ -47,6 +48,8 @@ public class DeadlineControlSet extends TaskEditControlFragment {
private static final int REQUEST_TIME = 505;
private static final String EXTRA_DATE = "extra_date";
private static final String EXTRA_TIME = "extra_time";
private static final String FRAG_TAG_TIME_PICKER = "frag_tag_time_picker";
@Inject Preferences preferences;
@Inject @ForActivity Context context;
@ -262,9 +265,8 @@ public class DeadlineControlSet extends TaskEditControlFragment {
setTime(dateShortcutNight);
break;
case 6:
Intent intent = new Intent(context, TimePickerActivity.class);
intent.putExtra(TimePickerActivity.EXTRA_TIMESTAMP, getDueDateTime());
startActivityForResult(intent, REQUEST_TIME);
newTimePicker(this, REQUEST_TIME, getDueDateTime())
.show(getParentFragmentManager(), FRAG_TAG_TIME_PICKER);
updateDueTimeOptions();
break;
}
@ -311,7 +313,7 @@ public class DeadlineControlSet extends TaskEditControlFragment {
}
} else if (requestCode == REQUEST_TIME) {
if (resultCode == Activity.RESULT_OK) {
long timestamp = data.getLongExtra(TimePickerActivity.EXTRA_TIMESTAMP, 0L);
long timestamp = data.getLongExtra(MyTimePickerDialog.EXTRA_TIMESTAMP, 0L);
DateTime dateTime = new DateTime(timestamp);
setTime(dateTime.getMillisOfDay());
} else {

@ -7,7 +7,7 @@ import android.util.AttributeSet;
import androidx.preference.Preference;
import com.todoroo.andlib.utility.DateUtilities;
import org.tasks.R;
import org.tasks.activities.TimePickerActivity;
import org.tasks.dialogs.MyTimePickerDialog;
import org.tasks.time.DateTime;
public class TimePreference extends Preference {
@ -52,7 +52,7 @@ public class TimePreference extends Preference {
}
public void handleTimePickerActivityIntent(Intent data) {
long timestamp = data.getLongExtra(TimePickerActivity.EXTRA_TIMESTAMP, 0L);
long timestamp = data.getLongExtra(MyTimePickerDialog.EXTRA_TIMESTAMP, 0L);
int millisOfDay = new DateTime(timestamp).getMillisOfDay();
if (callChangeListener(millisOfDay)) {
persistInt(millisOfDay);

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="is_dark">true</bool>
</resources>

@ -2,4 +2,5 @@
<resources>
<bool name="two_pane_layout">false</bool>
<bool name="default_bundle_notifications">false</bool>
<bool name="is_dark">false</bool>
</resources>

@ -175,6 +175,8 @@
<item name="rippleColor">@color/button_accent_ripple</item>
</style>
<style name="mdtp_ActionButton.Text" parent="Widget.MaterialComponents.Button.TextButton.Dialog.Flush"/>
<style name="AlertButtonStyle" parent="Widget.MaterialComponents.Button.TextButton.Dialog.Flush">
<item name="android:textColor">?attr/colorSecondary</item>
</style>

@ -25,6 +25,7 @@
<item name="nnf_dir_icon_color">?attr/colorAccent</item>
<item name="card_elevation">2dp</item>
<item name="horizontal_divider">2</item> <!-- View.GONE -->
<item name="mdtp_theme_dark">@bool/is_dark</item>
</style>
<style name="Tasks" parent="TasksBase"/>

Loading…
Cancel
Save