Skip to content

Commit

Permalink
在没有 TODO 时健身视图显示加载动画:小鹿和幽灵,晚上未完成健身任务显示警告
Browse files Browse the repository at this point in the history
  • Loading branch information
mazj committed Feb 6, 2024
1 parent 8b108d8 commit 22ea416
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 97 deletions.
Binary file added assets/bese.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/ghost.json

Large diffs are not rendered by default.

25 changes: 22 additions & 3 deletions lib/api/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ class Config with _$Config {
@Default(false) bool showBingWallpaper,
@Default("") String cyberPass,
@Default(true) bool demoMode,
@Default(true) bool useAnimationInHealthViewWhenNoTodo,
@Default(false) bool showFatWarningAfter17IfLazy,
@Default(0.1) double volumeNormal,
@Default(0.5) double volumeOpenBluetooth}) = _Config;

factory Config.fromJson(Map<String, dynamic> json) => _$ConfigFromJson(json);
}

extension ConfigHelper on Config {
bool get showLoadingAnimationIfNoTodo =>
showBingWallpaper ? false : useAnimationInHealthViewWhenNoTodo;

String get base64Token =>
"Basic ${base64Encode(utf8.encode('$user:$password'))}";

Expand Down Expand Up @@ -56,17 +61,21 @@ class Configs extends _$Configs {

set(String user, String pass, int duration, bool showWallpaper,
{bool demoMode = false,
bool useAnimalInHealthViewWhenNoTodo = false,
required double minVol,
required double maxVol}) async {
required double maxVol,
required bool showWortoutWarning}) async {
final c = Config(
user: user,
password: pass,
cyberPass: encryptPassword(pass, 60 * 60 * 24 * 30),
fetchSeconds: duration,
showBingWallpaper: showWallpaper,
useAnimationInHealthViewWhenNoTodo: useAnimalInHealthViewWhenNoTodo,
demoMode: demoMode,
volumeNormal: minVol,
volumeOpenBluetooth: maxVol);
volumeOpenBluetooth: maxVol,
showFatWarningAfter17IfLazy: showWortoutWarning);
final s = await SharedPreferences.getInstance();
await s.setString("config", jsonEncode(c.toJson()));
data = c;
Expand Down Expand Up @@ -243,10 +252,20 @@ showWaitingBar(BuildContext context,
}

Future<bool> showSimpleMessage(BuildContext context,
{String? title, required String content, bool withPopFirst = false}) async {
{String? title,
required String content,
bool withPopFirst = false,
bool useSnackBar = false,
int snackBarDuration = 500}) async {
if (withPopFirst) {
Navigator.of(context).pop();
}
if (useSnackBar) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(content),
duration: Duration(milliseconds: snackBarDuration)));
return true;
}
return await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
Expand Down
59 changes: 58 additions & 1 deletion lib/api/common.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ mixin _$Config {
bool get showBingWallpaper => throw _privateConstructorUsedError;
String get cyberPass => throw _privateConstructorUsedError;
bool get demoMode => throw _privateConstructorUsedError;
bool get useAnimationInHealthViewWhenNoTodo =>
throw _privateConstructorUsedError;
bool get showFatWarningAfter17IfLazy => throw _privateConstructorUsedError;
double get volumeNormal => throw _privateConstructorUsedError;
double get volumeOpenBluetooth => throw _privateConstructorUsedError;

Expand All @@ -46,6 +49,8 @@ abstract class $ConfigCopyWith<$Res> {
bool showBingWallpaper,
String cyberPass,
bool demoMode,
bool useAnimationInHealthViewWhenNoTodo,
bool showFatWarningAfter17IfLazy,
double volumeNormal,
double volumeOpenBluetooth});
}
Expand All @@ -69,6 +74,8 @@ class _$ConfigCopyWithImpl<$Res, $Val extends Config>
Object? showBingWallpaper = null,
Object? cyberPass = null,
Object? demoMode = null,
Object? useAnimationInHealthViewWhenNoTodo = null,
Object? showFatWarningAfter17IfLazy = null,
Object? volumeNormal = null,
Object? volumeOpenBluetooth = null,
}) {
Expand Down Expand Up @@ -97,6 +104,15 @@ class _$ConfigCopyWithImpl<$Res, $Val extends Config>
? _value.demoMode
: demoMode // ignore: cast_nullable_to_non_nullable
as bool,
useAnimationInHealthViewWhenNoTodo: null ==
useAnimationInHealthViewWhenNoTodo
? _value.useAnimationInHealthViewWhenNoTodo
: useAnimationInHealthViewWhenNoTodo // ignore: cast_nullable_to_non_nullable
as bool,
showFatWarningAfter17IfLazy: null == showFatWarningAfter17IfLazy
? _value.showFatWarningAfter17IfLazy
: showFatWarningAfter17IfLazy // ignore: cast_nullable_to_non_nullable
as bool,
volumeNormal: null == volumeNormal
? _value.volumeNormal
: volumeNormal // ignore: cast_nullable_to_non_nullable
Expand All @@ -123,6 +139,8 @@ abstract class _$$ConfigImplCopyWith<$Res> implements $ConfigCopyWith<$Res> {
bool showBingWallpaper,
String cyberPass,
bool demoMode,
bool useAnimationInHealthViewWhenNoTodo,
bool showFatWarningAfter17IfLazy,
double volumeNormal,
double volumeOpenBluetooth});
}
Expand All @@ -144,6 +162,8 @@ class __$$ConfigImplCopyWithImpl<$Res>
Object? showBingWallpaper = null,
Object? cyberPass = null,
Object? demoMode = null,
Object? useAnimationInHealthViewWhenNoTodo = null,
Object? showFatWarningAfter17IfLazy = null,
Object? volumeNormal = null,
Object? volumeOpenBluetooth = null,
}) {
Expand Down Expand Up @@ -172,6 +192,15 @@ class __$$ConfigImplCopyWithImpl<$Res>
? _value.demoMode
: demoMode // ignore: cast_nullable_to_non_nullable
as bool,
useAnimationInHealthViewWhenNoTodo: null ==
useAnimationInHealthViewWhenNoTodo
? _value.useAnimationInHealthViewWhenNoTodo
: useAnimationInHealthViewWhenNoTodo // ignore: cast_nullable_to_non_nullable
as bool,
showFatWarningAfter17IfLazy: null == showFatWarningAfter17IfLazy
? _value.showFatWarningAfter17IfLazy
: showFatWarningAfter17IfLazy // ignore: cast_nullable_to_non_nullable
as bool,
volumeNormal: null == volumeNormal
? _value.volumeNormal
: volumeNormal // ignore: cast_nullable_to_non_nullable
Expand All @@ -194,6 +223,8 @@ class _$ConfigImpl with DiagnosticableTreeMixin implements _Config {
this.showBingWallpaper = false,
this.cyberPass = "",
this.demoMode = true,
this.useAnimationInHealthViewWhenNoTodo = true,
this.showFatWarningAfter17IfLazy = false,
this.volumeNormal = 0.1,
this.volumeOpenBluetooth = 0.5});

