diff --git a/app/src/main/java/com/todoroo/astrid/activity/MainActivity.kt b/app/src/main/java/com/todoroo/astrid/activity/MainActivity.kt index 624ded33f..c649bd9c8 100644 --- a/app/src/main/java/com/todoroo/astrid/activity/MainActivity.kt +++ b/app/src/main/java/com/todoroo/astrid/activity/MainActivity.kt @@ -19,6 +19,7 @@ import androidx.drawerlayout.widget.DrawerLayout.SimpleDrawerListener import androidx.fragment.app.FragmentManager import androidx.lifecycle.lifecycleScope import com.todoroo.andlib.utility.AndroidUtilities +import com.todoroo.astrid.activity.TaskEditFragment.Companion.newTaskEditFragment import com.todoroo.astrid.activity.TaskEditFragment.TaskEditFragmentCallbackHandler import com.todoroo.astrid.activity.TaskListFragment.TaskListFragmentCallbackHandler import com.todoroo.astrid.api.Filter @@ -27,12 +28,15 @@ import com.todoroo.astrid.data.Task import com.todoroo.astrid.service.TaskCreator import com.todoroo.astrid.timers.TimerControlSet.TimerControlSetCallback import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.async import kotlinx.coroutines.launch import org.tasks.LocalBroadcastManager import org.tasks.R import org.tasks.activities.TagSettingsActivity import org.tasks.billing.Inventory +import org.tasks.data.LocationDao import org.tasks.data.Place +import org.tasks.data.TagDataDao import org.tasks.databinding.TaskListActivityBinding import org.tasks.dialogs.SortDialog.SortDialogCallback import org.tasks.dialogs.WhatsNewDialog @@ -67,6 +71,9 @@ class MainActivity : InjectingAppCompatActivity(), TaskListFragmentCallbackHandl @Inject lateinit var playServices: PlayServices @Inject lateinit var inventory: Inventory @Inject lateinit var colorProvider: ColorProvider + @Inject lateinit var locationDao: LocationDao + @Inject lateinit var tagDataDao: TagDataDao + private lateinit var navigationDrawer: NavigationDrawerFragment private var currentNightMode = 0 private var currentPro = false @@ -230,7 +237,8 @@ class MainActivity : InjectingAppCompatActivity(), TaskListFragmentCallbackHandl private fun openTaskListFragment(taskListFragment: TaskListFragment, force: Boolean) { AndroidUtilities.assertMainThread() val newFilter = taskListFragment.getFilter() - if (filter != null && !force + if (filter != null + && !force && filter!!.areItemsTheSame(newFilter) && filter!!.areContentsTheSame(newFilter)) { return @@ -239,12 +247,11 @@ class MainActivity : InjectingAppCompatActivity(), TaskListFragmentCallbackHandl navigationDrawer.setSelected(filter) defaultFilterProvider.lastViewedFilter = newFilter applyTheme() - val fragmentManager = supportFragmentManager - fragmentManager + supportFragmentManager .beginTransaction() .replace(R.id.master, taskListFragment, FRAG_TAG_TASK_LIST) - .commit() - fragmentManager.executePendingTransactions() + .commitNow() + } private fun applyTheme() { @@ -301,27 +308,20 @@ class MainActivity : InjectingAppCompatActivity(), TaskListFragmentCallbackHandl val taskEditFragment = taskEditFragment taskEditFragment?.save() clearUi() - if (task.isNew) { - openTask(task) - } else { - lifecycleScope.launch { - openTask(taskDao.fetch(task.id)) - } + lifecycleScope.launch { + val list = async { defaultFilterProvider.getList(task) } + val location = async { locationDao.getLocation(task, preferences) } + val tags = async { tagDataDao.getTags(task) } + val fragment = newTaskEditFragment( + task, filterColor, list.await(), location.await(), tags.await()) + supportFragmentManager.beginTransaction() + .replace(R.id.detail, fragment, TaskEditFragment.TAG_TASKEDIT_FRAGMENT) + .addToBackStack(TaskEditFragment.TAG_TASKEDIT_FRAGMENT) + .commit() + showDetailFragment() } } - private fun openTask(task: Task?) { - supportFragmentManager - .beginTransaction() - .replace( - R.id.detail, - TaskEditFragment.newTaskEditFragment(task, filterColor), - TaskEditFragment.TAG_TASKEDIT_FRAGMENT) - .addToBackStack(TaskEditFragment.TAG_TASKEDIT_FRAGMENT) - .commit() - showDetailFragment() - } - override fun onNavigationIconClicked() { hideKeyboard() navigationDrawer.openDrawer() diff --git a/app/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.kt b/app/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.kt index a437cc39b..341a6e74e 100755 --- a/app/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.kt +++ b/app/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.kt @@ -27,7 +27,9 @@ import com.google.android.material.appbar.AppBarLayout.Behavior.DragCallback import com.google.android.material.appbar.AppBarLayout.OnOffsetChangedListener import com.todoroo.andlib.utility.AndroidUtilities import com.todoroo.andlib.utility.DateUtilities +import com.todoroo.astrid.api.CaldavFilter import com.todoroo.astrid.api.Filter +import com.todoroo.astrid.api.GtasksFilter import com.todoroo.astrid.dao.TaskDao import com.todoroo.astrid.data.Task import com.todoroo.astrid.notes.CommentsController @@ -38,9 +40,12 @@ import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.NonCancellable import kotlinx.coroutines.launch import kotlinx.coroutines.withContext +import org.tasks.BuildConfig import org.tasks.R import org.tasks.Strings.isNullOrEmpty import org.tasks.analytics.Firebase +import org.tasks.data.Location +import org.tasks.data.TagData import org.tasks.data.UserActivity import org.tasks.data.UserActivityDao import org.tasks.databinding.FragmentTaskEditBinding @@ -170,7 +175,8 @@ class TaskEditFragment : Fragment(), Toolbar.OnMenuItemClickListener { commentsController.initialize(model, binding.comments) commentsController.reloadView() val fragmentManager = childFragmentManager - val taskEditControlFragments = taskEditControlSetFragmentManager.getOrCreateFragments(this, model) + val taskEditControlFragments = + taskEditControlSetFragmentManager.getOrCreateFragments(fragmentManager, model, arguments) val visibleSize = taskEditControlSetFragmentManager.visibleSize val fragmentTransaction = fragmentManager.beginTransaction() for (i in taskEditControlFragments.indices) { @@ -384,12 +390,27 @@ class TaskEditFragment : Fragment(), Toolbar.OnMenuItemClickListener { const val TAG_TASKEDIT_FRAGMENT = "taskedit_fragment" private const val EXTRA_TASK = "extra_task" private const val EXTRA_THEME = "extra_theme" + const val EXTRA_LIST = "extra_list" + const val EXTRA_PLACE = "extra_place" + const val EXTRA_TAGS = "extra_tags" private const val EXTRA_COMPLETED = "extra_completed" - fun newTaskEditFragment(task: Task?, themeColor: ThemeColor?): TaskEditFragment { + + fun newTaskEditFragment( + task: Task, + themeColor: ThemeColor?, + filter: Filter, + place: Location?, + tags: ArrayList): TaskEditFragment { + if (BuildConfig.DEBUG) { + require(filter is GtasksFilter || filter is CaldavFilter) + } val taskEditFragment = TaskEditFragment() val arguments = Bundle() arguments.putParcelable(EXTRA_TASK, task) arguments.putParcelable(EXTRA_THEME, themeColor) + arguments.putParcelable(EXTRA_LIST, filter) + arguments.putParcelable(EXTRA_PLACE, place) + arguments.putParcelableArrayList(EXTRA_TAGS, tags) taskEditFragment.arguments = arguments return taskEditFragment } diff --git a/app/src/main/java/com/todoroo/astrid/files/FilesControlSet.kt b/app/src/main/java/com/todoroo/astrid/files/FilesControlSet.kt index 8c18546b6..90fb5c152 100644 --- a/app/src/main/java/com/todoroo/astrid/files/FilesControlSet.kt +++ b/app/src/main/java/com/todoroo/astrid/files/FilesControlSet.kt @@ -47,7 +47,7 @@ class FilesControlSet : TaskEditControlFragment() { private var taskUuid: String? = null - override suspend fun createView(savedInstanceState: Bundle?) { + override fun createView(savedInstanceState: Bundle?) { taskUuid = task.uuid if (savedInstanceState == null) { if (task.hasTransitory(TaskAttachment.KEY)) { @@ -57,9 +57,11 @@ class FilesControlSet : TaskEditControlFragment() { } } - taskAttachmentDao - .getAttachments(task.uuid) - .forEach { addAttachment(it) } + lifecycleScope.launch { + taskAttachmentDao + .getAttachments(task.uuid) + .forEach { addAttachment(it) } + } } @OnClick(R.id.add_attachment) diff --git a/app/src/main/java/com/todoroo/astrid/repeats/RepeatControlSet.kt b/app/src/main/java/com/todoroo/astrid/repeats/RepeatControlSet.kt index f8932844a..f2bf6c965 100644 --- a/app/src/main/java/com/todoroo/astrid/repeats/RepeatControlSet.kt +++ b/app/src/main/java/com/todoroo/astrid/repeats/RepeatControlSet.kt @@ -86,7 +86,7 @@ class RepeatControlSet : TaskEditControlFragment() { } } - override suspend fun createView(savedInstanceState: Bundle?) { + override fun createView(savedInstanceState: Bundle?) { if (savedInstanceState == null) { repeatAfterCompletion = task.repeatAfterCompletion() dueDate = task.dueDate diff --git a/app/src/main/java/com/todoroo/astrid/tags/TagsControlSet.kt b/app/src/main/java/com/todoroo/astrid/tags/TagsControlSet.kt index e5af9a5f8..23eb2f88e 100644 --- a/app/src/main/java/com/todoroo/astrid/tags/TagsControlSet.kt +++ b/app/src/main/java/com/todoroo/astrid/tags/TagsControlSet.kt @@ -13,6 +13,7 @@ import android.widget.TextView import butterknife.BindView import com.google.android.material.chip.ChipGroup import com.todoroo.andlib.utility.DateUtilities +import com.todoroo.astrid.activity.TaskEditFragment import com.todoroo.astrid.data.Task import dagger.hilt.android.AndroidEntryPoint import org.tasks.R @@ -45,13 +46,9 @@ class TagsControlSet : TaskEditControlFragment() { private lateinit var originalTags: ArrayList private lateinit var selectedTags: ArrayList - override suspend fun createView(savedInstanceState: Bundle?) { + override fun createView(savedInstanceState: Bundle?) { if (savedInstanceState == null) { - originalTags = ArrayList(if (task.isNew) { - task.tags.mapNotNull { tagDataDao.getTagByName(it) } - } else { - tagDataDao.getTagDataForTask(task.id) - }) + originalTags = requireArguments().getParcelableArrayList(TaskEditFragment.EXTRA_TAGS)!! selectedTags = ArrayList(originalTags) refreshDisplayView() } else { diff --git a/app/src/main/java/com/todoroo/astrid/timers/TimerControlSet.kt b/app/src/main/java/com/todoroo/astrid/timers/TimerControlSet.kt index 8f6797ea7..2ae48d312 100644 --- a/app/src/main/java/com/todoroo/astrid/timers/TimerControlSet.kt +++ b/app/src/main/java/com/todoroo/astrid/timers/TimerControlSet.kt @@ -56,7 +56,7 @@ class TimerControlSet : TaskEditControlFragment() { private lateinit var dialogView: View private lateinit var callback: TimerControlSetCallback - override suspend fun createView(savedInstanceState: Bundle?) { + override fun createView(savedInstanceState: Bundle?) { val elapsedSeconds: Int val estimatedSeconds: Int if (savedInstanceState == null) { diff --git a/app/src/main/java/com/todoroo/astrid/ui/HideUntilControlSet.kt b/app/src/main/java/com/todoroo/astrid/ui/HideUntilControlSet.kt index d05a078ad..3cd496a73 100644 --- a/app/src/main/java/com/todoroo/astrid/ui/HideUntilControlSet.kt +++ b/app/src/main/java/com/todoroo/astrid/ui/HideUntilControlSet.kt @@ -70,7 +70,7 @@ class HideUntilControlSet : TaskEditControlFragment(), OnItemSelectedListener { override val isClickable: Boolean get() = true - override suspend fun createView(savedInstanceState: Bundle?) { + override fun createView(savedInstanceState: Bundle?) { adapter = object : HiddenTopArrayAdapter( activity, android.R.layout.simple_spinner_item, spinnerItems) { override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { diff --git a/app/src/main/java/com/todoroo/astrid/ui/ReminderControlSet.kt b/app/src/main/java/com/todoroo/astrid/ui/ReminderControlSet.kt index b30b91879..760306dbe 100644 --- a/app/src/main/java/com/todoroo/astrid/ui/ReminderControlSet.kt +++ b/app/src/main/java/com/todoroo/astrid/ui/ReminderControlSet.kt @@ -10,9 +10,7 @@ import android.content.DialogInterface import android.content.Intent import android.graphics.Paint import android.os.Bundle -import android.view.LayoutInflater import android.view.View -import android.view.ViewGroup import android.widget.LinearLayout import android.widget.TextView import androidx.annotation.StringRes @@ -64,18 +62,17 @@ class ReminderControlSet : TaskEditControlFragment() { private var whenDue = false private var whenOverdue = false - override suspend fun createView(savedInstanceState: Bundle?) { + override fun createView(savedInstanceState: Bundle?) { mode.paintFlags = mode.paintFlags or Paint.UNDERLINE_TEXT_FLAG taskId = task.id if (savedInstanceState == null) { flags = task.reminderFlags randomReminder = task.reminderPeriod - setup(currentAlarms()) } else { flags = savedInstanceState.getInt(EXTRA_FLAGS) randomReminder = savedInstanceState.getLong(EXTRA_RANDOM_REMINDER) - setup(savedInstanceState.getLongArray(EXTRA_ALARMS)!!.toList()) } + setup(savedInstanceState) } private suspend fun currentAlarms(): List { @@ -149,7 +146,7 @@ class ReminderControlSet : TaskEditControlFragment() { return TAG } - private fun setup(alarms: List) { + private fun setup(savedInstanceState: Bundle?) { setValue(flags) alertContainer.removeAllViews() if (whenDue) { @@ -161,8 +158,12 @@ class ReminderControlSet : TaskEditControlFragment() { if (randomReminder > 0) { addRandomReminder(randomReminder) } - for (timestamp in alarms) { - addAlarmRow(timestamp) + if (savedInstanceState == null) { + lifecycleScope.launch { + currentAlarms().forEach { addAlarmRow(it) } + } + } else { + savedInstanceState.getLongArray(EXTRA_ALARMS)?.forEach { addAlarmRow(it) } } } diff --git a/app/src/main/java/org/tasks/data/LocationDao.kt b/app/src/main/java/org/tasks/data/LocationDao.kt index 760bc653a..05e78a8e6 100644 --- a/app/src/main/java/org/tasks/data/LocationDao.kt +++ b/app/src/main/java/org/tasks/data/LocationDao.kt @@ -3,7 +3,9 @@ package org.tasks.data import androidx.lifecycle.LiveData import androidx.room.* import com.todoroo.astrid.api.FilterListItem.NO_ORDER +import com.todoroo.astrid.data.Task import org.tasks.filters.LocationFilters +import org.tasks.preferences.Preferences import org.tasks.time.DateTimeUtils.currentTimeMillis @Dao @@ -115,4 +117,17 @@ interface LocationDao { @Query("UPDATE places SET place_order = :order WHERE place_id = :id") suspend fun setOrder(id: Long, order: Int) + + suspend fun getLocation(task: Task, preferences: Preferences): Location? { + if (task.isNew) { + if (task.hasTransitory(Place.KEY)) { + getPlace(task.getTransitory(Place.KEY)!!)?.let { + return Location(Geofence(it.uid, preferences), it) + } + } + } else { + return getGeofences(task.id) + } + return null + } } \ No newline at end of file diff --git a/app/src/main/java/org/tasks/data/TagDataDao.kt b/app/src/main/java/org/tasks/data/TagDataDao.kt index 1e70b57e6..4001172e6 100644 --- a/app/src/main/java/org/tasks/data/TagDataDao.kt +++ b/app/src/main/java/org/tasks/data/TagDataDao.kt @@ -155,4 +155,10 @@ abstract class TagDataDao { @Query("UPDATE tagdata SET td_order = :order WHERE _id = :id") abstract suspend fun setOrder(id: Long, order: Int) + + suspend fun getTags(task: Task) = ArrayList(if (task.isNew) { + task.tags.mapNotNull { getTagByName(it) } + } else { + getTagDataForTask(task.id) + }) } \ No newline at end of file diff --git a/app/src/main/java/org/tasks/fragments/CommentBarFragment.kt b/app/src/main/java/org/tasks/fragments/CommentBarFragment.kt index 065ba41fb..35d2bad65 100644 --- a/app/src/main/java/org/tasks/fragments/CommentBarFragment.kt +++ b/app/src/main/java/org/tasks/fragments/CommentBarFragment.kt @@ -65,7 +65,7 @@ class CommentBarFragment : TaskEditControlFragment() { return view } - override suspend fun createView(savedInstanceState: Bundle?) { + override fun createView(savedInstanceState: Bundle?) { if (savedInstanceState != null) { val uri = savedInstanceState.getString(EXTRA_PICTURE) if (uri != null) { diff --git a/app/src/main/java/org/tasks/fragments/TaskEditControlSetFragmentManager.kt b/app/src/main/java/org/tasks/fragments/TaskEditControlSetFragmentManager.kt index f2579aea7..d59728664 100644 --- a/app/src/main/java/org/tasks/fragments/TaskEditControlSetFragmentManager.kt +++ b/app/src/main/java/org/tasks/fragments/TaskEditControlSetFragmentManager.kt @@ -4,7 +4,6 @@ import android.content.Context import android.os.Bundle import androidx.fragment.app.FragmentManager import com.todoroo.astrid.activity.BeastModePreferences -import com.todoroo.astrid.activity.TaskEditFragment import com.todoroo.astrid.data.Task import com.todoroo.astrid.files.FilesControlSet import com.todoroo.astrid.repeats.RepeatControlSet @@ -34,12 +33,12 @@ class TaskEditControlSetFragmentManager @Inject constructor( } fun getOrCreateFragments( - taskEditFragment: TaskEditFragment, task: Task): List { - val arguments = Bundle() + fragmentManager: FragmentManager, + task: Task, + arguments: Bundle): List { arguments.putParcelable(TaskEditControlFragment.EXTRA_TASK, task) arguments.putBoolean(TaskEditControlFragment.EXTRA_IS_NEW, task.isNew) val fragments: MutableList = ArrayList() - val fragmentManager = taskEditFragment.childFragmentManager for (i in displayOrder.indices) { val tag = displayOrder[i] var fragment = fragmentManager.findFragmentByTag(tag) as TaskEditControlFragment? diff --git a/app/src/main/java/org/tasks/preferences/DefaultFilterProvider.kt b/app/src/main/java/org/tasks/preferences/DefaultFilterProvider.kt index 1dd2af609..ebaf8e5b6 100644 --- a/app/src/main/java/org/tasks/preferences/DefaultFilterProvider.kt +++ b/app/src/main/java/org/tasks/preferences/DefaultFilterProvider.kt @@ -5,6 +5,7 @@ import com.todoroo.astrid.api.* import com.todoroo.astrid.api.Filter import com.todoroo.astrid.core.BuiltInFilterExposer import com.todoroo.astrid.core.BuiltInFilterExposer.getMyTasksFilter +import com.todoroo.astrid.data.Task import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.coroutines.runBlocking import org.tasks.R @@ -21,7 +22,8 @@ class DefaultFilterProvider @Inject constructor( private val tagDataDao: TagDataDao, private val googleTaskListDao: GoogleTaskListDao, private val caldavDao: CaldavDao, - private val locationDao: LocationDao) { + private val locationDao: LocationDao, + private val googleTaskDao: GoogleTaskDao) { @Deprecated("use coroutines") var dashclockFilter: Filter @@ -153,6 +155,39 @@ class DefaultFilterProvider @Inject constructor( return FILTER_MY_TASKS } + suspend fun getList(task: Task): Filter { + var originalList: Filter? = null + if (task.isNew) { + if (task.hasTransitory(GoogleTask.KEY)) { + val listId = task.getTransitory(GoogleTask.KEY)!! + val googleTaskList = googleTaskListDao.getByRemoteId(listId) + if (googleTaskList != null) { + originalList = GtasksFilter(googleTaskList) + } + } else if (task.hasTransitory(CaldavTask.KEY)) { + val caldav = caldavDao.getCalendarByUuid(task.getTransitory(CaldavTask.KEY)!!) + if (caldav != null) { + originalList = CaldavFilter(caldav) + } + } + } else { + val googleTask = googleTaskDao.getByTaskId(task.id) + val caldavTask = caldavDao.getTask(task.id) + if (googleTask != null) { + val googleTaskList = googleTaskListDao.getByRemoteId(googleTask.listId!!) + if (googleTaskList != null) { + originalList = GtasksFilter(googleTaskList) + } + } else if (caldavTask != null) { + val calendarByUuid = caldavDao.getCalendarByUuid(caldavTask.calendar!!) + if (calendarByUuid != null) { + originalList = CaldavFilter(calendarByUuid) + } + } + } + return originalList ?: getDefaultList() + } + companion object { private const val TYPE_FILTER = 0 private const val TYPE_CUSTOM_FILTER = 1 diff --git a/app/src/main/java/org/tasks/ui/CalendarControlSet.kt b/app/src/main/java/org/tasks/ui/CalendarControlSet.kt index aae197a37..529a955c0 100644 --- a/app/src/main/java/org/tasks/ui/CalendarControlSet.kt +++ b/app/src/main/java/org/tasks/ui/CalendarControlSet.kt @@ -53,7 +53,7 @@ class CalendarControlSet : TaskEditControlFragment() { private var calendarId: String? = null private var eventUri: String? = null - override suspend fun createView(savedInstanceState: Bundle?) { + override fun createView(savedInstanceState: Bundle?) { val canAccessCalendars = permissionChecker.canAccessCalendars() if (savedInstanceState != null) { eventUri = savedInstanceState.getString(EXTRA_URI) diff --git a/app/src/main/java/org/tasks/ui/DeadlineControlSet.kt b/app/src/main/java/org/tasks/ui/DeadlineControlSet.kt index b27831769..cab9f1b84 100644 --- a/app/src/main/java/org/tasks/ui/DeadlineControlSet.kt +++ b/app/src/main/java/org/tasks/ui/DeadlineControlSet.kt @@ -37,7 +37,7 @@ class DeadlineControlSet : TaskEditControlFragment() { callback = activity as DueDateChangeListener } - override suspend fun createView(savedInstanceState: Bundle?) { + override fun createView(savedInstanceState: Bundle?) { date = savedInstanceState?.getLong(EXTRA_DATE) ?: task.dueDate refreshDisplayView() } diff --git a/app/src/main/java/org/tasks/ui/DescriptionControlSet.kt b/app/src/main/java/org/tasks/ui/DescriptionControlSet.kt index df473fd56..621e25447 100644 --- a/app/src/main/java/org/tasks/ui/DescriptionControlSet.kt +++ b/app/src/main/java/org/tasks/ui/DescriptionControlSet.kt @@ -22,7 +22,7 @@ class DescriptionControlSet : TaskEditControlFragment() { private var description: String? = null - override suspend fun createView(savedInstanceState: Bundle?) { + override fun createView(savedInstanceState: Bundle?) { description = if (savedInstanceState == null) { stripCarriageReturns(task.notes) } else { diff --git a/app/src/main/java/org/tasks/ui/ListFragment.kt b/app/src/main/java/org/tasks/ui/ListFragment.kt index 502299581..174c11068 100644 --- a/app/src/main/java/org/tasks/ui/ListFragment.kt +++ b/app/src/main/java/org/tasks/ui/ListFragment.kt @@ -3,23 +3,17 @@ package org.tasks.ui import android.app.Activity import android.content.Intent import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.lifecycle.lifecycleScope import butterknife.BindView import com.google.android.material.chip.ChipGroup +import com.todoroo.astrid.activity.TaskEditFragment import com.todoroo.astrid.api.CaldavFilter import com.todoroo.astrid.api.Filter import com.todoroo.astrid.api.GtasksFilter import com.todoroo.astrid.data.Task import com.todoroo.astrid.service.TaskMover import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.launch import org.tasks.R import org.tasks.activities.ListPicker -import org.tasks.data.* -import org.tasks.preferences.DefaultFilterProvider import javax.inject.Inject @AndroidEntryPoint @@ -27,10 +21,6 @@ class ListFragment : TaskEditControlFragment() { @BindView(R.id.chip_group) lateinit var chipGroup: ChipGroup - @Inject lateinit var googleTaskListDao: GoogleTaskListDao - @Inject lateinit var googleTaskDao: GoogleTaskDao - @Inject lateinit var caldavDao: CaldavDao - @Inject lateinit var defaultFilterProvider: DefaultFilterProvider @Inject lateinit var taskMover: TaskMover @Inject lateinit var chipProvider: ChipProvider @@ -47,39 +37,9 @@ class ListFragment : TaskEditControlFragment() { callback = activity as OnListChanged } - override suspend fun createView(savedInstanceState: Bundle?) { + override fun createView(savedInstanceState: Bundle?) { if (savedInstanceState == null) { - if (task.isNew) { - if (task.hasTransitory(GoogleTask.KEY)) { - val listId = task.getTransitory(GoogleTask.KEY)!! - val googleTaskList = googleTaskListDao.getByRemoteId(listId) - if (googleTaskList != null) { - originalList = GtasksFilter(googleTaskList) - } - } else if (task.hasTransitory(CaldavTask.KEY)) { - val caldav = caldavDao.getCalendarByUuid(task.getTransitory(CaldavTask.KEY)!!) - if (caldav != null) { - originalList = CaldavFilter(caldav) - } - } - } else { - val googleTask = googleTaskDao.getByTaskId(task.id) - val caldavTask = caldavDao.getTask(task.id) - if (googleTask != null) { - val googleTaskList = googleTaskListDao.getByRemoteId(googleTask.listId!!) - if (googleTaskList != null) { - originalList = GtasksFilter(googleTaskList) - } - } else if (caldavTask != null) { - val calendarByUuid = caldavDao.getCalendarByUuid(caldavTask.calendar!!) - if (calendarByUuid != null) { - originalList = CaldavFilter(calendarByUuid) - } - } - } - if (originalList == null) { - originalList = defaultFilterProvider.defaultList - } + originalList = requireArguments().getParcelable(TaskEditFragment.EXTRA_LIST)!! setSelected(originalList!!) } else { originalList = savedInstanceState.getParcelable(EXTRA_ORIGINAL_LIST) diff --git a/app/src/main/java/org/tasks/ui/LocationControlSet.kt b/app/src/main/java/org/tasks/ui/LocationControlSet.kt index 55d70f506..525f20d9f 100644 --- a/app/src/main/java/org/tasks/ui/LocationControlSet.kt +++ b/app/src/main/java/org/tasks/ui/LocationControlSet.kt @@ -8,20 +8,17 @@ import android.os.Parcelable import android.text.SpannableString import android.text.Spanned import android.text.style.ClickableSpan -import android.view.LayoutInflater import android.view.View -import android.view.ViewGroup import android.widget.ImageView import android.widget.TextView import androidx.core.util.Pair -import androidx.lifecycle.lifecycleScope import butterknife.BindView import butterknife.OnClick import com.todoroo.andlib.utility.DateUtilities +import com.todoroo.astrid.activity.TaskEditFragment import com.todoroo.astrid.data.SyncFlags import com.todoroo.astrid.data.Task import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.launch import org.tasks.PermissionUtil.verifyPermissions import org.tasks.R import org.tasks.Strings.isNullOrEmpty @@ -59,18 +56,9 @@ class LocationControlSet : TaskEditControlFragment() { private var original: Location? = null private var location: Location? = null - override suspend fun createView(savedInstanceState: Bundle?) { + override fun createView(savedInstanceState: Bundle?) { if (savedInstanceState == null) { - if (task.isNew) { - if (task.hasTransitory(Place.KEY)) { - val place = locationDao.getPlace(task.getTransitory(Place.KEY)!!) - if (place != null) { - original = Location(Geofence(place.uid, preferences), place) - } - } - } else { - original = locationDao.getGeofences(task.id) - } + original = requireArguments().getParcelable(TaskEditFragment.EXTRA_PLACE) if (original != null) { setLocation(Location(original!!.geofence, original!!.place)) } diff --git a/app/src/main/java/org/tasks/ui/PriorityControlSet.kt b/app/src/main/java/org/tasks/ui/PriorityControlSet.kt index 69fe8097b..4a8437d77 100644 --- a/app/src/main/java/org/tasks/ui/PriorityControlSet.kt +++ b/app/src/main/java/org/tasks/ui/PriorityControlSet.kt @@ -38,7 +38,7 @@ class PriorityControlSet : TaskEditControlFragment() { priority = getPriority() } - override suspend fun createView(savedInstanceState: Bundle?) { + override fun createView(savedInstanceState: Bundle?) { priority = savedInstanceState?.getInt(EXTRA_PRIORITY) ?: task.priority when (priority) { 0 -> priorityHigh.isChecked = true diff --git a/app/src/main/java/org/tasks/ui/SubtaskControlSet.kt b/app/src/main/java/org/tasks/ui/SubtaskControlSet.kt index c8d2c5f13..17e2a9096 100644 --- a/app/src/main/java/org/tasks/ui/SubtaskControlSet.kt +++ b/app/src/main/java/org/tasks/ui/SubtaskControlSet.kt @@ -79,7 +79,7 @@ class SubtaskControlSet : TaskEditControlFragment(), SubtaskViewHolder.Callbacks outState.putParcelableArrayList(EXTRA_NEW_SUBTASKS, newSubtasks) } - override suspend fun createView(savedInstanceState: Bundle?) { + override fun createView(savedInstanceState: Bundle?) { viewModel = ViewModelProvider(this).get(TaskListViewModel::class.java) if (savedInstanceState != null) { for (task in savedInstanceState.getParcelableArrayList(EXTRA_NEW_SUBTASKS)!!) { diff --git a/app/src/main/java/org/tasks/ui/TaskEditControlFragment.kt b/app/src/main/java/org/tasks/ui/TaskEditControlFragment.kt index af1871d6b..d5166399a 100644 --- a/app/src/main/java/org/tasks/ui/TaskEditControlFragment.kt +++ b/app/src/main/java/org/tasks/ui/TaskEditControlFragment.kt @@ -12,7 +12,6 @@ import androidx.lifecycle.lifecycleScope import butterknife.ButterKnife import com.todoroo.astrid.data.Task import kotlinx.coroutines.launch -import kotlinx.coroutines.runBlocking import org.tasks.R abstract class TaskEditControlFragment : Fragment() { @@ -40,7 +39,7 @@ abstract class TaskEditControlFragment : Fragment() { return view } - protected abstract suspend fun createView(savedInstanceState: Bundle?) + protected abstract fun createView(savedInstanceState: Bundle?) override fun onAttach(activity: Activity) { super.onAttach(activity)