Create views in suspending function

pull/1047/head
Alex Baker 4 years ago
parent 2b6af062f6
commit 012663eebe

@ -5,8 +5,9 @@
*/
package com.todoroo.astrid.alarms
import kotlinx.coroutines.runBlocking
import org.tasks.data.Alarm
import org.tasks.data.AlarmDaoBlocking
import org.tasks.data.AlarmDao
import org.tasks.jobs.AlarmEntry
import org.tasks.jobs.NotificationQueue
import java.util.*
@ -20,12 +21,13 @@ import javax.inject.Singleton
*/
@Singleton
class AlarmService @Inject constructor(
private val alarmDao: AlarmDaoBlocking,
private val alarmDao: AlarmDao,
private val jobs: NotificationQueue) {
fun rescheduleAlarms(taskId: Long, oldDueDate: Long, newDueDate: Long) {
// TODO: remove runBlocking
fun rescheduleAlarms(taskId: Long, oldDueDate: Long, newDueDate: Long) = runBlocking {
if (newDueDate <= 0 || newDueDate <= oldDueDate) {
return
return@runBlocking
}
val alarms: MutableSet<Long> = LinkedHashSet()
for (alarm in getAlarms(taskId)) {
@ -36,7 +38,7 @@ class AlarmService @Inject constructor(
}
}
fun getAlarms(taskId: Long): List<Alarm> {
suspend fun getAlarms(taskId: Long): List<Alarm> {
return alarmDao.getAlarms(taskId)
}
@ -45,7 +47,7 @@ class AlarmService @Inject constructor(
*
* @return true if data was changed
*/
fun synchronizeAlarms(taskId: Long, timestamps: MutableSet<Long>): Boolean {
suspend fun synchronizeAlarms(taskId: Long, timestamps: MutableSet<Long>): Boolean {
var changed = false
for (item in alarmDao.getAlarms(taskId)) {
if (!timestamps.remove(item.time)) {
@ -64,25 +66,25 @@ class AlarmService @Inject constructor(
return changed
}
private fun getActiveAlarmsForTask(taskId: Long): List<Alarm> {
private suspend fun getActiveAlarmsForTask(taskId: Long): List<Alarm> {
return alarmDao.getActiveAlarms(taskId)
}
/** Schedules all alarms */
fun scheduleAllAlarms() {
// TODO: remove runBlocking
fun scheduleAllAlarms() = runBlocking {
for (alarm in alarmDao.getActiveAlarms()) {
scheduleAlarm(alarm)
}
}
fun cancelAlarms(taskId: Long) {
suspend fun cancelAlarms(taskId: Long) {
for (alarm in getActiveAlarmsForTask(taskId)) {
jobs.cancelAlarm(alarm.id)
}
}
/** Schedules alarms for a single task */
private fun scheduleAlarms(taskId: Long) {
private suspend fun scheduleAlarms(taskId: Long) {
for (alarm in getActiveAlarmsForTask(taskId)) {
scheduleAlarm(alarm)
}

@ -10,18 +10,20 @@ import android.app.Activity
import android.content.Intent
import android.net.Uri
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.lifecycle.lifecycleScope
import butterknife.BindView
import butterknife.OnClick
import com.todoroo.astrid.data.Task
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.tasks.R
import org.tasks.data.TaskAttachment
import org.tasks.data.TaskAttachmentDaoBlocking
import org.tasks.data.TaskAttachmentDao
import org.tasks.dialogs.AddAttachmentDialog
import org.tasks.dialogs.DialogBuilder
import org.tasks.files.FileHelper
@ -33,7 +35,7 @@ import javax.inject.Inject
@AndroidEntryPoint
class FilesControlSet : TaskEditControlFragment() {
@Inject lateinit var activity: Activity
@Inject lateinit var taskAttachmentDao: TaskAttachmentDaoBlocking
@Inject lateinit var taskAttachmentDao: TaskAttachmentDao
@Inject lateinit var dialogBuilder: DialogBuilder
@Inject lateinit var preferences: Preferences
@ -44,14 +46,9 @@ class FilesControlSet : TaskEditControlFragment() {
lateinit var addAttachment: TextView
private var taskUuid: String? = null
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = super.onCreateView(inflater, container, savedInstanceState)
override suspend fun createView(savedInstanceState: Bundle?) {
taskUuid = task.uuid
for (attachment in taskAttachmentDao.getAttachments(taskUuid!!)) {
addAttachment(attachment)
}
if (savedInstanceState == null) {
if (task.hasTransitory(TaskAttachment.KEY)) {
for (uri in (task.getTransitory<ArrayList<Uri>>(TaskAttachment.KEY))!!) {
@ -59,7 +56,10 @@ class FilesControlSet : TaskEditControlFragment() {
}
}
}
return view
taskAttachmentDao
.getAttachments(task.uuid)
.forEach { addAttachment(it) }
}
@OnClick(R.id.add_attachment)
@ -118,9 +118,13 @@ class FilesControlSet : TaskEditControlFragment() {
dialogBuilder
.newDialog(R.string.premium_remove_file_confirm)
.setPositiveButton(android.R.string.ok) { _, _ ->
taskAttachmentDao.delete(taskAttachment)
FileHelper.delete(context, taskAttachment.parseUri())
attachmentContainer.removeView(fileRow)
lifecycleScope.launch {
withContext(NonCancellable) {
taskAttachmentDao.delete(taskAttachment)
FileHelper.delete(context, taskAttachment.parseUri())
}
attachmentContainer.removeView(fileRow)
}
}
.setNegativeButton(android.R.string.cancel, null)
.show()
@ -138,8 +142,10 @@ class FilesControlSet : TaskEditControlFragment() {
private fun newAttachment(output: Uri) {
val attachment = TaskAttachment(taskUuid!!, output, FileHelper.getFilename(context, output)!!)
taskAttachmentDao.createNew(attachment)
addAttachment(attachment)
lifecycleScope.launch {
taskAttachmentDao.createNew(attachment)
addAttachment(attachment)
}
}
companion object {

@ -7,7 +7,6 @@ package com.todoroo.astrid.repeats
import android.app.Activity
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.AdapterView
@ -87,9 +86,7 @@ class RepeatControlSet : TaskEditControlFragment() {
}
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = super.onCreateView(inflater, container, savedInstanceState)
override suspend fun createView(savedInstanceState: Bundle?) {
if (savedInstanceState == null) {
repeatAfterCompletion = task.repeatAfterCompletion()
dueDate = task.dueDate
@ -129,7 +126,7 @@ class RepeatControlSet : TaskEditControlFragment() {
if (parent is AdapterView<*>) {
selectedItemPosition = parent.selectedItemPosition
}
val tv = inflater.inflate(android.R.layout.simple_spinner_item, parent, false) as TextView
val tv = activity.layoutInflater.inflate(android.R.layout.simple_spinner_item, parent, false) as TextView
tv.setPadding(0, 0, 0, 0)
tv.text = repeatTypes[selectedItemPosition]
return tv
@ -141,7 +138,6 @@ class RepeatControlSet : TaskEditControlFragment() {
typeSpinner.adapter = typeAdapter
typeSpinner.setSelection(if (repeatAfterCompletion) TYPE_COMPLETION_DATE else TYPE_DUE_DATE)
refreshDisplayView()
return view
}
@OnItemSelected(R.id.repeatType)

@ -8,9 +8,7 @@ package com.todoroo.astrid.tags
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 android.widget.TextView
import butterknife.BindView
import com.google.android.material.chip.ChipGroup
@ -18,9 +16,9 @@ import com.todoroo.andlib.utility.DateUtilities
import com.todoroo.astrid.data.Task
import dagger.hilt.android.AndroidEntryPoint
import org.tasks.R
import org.tasks.data.TagDaoBlocking
import org.tasks.data.TagDao
import org.tasks.data.TagData
import org.tasks.data.TagDataDaoBlocking
import org.tasks.data.TagDataDao
import org.tasks.tags.TagPickerActivity
import org.tasks.ui.ChipProvider
import org.tasks.ui.TaskEditControlFragment
@ -34,8 +32,8 @@ import javax.inject.Inject
*/
@AndroidEntryPoint
class TagsControlSet : TaskEditControlFragment() {
@Inject lateinit var tagDao: TagDaoBlocking
@Inject lateinit var tagDataDao: TagDataDaoBlocking
@Inject lateinit var tagDao: TagDao
@Inject lateinit var tagDataDao: TagDataDao
@Inject lateinit var chipProvider: ChipProvider
@BindView(R.id.no_tags)
@ -46,23 +44,21 @@ class TagsControlSet : TaskEditControlFragment() {
private lateinit var originalTags: ArrayList<TagData>
private lateinit var selectedTags: ArrayList<TagData>
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = super.onCreateView(inflater, container, savedInstanceState)
if (savedInstanceState != null) {
selectedTags = savedInstanceState.getParcelableArrayList(EXTRA_SELECTED_TAGS)!!
originalTags = savedInstanceState.getParcelableArrayList(EXTRA_ORIGINAL_TAGS)!!
} else {
override suspend fun createView(savedInstanceState: Bundle?) {
if (savedInstanceState == null) {
originalTags = ArrayList(if (task.isNew) {
task.tags.mapNotNull(tagDataDao::getTagByName)
task.tags.mapNotNull { tagDataDao.getTagByName(it) }
} else {
tagDataDao.getTagDataForTask(task.id)
})
selectedTags = ArrayList(originalTags)
refreshDisplayView()
} else {
selectedTags = savedInstanceState.getParcelableArrayList(EXTRA_SELECTED_TAGS)!!
originalTags = savedInstanceState.getParcelableArrayList(EXTRA_ORIGINAL_TAGS)!!
refreshDisplayView()
}
refreshDisplayView()
return view
}
override fun onSaveInstanceState(outState: Bundle) {

@ -10,9 +10,7 @@ import android.os.Bundle
import android.os.SystemClock
import android.text.format.DateFormat
import android.text.format.DateUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Chronometer
import android.widget.Chronometer.OnChronometerTickListener
import android.widget.ImageView
@ -58,9 +56,7 @@ class TimerControlSet : TaskEditControlFragment() {
private lateinit var dialogView: View
private lateinit var callback: TimerControlSetCallback
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = super.onCreateView(inflater, container, savedInstanceState)
override suspend fun createView(savedInstanceState: Bundle?) {
val elapsedSeconds: Int
val estimatedSeconds: Int
if (savedInstanceState == null) {
@ -72,13 +68,12 @@ class TimerControlSet : TaskEditControlFragment() {
elapsedSeconds = savedInstanceState.getInt(EXTRA_ELAPSED)
estimatedSeconds = savedInstanceState.getInt(EXTRA_ESTIMATED)
}
dialogView = inflater.inflate(R.layout.control_set_timers_dialog, null)
dialogView = activity.layoutInflater.inflate(R.layout.control_set_timers_dialog, null)
estimated = TimeDurationControlSet(activity, dialogView, R.id.estimatedDuration, theme)
elapsed = TimeDurationControlSet(activity, dialogView, R.id.elapsedDuration, theme)
estimated.setTimeDuration(estimatedSeconds)
elapsed.setTimeDuration(elapsedSeconds)
refresh()
return view
}
override fun onAttach(activity: Activity) {

@ -8,7 +8,6 @@ package com.todoroo.astrid.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 android.widget.*
@ -71,9 +70,7 @@ class HideUntilControlSet : TaskEditControlFragment(), OnItemSelectedListener {
override val isClickable: Boolean
get() = true
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = super.onCreateView(inflater, container, savedInstanceState)
override suspend fun createView(savedInstanceState: Bundle?) {
adapter = object : HiddenTopArrayAdapter<HideUntilValue>(
activity, android.R.layout.simple_spinner_item, spinnerItems) {
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
@ -81,7 +78,7 @@ class HideUntilControlSet : TaskEditControlFragment(), OnItemSelectedListener {
if (parent is AdapterView<*>) {
selectedItemPosition = parent.selectedItemPosition
}
val tv = inflater.inflate(android.R.layout.simple_spinner_item, parent, false) as TextView
val tv = activity.layoutInflater.inflate(android.R.layout.simple_spinner_item, parent, false) as TextView
tv.setPadding(0, 0, 0, 0)
val value = getItem(selectedItemPosition)
if (value!!.setting == Task.HIDE_UNTIL_NONE) {
@ -139,7 +136,6 @@ class HideUntilControlSet : TaskEditControlFragment(), OnItemSelectedListener {
spinner.setSelection(selection)
spinner.onItemSelectedListener = this
refreshDisplayView()
return view
}
override val layout: Int

@ -16,12 +16,14 @@ import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.annotation.StringRes
import androidx.lifecycle.lifecycleScope
import butterknife.BindView
import butterknife.OnClick
import com.todoroo.andlib.utility.DateUtilities
import com.todoroo.astrid.alarms.AlarmService
import com.todoroo.astrid.data.Task
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import org.tasks.R
import org.tasks.activities.DateAndTimePickerActivity
import org.tasks.data.Alarm
@ -61,10 +63,8 @@ class ReminderControlSet : TaskEditControlFragment() {
private var randomControlSet: RandomReminderControlSet? = null
private var whenDue = false
private var whenOverdue = false
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = super.onCreateView(inflater, container, savedInstanceState)
override suspend fun createView(savedInstanceState: Bundle?) {
mode.paintFlags = mode.paintFlags or Paint.UNDERLINE_TEXT_FLAG
taskId = task.id
if (savedInstanceState == null) {
@ -76,10 +76,9 @@ class ReminderControlSet : TaskEditControlFragment() {
randomReminder = savedInstanceState.getLong(EXTRA_RANDOM_REMINDER)
setup(savedInstanceState.getLongArray(EXTRA_ALARMS)!!.toList())
}
return view
}
private fun currentAlarms(): List<Long> {
private suspend fun currentAlarms(): List<Long> {
return if (taskId == Task.NO_ID) {
emptyList()
} else {

@ -30,7 +30,7 @@ abstract class TagDao {
abstract suspend fun delete(tags: List<Tag>)
@Transaction
open suspend fun applyTags(task: Task, tagDataDao: TagDataDaoBlocking, current: List<TagData>): Boolean {
open suspend fun applyTags(task: Task, tagDataDao: TagDataDao, current: List<TagData>): Boolean {
val taskId = task.id
val existing = HashSet(tagDataDao.getTagDataForTask(taskId))
val selected = HashSet<TagData>(current)

@ -39,7 +39,7 @@ class TagDaoBlocking @Inject constructor(private val dao: TagDao) {
}
fun applyTags(task: Task, tagDataDao: TagDataDaoBlocking, current: List<TagData>): Boolean = runBlocking {
dao.applyTags(task, tagDataDao, current)
dao.applyTags(task, tagDataDao.dao, current)
}
fun insert(task: Task, tags: Collection<TagData>) = runBlocking {

@ -9,7 +9,7 @@ import org.tasks.time.DateTimeUtils.currentTimeMillis
import javax.inject.Inject
@Deprecated("use coroutines")
class TagDataDaoBlocking @Inject constructor(private val dao: TagDataDao) {
class TagDataDaoBlocking @Inject constructor(val dao: TagDataDao) {
fun subscribeToTags(): LiveData<List<TagData>> {
return dao.subscribeToTags()
}

@ -62,6 +62,10 @@ class CommentBarFragment : TaskEditControlFragment() {
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(layout, container, false)
ButterKnife.bind(this, view)
return view
}
override suspend fun createView(savedInstanceState: Bundle?) {
if (savedInstanceState != null) {
val uri = savedInstanceState.getString(EXTRA_PICTURE)
if (uri != null) {
@ -77,7 +81,6 @@ class CommentBarFragment : TaskEditControlFragment() {
}
commentBar.setBackgroundColor(themeColor.primaryColor)
resetPictureButton()
return view
}
override val layout: Int

@ -7,6 +7,7 @@ import androidx.work.WorkerParameters
import com.todoroo.astrid.alarms.AlarmService
import com.todoroo.astrid.reminders.ReminderService
import com.todoroo.astrid.timers.TimerPlugin
import kotlinx.coroutines.runBlocking
import org.tasks.analytics.Firebase
import org.tasks.data.DeletionDaoBlocking
import org.tasks.data.LocationDaoBlocking
@ -39,7 +40,9 @@ class CleanupWork @WorkerInject constructor(
return Result.failure()
}
tasks.forEach { task ->
alarmService.cancelAlarms(task)
runBlocking {
alarmService.cancelAlarms(task)
}
reminderService.cancelReminder(task)
notificationManager.cancel(task)
locationDao.getGeofencesForTask(task).forEach {

@ -52,10 +52,8 @@ class CalendarControlSet : TaskEditControlFragment() {
private var calendarId: String? = null
private var eventUri: String? = null
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = super.onCreateView(inflater, container, savedInstanceState)
override suspend fun createView(savedInstanceState: Bundle?) {
val canAccessCalendars = permissionChecker.canAccessCalendars()
if (savedInstanceState != null) {
eventUri = savedInstanceState.getString(EXTRA_URI)
@ -81,7 +79,6 @@ class CalendarControlSet : TaskEditControlFragment() {
eventUri = null
}
refreshDisplayView()
return view
}
override val layout: Int

@ -3,9 +3,6 @@ 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 android.widget.TextView
import butterknife.BindView
import com.todoroo.andlib.utility.DateUtilities
@ -40,12 +37,9 @@ class DeadlineControlSet : TaskEditControlFragment() {
callback = activity as DueDateChangeListener
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = super.onCreateView(inflater, container, savedInstanceState)
override suspend fun createView(savedInstanceState: Bundle?) {
date = savedInstanceState?.getLong(EXTRA_DATE) ?: task.dueDate
refreshDisplayView()
return view
}
override fun onRowClick() {

@ -1,9 +1,6 @@
package org.tasks.ui
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.EditText
import butterknife.BindView
import butterknife.OnTextChanged
@ -24,10 +21,8 @@ class DescriptionControlSet : TaskEditControlFragment() {
lateinit var editText: EditText
private var description: String? = null
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = super.onCreateView(inflater, container, savedInstanceState)
override suspend fun createView(savedInstanceState: Bundle?) {
description = if (savedInstanceState == null) {
stripCarriageReturns(task.notes)
} else {
@ -39,7 +34,6 @@ class DescriptionControlSet : TaskEditControlFragment() {
if (preferences.getBoolean(R.string.p_linkify_task_edit, false)) {
linkify.linkify(editText)
}
return view
}
override fun onSaveInstanceState(outState: Bundle) {

@ -6,6 +6,7 @@ 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.api.CaldavFilter
@ -14,6 +15,7 @@ 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.*
@ -25,9 +27,9 @@ class ListFragment : TaskEditControlFragment() {
@BindView(R.id.chip_group)
lateinit var chipGroup: ChipGroup
@Inject lateinit var googleTaskListDao: GoogleTaskListDaoBlocking
@Inject lateinit var googleTaskDao: GoogleTaskDaoBlocking
@Inject lateinit var caldavDao: CaldavDaoBlocking
@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
@ -45,13 +47,8 @@ class ListFragment : TaskEditControlFragment() {
callback = activity as OnListChanged
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = super.onCreateView(inflater, container, savedInstanceState)
if (savedInstanceState != null) {
originalList = savedInstanceState.getParcelable(EXTRA_ORIGINAL_LIST)
setSelected(savedInstanceState.getParcelable(EXTRA_SELECTED_LIST)!!)
} else {
override suspend fun createView(savedInstanceState: Bundle?) {
if (savedInstanceState == null) {
if (task.isNew) {
if (task.hasTransitory(GoogleTask.KEY)) {
val listId = task.getTransitory<String>(GoogleTask.KEY)!!
@ -84,8 +81,10 @@ class ListFragment : TaskEditControlFragment() {
originalList = defaultFilterProvider.defaultList
}
setSelected(originalList!!)
} else {
originalList = savedInstanceState.getParcelable(EXTRA_ORIGINAL_LIST)
setSelected(savedInstanceState.getParcelable(EXTRA_SELECTED_LIST)!!)
}
return view
}
private fun setSelected(filter: Filter) {

@ -14,18 +14,20 @@ 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.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
import org.tasks.data.Geofence
import org.tasks.data.Location
import org.tasks.data.LocationDaoBlocking
import org.tasks.data.LocationDao
import org.tasks.data.Place
import org.tasks.dialogs.DialogBuilder
import org.tasks.dialogs.GeofenceDialog
@ -40,7 +42,7 @@ class LocationControlSet : TaskEditControlFragment() {
@Inject lateinit var preferences: Preferences
@Inject lateinit var dialogBuilder: DialogBuilder
@Inject lateinit var geofenceApi: GeofenceApi
@Inject lateinit var locationDao: LocationDaoBlocking
@Inject lateinit var locationDao: LocationDao
@Inject lateinit var device: Device
@Inject lateinit var permissionRequestor: FragmentPermissionRequestor
@Inject lateinit var permissionChecker: PermissionChecker
@ -56,10 +58,8 @@ class LocationControlSet : TaskEditControlFragment() {
private var original: Location? = null
private var location: Location? = null
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = super.onCreateView(inflater, container, savedInstanceState)
override suspend fun createView(savedInstanceState: Bundle?) {
if (savedInstanceState == null) {
if (task.isNew) {
if (task.hasTransitory(Place.KEY)) {
@ -72,13 +72,12 @@ class LocationControlSet : TaskEditControlFragment() {
original = locationDao.getGeofences(task.id)
}
if (original != null) {
location = Location(original!!.geofence, original!!.place)
setLocation(Location(original!!.geofence, original!!.place))
}
} else {
original = savedInstanceState.getParcelable(EXTRA_ORIGINAL)
location = savedInstanceState.getParcelable(EXTRA_LOCATION)
}
return view
}
override fun onResume() {

@ -38,9 +38,7 @@ class PriorityControlSet : TaskEditControlFragment() {
priority = getPriority()
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = super.onCreateView(inflater, container, savedInstanceState)
override suspend fun createView(savedInstanceState: Bundle?) {
priority = savedInstanceState?.getInt(EXTRA_PRIORITY) ?: task.priority
when (priority) {
0 -> priorityHigh.isChecked = true
@ -52,7 +50,6 @@ class PriorityControlSet : TaskEditControlFragment() {
tintRadioButton(priorityMedium, 1)
tintRadioButton(priorityLow, 2)
tintRadioButton(priorityNone, 3)
return view
}
override fun onSaveInstanceState(outState: Bundle) {

@ -15,6 +15,7 @@ import android.widget.EditText
import android.widget.LinearLayout
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
@ -28,13 +29,14 @@ import com.todoroo.astrid.activity.MainActivity
import com.todoroo.astrid.api.CaldavFilter
import com.todoroo.astrid.api.Filter
import com.todoroo.astrid.api.GtasksFilter
import com.todoroo.astrid.dao.TaskDaoBlocking
import com.todoroo.astrid.dao.TaskDao
import com.todoroo.astrid.dao.TaskDao.TaskCriteria.activeAndVisible
import com.todoroo.astrid.data.Task
import com.todoroo.astrid.service.TaskCompleter
import com.todoroo.astrid.service.TaskCreator
import com.todoroo.astrid.ui.CheckableImageView
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import org.tasks.LocalBroadcastManager
import org.tasks.R
import org.tasks.Strings.isNullOrEmpty
@ -57,11 +59,11 @@ class SubtaskControlSet : TaskEditControlFragment(), SubtaskViewHolder.Callbacks
@Inject lateinit var activity: Activity
@Inject lateinit var taskCompleter: TaskCompleter
@Inject lateinit var localBroadcastManager: LocalBroadcastManager
@Inject lateinit var googleTaskDao: GoogleTaskDaoBlocking
@Inject lateinit var googleTaskDao: GoogleTaskDao
@Inject lateinit var toaster: Toaster
@Inject lateinit var taskCreator: TaskCreator
@Inject lateinit var caldavDao: CaldavDaoBlocking
@Inject lateinit var taskDao: TaskDaoBlocking
@Inject lateinit var caldavDao: CaldavDao
@Inject lateinit var taskDao: TaskDao
@Inject lateinit var locale: Locale
@Inject lateinit var checkBoxProvider: CheckBoxProvider
@Inject lateinit var chipProvider: ChipProvider
@ -77,9 +79,7 @@ class SubtaskControlSet : TaskEditControlFragment(), SubtaskViewHolder.Callbacks
outState.putParcelableArrayList(EXTRA_NEW_SUBTASKS, newSubtasks)
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = super.onCreateView(inflater, container, savedInstanceState)
override suspend fun createView(savedInstanceState: Bundle?) {
viewModel = ViewModelProvider(this).get(TaskListViewModel::class.java)
if (savedInstanceState != null) {
for (task in savedInstanceState.getParcelableArrayList<Task>(EXTRA_NEW_SUBTASKS)!!) {
@ -96,7 +96,6 @@ class SubtaskControlSet : TaskEditControlFragment(), SubtaskViewHolder.Callbacks
viewModel.observe(this, Observer { list: List<TaskContainer?>? -> recyclerAdapter.submitList(list) })
recyclerView!!.adapter = recyclerAdapter
}
return view
}
override val layout: Int
@ -162,8 +161,10 @@ class SubtaskControlSet : TaskEditControlFragment(), SubtaskViewHolder.Callbacks
override fun onResume() {
super.onResume()
localBroadcastManager.registerRefreshReceiver(refreshReceiver)
googleTask = googleTaskDao.getByTaskId(task.id)
updateUI()
lifecycleScope.launch {
googleTask = googleTaskDao.getByTaskId(task.id)
updateUI()
}
}
override fun onPause() {
@ -254,8 +255,10 @@ class SubtaskControlSet : TaskEditControlFragment(), SubtaskViewHolder.Callbacks
}
override fun toggleSubtask(taskId: Long, collapsed: Boolean) {
taskDao.setCollapsed(taskId, collapsed)
localBroadcastManager.broadcastRefresh()
lifecycleScope.launch {
taskDao.setCollapsed(taskId, collapsed)
localBroadcastManager.broadcastRefresh()
}
}
override fun complete(task: Task, completed: Boolean) {

@ -8,8 +8,10 @@ import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout
import androidx.fragment.app.Fragment
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
@ -30,9 +32,16 @@ abstract class TaskEditControlFragment : Fragment() {
content.setOnClickListener { onRowClick() }
}
ButterKnife.bind(this, view)
lifecycleScope.launch {
createView(savedInstanceState)
}
return view
}
protected abstract suspend fun createView(savedInstanceState: Bundle?)
override fun onAttach(activity: Activity) {
super.onAttach(activity)
val args = requireArguments()

Loading…
Cancel
Save