Skip to content

Commit

Permalink
Merge pull request #395 from atsign-foundation/bugfix/resolve-remaini…
Browse files Browse the repository at this point in the history
…ng-issues

fix: resolve remaining issues
  • Loading branch information
sonle-geekyants authored Jan 26, 2024
2 parents 1f071cf + f7d9723 commit 8735c00
Show file tree
Hide file tree
Showing 9 changed files with 555 additions and 539 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -377,24 +377,34 @@ class _DesktopAddGroupState extends State<DesktopAddGroup> {
if (mounted) {
if (result.runtimeType == AlreadyExistsException) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(TextConstants().GROUP_ALREADY_EXISTS)));
content: Text(TextConstants().GROUP_ALREADY_EXISTS),
backgroundColor: ColorConstants.redAlert,
));
} else if (result.runtimeType == InvalidAtSignException) {
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text(result.content)));
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(result.content),
backgroundColor: ColorConstants.redAlert,
));
} else {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(TextConstants().SERVICE_ERROR)));
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(TextConstants().SERVICE_ERROR),
backgroundColor: ColorConstants.redAlert,
));
}
}
} else {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(TextConstants().SERVICE_ERROR)));
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(TextConstants().SERVICE_ERROR),
backgroundColor: ColorConstants.redAlert,
));
}
}
} else {
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text(TextConstants().EMPTY_NAME)));
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(TextConstants().EMPTY_NAME),
backgroundColor: ColorConstants.redAlert,
));
}

