mirror of https://github.com/tasks/tasks
Use coroutines in TaskEditActivity and UriHandler
parent
6debb8b0ab
commit
e4b2dc932e
@ -1,53 +0,0 @@
|
||||
package com.todoroo.astrid.activity;
|
||||
|
||||
import com.todoroo.astrid.dao.TaskDaoBlocking;
|
||||
import com.todoroo.astrid.service.TaskCreator;
|
||||
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 javax.inject.Inject;
|
||||
import org.tasks.injection.InjectingAppCompatActivity;
|
||||
import org.tasks.intents.TaskIntents;
|
||||
|
||||
@AndroidEntryPoint
|
||||
public class TaskEditActivity extends InjectingAppCompatActivity {
|
||||
|
||||
private static final String TOKEN_ID = "id";
|
||||
|
||||
@Inject TaskCreator taskCreator;
|
||||
@Inject TaskDaoBlocking taskDao;
|
||||
private CompositeDisposable disposables;
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
long taskId = getIntent().getLongExtra(TOKEN_ID, 0);
|
||||
|
||||
disposables = new CompositeDisposable();
|
||||
|
||||
if (taskId == 0) {
|
||||
startActivity(TaskIntents.getEditTaskIntent(this, taskCreator.createWithValues("")));
|
||||
finish();
|
||||
} else {
|
||||
disposables.add(
|
||||
Single.fromCallable(() -> taskDao.fetchBlocking(taskId))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(
|
||||
task -> {
|
||||
startActivity(TaskIntents.getEditTaskIntent(this, task));
|
||||
finish();
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
|
||||
disposables.dispose();
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.todoroo.astrid.activity
|
||||
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.todoroo.astrid.dao.TaskDao
|
||||
import com.todoroo.astrid.service.TaskCreator
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.launch
|
||||
import org.tasks.injection.InjectingAppCompatActivity
|
||||
import org.tasks.intents.TaskIntents
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
class TaskEditActivity : InjectingAppCompatActivity() {
|
||||
@Inject lateinit var taskCreator: TaskCreator
|
||||
@Inject lateinit var taskDao: TaskDao
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
val taskId = intent.getLongExtra(TOKEN_ID, 0)
|
||||
if (taskId > 0) {
|
||||
lifecycleScope.launch {
|
||||
val task = taskDao.fetch(taskId)
|
||||
task?.let {
|
||||
startActivity(TaskIntents.getEditTaskIntent(this@TaskEditActivity, it))
|
||||
}
|
||||
finish()
|
||||
}
|
||||
} else {
|
||||
startActivity(TaskIntents.getEditTaskIntent(this, taskCreator.createWithValues("")))
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TOKEN_ID = "id"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue