Move noncancellable context to save

pull/1051/head
Alex Baker 4 years ago
parent 0226440833
commit 43814b0810

@ -27,9 +27,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.NonCancellable
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.tasks.LocalBroadcastManager
import org.tasks.R
import org.tasks.activities.TagSettingsActivity
@ -175,10 +173,11 @@ class MainActivity : InjectingAppCompatActivity(), TaskListFragmentCallbackHandl
val intent = intent
val openFilter = intent.hasExtra(OPEN_FILTER)
val loadFilter = intent.hasExtra(LOAD_FILTER)
val tef = taskEditFragment
if (tef != null && (openFilter || loadFilter)) {
lifecycleScope.launch(NonCancellable) {
tef.save()
if (openFilter || loadFilter) {
taskEditFragment?.let {
lifecycleScope.launch {
it.save()
}
}
}
if (loadFilter || !openFilter && filter == null) {
@ -312,9 +311,7 @@ class MainActivity : InjectingAppCompatActivity(), TaskListFragmentCallbackHandl
lifecycleScope.launch {
taskEditFragment?.let {
it.editViewModel.cleared.removeObservers(this@MainActivity)
withContext(NonCancellable) {
it.save()
}
it.save()
}
clearUi()
val fragment = newTaskEditFragment(
@ -344,7 +341,7 @@ class MainActivity : InjectingAppCompatActivity(), TaskListFragmentCallbackHandl
}
taskEditFragment?.let {
if (preferences.backButtonSavesTask()) {
lifecycleScope.launch(NonCancellable) {
lifecycleScope.launch {
it.save()
}
} else {

@ -103,7 +103,7 @@ class TaskEditFragment : Fragment(), Toolbar.OnMenuItemClickListener {
val toolbar = binding.toolbar
toolbar.navigationIcon = context.getDrawable(R.drawable.ic_outline_save_24px)
toolbar.setNavigationOnClickListener {
lifecycleScope.launch(NonCancellable) {
lifecycleScope.launch {
save()
}
}
@ -153,7 +153,7 @@ class TaskEditFragment : Fragment(), Toolbar.OnMenuItemClickListener {
binding.fab.setImageResource(R.drawable.ic_outline_check_box_24px)
} else {
editViewModel.completed = true
lifecycleScope.launch(NonCancellable) {
lifecycleScope.launch {
save()
}
}
@ -251,7 +251,7 @@ class TaskEditFragment : Fragment(), Toolbar.OnMenuItemClickListener {
}
/** Save task model from values in UI components */
suspend fun save() {
suspend fun save() = withContext(NonCancellable) {
val saved = editViewModel.save()
if (saved && editViewModel.isNew) {
(activity as MainActivity?)?.taskListFragment?.let { taskListFragment ->

Loading…
Cancel
Save