Force a due date for recurring tasks

pull/2436/head
Alex Baker 1 year ago
parent 691dc635a9
commit 804c0f974a

@ -450,13 +450,14 @@ class TaskEditFragment : Fragment(), Toolbar.OnMenuItemClickListener {
onClick = {
DateTimePicker
.newDateTimePicker(
this@TaskEditFragment,
REQUEST_DATE,
editViewModel.dueDate.value,
preferences.getBoolean(
target = this@TaskEditFragment,
rc = REQUEST_DATE,
current = editViewModel.dueDate.value,
autoClose = preferences.getBoolean(
R.string.p_auto_dismiss_datetime_edit_screen,
false
)
),
hideNoDate = editViewModel.recurrence.value?.isNotBlank() == true,
)
.show(parentFragmentManager, FRAG_TAG_DATE_PICKER)
}

@ -34,7 +34,11 @@ class RepeatControlSet : TaskEditControlFragment() {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == REQUEST_RECURRENCE) {
if (resultCode == RESULT_OK) {
viewModel.recurrence.value = data?.getStringExtra(BasicRecurrenceDialog.EXTRA_RRULE)
val result = data?.getStringExtra(BasicRecurrenceDialog.EXTRA_RRULE)
viewModel.recurrence.value = result
if (result?.isNotBlank() == true && viewModel.dueDate.value == 0L) {
viewModel.setDueDate(DateTime().startOfDay().millis)
}
}
} else {
super.onActivityResult(requestCode, resultCode, data)

@ -7,6 +7,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isGone
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import com.todoroo.andlib.utility.DateUtilities
@ -25,8 +26,14 @@ import org.tasks.time.DateTime
import org.tasks.time.DateTimeUtils.millisOfDay
import org.tasks.time.DateTimeUtils.startOfDay
import java.time.format.FormatStyle
import java.util.*
import java.util.Calendar.*
import java.util.Calendar.FRIDAY
import java.util.Calendar.MONDAY
import java.util.Calendar.SATURDAY
import java.util.Calendar.SUNDAY
import java.util.Calendar.THURSDAY
import java.util.Calendar.TUESDAY
import java.util.Calendar.WEDNESDAY
import java.util.Locale
import javax.inject.Inject
@AndroidEntryPoint
@ -56,6 +63,7 @@ class DateTimePicker : BaseDateTimePicker() {
const val EXTRA_TIME = "extra_time"
const val EXTRA_TASKS = "extra_tasks"
const val EXTRA_TIMESTAMP = "extra_timestamp"
const val EXTRA_HIDE_NO_DATE = "extra_hide_no_date"
private const val REQUEST_TIME = 10101
private const val FRAG_TAG_TIME_PICKER = "frag_tag_time_picker"
private const val NO_DAY = 0L
@ -63,26 +71,37 @@ class DateTimePicker : BaseDateTimePicker() {
private const val MULTIPLE_DAYS = -1L
private const val MULTIPLE_TIMES = -1
fun newDateTimePicker(autoClose: Boolean, vararg tasks: Task): DateTimePicker {
val bundle = Bundle()
bundle.putLongArray(EXTRA_TASKS, tasks.map { it.id }.toLongArray())
fun newDateTimePicker(
autoClose: Boolean,
vararg tasks: Task
): DateTimePicker {
val fragment = DateTimePicker()
val dueDates = tasks.map { it.dueDate.startOfDay() }.toSet()
val dueTimes = tasks.map { it.dueDate.millisOfDay() }.toSet()
bundle.putLong(EXTRA_DAY, if (dueDates.size == 1) dueDates.first() else MULTIPLE_DAYS)
bundle.putInt(EXTRA_TIME, if (dueTimes.size == 1) dueTimes.first() else MULTIPLE_TIMES)
bundle.putBoolean(EXTRA_AUTO_CLOSE, autoClose)
val fragment = DateTimePicker()
fragment.arguments = bundle
fragment.arguments = Bundle().apply {
putLongArray(EXTRA_TASKS, tasks.map { it.id }.toLongArray())
putLong(EXTRA_DAY, if (dueDates.size == 1) dueDates.first() else MULTIPLE_DAYS)
putInt(EXTRA_TIME, if (dueTimes.size == 1) dueTimes.first() else MULTIPLE_TIMES)
putBoolean(EXTRA_HIDE_NO_DATE, tasks.any { it.isRecurring })
putBoolean(EXTRA_AUTO_CLOSE, autoClose)
}
return fragment
}
fun newDateTimePicker(target: Fragment, rc: Int, current: Long, autoClose: Boolean): DateTimePicker {
val bundle = Bundle()
bundle.putLong(EXTRA_DAY, current.startOfDay())
bundle.putInt(EXTRA_TIME, current.millisOfDay())
bundle.putBoolean(EXTRA_AUTO_CLOSE, autoClose)
fun newDateTimePicker(
target: Fragment,
rc: Int,
current: Long,
autoClose: Boolean,
hideNoDate: Boolean,
): DateTimePicker {
val fragment = DateTimePicker()
fragment.arguments = bundle
fragment.arguments = Bundle().apply {
putLong(EXTRA_DAY, current.startOfDay())
putInt(EXTRA_TIME, current.millisOfDay())
putBoolean(EXTRA_AUTO_CLOSE, autoClose)
putBoolean(EXTRA_HIDE_NO_DATE, hideNoDate)
}
fragment.setTargetFragment(target, rc)
return fragment
}
@ -105,6 +124,7 @@ class DateTimePicker : BaseDateTimePicker() {
else -> throw IllegalArgumentException()
}
)
noDateButton.isGone = requireArguments().getBoolean(EXTRA_HIDE_NO_DATE, false)
noDateButton.setOnClickListener { clearDate() }
noTime.setOnClickListener { clearTime() }
todayButton.setOnClickListener { setToday() }

Loading…
Cancel
Save