2022-07-28 18:59:26 +02:00
|
|
|
import 'dart:async';
|
|
|
|
|
2024-07-09 19:00:24 +02:00
|
|
|
import 'package:copy_with/copy_with.dart';
|
2021-09-14 23:00:24 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
2024-07-09 19:00:24 +02:00
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2021-09-14 23:00:24 +02:00
|
|
|
import 'package:logging/logging.dart';
|
|
|
|
import 'package:nc_photos/account.dart';
|
2024-07-09 19:00:24 +02:00
|
|
|
import 'package:nc_photos/bloc_util.dart';
|
|
|
|
import 'package:nc_photos/controller/account_controller.dart';
|
2022-10-15 16:29:18 +02:00
|
|
|
import 'package:nc_photos/entity/file_descriptor.dart';
|
2021-09-14 23:00:24 +02:00
|
|
|
import 'package:nc_photos/entity/file_util.dart' as file_util;
|
|
|
|
import 'package:nc_photos/k.dart' as k;
|
|
|
|
import 'package:nc_photos/theme.dart';
|
|
|
|
import 'package:nc_photos/widget/disposable.dart';
|
|
|
|
import 'package:nc_photos/widget/horizontal_page_viewer.dart';
|
|
|
|
import 'package:nc_photos/widget/image_viewer.dart';
|
|
|
|
import 'package:nc_photos/widget/slideshow_dialog.dart';
|
|
|
|
import 'package:nc_photos/widget/video_viewer.dart';
|
|
|
|
import 'package:nc_photos/widget/viewer_mixin.dart';
|
|
|
|
import 'package:nc_photos/widget/wakelock_util.dart';
|
2022-12-16 16:01:04 +01:00
|
|
|
import 'package:np_codegen/np_codegen.dart';
|
2023-08-20 21:04:55 +02:00
|
|
|
import 'package:np_ui/np_ui.dart';
|
2024-07-09 19:00:24 +02:00
|
|
|
import 'package:to_string/to_string.dart';
|
2022-12-16 16:01:04 +01:00
|
|
|
|
|
|
|
part 'slideshow_viewer.g.dart';
|
2024-07-09 19:00:24 +02:00
|
|
|
part 'slideshow_viewer/bloc.dart';
|
|
|
|
part 'slideshow_viewer/state_event.dart';
|
|
|
|
part 'slideshow_viewer/view.dart';
|
2021-09-14 23:00:24 +02:00
|
|
|
|
|
|
|
class SlideshowViewerArguments {
|
2024-07-09 19:00:24 +02:00
|
|
|
const SlideshowViewerArguments(
|
2021-09-14 23:00:24 +02:00
|
|
|
this.account,
|
2024-07-09 19:00:24 +02:00
|
|
|
this.files,
|
2021-09-14 23:00:24 +02:00
|
|
|
this.startIndex,
|
|
|
|
this.config,
|
|
|
|
);
|
|
|
|
|
|
|
|
final Account account;
|
2024-07-09 19:00:24 +02:00
|
|
|
final List<FileDescriptor> files;
|
2021-09-14 23:00:24 +02:00
|
|
|
final int startIndex;
|
|
|
|
final SlideshowConfig config;
|
|
|
|
}
|
|
|
|
|
2024-07-09 19:00:24 +02:00
|
|
|
class SlideshowViewer extends StatelessWidget {
|
2021-09-14 23:00:24 +02:00
|
|
|
static const routeName = "/slideshow-viewer";
|
|
|
|
|
|
|
|
static Route buildRoute(SlideshowViewerArguments args) => MaterialPageRoute(
|
|
|
|
builder: (context) => SlideshowViewer.fromArgs(args),
|
|
|
|
);
|
|
|
|
|
2021-09-15 08:58:06 +02:00
|
|
|
const SlideshowViewer({
|
2024-05-28 17:10:33 +02:00
|
|
|
super.key,
|
2021-09-14 23:00:24 +02:00
|
|
|
required this.account,
|
2024-07-09 19:00:24 +02:00
|
|
|
required this.files,
|
2021-09-14 23:00:24 +02:00
|
|
|
required this.startIndex,
|
|
|
|
required this.config,
|
2024-05-28 17:10:33 +02:00
|
|
|
});
|
2021-09-14 23:00:24 +02:00
|
|
|
|
|
|
|
SlideshowViewer.fromArgs(SlideshowViewerArguments args, {Key? key})
|
|
|
|
: this(
|
|
|
|
key: key,
|
|
|
|
account: args.account,
|
2024-07-09 19:00:24 +02:00
|
|
|
files: args.files,
|
2021-09-14 23:00:24 +02:00
|
|
|
startIndex: args.startIndex,
|
|
|
|
config: args.config,
|
|
|
|
);
|
|
|
|
|
|
|
|
@override
|
2024-07-09 19:00:24 +02:00
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return BlocProvider(
|
|
|
|
create: (context) => _Bloc(
|
|
|
|
account: context.read<AccountController>().account,
|
|
|
|
files: files,
|
|
|
|
startIndex: startIndex,
|
|
|
|
config: config,
|
|
|
|
)..add(const _Init()),
|
|
|
|
child: const _WrappedSlideshowViewer(),
|
|
|
|
);
|
|
|
|
}
|
2021-09-14 23:00:24 +02:00
|
|
|
|
|
|
|
final Account account;
|
2024-07-09 19:00:24 +02:00
|
|
|
final List<FileDescriptor> files;
|
2021-09-14 23:00:24 +02:00
|
|
|
final int startIndex;
|
|
|
|
final SlideshowConfig config;
|
|
|
|
}
|
|
|
|
|
2024-07-09 19:00:24 +02:00
|
|
|
class _WrappedSlideshowViewer extends StatefulWidget {
|
|
|
|
const _WrappedSlideshowViewer();
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => _WrappedSlideshowViewerState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _WrappedSlideshowViewerState extends State<_WrappedSlideshowViewer>
|
2021-09-14 23:00:24 +02:00
|
|
|
with
|
2024-07-09 19:00:24 +02:00
|
|
|
DisposableManagerMixin<_WrappedSlideshowViewer>,
|
|
|
|
ViewerControllersMixin<_WrappedSlideshowViewer> {
|
2021-09-14 23:00:24 +02:00
|
|
|
@override
|
2024-07-09 19:00:24 +02:00
|
|
|
void initState() {
|
2021-09-14 23:00:24 +02:00
|
|
|
super.initState();
|
2021-09-15 17:13:38 +02:00
|
|
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);
|
2021-09-14 23:00:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2024-07-09 19:00:24 +02:00
|
|
|
List<Disposable> initDisposables() {
|
2021-09-14 23:00:24 +02:00
|
|
|
return [
|
|
|
|
...super.initDisposables(),
|
|
|
|
WakelockControllerDisposable(),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2024-07-09 19:00:24 +02:00
|
|
|
Widget build(BuildContext context) {
|
2022-11-12 10:55:33 +01:00
|
|
|
return Theme(
|
2023-08-19 18:47:56 +02:00
|
|
|
data: buildDarkTheme(context),
|
2024-07-09 19:00:24 +02:00
|
|
|
child: const Scaffold(
|
|
|
|
body: _Body(),
|
2021-09-14 23:00:24 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2024-07-09 19:00:24 +02:00
|
|
|
}
|
2021-09-14 23:00:24 +02:00
|
|
|
|
2024-07-09 19:00:24 +02:00
|
|
|
// typedef _BlocBuilder = BlocBuilder<_Bloc, _State>;
|
|
|
|
// typedef _BlocListener = BlocListener<_Bloc, _State>;
|
|
|
|
typedef _BlocListenerT<T> = BlocListenerT<_Bloc, _State, T>;
|
|
|
|
typedef _BlocSelector<T> = BlocSelector<_Bloc, _State, T>;
|
2021-09-14 23:00:24 +02:00
|
|
|
|
2024-07-09 19:00:24 +02:00
|
|
|
extension on BuildContext {
|
|
|
|
_Bloc get bloc => read<_Bloc>();
|
|
|
|
// _State get state => bloc.state;
|
|
|
|
void addEvent(_Event event) => bloc.add(event);
|
2021-09-14 23:00:24 +02:00
|
|
|
}
|