Skip to content

Commit

Permalink
Merge pull request #112 from atsign-foundation/feat/596
Browse files Browse the repository at this point in the history
Feat/596
  • Loading branch information
sarika01 authored May 12, 2022
2 parents 295e066 + 5b969ea commit d1acb24
Show file tree
Hide file tree
Showing 10 changed files with 309 additions and 130 deletions.
2 changes: 2 additions & 0 deletions lib/app.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:atsign_atmosphere_pro/view_models/file_download_checker.dart';
import 'package:atsign_atmosphere_pro/desktop_routes/desktop_routes.dart';
import 'package:atsign_atmosphere_pro/view_models/file_progress_provider.dart';
import 'package:atsign_atmosphere_pro/view_models/internet_connectivity_checker.dart';
import 'package:atsign_atmosphere_pro/view_models/side_bar_provider.dart';
import 'package:atsign_atmosphere_pro/view_models/switch_atsign_provider.dart';
Expand Down Expand Up @@ -51,6 +52,7 @@ class _MyAppState extends State<MyApp> {
ChangeNotifierProvider(create: (context) => NestedRouteProvider()),
ChangeNotifierProvider(create: (context) => SwitchAtsignProvider()),
ChangeNotifierProvider(create: (context) => FileDownloadChecker()),
ChangeNotifierProvider(create: (context) => FileProgressProvider()),
ChangeNotifierProvider(
create: (context) => InternetConnectivityChecker())
],
Expand Down
27 changes: 13 additions & 14 deletions lib/data_models/file_transfer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@ class FileTransfer {
bool? isUpdate;
bool? isDownloading;
bool? isWidgetOpen;
FileTransferProgress? fileTransferProgress;
FileTransfer(
{this.url,
this.files,
this.expiry,
this.platformFiles,
this.date,
this.key,
this.isUpdate = false,
this.isDownloading = false,
this.isWidgetOpen = false,
this.fileTransferProgress}) {
FileTransfer({
this.url,
this.files,
this.expiry,
this.platformFiles,
this.date,
this.key,
this.isUpdate = false,
this.isDownloading = false,
this.isWidgetOpen = false,
}) {
this.expiry = expiry ?? DateTime.now().add(Duration(days: 6));
this.date = date ?? DateTime.now();

Expand Down Expand Up @@ -216,8 +215,8 @@ class DownloadAcknowledgement {

class FileTransferProgress {
FileState fileState;
double percent;
String fileName;
double? percent;
String? fileName;
FileTransferProgress(this.fileState, this.percent, this.fileName);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';

import 'package:atsign_atmosphere_pro/data_models/file_transfer.dart';
import 'package:atsign_atmosphere_pro/screens/common_widgets/labelled_circular_progress.dart';
import 'package:atsign_atmosphere_pro/services/backend_service.dart';
import 'package:atsign_atmosphere_pro/services/common_utility_functions.dart';
import 'package:atsign_atmosphere_pro/services/navigation_service.dart';
Expand All @@ -9,6 +10,7 @@ import 'package:atsign_atmosphere_pro/utils/colors.dart';
import 'package:atsign_atmosphere_pro/utils/constants.dart';
import 'package:atsign_atmosphere_pro/utils/text_strings.dart';
import 'package:atsign_atmosphere_pro/utils/text_styles.dart';
import 'package:atsign_atmosphere_pro/view_models/file_progress_provider.dart';
import 'package:atsign_atmosphere_pro/view_models/history_provider.dart';
import 'package:flutter/material.dart';
import 'package:at_common_flutter/services/size_config.dart';
Expand Down Expand Up @@ -152,10 +154,14 @@ class _DesktopReceivedFileDetailsState
widget.fileTransfer!.isDownloading!
? Padding(
padding: const EdgeInsets.only(right: 10.0),
child: SizedBox(
width: 30,
height: 30,
child: CircularProgressIndicator()),
child: Consumer<FileProgressProvider>(
builder: (_c, provider, _) {
var fileTransferProgress =
provider.receivedFileProgress[
widget.fileTransfer!.key!];

return getDownloadStatus(fileTransferProgress);
}),
)
: isDownloadAvailable
? Padding(
Expand Down Expand Up @@ -284,18 +290,25 @@ class _DesktopReceivedFileDetailsState
],
),
SizedBox(height: 15.toHeight),
RichText(
text: TextSpan(
text:
'${DateFormat("MM-dd-yyyy").format(widget.fileTransfer!.date!)} | ${DateFormat('kk: mm').format(widget.fileTransfer!.date!)} | ',
style: CustomTextStyles.greyText15,
children: [
widget.fileTransfer!.isDownloading!
? TextSpan(
text: '${getFileStateMessage()}',
style: CustomTextStyles.blueRegular14)
: TextSpan(text: ''),
]),
Consumer<FileProgressProvider>(
builder: (_context, provider, _widget) {
var fileTransferProgress =
provider.receivedFileProgress[widget.fileTransfer!.key!];
return RichText(
text: TextSpan(
text:
'${DateFormat("MM-dd-yyyy").format(widget.fileTransfer!.date!)} | ${DateFormat('kk: mm').format(widget.fileTransfer!.date!)} | ',
style: CustomTextStyles.greyText15,
children: [
widget.fileTransfer!.isDownloading!
? TextSpan(
text:
'${getFileStateMessage(fileTransferProgress)}',
style: CustomTextStyles.blueRegular14)
: TextSpan(text: ''),
]),
);
},
),
SizedBox(height: 15.toHeight),
SizedBox(height: 15.toHeight),
Expand Down Expand Up @@ -470,9 +483,7 @@ class _DesktopReceivedFileDetailsState
}
}

String getFileStateMessage() {
FileTransferProgress? fileTransferProgress =
widget.fileTransfer!.fileTransferProgress;
String getFileStateMessage(FileTransferProgress? fileTransferProgress) {
if (fileTransferProgress == null) {
return '';
}
Expand All @@ -492,4 +503,20 @@ class _DesktopReceivedFileDetailsState
}
return fileState;
}

Widget getDownloadStatus(FileTransferProgress? fileTransferProgress) {
Widget spinner = CircularProgressIndicator();

if (fileTransferProgress == null) {
return spinner;
}

if (fileTransferProgress.fileState == FileState.download &&
fileTransferProgress.percent != null) {
spinner = LabelledCircularProgressIndicator(
value: (fileTransferProgress.percent! / 100));
}

return spinner;
}
}
32 changes: 32 additions & 0 deletions lib/screens/common_widgets/labelled_circular_progress.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:flutter/material.dart';

import '../../utils/colors.dart';

class LabelledCircularProgressIndicator extends StatelessWidget {
double? value;
LabelledCircularProgressIndicator({this.value});
@override
Widget build(BuildContext context) {
return SizedBox(
child: Stack(
children: [
CircularProgressIndicator(value: value),
value != null
? Positioned(
top: 10,
child: Padding(
padding: EdgeInsets.only(left: 8),
child: Text((value! * 100).toStringAsFixed(0) + '%',
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold,
color: ColorConstants.blueText,
)),
),
)
: SizedBox()
],
),
);
}
}
Loading

0 comments on commit d1acb24

Please sign in to comment.