Use coroutines in notification & snooze activities

pull/1055/head
Alex Baker 4 years ago
parent eb70cd86f8
commit 0a1a1d870d

@ -3,13 +3,11 @@ package org.tasks.reminders
import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.todoroo.astrid.dao.TaskDaoBlocking
import com.todoroo.astrid.data.Task
import androidx.lifecycle.lifecycleScope
import com.todoroo.astrid.dao.TaskDao
import dagger.hilt.android.AndroidEntryPoint
import io.reactivex.Single
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.launch
import org.tasks.injection.InjectingAppCompatActivity
import org.tasks.intents.TaskIntents
import org.tasks.notifications.NotificationManager
@ -21,7 +19,7 @@ import javax.inject.Inject
@AndroidEntryPoint
class NotificationActivity : InjectingAppCompatActivity(), NotificationDialog.NotificationHandler {
@Inject lateinit var notificationManager: NotificationManager
@Inject lateinit var taskDao: TaskDaoBlocking
@Inject lateinit var taskDao: TaskDao
@Inject lateinit var themeAccent: ThemeAccent
private var taskId: Long = 0
@ -56,17 +54,16 @@ class NotificationActivity : InjectingAppCompatActivity(), NotificationDialog.No
}
override fun edit() {
notificationManager.cancel(taskId)
disposables!!.add(
Single.fromCallable { taskDao.fetchBlocking(taskId) }
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{ task: Task? ->
startActivity(TaskIntents.getEditTaskIntent(this, null, task))
finish()
}
) { Timber.e("Task not found: $taskId") })
lifecycleScope.launch {
notificationManager.cancel(taskId)
taskDao.fetch(taskId)
?.let {
startActivity(
TaskIntents.getEditTaskIntent(this@NotificationActivity, null, it))
}
?: Timber.e("Failed to find task $taskId")
finish()
}
}
override fun snooze() {

@ -5,9 +5,12 @@ import android.content.Context
import android.content.DialogInterface
import android.content.Intent
import android.os.Bundle
import com.todoroo.astrid.dao.TaskDaoBlocking
import androidx.lifecycle.lifecycleScope
import com.todoroo.astrid.dao.TaskDao
import com.todoroo.astrid.reminders.ReminderService
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.launch
import org.tasks.activities.DateAndTimePickerActivity
import org.tasks.dialogs.MyTimePickerDialog
import org.tasks.injection.InjectingAppCompatActivity
@ -20,7 +23,7 @@ import javax.inject.Inject
@AndroidEntryPoint
class SnoozeActivity : InjectingAppCompatActivity(), SnoozeCallback, DialogInterface.OnCancelListener {
@Inject lateinit var notificationManager: NotificationManager
@Inject lateinit var taskDao: TaskDaoBlocking
@Inject lateinit var taskDao: TaskDao
@Inject lateinit var reminderService: ReminderService
@Inject lateinit var themeAccent: ThemeAccent
@ -57,9 +60,11 @@ class SnoozeActivity : InjectingAppCompatActivity(), SnoozeCallback, DialogInter
}
override fun snoozeForTime(time: DateTime) {
taskDao.snooze(taskIds, time.millis)
reminderService.scheduleAllAlarms(taskIds)
notificationManager.cancel(taskIds)
lifecycleScope.launch(NonCancellable) {
taskDao.snooze(taskIds, time.millis)
reminderService.scheduleAllAlarms(taskIds)
notificationManager.cancel(taskIds)
}
setResult(Activity.RESULT_OK)
finish()
}

Loading…
Cancel
Save