setState(() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import 'dart:io';

import 'package:atsign_atmosphere_pro/data_models/file_modal.dart';
import 'package:atsign_atmosphere_pro/desktop_routes/desktop_routes.dart';
import 'package:atsign_atmosphere_pro/services/common_utility_functions.dart';
import 'package:atsign_atmosphere_pro/services/navigation_service.dart';
import 'package:atsign_atmosphere_pro/services/snackbar_service.dart';
import 'package:atsign_atmosphere_pro/utils/colors.dart';
import 'package:atsign_atmosphere_pro/utils/file_utils.dart';
import 'package:atsign_atmosphere_pro/utils/vectors.dart';
import 'package:atsign_atmosphere_pro/view_models/file_progress_provider.dart';
import 'package:atsign_atmosphere_pro/view_models/file_transfer_provider.dart';
import 'package:atsign_atmosphere_pro/view_models/history_provider.dart';
import 'package:atsign_atmosphere_pro/view_models/my_files_provider.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:provider/provider.dart';

class DesktopFileFunctionList extends StatelessWidget {
final String filePath;
final String sentFilePath;
final String idKey;
final DateTime date;
final String name;
final int size;
final bool isDownloading;
final bool isDownloaded;
final HistoryType type;

const DesktopFileFunctionList({
required this.filePath,
Expand All @@ -32,11 +33,13 @@ class DesktopFileFunctionList extends StatelessWidget {
required this.isDownloading,
required this.isDownloaded,
required this.idKey,
required this.sentFilePath,
required this.type,
});

@override
Widget build(BuildContext context) {
return File(filePath).existsSync()
return isDownloaded
? Row(
mainAxisSize: MainAxisSize.min,
children: [
Expand All @@ -46,8 +49,11 @@ class DesktopFileFunctionList extends StatelessWidget {
FileTransferProvider.appClosedSharedFiles.add(PlatformFile(
name: name,
size: size,
path: filePath,
bytes: File(filePath).readAsBytesSync(),
path: File(filePath).existsSync() ? filePath : sentFilePath,
bytes: File(File(filePath).existsSync()
? filePath
: sentFilePath)
.readAsBytesSync(),
));

Provider.of<FileTransferProvider>(context, listen: false)
Expand All @@ -58,33 +64,16 @@ class DesktopFileFunctionList extends StatelessWidget {
),
SizedBox(width: 4),
buildOptionButton(
onTap: () {
CommonUtilityFunctions().showConfirmationDialog(
() async {
await File(filePath).delete();
await Provider.of<MyFilesProvider>(
NavService.navKey.currentContext!,
listen: false)
.removeParticularFile(
idKey,
filePath.split(Platform.pathSeparator).last,
);

await Provider.of<MyFilesProvider>(
NavService.navKey.currentContext!,
listen: false)
.getAllFiles();
SnackbarService().showSnackbar(
context,
"Successfully deleted the file",
bgColor: ColorConstants.successColor,
);
Provider.of<HistoryProvider>(
NavService.navKey.currentContext!,
listen: false)
onTap: () async {
await FileUtils.deleteFile(
File(filePath).existsSync() ? filePath : sentFilePath,
fileTransferId: idKey,
date: date,
onComplete: () {
Provider.of<HistoryProvider>(context, listen: false)
.notify();
},
'Are you sure you want to delete the file(s)?',
type: type,
);
},
icon: AppVectors.icDeleteFile,
Expand Down Expand Up @@ -123,27 +112,24 @@ class DesktopFileFunctionList extends StatelessWidget {
),
],
)
: isDownloaded
? SizedBox.shrink()
: isDownloading
? SizedBox(
: isDownloading
? SizedBox(
width: 28,
height: 28,
child: CircularProgressIndicator(
strokeWidth: 1,
color: ColorConstants.downloadIndicatorColor,
),
)
: CommonUtilityFunctions().isFileDownloadAvailable(date) &&
!isDownloaded
? SvgPicture.asset(
AppVectors.icDownloadFile,
width: 28,
height: 28,
child: CircularProgressIndicator(
strokeWidth: 1,
color: ColorConstants.downloadIndicatorColor,
),
fit: BoxFit.cover,
)
: (CommonUtilityFunctions().isFileDownloadAvailable(
date,
))
? SvgPicture.asset(
AppVectors.icDownloadFile,
width: 28,
height: 28,
fit: BoxFit.cover,
)
: SizedBox.shrink();
: SizedBox.shrink();
},
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,31 @@ class DesktopHistoryFileItem extends StatefulWidget {

class _DesktopHistoryFileItemState extends State<DesktopHistoryFileItem> {
String filePath = '';
String sentFilePath = '';
late String fileFormat;
bool isDownloading = false;
late bool isDownloaded = File(filePath).existsSync();
late bool isDownloaded =
File(filePath).existsSync() || File(sentFilePath).existsSync();

@override
void initState() {
getFilePath();
super.initState();
fileFormat = '.${widget.data.name?.split('.').last}';
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
await getFilePath();
});
}

Future<void> getFilePath() async {
final result = widget.type == HistoryType.received
? await MixedConstants.getFileDownloadLocation(
sharedBy: widget.fileTransfer.sender)
: await MixedConstants.getFileSentLocation();
setState(() {
filePath = result + Platform.pathSeparator + (widget.data.name ?? "");
});
void getFilePath() {
filePath = MixedConstants.getFileDownloadLocationSync(
sharedBy: widget.fileTransfer.sender ?? '') +
Platform.pathSeparator +
(widget.data.name ?? "");
sentFilePath = MixedConstants.getFileSentLocationSync() +
Platform.pathSeparator +
(widget.data.name ?? '');
setState(() {});
}

Future<void> downloadFiles(FileData file) async {
Future<void> downloadFiles() async {
if (isDownloading) {
SnackbarService().showSnackbar(
context,
Expand Down Expand Up @@ -100,6 +101,9 @@ class _DesktopHistoryFileItemState extends State<DesktopHistoryFileItem> {
TextStrings.noInternetMsg,
bgColor: ColorConstants.redAlert,
);
setState(() {
isDownloading = false;
});
return;
}
var result = await Provider.of<HistoryProvider>(
Expand All @@ -109,28 +113,26 @@ class _DesktopHistoryFileItemState extends State<DesktopHistoryFileItem> {
widget.fileTransfer.key,
widget.fileTransfer.sender ?? '',
false,
file.name ?? '',
widget.data.name ?? '',
);
if (result is bool && result) {
SnackbarService().showSnackbar(
NavService.navKey.currentContext!,
TextStrings().fileDownloadd,
bgColor: ColorConstants.successGreen,
);
setState(() {
isDownloading = false;

isDownloaded = true;
});
await Provider.of<MyFilesProvider>(NavService.navKey.currentContext!,
listen: false)
.saveNewDataInMyFiles(widget.fileTransfer);
// send download acknowledgement
await Provider.of<HistoryProvider>(NavService.navKey.currentContext!,
listen: false)
.sendFileDownloadAcknowledgement(widget.fileTransfer);
if (mounted) {
setState(() {
isDownloading = false;

isDownloaded = true;
});
SnackbarService().showSnackbar(
NavService.navKey.currentContext!,
TextStrings().fileDownloadd,
bgColor: ColorConstants.successGreen,
);
}
} else if (result is bool && !result) {
SnackbarService().showSnackbar(
NavService.navKey.currentContext!,
Expand All @@ -153,20 +155,21 @@ class _DesktopHistoryFileItemState extends State<DesktopHistoryFileItem> {
children: [
InkWell(
onTap: () async {
File test = File(filePath);
bool fileExists = await test.exists();
fileExists
? await OpenFile.open(filePath)
: CommonUtilityFunctions()
!isDownloaded
? CommonUtilityFunctions()
.checkForDownloadAvailability(widget.fileTransfer)
? await downloadFiles(widget.data)
? await downloadFiles()
: CommonUtilityFunctions().showFileHasExpiredDialog(
MediaQuery.textScaleFactorOf(context),
);
)
: await OpenFile.open(
File(filePath).existsSync() ? filePath : sentFilePath,
);
},
child: buildFileCard(),
),
if (File(filePath).existsSync()) buildMarkRead(),
if (File(filePath).existsSync() || File(sentFilePath).existsSync())
buildMarkRead(),
],
);
}
Expand Down Expand Up @@ -208,7 +211,7 @@ class _DesktopHistoryFileItemState extends State<DesktopHistoryFileItem> {
width: 50,
child: thumbnail(
fileFormat.substring(1),
filePath,
File(filePath).existsSync() ? filePath : sentFilePath,
),
),
),
Expand Down Expand Up @@ -241,22 +244,22 @@ class _DesktopHistoryFileItemState extends State<DesktopHistoryFileItem> {
],
),
),
if (widget.type != HistoryType.send) buildSizeText(),
buildSizeText(),
],
),
),
SizedBox(width: 4),
widget.type == HistoryType.send
? buildSizeText()
: DesktopFileFunctionList(
filePath: filePath,
date: widget.fileTransfer.date ?? DateTime.now(),
idKey: widget.fileTransfer.key,
name: widget.data.name ?? '',
size: widget.data.size ?? 0,
isDownloaded: isDownloaded,
isDownloading: isDownloading,
),
DesktopFileFunctionList(
filePath: filePath,
sentFilePath: sentFilePath,
date: widget.fileTransfer.date ?? DateTime.now(),
idKey: widget.fileTransfer.key,
name: widget.data.name ?? '',
size: widget.data.size ?? 0,
isDownloaded: isDownloaded,
isDownloading: isDownloading,
type: widget.type,
),
],
);
}
Expand Down
Loading

0 comments on commit 8735c00

Please sign in to comment.