Expand All @@ -220,14 +251,20 @@ class _$ConfigImpl with DiagnosticableTreeMixin implements _Config {
final bool demoMode;
@override
@JsonKey()
final bool useAnimationInHealthViewWhenNoTodo;
@override
@JsonKey()
final bool showFatWarningAfter17IfLazy;
@override
@JsonKey()
final double volumeNormal;
@override
@JsonKey()
final double volumeOpenBluetooth;

@override
String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) {
return 'Config(user: $user, password: $password, fetchSeconds: $fetchSeconds, showBingWallpaper: $showBingWallpaper, cyberPass: $cyberPass, demoMode: $demoMode, volumeNormal: $volumeNormal, volumeOpenBluetooth: $volumeOpenBluetooth)';
return 'Config(user: $user, password: $password, fetchSeconds: $fetchSeconds, showBingWallpaper: $showBingWallpaper, cyberPass: $cyberPass, demoMode: $demoMode, useAnimationInHealthViewWhenNoTodo: $useAnimationInHealthViewWhenNoTodo, showFatWarningAfter17IfLazy: $showFatWarningAfter17IfLazy, volumeNormal: $volumeNormal, volumeOpenBluetooth: $volumeOpenBluetooth)';
}

@override
Expand All @@ -241,6 +278,10 @@ class _$ConfigImpl with DiagnosticableTreeMixin implements _Config {
..add(DiagnosticsProperty('showBingWallpaper', showBingWallpaper))
..add(DiagnosticsProperty('cyberPass', cyberPass))
..add(DiagnosticsProperty('demoMode', demoMode))
..add(DiagnosticsProperty('useAnimationInHealthViewWhenNoTodo',
useAnimationInHealthViewWhenNoTodo))
..add(DiagnosticsProperty(
'showFatWarningAfter17IfLazy', showFatWarningAfter17IfLazy))
..add(DiagnosticsProperty('volumeNormal', volumeNormal))
..add(DiagnosticsProperty('volumeOpenBluetooth', volumeOpenBluetooth));
}
Expand All @@ -261,6 +302,14 @@ class _$ConfigImpl with DiagnosticableTreeMixin implements _Config {
other.cyberPass == cyberPass) &&
(identical(other.demoMode, demoMode) ||
other.demoMode == demoMode) &&
(identical(other.useAnimationInHealthViewWhenNoTodo,
useAnimationInHealthViewWhenNoTodo) ||
other.useAnimationInHealthViewWhenNoTodo ==
useAnimationInHealthViewWhenNoTodo) &&
(identical(other.showFatWarningAfter17IfLazy,
showFatWarningAfter17IfLazy) ||
other.showFatWarningAfter17IfLazy ==
showFatWarningAfter17IfLazy) &&
(identical(other.volumeNormal, volumeNormal) ||
other.volumeNormal == volumeNormal) &&
(identical(other.volumeOpenBluetooth, volumeOpenBluetooth) ||
Expand All @@ -277,6 +326,8 @@ class _$ConfigImpl with DiagnosticableTreeMixin implements _Config {
showBingWallpaper,
cyberPass,
demoMode,
useAnimationInHealthViewWhenNoTodo,
showFatWarningAfter17IfLazy,
volumeNormal,
volumeOpenBluetooth);

Expand All @@ -302,6 +353,8 @@ abstract class _Config implements Config {
final bool showBingWallpaper,
final String cyberPass,
final bool demoMode,
final bool useAnimationInHealthViewWhenNoTodo,
final bool showFatWarningAfter17IfLazy,
final double volumeNormal,
final double volumeOpenBluetooth}) = _$ConfigImpl;

