Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add indicator for image downloads #1075

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 42 additions & 27 deletions lib/shared/image_viewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class _ImageViewerState extends State<ImageViewer> with TickerProviderStateMixin
/// User Settings
bool isUserLoggedIn = false;
bool isDownloadingMedia = false;
bool isSavingMedia = false;
late double imageWidth = 0;
late double imageHeight = 0;
late double maxZoomLevel = 3;
Expand Down Expand Up @@ -419,39 +420,53 @@ class _ImageViewerState extends State<ImageViewer> with TickerProviderStateMixin
return;
}

// Save image on Linux platform
if (Platform.isLinux) {
final filePath = '${(await getApplicationDocumentsDirectory()).path}/Thunder/${basename(file.path)}';
setState(() => isSavingMedia = true);

File(filePath)
..createSync(recursive: true)
..writeAsBytesSync(file.readAsBytesSync());
try {
// Save image on Linux platform
if (Platform.isLinux) {
final filePath = '${(await getApplicationDocumentsDirectory()).path}/Thunder/${basename(file.path)}';

return setState(() => downloaded = true);
}
File(filePath)
..createSync(recursive: true)
..writeAsBytesSync(file.readAsBytesSync());

// Save image on all other supported platforms (Android, iOS, macOS, Windows)
try {
await Gal.putImage(file.path, album: "Thunder");
setState(() => downloaded = true);
} on GalException catch (e) {
if (context.mounted) showSnackbar(context, e.type.message, customState: _imageViewer.currentState);
setState(() => downloaded = false);
return setState(() => downloaded = true);
}

// Save image on all other supported platforms (Android, iOS, macOS, Windows)
try {
await Gal.putImage(file.path, album: "Thunder");
setState(() => downloaded = true);
} on GalException catch (e) {
if (context.mounted) showSnackbar(context, e.type.message, customState: _imageViewer.currentState);
setState(() => downloaded = false);
}
} finally {
setState(() => isSavingMedia = false);
}
},
icon: downloaded
? const Icon(
Icons.check_circle,
semanticLabel: 'Downloaded',
color: Colors.white,
shadows: <Shadow>[Shadow(color: Colors.black45, blurRadius: 50.0)],
icon: isSavingMedia
? SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
color: Colors.white.withOpacity(0.90),
),
)
: Icon(
Icons.download,
semanticLabel: "Download",
color: Colors.white.withOpacity(0.90),
shadows: const <Shadow>[Shadow(color: Colors.black, blurRadius: 50.0)],
),
: downloaded
? const Icon(
Icons.check_circle,
semanticLabel: 'Downloaded',
color: Colors.white,
shadows: <Shadow>[Shadow(color: Colors.black45, blurRadius: 50.0)],
)
: Icon(
Icons.download,
semanticLabel: "Download",
color: Colors.white.withOpacity(0.90),
shadows: const <Shadow>[Shadow(color: Colors.black, blurRadius: 50.0)],
),
),
),
if (widget.navigateToPost != null)
Expand Down
Loading