Skip to content

Commit

Permalink
refactor download file notifier
Browse files Browse the repository at this point in the history
  • Loading branch information
shiosyakeyakini-info committed Jul 14, 2024
1 parent c8b8b36 commit 1c318b3
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 36 deletions.
21 changes: 12 additions & 9 deletions lib/state_notifier/common/download_file_notifier.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import 'package:device_info_plus/device_info_plus.dart';
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:image_gallery_saver/image_gallery_saver.dart';
import 'package:miria/providers.dart';
import 'package:misskey_dart/misskey_dart.dart' hide Permission;
import 'package:permission_handler/permission_handler.dart';
import "package:device_info_plus/device_info_plus.dart";
import "package:dio/dio.dart";
import "package:flutter/foundation.dart";
import "package:image_gallery_saver/image_gallery_saver.dart";
import "package:miria/providers.dart";
import "package:misskey_dart/misskey_dart.dart" hide Permission;
import "package:permission_handler/permission_handler.dart";
import "package:riverpod_annotation/riverpod_annotation.dart";

class DownloadFileNotifier extends Notifier<void> {
part "download_file_notifier.g.dart";

@Riverpod(keepAlive: true)
class DownloadFileNotifier extends _$DownloadFileNotifier {
@override
void build() {
return;
Expand Down
27 changes: 27 additions & 0 deletions lib/state_notifier/common/download_file_notifier.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 21 additions & 24 deletions lib/view/common/image_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@

import "dart:math";

import "package:device_info_plus/device_info_plus.dart";
import "package:dio/dio.dart";
import "package:flutter/foundation.dart";
import "package:flutter/material.dart";
import "package:flutter/services.dart";
import "package:flutter_gen/gen_l10n/app_localizations.dart";
import "package:hooks_riverpod/hooks_riverpod.dart";
import "package:image_gallery_saver/image_gallery_saver.dart";
import "package:miria/providers.dart";
import "package:miria/state_notifier/common/download_file_notifier.dart";
import "package:miria/view/common/interactive_viewer.dart" as iv;
import "package:miria/view/common/misskey_notes/network_image.dart";
import "package:permission_handler/permission_handler.dart";
import "package:misskey_dart/misskey_dart.dart";

class ImageDialog extends ConsumerStatefulWidget {
final List<DriveFile> driveFiles;
Expand Down Expand Up @@ -167,16 +163,16 @@ class ImageDialogState extends ConsumerState<ImageDialog> {
? const ScrollPhysics()
: const NeverScrollableScrollPhysics(),
children: [
for (final url in widget.driveFiles)
for (final file in widget.driveFiles)
ScaleNotifierInteractiveViewer(
imageUrl: file.url,
controller: _transformationController,
onScaleChanged: (scaleUpdated) =>
setState(() {
scale = scaleUpdated;
}),
),
)
imageUrl: file.url,
controller: _transformationController,
onScaleChanged: (scaleUpdated) => setState(() {
scale = scaleUpdated;
}),
maxScale: maxScale,
isEnableScale: !isDoubleTap,
),
],
),
),
Expand Down Expand Up @@ -218,15 +214,16 @@ class ImageDialogState extends ConsumerState<ImageDialog> {
top: 10,
child: RawMaterialButton(
onPressed: () async {
final page = pageController.page?.toInt();
if (page == null) return;
final driveFile = widget.driveFiles[page];
await ref
.read(downloadFileNotifierProvider.notifier)
.downloadFile(driveFile);
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(S.of(context).savedImage)));
final page = pageController.page?.toInt();
if (page == null) return;
final driveFile = widget.driveFiles[page];
await ref
.read(downloadFileNotifierProvider.notifier)
.downloadFile(driveFile);
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(S.of(context).savedImage)),
);
},
constraints:
const BoxConstraints(minWidth: 0, minHeight: 0),
Expand Down
2 changes: 1 addition & 1 deletion lib/view/common/misskey_notes/misskey_file_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class MisskeyImage extends HookConsumerWidget {
await showDialog(
context: context,
builder: (context) => ImageDialog(
imageUrlList: targetFiles,
driveFiles: targetFiles,
initialPage: position,
),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/view/misskey_page_page/misskey_page_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class PageContent extends ConsumerWidget {
onTap: () async => showDialog(
context: context,
builder: (context) =>
ImageDialog(driveFiles: [url], initialPage: 0),
ImageDialog(driveFiles: [file], initialPage: 0),
),
child: NetworkImageView(
url: thumbnailUrl ?? url,
Expand Down
2 changes: 1 addition & 1 deletion lib/view/user_page/user_info_notifier.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1c318b3

Please sign in to comment.