Remove coroutines from fragment setup

pull/1047/head
Alex Baker 4 years ago
parent 964dff6b76
commit 443ac9e9e5

@ -19,6 +19,7 @@ import androidx.drawerlayout.widget.DrawerLayout.SimpleDrawerListener
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.todoroo.andlib.utility.AndroidUtilities 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.TaskEditFragment.TaskEditFragmentCallbackHandler
import com.todoroo.astrid.activity.TaskListFragment.TaskListFragmentCallbackHandler import com.todoroo.astrid.activity.TaskListFragment.TaskListFragmentCallbackHandler
import com.todoroo.astrid.api.Filter 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.service.TaskCreator
import com.todoroo.astrid.timers.TimerControlSet.TimerControlSetCallback import com.todoroo.astrid.timers.TimerControlSet.TimerControlSetCallback
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.async
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.tasks.LocalBroadcastManager import org.tasks.LocalBroadcastManager
import org.tasks.R import org.tasks.R
import org.tasks.activities.TagSettingsActivity import org.tasks.activities.TagSettingsActivity
import org.tasks.billing.Inventory import org.tasks.billing.Inventory
import org.tasks.data.LocationDao
import org.tasks.data.Place import org.tasks.data.Place
import org.tasks.data.TagDataDao
import org.tasks.databinding.TaskListActivityBinding import org.tasks.databinding.TaskListActivityBinding
import org.tasks.dialogs.SortDialog.SortDialogCallback import org.tasks.dialogs.SortDialog.SortDialogCallback
import org.tasks.dialogs.WhatsNewDialog import org.tasks.dialogs.WhatsNewDialog
@ -67,6 +71,9 @@ class MainActivity : InjectingAppCompatActivity(), TaskListFragmentCallbackHandl
@Inject lateinit var playServices: PlayServices @Inject lateinit var playServices: PlayServices
@Inject lateinit var inventory: Inventory @Inject lateinit var inventory: Inventory
@Inject lateinit var colorProvider: ColorProvider @Inject lateinit var colorProvider: ColorProvider
@Inject lateinit var locationDao: LocationDao
@Inject lateinit var tagDataDao: TagDataDao
private lateinit var navigationDrawer: NavigationDrawerFragment private lateinit var navigationDrawer: NavigationDrawerFragment
private var currentNightMode = 0 private var currentNightMode = 0
private var currentPro = false private var currentPro = false
@ -230,7 +237,8 @@ class MainActivity : InjectingAppCompatActivity(), TaskListFragmentCallbackHandl
private fun openTaskListFragment(taskListFragment: TaskListFragment, force: Boolean) { private fun openTaskListFragment(taskListFragment: TaskListFragment, force: Boolean) {
AndroidUtilities.assertMainThread() AndroidUtilities.assertMainThread()
val newFilter = taskListFragment.getFilter() val newFilter = taskListFragment.getFilter()
if (filter != null && !force if (filter != null
&& !force
&& filter!!.areItemsTheSame(newFilter) && filter!!.areItemsTheSame(newFilter)
&& filter!!.areContentsTheSame(newFilter)) { && filter!!.areContentsTheSame(newFilter)) {
return return
@ -239,12 +247,11 @@ class MainActivity : InjectingAppCompatActivity(), TaskListFragmentCallbackHandl
navigationDrawer.setSelected(filter) navigationDrawer.setSelected(filter)
defaultFilterProvider.lastViewedFilter = newFilter defaultFilterProvider.lastViewedFilter = newFilter
applyTheme() applyTheme()
val fragmentManager = supportFragmentManager supportFragmentManager
fragmentManager
.beginTransaction() .beginTransaction()
.replace(R.id.master, taskListFragment, FRAG_TAG_TASK_LIST) .replace(R.id.master, taskListFragment, FRAG_TAG_TASK_LIST)
.commit() .commitNow()
fragmentManager.executePendingTransactions()
} }
private fun applyTheme() { private fun applyTheme() {
@ -301,27 +308,20 @@ class MainActivity : InjectingAppCompatActivity(), TaskListFragmentCallbackHandl
val taskEditFragment = taskEditFragment val taskEditFragment = taskEditFragment
taskEditFragment?.save() taskEditFragment?.save()
clearUi() clearUi()
if (task.isNew) { lifecycleScope.launch {
openTask(task) val list = async { defaultFilterProvider.getList(task) }
} else { val location = async { locationDao.getLocation(task, preferences) }
lifecycleScope.launch { val tags = async { tagDataDao.getTags(task) }
openTask(taskDao.fetch(task.id)) 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() { override fun onNavigationIconClicked() {
hideKeyboard() hideKeyboard()
navigationDrawer.openDrawer() navigationDrawer.openDrawer()

@ -27,7 +27,9 @@ import com.google.android.material.appbar.AppBarLayout.Behavior.DragCallback
import com.google.android.material.appbar.AppBarLayout.OnOffsetChangedListener import com.google.android.material.appbar.AppBarLayout.OnOffsetChangedListener
import com.todoroo.andlib.utility.AndroidUtilities import com.todoroo.andlib.utility.AndroidUtilities
import com.todoroo.andlib.utility.DateUtilities import com.todoroo.andlib.utility.DateUtilities
import com.todoroo.astrid.api.CaldavFilter
import com.todoroo.astrid.api.Filter import com.todoroo.astrid.api.Filter
import com.todoroo.astrid.api.GtasksFilter
import com.todoroo.astrid.dao.TaskDao import com.todoroo.astrid.dao.TaskDao
import com.todoroo.astrid.data.Task import com.todoroo.astrid.data.Task
import com.todoroo.astrid.notes.CommentsController import com.todoroo.astrid.notes.CommentsController
@ -38,9 +40,12 @@ import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.NonCancellable import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.tasks.BuildConfig
import org.tasks.R import org.tasks.R
import org.tasks.Strings.isNullOrEmpty import org.tasks.Strings.isNullOrEmpty
import org.tasks.analytics.Firebase import org.tasks.analytics.Firebase
import org.tasks.data.Location
import org.tasks.data.TagData
import org.tasks.data.UserActivity import org.tasks.data.UserActivity
import org.tasks.data.UserActivityDao import org.tasks.data.UserActivityDao
import org.tasks.databinding.FragmentTaskEditBinding import org.tasks.databinding.FragmentTaskEditBinding
@ -170,7 +175,8 @@ class TaskEditFragment : Fragment(), Toolbar.OnMenuItemClickListener {
commentsController.initialize(model, binding.comments) commentsController.initialize(model, binding.comments)
commentsController.reloadView() commentsController.reloadView()
val fragmentManager = childFragmentManager val fragmentManager = childFragmentManager
val taskEditControlFragments = taskEditControlSetFragmentManager.getOrCreateFragments(this, model) val taskEditControlFragments =
taskEditControlSetFragmentManager.getOrCreateFragments(fragmentManager, model, arguments)
val visibleSize = taskEditControlSetFragmentManager.visibleSize val visibleSize = taskEditControlSetFragmentManager.visibleSize
val fragmentTransaction = fragmentManager.beginTransaction() val fragmentTransaction = fragmentManager.beginTransaction()
for (i in taskEditControlFragments.indices) { for (i in taskEditControlFragments.indices) {
@ -384,12 +390,27 @@ class TaskEditFragment : Fragment(), Toolbar.OnMenuItemClickListener {
const val TAG_TASKEDIT_FRAGMENT = "taskedit_fragment" const val TAG_TASKEDIT_FRAGMENT = "taskedit_fragment"
private const val EXTRA_TASK = "extra_task" private const val EXTRA_TASK = "extra_task"
private const val EXTRA_THEME = "extra_theme" 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" 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<TagData>): TaskEditFragment {
if (BuildConfig.DEBUG) {
require(filter is GtasksFilter || filter is CaldavFilter)
}
val taskEditFragment = TaskEditFragment() val taskEditFragment = TaskEditFragment()
val arguments = Bundle() val arguments = Bundle()
arguments.putParcelable(EXTRA_TASK, task) arguments.putParcelable(EXTRA_TASK, task)
arguments.putParcelable(EXTRA_THEME, themeColor) arguments.putParcelable(EXTRA_THEME, themeColor)
arguments.putParcelable(EXTRA_LIST, filter)
arguments.putParcelable(EXTRA_PLACE, place)
arguments.putParcelableArrayList(EXTRA_TAGS, tags)
taskEditFragment.arguments = arguments taskEditFragment.arguments = arguments
return taskEditFragment return taskEditFragment
} }

@ -47,7 +47,7 @@ class FilesControlSet : TaskEditControlFragment() {
private var taskUuid: String? = null private var taskUuid: String? = null
override suspend fun createView(savedInstanceState: Bundle?) { override fun createView(savedInstanceState: Bundle?) {
taskUuid = task.uuid taskUuid = task.uuid
if (savedInstanceState == null) { if (savedInstanceState == null) {
if (task.hasTransitory(TaskAttachment.KEY)) { if (task.hasTransitory(TaskAttachment.KEY)) {
@ -57,9 +57,11 @@ class FilesControlSet : TaskEditControlFragment() {
} }
} }
taskAttachmentDao lifecycleScope.launch {
.getAttachments(task.uuid) taskAttachmentDao
.forEach { addAttachment(it) } .getAttachments(task.uuid)
.forEach { addAttachment(it) }
}
} }
@OnClick(R.id.add_attachment) @OnClick(R.id.add_attachment)

@ -86,7 +86,7 @@ class RepeatControlSet : TaskEditControlFragment() {
} }
} }
override suspend fun createView(savedInstanceState: Bundle?) { override fun createView(savedInstanceState: Bundle?) {
if (savedInstanceState == null) { if (savedInstanceState == null) {
repeatAfterCompletion = task.repeatAfterCompletion() repeatAfterCompletion = task.repeatAfterCompletion()
dueDate = task.dueDate dueDate = task.dueDate

@ -13,6 +13,7 @@ import android.widget.TextView
import butterknife.BindView import butterknife.BindView
import com.google.android.material.chip.ChipGroup import com.google.android.material.chip.ChipGroup
import com.todoroo.andlib.utility.DateUtilities import com.todoroo.andlib.utility.DateUtilities
import com.todoroo.astrid.activity.TaskEditFragment
import com.todoroo.astrid.data.Task import com.todoroo.astrid.data.Task
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import org.tasks.R import org.tasks.R
@ -45,13 +46,9 @@ class TagsControlSet : TaskEditControlFragment() {
private lateinit var originalTags: ArrayList<TagData> private lateinit var originalTags: ArrayList<TagData>
private lateinit var selectedTags: ArrayList<TagData> private lateinit var selectedTags: ArrayList<TagData>
override suspend fun createView(savedInstanceState: Bundle?) { override fun createView(savedInstanceState: Bundle?) {
if (savedInstanceState == null) { if (savedInstanceState == null) {
originalTags = ArrayList(if (task.isNew) { originalTags = requireArguments().getParcelableArrayList(TaskEditFragment.EXTRA_TAGS)!!
task.tags.mapNotNull { tagDataDao.getTagByName(it) }
} else {
tagDataDao.getTagDataForTask(task.id)
})
selectedTags = ArrayList(originalTags) selectedTags = ArrayList(originalTags)
refreshDisplayView() refreshDisplayView()
} else { } else {

@ -56,7 +56,7 @@ class TimerControlSet : TaskEditControlFragment() {
private lateinit var dialogView: View private lateinit var dialogView: View
private lateinit var callback: TimerControlSetCallback private lateinit var callback: TimerControlSetCallback
override suspend fun createView(savedInstanceState: Bundle?) { override fun createView(savedInstanceState: Bundle?) {
val elapsedSeconds: Int val elapsedSeconds: Int
val estimatedSeconds: Int val estimatedSeconds: Int
if (savedInstanceState == null) { if (savedInstanceState == null) {

@ -70,7 +70,7 @@ class HideUntilControlSet : TaskEditControlFragment(), OnItemSelectedListener {
override val isClickable: Boolean override val isClickable: Boolean
get() = true get() = true
override suspend fun createView(savedInstanceState: Bundle?) { override fun createView(savedInstanceState: Bundle?) {
adapter = object : HiddenTopArrayAdapter<HideUntilValue>( adapter = object : HiddenTopArrayAdapter<HideUntilValue>(
activity, android.R.layout.simple_spinner_item, spinnerItems) { activity, android.R.layout.simple_spinner_item, spinnerItems) {
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {

@ -10,9 +10,7 @@ import android.content.DialogInterface
import android.content.Intent import android.content.Intent
import android.graphics.Paint import android.graphics.Paint
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.TextView import android.widget.TextView
import androidx.annotation.StringRes import androidx.annotation.StringRes
@ -64,18 +62,17 @@ class ReminderControlSet : TaskEditControlFragment() {
private var whenDue = false private var whenDue = false
private var whenOverdue = 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 mode.paintFlags = mode.paintFlags or Paint.UNDERLINE_TEXT_FLAG
taskId = task.id taskId = task.id
if (savedInstanceState == null) { if (savedInstanceState == null) {
flags = task.reminderFlags flags = task.reminderFlags
randomReminder = task.reminderPeriod randomReminder = task.reminderPeriod
setup(currentAlarms())
} else { } else {
flags = savedInstanceState.getInt(EXTRA_FLAGS) flags = savedInstanceState.getInt(EXTRA_FLAGS)
randomReminder = savedInstanceState.getLong(EXTRA_RANDOM_REMINDER) randomReminder = savedInstanceState.getLong(EXTRA_RANDOM_REMINDER)
setup(savedInstanceState.getLongArray(EXTRA_ALARMS)!!.toList())
} }
setup(savedInstanceState)
} }
private suspend fun currentAlarms(): List<Long> { private suspend fun currentAlarms(): List<Long> {
@ -149,7 +146,7 @@ class ReminderControlSet : TaskEditControlFragment() {
return TAG return TAG
} }
private fun setup(alarms: List<Long>) { private fun setup(savedInstanceState: Bundle?) {
setValue(flags) setValue(flags)
alertContainer.removeAllViews() alertContainer.removeAllViews()
if (whenDue) { if (whenDue) {
@ -161,8 +158,12 @@ class ReminderControlSet : TaskEditControlFragment() {
if (randomReminder > 0) { if (randomReminder > 0) {
addRandomReminder(randomReminder) addRandomReminder(randomReminder)
} }
for (timestamp in alarms) { if (savedInstanceState == null) {
addAlarmRow(timestamp) lifecycleScope.launch {
currentAlarms().forEach { addAlarmRow(it) }
}
} else {
savedInstanceState.getLongArray(EXTRA_ALARMS)?.forEach { addAlarmRow(it) }
} }
} }

@ -3,7 +3,9 @@ package org.tasks.data
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.room.* import androidx.room.*
import com.todoroo.astrid.api.FilterListItem.NO_ORDER import com.todoroo.astrid.api.FilterListItem.NO_ORDER
import com.todoroo.astrid.data.Task
import org.tasks.filters.LocationFilters import org.tasks.filters.LocationFilters
import org.tasks.preferences.Preferences
import org.tasks.time.DateTimeUtils.currentTimeMillis import org.tasks.time.DateTimeUtils.currentTimeMillis
@Dao @Dao
@ -115,4 +117,17 @@ interface LocationDao {
@Query("UPDATE places SET place_order = :order WHERE place_id = :id") @Query("UPDATE places SET place_order = :order WHERE place_id = :id")
suspend fun setOrder(id: Long, order: Int) 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<String>(Place.KEY)!!)?.let {
return Location(Geofence(it.uid, preferences), it)
}
}
} else {
return getGeofences(task.id)
}
return null
}
} }

@ -155,4 +155,10 @@ abstract class TagDataDao {
@Query("UPDATE tagdata SET td_order = :order WHERE _id = :id") @Query("UPDATE tagdata SET td_order = :order WHERE _id = :id")
abstract suspend fun setOrder(id: Long, order: Int) 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)
})
} }

@ -65,7 +65,7 @@ class CommentBarFragment : TaskEditControlFragment() {
return view return view
} }
override suspend fun createView(savedInstanceState: Bundle?) { override fun createView(savedInstanceState: Bundle?) {
if (savedInstanceState != null) { if (savedInstanceState != null) {
val uri = savedInstanceState.getString(EXTRA_PICTURE) val uri = savedInstanceState.getString(EXTRA_PICTURE)
if (uri != null) { if (uri != null) {

@ -4,7 +4,6 @@ import android.content.Context
import android.os.Bundle import android.os.Bundle
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import com.todoroo.astrid.activity.BeastModePreferences import com.todoroo.astrid.activity.BeastModePreferences
import com.todoroo.astrid.activity.TaskEditFragment
import com.todoroo.astrid.data.Task import com.todoroo.astrid.data.Task
import com.todoroo.astrid.files.FilesControlSet import com.todoroo.astrid.files.FilesControlSet
import com.todoroo.astrid.repeats.RepeatControlSet import com.todoroo.astrid.repeats.RepeatControlSet
@ -34,12 +33,12 @@ class TaskEditControlSetFragmentManager @Inject constructor(
} }
fun getOrCreateFragments( fun getOrCreateFragments(
taskEditFragment: TaskEditFragment, task: Task): List<TaskEditControlFragment> { fragmentManager: FragmentManager,
val arguments = Bundle() task: Task,
arguments: Bundle): List<TaskEditControlFragment> {
arguments.putParcelable(TaskEditControlFragment.EXTRA_TASK, task) arguments.putParcelable(TaskEditControlFragment.EXTRA_TASK, task)
arguments.putBoolean(TaskEditControlFragment.EXTRA_IS_NEW, task.isNew) arguments.putBoolean(TaskEditControlFragment.EXTRA_IS_NEW, task.isNew)
val fragments: MutableList<TaskEditControlFragment> = ArrayList() val fragments: MutableList<TaskEditControlFragment> = ArrayList()
val fragmentManager = taskEditFragment.childFragmentManager
for (i in displayOrder.indices) { for (i in displayOrder.indices) {
val tag = displayOrder[i] val tag = displayOrder[i]
var fragment = fragmentManager.findFragmentByTag(tag) as TaskEditControlFragment? var fragment = fragmentManager.findFragmentByTag(tag) as TaskEditControlFragment?

@ -5,6 +5,7 @@ import com.todoroo.astrid.api.*
import com.todoroo.astrid.api.Filter import com.todoroo.astrid.api.Filter
import com.todoroo.astrid.core.BuiltInFilterExposer import com.todoroo.astrid.core.BuiltInFilterExposer
import com.todoroo.astrid.core.BuiltInFilterExposer.getMyTasksFilter import com.todoroo.astrid.core.BuiltInFilterExposer.getMyTasksFilter
import com.todoroo.astrid.data.Task
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import org.tasks.R import org.tasks.R
@ -21,7 +22,8 @@ class DefaultFilterProvider @Inject constructor(
private val tagDataDao: TagDataDao, private val tagDataDao: TagDataDao,
private val googleTaskListDao: GoogleTaskListDao, private val googleTaskListDao: GoogleTaskListDao,
private val caldavDao: CaldavDao, private val caldavDao: CaldavDao,
private val locationDao: LocationDao) { private val locationDao: LocationDao,
private val googleTaskDao: GoogleTaskDao) {
@Deprecated("use coroutines") @Deprecated("use coroutines")
var dashclockFilter: Filter var dashclockFilter: Filter
@ -153,6 +155,39 @@ class DefaultFilterProvider @Inject constructor(
return FILTER_MY_TASKS 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<String>(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 { companion object {
private const val TYPE_FILTER = 0 private const val TYPE_FILTER = 0
private const val TYPE_CUSTOM_FILTER = 1 private const val TYPE_CUSTOM_FILTER = 1

@ -53,7 +53,7 @@ class CalendarControlSet : TaskEditControlFragment() {
private var calendarId: String? = null private var calendarId: String? = null
private var eventUri: String? = null private var eventUri: String? = null
override suspend fun createView(savedInstanceState: Bundle?) { override fun createView(savedInstanceState: Bundle?) {
val canAccessCalendars = permissionChecker.canAccessCalendars() val canAccessCalendars = permissionChecker.canAccessCalendars()
if (savedInstanceState != null) { if (savedInstanceState != null) {
eventUri = savedInstanceState.getString(EXTRA_URI) eventUri = savedInstanceState.getString(EXTRA_URI)

@ -37,7 +37,7 @@ class DeadlineControlSet : TaskEditControlFragment() {
callback = activity as DueDateChangeListener callback = activity as DueDateChangeListener
} }
override suspend fun createView(savedInstanceState: Bundle?) { override fun createView(savedInstanceState: Bundle?) {
date = savedInstanceState?.getLong(EXTRA_DATE) ?: task.dueDate date = savedInstanceState?.getLong(EXTRA_DATE) ?: task.dueDate
refreshDisplayView() refreshDisplayView()
} }

@ -22,7 +22,7 @@ class DescriptionControlSet : TaskEditControlFragment() {
private var description: String? = null private var description: String? = null
override suspend fun createView(savedInstanceState: Bundle?) { override fun createView(savedInstanceState: Bundle?) {
description = if (savedInstanceState == null) { description = if (savedInstanceState == null) {
stripCarriageReturns(task.notes) stripCarriageReturns(task.notes)
} else { } else {

@ -3,23 +3,17 @@ package org.tasks.ui
import android.app.Activity import android.app.Activity
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.lifecycleScope
import butterknife.BindView import butterknife.BindView
import com.google.android.material.chip.ChipGroup import com.google.android.material.chip.ChipGroup
import com.todoroo.astrid.activity.TaskEditFragment
import com.todoroo.astrid.api.CaldavFilter import com.todoroo.astrid.api.CaldavFilter
import com.todoroo.astrid.api.Filter import com.todoroo.astrid.api.Filter
import com.todoroo.astrid.api.GtasksFilter import com.todoroo.astrid.api.GtasksFilter
import com.todoroo.astrid.data.Task import com.todoroo.astrid.data.Task
import com.todoroo.astrid.service.TaskMover import com.todoroo.astrid.service.TaskMover
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import org.tasks.R import org.tasks.R
import org.tasks.activities.ListPicker import org.tasks.activities.ListPicker
import org.tasks.data.*
import org.tasks.preferences.DefaultFilterProvider
import javax.inject.Inject import javax.inject.Inject
@AndroidEntryPoint @AndroidEntryPoint
@ -27,10 +21,6 @@ class ListFragment : TaskEditControlFragment() {
@BindView(R.id.chip_group) @BindView(R.id.chip_group)
lateinit var chipGroup: ChipGroup 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 taskMover: TaskMover
@Inject lateinit var chipProvider: ChipProvider @Inject lateinit var chipProvider: ChipProvider
@ -47,39 +37,9 @@ class ListFragment : TaskEditControlFragment() {
callback = activity as OnListChanged callback = activity as OnListChanged
} }
override suspend fun createView(savedInstanceState: Bundle?) { override fun createView(savedInstanceState: Bundle?) {
if (savedInstanceState == null) { if (savedInstanceState == null) {
if (task.isNew) { originalList = requireArguments().getParcelable(TaskEditFragment.EXTRA_LIST)!!
if (task.hasTransitory(GoogleTask.KEY)) {
val listId = task.getTransitory<String>(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
}
setSelected(originalList!!) setSelected(originalList!!)
} else { } else {
originalList = savedInstanceState.getParcelable(EXTRA_ORIGINAL_LIST) originalList = savedInstanceState.getParcelable(EXTRA_ORIGINAL_LIST)

@ -8,20 +8,17 @@ import android.os.Parcelable
import android.text.SpannableString import android.text.SpannableString
import android.text.Spanned import android.text.Spanned
import android.text.style.ClickableSpan import android.text.style.ClickableSpan
import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup
import android.widget.ImageView import android.widget.ImageView
import android.widget.TextView import android.widget.TextView
import androidx.core.util.Pair import androidx.core.util.Pair
import androidx.lifecycle.lifecycleScope
import butterknife.BindView import butterknife.BindView
import butterknife.OnClick import butterknife.OnClick
import com.todoroo.andlib.utility.DateUtilities import com.todoroo.andlib.utility.DateUtilities
import com.todoroo.astrid.activity.TaskEditFragment
import com.todoroo.astrid.data.SyncFlags import com.todoroo.astrid.data.SyncFlags
import com.todoroo.astrid.data.Task import com.todoroo.astrid.data.Task
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import org.tasks.PermissionUtil.verifyPermissions import org.tasks.PermissionUtil.verifyPermissions
import org.tasks.R import org.tasks.R
import org.tasks.Strings.isNullOrEmpty import org.tasks.Strings.isNullOrEmpty
@ -59,18 +56,9 @@ class LocationControlSet : TaskEditControlFragment() {
private var original: Location? = null private var original: Location? = null
private var location: Location? = null private var location: Location? = null
override suspend fun createView(savedInstanceState: Bundle?) { override fun createView(savedInstanceState: Bundle?) {
if (savedInstanceState == null) { if (savedInstanceState == null) {
if (task.isNew) { original = requireArguments().getParcelable(TaskEditFragment.EXTRA_PLACE)
if (task.hasTransitory(Place.KEY)) {
val place = locationDao.getPlace(task.getTransitory<String>(Place.KEY)!!)
if (place != null) {
original = Location(Geofence(place.uid, preferences), place)
}
}
} else {
original = locationDao.getGeofences(task.id)
}
if (original != null) { if (original != null) {
setLocation(Location(original!!.geofence, original!!.place)) setLocation(Location(original!!.geofence, original!!.place))
} }

@ -38,7 +38,7 @@ class PriorityControlSet : TaskEditControlFragment() {
priority = getPriority() priority = getPriority()
} }
override suspend fun createView(savedInstanceState: Bundle?) { override fun createView(savedInstanceState: Bundle?) {
priority = savedInstanceState?.getInt(EXTRA_PRIORITY) ?: task.priority priority = savedInstanceState?.getInt(EXTRA_PRIORITY) ?: task.priority
when (priority) { when (priority) {
0 -> priorityHigh.isChecked = true 0 -> priorityHigh.isChecked = true

@ -79,7 +79,7 @@ class SubtaskControlSet : TaskEditControlFragment(), SubtaskViewHolder.Callbacks
outState.putParcelableArrayList(EXTRA_NEW_SUBTASKS, newSubtasks) outState.putParcelableArrayList(EXTRA_NEW_SUBTASKS, newSubtasks)
} }
override suspend fun createView(savedInstanceState: Bundle?) { override fun createView(savedInstanceState: Bundle?) {
viewModel = ViewModelProvider(this).get(TaskListViewModel::class.java) viewModel = ViewModelProvider(this).get(TaskListViewModel::class.java)
if (savedInstanceState != null) { if (savedInstanceState != null) {
for (task in savedInstanceState.getParcelableArrayList<Task>(EXTRA_NEW_SUBTASKS)!!) { for (task in savedInstanceState.getParcelableArrayList<Task>(EXTRA_NEW_SUBTASKS)!!) {

@ -12,7 +12,6 @@ import androidx.lifecycle.lifecycleScope
import butterknife.ButterKnife import butterknife.ButterKnife
import com.todoroo.astrid.data.Task import com.todoroo.astrid.data.Task
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import org.tasks.R import org.tasks.R
abstract class TaskEditControlFragment : Fragment() { abstract class TaskEditControlFragment : Fragment() {
@ -40,7 +39,7 @@ abstract class TaskEditControlFragment : Fragment() {
return view return view
} }
protected abstract suspend fun createView(savedInstanceState: Bundle?) protected abstract fun createView(savedInstanceState: Bundle?)
override fun onAttach(activity: Activity) { override fun onAttach(activity: Activity) {
super.onAttach(activity) super.onAttach(activity)

Loading…
Cancel
Save