From 4cd6e081f5ec8d0f712765fdf48304af88d1f6ae Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Mon, 17 Aug 2020 16:19:23 -0500 Subject: [PATCH] Load task edit info in parallel --- .../todoroo/astrid/activity/MainActivity.kt | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) 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 e4b93b8b5..e792456bf 100644 --- a/app/src/main/java/com/todoroo/astrid/activity/MainActivity.kt +++ b/app/src/main/java/com/todoroo/astrid/activity/MainActivity.kt @@ -26,7 +26,7 @@ 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.launch +import kotlinx.coroutines.* import org.tasks.BuildConfig import org.tasks.LocalBroadcastManager import org.tasks.R @@ -355,17 +355,27 @@ class MainActivity : InjectingAppCompatActivity(), TaskListFragmentCallbackHandl it.save() } clearUi() - val fragment = newTaskEditFragment( - task, - defaultFilterProvider.getList(task), - locationDao.getLocation(task, preferences), - tagDataDao.getTags(task), - alarmDao.getAlarms(task), - filterColor) - supportFragmentManager.beginTransaction() - .replace(R.id.detail, fragment, TaskEditFragment.TAG_TASKEDIT_FRAGMENT) - .runOnCommit(this::showDetailFragment) - .commitNow() + coroutineScope { + val freshTask = async { if (task.isNew) task else taskDao.fetch(task.id) ?: task } + val list = async { defaultFilterProvider.getList(task) } + val location = async { locationDao.getLocation(task, preferences) } + val tags = async { tagDataDao.getTags(task) } + val alarms = async { alarmDao.getAlarms(task) } + val fragment = withContext(Dispatchers.Default) { + newTaskEditFragment( + freshTask.await(), + list.await(), + location.await(), + tags.await(), + alarms.await(), + filterColor) + } + supportFragmentManager.beginTransaction() + .replace(R.id.detail, fragment, TaskEditFragment.TAG_TASKEDIT_FRAGMENT) + .runOnCommit { showDetailFragment() } + .commitNow() + + } } override fun onNavigationIconClicked() {