TF-3488 Add hide download taskbar feature
This commit is contained in:
+5
@@ -9,12 +9,14 @@ typedef UpdateDownloadTaskStateCallback = DownloadTaskState Function(DownloadTas
|
||||
class DownloadController extends GetxController {
|
||||
|
||||
final listDownloadTaskState = RxList<DownloadTaskState>();
|
||||
final hideDownloadTaskbar = RxBool(false);
|
||||
|
||||
bool get notEmptyListDownloadTask => listDownloadTaskState.isNotEmpty;
|
||||
|
||||
void addDownloadTask(DownloadTaskState task) {
|
||||
log('DownloadController::addDownloadTask(): ${task.taskId}');
|
||||
listDownloadTaskState.add(task);
|
||||
hideDownloadTaskbar.value = false;
|
||||
}
|
||||
|
||||
void updateDownloadTaskByTaskId(
|
||||
@@ -37,5 +39,8 @@ class DownloadController extends GetxController {
|
||||
listDownloadTaskState.removeAt(matchIndex);
|
||||
listDownloadTaskState.refresh();
|
||||
}
|
||||
if (listDownloadTaskState.isEmpty) {
|
||||
hideDownloadTaskbar.value = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -202,7 +202,7 @@ class MailboxDashBoardView extends BaseMailboxDashBoardView {
|
||||
? const SearchMailboxView()
|
||||
: const SizedBox.shrink()
|
||||
),
|
||||
_buildDownloadTaskStateWidget(),
|
||||
_buildDownloadTaskStateWidget(AppLocalizations.of(context)),
|
||||
]),
|
||||
);
|
||||
}
|
||||
@@ -413,30 +413,50 @@ class MailboxDashBoardView extends BaseMailboxDashBoardView {
|
||||
controller.dispatchAction(FilterMessageAction(FilterMessageOption.all));
|
||||
}
|
||||
|
||||
Widget _buildDownloadTaskStateWidget() {
|
||||
Widget _buildDownloadTaskStateWidget(AppLocalizations appLocalizations) {
|
||||
return Obx(() {
|
||||
final listDownloadTasks = controller.downloadController.listDownloadTaskState;
|
||||
if (listDownloadTasks.isNotEmpty) {
|
||||
final hideDownloadTaskbar = controller.downloadController.hideDownloadTaskbar;
|
||||
if (listDownloadTasks.isNotEmpty && !hideDownloadTaskbar.value) {
|
||||
return Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: Container(
|
||||
color: AppColor.colorBackgroundSnackBar,
|
||||
height: 60,
|
||||
width: double.infinity,
|
||||
child: ListView.separated(
|
||||
scrollDirection: Axis.horizontal,
|
||||
padding: EdgeInsets.zero,
|
||||
itemCount: listDownloadTasks.length,
|
||||
separatorBuilder: (context, index) =>
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 5),
|
||||
child: VerticalDivider(
|
||||
color: Colors.grey,
|
||||
width: 2.5,
|
||||
thickness: 0.2),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ListView.separated(
|
||||
scrollDirection: Axis.horizontal,
|
||||
padding: EdgeInsets.zero,
|
||||
itemCount: listDownloadTasks.length,
|
||||
separatorBuilder: (context, index) =>
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 5),
|
||||
child: VerticalDivider(
|
||||
color: Colors.grey,
|
||||
width: 2.5,
|
||||
thickness: 0.2),
|
||||
),
|
||||
itemBuilder: (context, index) =>
|
||||
DownloadTaskItemWidget(listDownloadTasks[index])
|
||||
),
|
||||
itemBuilder: (context, index) =>
|
||||
DownloadTaskItemWidget(listDownloadTasks[index])
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: TMailButtonWidget.fromText(
|
||||
text: appLocalizations.hide,
|
||||
backgroundColor: Colors.transparent,
|
||||
textStyle: const TextStyle(
|
||||
color: AppColor.colorCancelButton,
|
||||
),
|
||||
onTapActionCallback: () {
|
||||
controller.downloadController.hideDownloadTaskbar.value = true;
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:model/download/download_task_id.dart';
|
||||
import 'package:model/email/attachment.dart';
|
||||
|
||||
@@ -9,13 +10,15 @@ class DownloadTaskState with EquatableMixin {
|
||||
final double progress;
|
||||
final int downloaded;
|
||||
final int total;
|
||||
final VoidCallback? onCancel;
|
||||
|
||||
DownloadTaskState({
|
||||
required this.taskId,
|
||||
required this.attachment,
|
||||
this.progress = 0,
|
||||
this.downloaded = 0,
|
||||
this.total = 0
|
||||
this.total = 0,
|
||||
this.onCancel,
|
||||
});
|
||||
|
||||
DownloadTaskState copyWith({
|
||||
@@ -23,14 +26,16 @@ class DownloadTaskState with EquatableMixin {
|
||||
Attachment? attachment,
|
||||
double? progress,
|
||||
int? downloaded,
|
||||
int? total
|
||||
int? total,
|
||||
VoidCallback? onCancel
|
||||
}) {
|
||||
return DownloadTaskState(
|
||||
taskId: taskId ?? this.taskId,
|
||||
attachment: attachment ?? this.attachment,
|
||||
progress: progress ?? this.progress,
|
||||
downloaded: downloaded ?? this.downloaded,
|
||||
total: total ?? this.total
|
||||
total: total ?? this.total,
|
||||
onCancel: onCancel ?? this.onCancel,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -46,5 +51,5 @@ class DownloadTaskState with EquatableMixin {
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [taskId, attachment, progress, downloaded, total];
|
||||
List<Object?> get props => [taskId, attachment, progress, downloaded, total, onCancel];
|
||||
}
|
||||
+10
-2
@@ -3,10 +3,12 @@ import 'package:byte_converter/byte_converter.dart';
|
||||
import 'package:core/presentation/extensions/color_extension.dart';
|
||||
import 'package:core/presentation/resources/image_paths.dart';
|
||||
import 'package:core/presentation/utils/style_utils.dart';
|
||||
import 'package:core/presentation/views/button/tmail_button_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:percent_indicator/circular_percent_indicator.dart';
|
||||
import 'package:tmail_ui_user/features/base/widget/circle_loading_widget.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/extensions/attachment_extension.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/download/download_task_state.dart';
|
||||
|
||||
@@ -43,7 +45,7 @@ class DownloadTaskItemWidget extends StatelessWidget {
|
||||
fit: BoxFit.fill),
|
||||
Center(
|
||||
child: taskState.percentDownloading == 0
|
||||
? const CircularProgressIndicator(color: AppColor.primaryColor, strokeWidth: 3)
|
||||
? const CircleLoadingWidget(strokeWidth: 3)
|
||||
: CircularPercentIndicator(
|
||||
percent: taskState.percentDownloading,
|
||||
backgroundColor: AppColor.colorBgMailboxSelected,
|
||||
@@ -83,7 +85,13 @@ class DownloadTaskItemWidget extends StatelessWidget {
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
),
|
||||
if (taskState.onCancel != null)
|
||||
TMailButtonWidget.fromIcon(
|
||||
icon: imagePaths.icClose,
|
||||
onTapActionCallback: taskState.onCancel,
|
||||
backgroundColor: Colors.transparent,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user