Change task mode to immunate.

This commit is contained in:
Stonegate 2021-01-02 16:46:35 +08:00
parent 656e5ccdea
commit 2e14835bd9
2 changed files with 15 additions and 10 deletions

View File

@ -53,8 +53,10 @@ class AutoDownloader {
for (var episodeTask in _episodeTasks) {
if (episodeTask.taskId == id) {
episodeTask.status = status;
episodeTask.progress = progress;
// episodeTask.status = status;
// episodeTask.progress = progress;
episodeTask =
episodeTask.copyWith(progress: progress, status: status);
if (status == DownloadTaskStatus.complete) {
_saveMediaId(episodeTask);
} else if (status == DownloadTaskStatus.failed) {
@ -213,8 +215,10 @@ class DownloadState extends ChangeNotifier {
for (var episodeTask in _episodeTasks) {
if (episodeTask.taskId == id) {
episodeTask.status = status;
episodeTask.progress = progress;
//episodeTask.status = status;
//episodeTask.progress = progress;
episodeTask =
episodeTask.copyWith(progress: progress, status: status);
if (status == DownloadTaskStatus.complete) {
_saveMediaId(episodeTask).then((value) {
notifyListeners();
@ -228,7 +232,7 @@ class DownloadState extends ChangeNotifier {
}
Future _saveMediaId(EpisodeTask episodeTask) async {
episodeTask.status = DownloadTaskStatus.complete;
episodeTask = episodeTask.copyWith(status: DownloadTaskStatus.complete);
final completeTask = await FlutterDownloader.loadTasksWithRawQuery(
query: "SELECT * FROM task WHERE task_id = '${episodeTask.taskId}'");
var filePath =
@ -343,7 +347,8 @@ class DownloadState extends ChangeNotifier {
for (var episodeTask in _episodeTasks) {
if (episodeTask.taskId == task.taskId) {
episodeTask.status = DownloadTaskStatus.undefined;
//episodeTask.status = DownloadTaskStatus.undefined;
episodeTask = episodeTask.copyWith(status: DownloadTaskStatus.undefined);
}
notifyListeners();
}

View File

@ -6,8 +6,8 @@ import 'episodebrief.dart';
class EpisodeTask extends Equatable {
final String taskId;
final EpisodeBrief episode;
int progress;
DownloadTaskStatus status;
final int progress;
final DownloadTaskStatus status;
EpisodeTask(
this.episode,
this.taskId, {
@ -15,9 +15,9 @@ class EpisodeTask extends Equatable {
this.status = DownloadTaskStatus.undefined,
});
EpisodeTask copyWith({String taskId}) {
EpisodeTask copyWith({String taskId, int progress, DownloadTaskStatus status}) {
return EpisodeTask(episode, taskId ?? this.taskId,
progress: progress, status: status);
progress: progress ?? this.progress, status: status ?? this.status);
}
@override