diff --git a/app/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java b/app/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java index f2aca943d..b8bc49b8b 100644 --- a/app/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java +++ b/app/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java @@ -89,6 +89,8 @@ import org.tasks.data.CaldavCalendar; import org.tasks.data.CaldavDao; import org.tasks.data.Place; import org.tasks.data.TagDataDao; +import org.tasks.data.TaskContainer; +import org.tasks.dialogs.DateTimePicker; import org.tasks.dialogs.DialogBuilder; import org.tasks.dialogs.SortDialog; import org.tasks.etesync.EteSyncCalendarSettingsActivity; @@ -128,9 +130,11 @@ public final class TaskListFragment extends InjectingFragment private static final String EXTRA_FILTER = "extra_filter"; private static final String FRAG_TAG_REMOTE_LIST_PICKER = "frag_tag_remote_list_picker"; private static final String FRAG_TAG_SORT_DIALOG = "frag_tag_sort_dialog"; + private static final String FRAG_TAG_DATE_TIME_PICKER = "frag_tag_date_time_picker"; private static final int REQUEST_LIST_SETTINGS = 10101; private static final int REQUEST_MOVE_TASKS = 10103; private static final int REQUEST_TAG_TASKS = 10106; + private static final int REQUEST_DUE_DATE = 10107; private static final int SEARCH_DEBOUNCE_TIMEOUT = 300; private final RefreshReceiver refreshReceiver = new RefreshReceiver(); @@ -634,6 +638,15 @@ public final class TaskListFragment extends InjectingFragment finishActionMode(); } break; + case REQUEST_DUE_DATE: + if (resultCode == RESULT_OK) { + long taskId = data.getLongExtra(DateTimePicker.EXTRA_TASK, 0L); + Task task = taskDao.fetch(taskId); + long dueDate = data.getLongExtra(DateTimePicker.EXTRA_TIMESTAMP, 0L); + task.setDueDateAdjustingHideUntil(dueDate); + taskDao.save(task); + } + break; default: super.onActivityResult(requestCode, resultCode, data); } @@ -756,6 +769,11 @@ 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); + } + public interface TaskListFragmentCallbackHandler { void onTaskListItemClicked(Task task); diff --git a/app/src/main/java/org/tasks/dialogs/DateTimePicker.kt b/app/src/main/java/org/tasks/dialogs/DateTimePicker.kt index c03891d98..2d00cf2f6 100644 --- a/app/src/main/java/org/tasks/dialogs/DateTimePicker.kt +++ b/app/src/main/java/org/tasks/dialogs/DateTimePicker.kt @@ -2,19 +2,14 @@ package org.tasks.dialogs import android.app.Activity import android.app.Activity.RESULT_OK -import android.app.Dialog import android.content.Intent import android.os.Bundle -import android.view.Gravity import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.FrameLayout -import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.fragment.app.Fragment import butterknife.ButterKnife import butterknife.OnClick -import com.google.android.material.bottomsheet.BottomSheetDialog import com.todoroo.andlib.utility.AndroidUtilities import com.todoroo.andlib.utility.AndroidUtilities.atLeastMarshmallow import com.todoroo.andlib.utility.DateUtilities @@ -50,14 +45,16 @@ class DateTimePicker : InjectingBottomSheetDialogFragment() { companion object { const val EXTRA_TIMESTAMP = "extra_timestamp" + const val EXTRA_TASK = "extra_task" 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, current: Long): DateTimePicker { + fun newDateTimePicker(target: Fragment, rc: Int, task: Long, current: Long): DateTimePicker { val bundle = Bundle() + bundle.putLong(EXTRA_TASK, task) bundle.putLong(EXTRA_TIMESTAMP, current) val fragment = DateTimePicker() fragment.arguments = bundle @@ -201,7 +198,10 @@ class DateTimePicker : InjectingBottomSheetDialogFragment() { private fun returnDate(date: Long? = selected?.millis) { selected = if (date == null || date <= 0) null else DateTime(date) - targetFragment?.onActivityResult(targetRequestCode, RESULT_OK, Intent().putExtra(EXTRA_TIMESTAMP, selected?.millis ?: 0)) + val intent = Intent() + intent.putExtra(EXTRA_TIMESTAMP, selected?.millis ?: 0) + intent.putExtra(EXTRA_TASK, arguments?.getLong(EXTRA_TASK) ?: 0) + targetFragment?.onActivityResult(targetRequestCode, RESULT_OK, intent) dismiss() } diff --git a/app/src/main/java/org/tasks/tasklist/TaskListRecyclerAdapter.java b/app/src/main/java/org/tasks/tasklist/TaskListRecyclerAdapter.java index 7d88f3164..b027a852b 100644 --- a/app/src/main/java/org/tasks/tasklist/TaskListRecyclerAdapter.java +++ b/app/src/main/java/org/tasks/tasklist/TaskListRecyclerAdapter.java @@ -1,20 +1,25 @@ package org.tasks.tasklist; import android.view.ViewGroup; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.ListUpdateCallback; import androidx.recyclerview.widget.RecyclerView; + import com.todoroo.astrid.activity.TaskListFragment; import com.todoroo.astrid.adapter.TaskAdapter; import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.dao.TaskDao; -import java.util.List; + import org.tasks.data.TaskContainer; +import org.tasks.dialogs.DateTimePicker; import org.tasks.intents.TaskIntents; import org.tasks.tasklist.ViewHolder.ViewHolderCallbacks; +import java.util.List; + public abstract class TaskListRecyclerAdapter extends RecyclerView.Adapter implements ViewHolderCallbacks, ListUpdateCallback { @@ -89,6 +94,11 @@ public abstract class TaskListRecyclerAdapter extends RecyclerView.Adapter