feat: save/share in the picture viewer, and a tap hides its chrome
- the viewer's top bar gains Save to Photos and Share on Android: saving writes through MediaStore into Pictures/Chamber Go (no permission on Android 10+, a runtime request on older versions), sharing hands a cache file to the system chooser through a FileProvider; both are a small native channel, not another plugin - dsh-Go keeps its title bar always visible; here a single tap hides the title, keys and page indicator and the next tap brings them back, so they do not cover the picture. Double-tap still zooms, swiping still pages at 1x, dragging pans while zoomed - version 0.6.6+606; the viewer test now covers the platform calls, chrome toggle, zoom, pan and paging
This commit is contained in:
1 parent
c2dabbe187
commit
fedc4dd79c
10 files changed
+471
-45
No files matched your search
@@ -1,7 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:openchamber/api/client.dart';
|
||||
import 'package:openchamber/api/transport.dart';
|
||||
import 'package:openchamber/l10n.dart';
|
||||
import 'package:openchamber/widgets/image_viewer.dart';
|
||||
|
||||
class _NoopTransport implements Transport {
|
||||
@@ -26,9 +28,12 @@ const _png =
|
||||
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==';
|
||||
|
||||
void main() {
|
||||
setUp(() => L10n.instance.apply(AppLanguage.en));
|
||||
tearDown(() => L10n.instance.apply(AppLanguage.zh));
|
||||
|
||||
final client = Client(Uri.parse('http://test'), transport: _NoopTransport());
|
||||
|
||||
Future<void> pumpViewer(WidgetTester tester) async {
|
||||
Future<void> pumpViewer(WidgetTester tester, {bool mediaActions = false}) async {
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: ImageViewerPage(
|
||||
images: const [
|
||||
@@ -37,6 +42,7 @@ void main() {
|
||||
],
|
||||
directory: '/home/me',
|
||||
client: client,
|
||||
mediaActions: mediaActions,
|
||||
),
|
||||
));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -83,4 +89,50 @@ void main() {
|
||||
expect(find.text('Two'), findsOneWidget);
|
||||
expect(find.text('2 / 2'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('save and share send the current picture to the platform',
|
||||
(tester) async {
|
||||
final calls = <MethodCall>[];
|
||||
const channel = MethodChannel('openchamber/media');
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, (call) async {
|
||||
calls.add(call);
|
||||
return true;
|
||||
});
|
||||
addTearDown(() => TestDefaultBinaryMessengerBinding.instance
|
||||
.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, null));
|
||||
|
||||
await pumpViewer(tester, mediaActions: true);
|
||||
|
||||
await tester.tap(find.byTooltip('Save to Photos'));
|
||||
await tester.pump();
|
||||
await tester.tap(find.byTooltip('Share'));
|
||||
await tester.pump();
|
||||
|
||||
expect(calls.map((call) => call.method),
|
||||
containsAll(['saveImage', 'shareImage']));
|
||||
final save = calls.firstWhere((call) => call.method == 'saveImage');
|
||||
final args = save.arguments as Map;
|
||||
expect(args['name'], 'One.png');
|
||||
expect(args['mime'], 'image/png');
|
||||
expect(args['bytes'], isA<Uint8List>());
|
||||
});
|
||||
|
||||
testWidgets('a tap hides the title and keys until the next tap',
|
||||
(tester) async {
|
||||
await pumpViewer(tester);
|
||||
|
||||
double chromeOpacity() => tester
|
||||
.widget<AnimatedOpacity>(find.byKey(const ValueKey('viewer-chrome')))
|
||||
.opacity;
|
||||
|
||||
expect(chromeOpacity(), 1);
|
||||
await tester.tap(find.byType(InteractiveViewer));
|
||||
await tester.pump(const Duration(milliseconds: 400));
|
||||
expect(chromeOpacity(), 0);
|
||||
await tester.tap(find.byType(InteractiveViewer));
|
||||
await tester.pump(const Duration(milliseconds: 400));
|
||||
expect(chromeOpacity(), 1);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user