Add option to disable date time picker auto close

pull/996/head
Alex Baker 5 years ago
parent 4f2eb2bf42
commit 516f4ce2b4

@ -770,8 +770,9 @@ public final class TaskListFragment extends InjectingFragment
}
public void showDateTimePicker(TaskContainer task) {
DateTimePicker.Companion.newDateTimePicker(this, REQUEST_DUE_DATE, task.getId(), task.getDueDate())
.show(getParentFragmentManager(), FRAG_TAG_DATE_TIME_PICKER);
DateTimePicker.Companion.newDateTimePicker(
this, REQUEST_DUE_DATE, task.getId(), task.getDueDate(), false)
.show(getParentFragmentManager(), FRAG_TAG_DATE_TIME_PICKER);
}
public interface TaskListFragmentCallbackHandler {

@ -61,7 +61,7 @@ public class Upgrader {
private static final int V7_0 = 617;
public static final int V8_2 = 675;
private static final int V8_5 = 700;
private static final int V8_8 = 715;
private static final int V8_8 = 717;
private final Context context;
private final Preferences preferences;
private final Tracker tracker;
@ -123,7 +123,10 @@ public class Upgrader {
run(from, V7_0, this::applyCaldavSubtasks);
run(from, V8_2, this::migrateColors);
run(from, V8_5, this::applyCaldavGeo);
run(from, V8_8, () -> preferences.setBoolean(R.string.p_linkify_task_edit, true));
run(from, V8_8, () -> {
preferences.setBoolean(R.string.p_linkify_task_edit, true);
preferences.setBoolean(R.string.p_auto_dismiss_datetime_edit_screen, true);
});
}
preferences.setCurrentVersion(to);
}

@ -53,16 +53,18 @@ class DateTimePicker : InjectingBottomSheetDialogFragment() {
companion object {
const val EXTRA_TIMESTAMP = "extra_timestamp"
const val EXTRA_TASK = "extra_task"
private const val EXTRA_AUTO_CLOSE = "extra_auto_close"
private const val EXTRA_SELECTED = "extra_selected"
private const val REQUEST_TIME = 10101
private const val REQUEST_DATE = 10102
private const val FRAG_TAG_TIME_PICKER = "frag_tag_time_picker"
private const val FRAG_TAG_DATE_PICKER = "frag_tag_date_picker"
fun newDateTimePicker(target: Fragment, rc: Int, task: Long, current: Long): DateTimePicker {
fun newDateTimePicker(target: Fragment, rc: Int, task: Long, current: Long, autoClose: Boolean): DateTimePicker {
val bundle = Bundle()
bundle.putLong(EXTRA_TASK, task)
bundle.putLong(EXTRA_TIMESTAMP, current)
bundle.putBoolean(EXTRA_AUTO_CLOSE, autoClose)
val fragment = DateTimePicker()
fragment.arguments = bundle
fragment.setTargetFragment(target, rc)
@ -105,7 +107,7 @@ class DateTimePicker : InjectingBottomSheetDialogFragment() {
return binding.root
}
private fun returnAutomatically(): Boolean = arguments?.getLong(EXTRA_TASK) ?: 0 == 0L
private fun closeAutomatically(): Boolean = arguments?.getBoolean(EXTRA_AUTO_CLOSE) ?: false
override fun onResume() {
super.onResume()
@ -209,7 +211,7 @@ class DateTimePicker : InjectingBottomSheetDialogFragment() {
private fun returnDate(date: Long? = selected?.millis) {
selected = if (date == null || date <= 0) null else DateTime(date)
if (returnAutomatically()) {
if (closeAutomatically()) {
sendSelected()
} else {
refreshButtons()
@ -233,7 +235,7 @@ class DateTimePicker : InjectingBottomSheetDialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val bottomSheetDialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
if (returnAutomatically()) {
if (closeAutomatically()) {
return bottomSheetDialog
}

@ -12,6 +12,7 @@ import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentManager;
import butterknife.BindView;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.data.Task;
@ -21,6 +22,7 @@ import org.tasks.dialogs.DateTimePicker;
import org.tasks.injection.ForActivity;
import org.tasks.injection.FragmentComponent;
import org.tasks.locale.Locale;
import org.tasks.preferences.Preferences;
import org.tasks.time.DateTime;
import org.threeten.bp.format.FormatStyle;
@ -34,6 +36,7 @@ public class DeadlineControlSet extends TaskEditControlFragment {
@Inject @ForActivity Context context;
@Inject Locale locale;
@Inject Preferences preferences;
@BindView(R.id.due_date)
TextView dueDate;
@ -73,7 +76,12 @@ public class DeadlineControlSet extends TaskEditControlFragment {
protected void onRowClick() {
FragmentManager fragmentManager = getParentFragmentManager();
if (fragmentManager.findFragmentByTag(FRAG_TAG_DATE_PICKER) == null) {
DateTimePicker.Companion.newDateTimePicker(this, REQUEST_DATE, 0, getDueDateTime())
DateTimePicker.Companion.newDateTimePicker(
this,
REQUEST_DATE,
0,
getDueDateTime(),
preferences.getBoolean(R.string.p_auto_dismiss_datetime_edit_screen, false))
.show(fragmentManager, FRAG_TAG_DATE_PICKER);
}
}

@ -300,4 +300,5 @@
<string name="p_collapse_filters">collapse_filters</string>
<string name="p_collapse_tags">collapse_tags</string>
<string name="p_collapse_locations">collapse_locations</string>
<string name="p_auto_dismiss_datetime_edit_screen">auto_dismiss_datetime_edit_screen</string>
</resources>

@ -578,4 +578,6 @@ File %1$s contained %2$s.\n\n
<string name="no_time">No time</string>
<string name="shortcut_pick_time">Pick time</string>
<string name="shortcut_pick_date">Pick date</string>
<string name="auto_dismiss_datetime">Autoclose date time picker</string>
<string name="auto_dismiss_datetime_summary">Close date time picker after selecting a date or time</string>
</resources>

@ -124,6 +124,12 @@
android:targetPackage="@string/app_package" />
</Preference>
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="@string/p_auto_dismiss_datetime_edit_screen"
android:title="@string/auto_dismiss_datetime"
android:summary="@string/auto_dismiss_datetime_summary" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="@string/p_linkify_task_edit"

Loading…
Cancel
Save