Expand All @@ -320,6 +373,10 @@ abstract class _Config implements Config {
@override
bool get demoMode;
@override
bool get useAnimationInHealthViewWhenNoTodo;
@override
bool get showFatWarningAfter17IfLazy;
@override
double get volumeNormal;
@override
double get volumeOpenBluetooth;
Expand Down
9 changes: 8 additions & 1 deletion lib/api/common.g.dart

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

2 changes: 1 addition & 1 deletion lib/api/dash.g.dart

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

101 changes: 59 additions & 42 deletions lib/chart.dart
Original file line number Diff line number Diff line change
@@ -1,56 +1,73 @@
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:screen_me/api/common.dart';
import 'package:screen_me/api/dash.dart';
import 'package:syncfusion_flutter_charts/charts.dart';

Widget buildChart(DashInfo? dashInfo, AnimationController controller) {
Widget buildChart(DashInfo? dashInfo, Config config) {
final mindfulMin = dashInfo?.fitnessInfo.mindful ?? 0.0;
final mindful100 = max(mindfulMin, 0.5) / 5 * 100;
final exec100 = max(dashInfo?.fitnessInfo.exercise ?? 3, 3) / 30 * 100;
final workout100 = max((dashInfo?.fitnessInfo.active ?? 50), 50) /
(dashInfo?.fitnessInfo.globalActive ?? 500.0) *
100;
return SfCircularChart(
legend: const Legend(
isVisible: false,
iconHeight: 20,
iconWidth: 20,
overflowMode: LegendItemOverflowMode.wrap),
series: <RadialBarSeries<ChartSampleData, String>>[
RadialBarSeries<ChartSampleData, String>(
animationDuration: 0,
maximumValue: 100,
radius: '100%',
gap: '2%',
innerRadius: '30%',
dataSource: <ChartSampleData>[
ChartSampleData(
x: 'Mindful',
y: mindful100,
text: '呼吸',
pointColor: const Color.fromRGBO(0, 201, 230, 1.0)),
ChartSampleData(
x: 'Exercise',
y: exec100,
text: '锻炼',
pointColor: const Color.fromRGBO(63, 224, 0, 1.0)),
ChartSampleData(
x: 'Active',
y: workout100,
text: '活动',
pointColor: const Color.fromRGBO(226, 1, 26, 1.0)),
],
cornerStyle: CornerStyle.bothCurve,
xValueMapper: (ChartSampleData data, _) => data.x as String,
yValueMapper: (ChartSampleData data, _) => data.y,
pointColorMapper: (ChartSampleData data, _) => data.pointColor,
trackColor: Colors.white,
trackBorderColor: Colors.black,
trackBorderWidth: 0,
trackOpacity: 0.15,
dataLabelMapper: (ChartSampleData data, _) => data.text,
dataLabelSettings: const DataLabelSettings(isVisible: true))
]);
final now = DateTime.now();
final fuckLazy = now.hour >= 18 && workout100 < 100;
return Stack(
alignment: Alignment.center,
children: [
fuckLazy
? KeyedSubtree(
key: UniqueKey(),
child:
Image.asset("assets/bese.png", width: 50, fit: BoxFit.contain)
.animate()
.shake(duration: const Duration(milliseconds: 1000)))
: const SizedBox(),
SfCircularChart(
legend: const Legend(
isVisible: false,
iconHeight: 20,
iconWidth: 20,
overflowMode: LegendItemOverflowMode.wrap),
series: <RadialBarSeries<ChartSampleData, String>>[
RadialBarSeries<ChartSampleData, String>(
animationDuration: 0,
maximumValue: 100,
radius: '100%',
gap: '2%',
innerRadius: '30%',
dataSource: <ChartSampleData>[
ChartSampleData(
x: 'Mindful',
y: mindful100,
text: '呼吸',
pointColor: const Color.fromRGBO(0, 201, 230, 1.0)),
ChartSampleData(
x: 'Exercise',
y: exec100,
text: '锻炼',
pointColor: const Color.fromRGBO(63, 224, 0, 1.0)),
ChartSampleData(
x: 'Active',
y: workout100,
text: '活动',
pointColor: const Color.fromRGBO(226, 1, 26, 1.0)),
],
cornerStyle: CornerStyle.bothCurve,
xValueMapper: (ChartSampleData data, _) => data.x as String,
yValueMapper: (ChartSampleData data, _) => data.y,
pointColorMapper: (ChartSampleData data, _) => data.pointColor,
trackColor: Colors.white,
trackBorderColor: Colors.black,
trackBorderWidth: 0,
trackOpacity: 0.15,
dataLabelMapper: (ChartSampleData data, _) => data.text,
dataLabelSettings: const DataLabelSettings(isVisible: true))
])
],
);
}

class ChartSampleData {
Expand Down

0 comments on commit 22ea416

Please sign in to comment.