Skip to content

Commit

Permalink
[timetable] hidden wallpaper
Browse files Browse the repository at this point in the history
  • Loading branch information
liplum committed Sep 23, 2024
1 parent 8249cf1 commit 9796010
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 23 deletions.
2 changes: 1 addition & 1 deletion lib/design/animation/progress.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class BlockWhenLoading extends StatelessWidget {
return [
AnimatedOpacity(
opacity: loading ? 0.5 : 1,
duration: Durations.medium1,
duration: Durations.short4,
child: AbsorbPointer(
absorbing: loading,
child: child,
Expand Down
8 changes: 7 additions & 1 deletion lib/design/widget/wallpaper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class WallpaperWidget extends StatelessWidget {

@override
Widget build(BuildContext context) {
if (!background.enabled || background.hidden) {
return const SizedBox.shrink();
}
if (kIsWeb) {
return _WallpaperWebImpl(
background: background,
Expand All @@ -28,7 +31,7 @@ class WallpaperWidget extends StatelessWidget {
return _WallpaperImpl(
background: background,
fade: fade,
fadeDuration: kDebugMode ? const Duration(milliseconds: 1000) : Durations.long1,
fadeDuration: kDebugMode ? const Duration(milliseconds: 1000) : Durations.medium3,
);
}
}
Expand All @@ -37,11 +40,13 @@ class WallpaperWidget extends StatelessWidget {
class WithWallpaper extends StatelessWidget {
final BackgroundImage background;
final Widget child;
final bool fade;

const WithWallpaper({
super.key,
required this.child,
required this.background,
this.fade = true,
});

@override
Expand All @@ -50,6 +55,7 @@ class WithWallpaper extends StatelessWidget {
Positioned.fill(
child: WallpaperWidget(
background: background,
fade: fade,
),
),
child,
Expand Down
1 change: 1 addition & 0 deletions lib/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class _MainStagePageState extends ConsumerState<MainStagePage> {
buildBody(),
].stack();
}

Widget buildBody() {
final items = buildItems();
if (context.isPortrait) {
Expand Down
16 changes: 14 additions & 2 deletions lib/timetable/p13n/entity/background.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,28 @@ class BackgroundImage {
final bool repeat;
@JsonKey()
final bool antialias;
@JsonKey()
final bool hidden;

const BackgroundImage({
required this.path,
this.opacity = 1.0,
this.repeat = true,
this.antialias = true,
this.hidden = false,
});

const BackgroundImage.disabled({
this.opacity = 1.0,
this.repeat = true,
this.antialias = true,
this.hidden = true,
}) : path = "";

bool get enabled => path.isNotEmpty;

ImageRepeat get imageRepeat => repeat ? ImageRepeat.repeat : ImageRepeat.noRepeat;

FilterQuality get filterQuality => antialias ? FilterQuality.low : FilterQuality.none;

factory BackgroundImage.fromJson(Map<String, dynamic> json) => _$BackgroundImageFromJson(json);
Expand All @@ -46,11 +51,18 @@ class BackgroundImage {
path == other.path &&
opacity == other.opacity &&
repeat == other.repeat &&
antialias == other.antialias;
antialias == other.antialias &&
hidden == other.hidden;
}

@override
int get hashCode => Object.hash(path, opacity, repeat, antialias);
int get hashCode => Object.hash(
path,
opacity,
repeat,
antialias,
hidden,
);

@override
String toString() {
Expand Down
8 changes: 8 additions & 0 deletions lib/timetable/p13n/entity/background.g.dart

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

29 changes: 27 additions & 2 deletions lib/timetable/p13n/page/background.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class _TimetableBackgroundEditorState extends State<TimetableBackgroundEditor> w
double opacity = 1.0;
bool repeat = true;
bool antialias = true;
bool hidden = false;
late final AnimationController $opacity;

_TimetableBackgroundEditorState() {
Expand All @@ -48,6 +49,7 @@ class _TimetableBackgroundEditorState extends State<TimetableBackgroundEditor> w
opacity = bk?.opacity ?? 1.0;
repeat = bk?.repeat ?? true;
antialias = bk?.antialias ?? true;
hidden = bk?.hidden ?? false;
}

@override
Expand Down Expand Up @@ -81,8 +83,22 @@ class _TimetableBackgroundEditorState extends State<TimetableBackgroundEditor> w
],
),
SliverList.list(children: [
buildImage().padH(10),
buildToolBar().padV(4),
onHidden(
child: buildImage(),
).padH(10),
onHidden(
child: buildToolBar(),
).padV(4),
CheckboxListTile(
secondary: Icon(hidden ? Icons.hide_image_outlined : Icons.image_outlined),
title: "Show wallpaper".text(),
value: !hidden,
onChanged: (_) {
setState(() {
hidden = !hidden;
});
},
),
if (rawPath != null && (Dev.on || (UniversalPlatform.isDesktop || kIsWeb)))
ListTile(
title: i18n.p13n.background.selectedImage.text(),
Expand All @@ -98,6 +114,14 @@ class _TimetableBackgroundEditorState extends State<TimetableBackgroundEditor> w
);
}

Widget onHidden({required Widget child}) {
return AnimatedOpacity(
opacity: hidden ? 0.3 : 1.0,
duration: Durations.short4,
child: child,
);
}

bool shouldSave() {
return buildBackgroundImage() != Settings.timetable.backgroundImage;
}
Expand Down Expand Up @@ -211,6 +235,7 @@ class _TimetableBackgroundEditorState extends State<TimetableBackgroundEditor> w
opacity: opacity,
repeat: repeat,
antialias: antialias,
hidden: hidden,
);
}

Expand Down
16 changes: 6 additions & 10 deletions lib/timetable/page/screenshot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,12 @@ class TimetableWeeklyScreenshotFilm extends StatelessWidget {
Widget build(BuildContext context) {
final style = TimetableStyle.of(context);
final background = style.background;
if (config.enableBackground && background.enabled) {
return [
Positioned.fill(
child: WallpaperWidget(
background: background,
fade: false,
),
),
buildBody(context, style),
].stack();
if (config.enableBackground) {
return WithWallpaper(
background: background,
fade: false,
child: buildBody(context, style),
);
}
return buildBody(context, style);
}
Expand Down
11 changes: 4 additions & 7 deletions lib/timetable/widget/timetable/board.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,10 @@ class TimetableBoard extends StatelessWidget {
Widget build(BuildContext context) {
final style = TimetableStyle.of(context);
final background = style.background;
if (background.enabled) {
return WithWallpaper(
background: background,
child: buildBoard(),
);
}
return buildBoard();
return WithWallpaper(
background: background,
child: buildBoard(),
);
}

Widget buildBoard() {
Expand Down

0 comments on commit 9796010

Please sign in to comment.