mirror of https://github.com/tasks/tasks
Remove TimePickerActivity
parent
2e23257d98
commit
abc9e7bfd0
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<bool name="is_dark">true</bool>
|
||||
</resources>
|
Loading…
Reference in New Issue