Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
linyi102 committed Nov 3, 2024
2 parents 9ad2488 + e892379 commit 40f14a1
Show file tree
Hide file tree
Showing 47 changed files with 1,479 additions and 526 deletions.
10 changes: 8 additions & 2 deletions lib/components/common_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ class CommonImage extends StatelessWidget {
{this.showIconWhenUrlIsEmptyOrError = true,
this.reduceMemCache = true,
this.memCacheWidth = 600,
this.fit = BoxFit.cover,
this.alignment = Alignment.center,
Key? key})
: super(key: key);
final String url;
final bool reduceMemCache;
final int memCacheWidth;
final bool showIconWhenUrlIsEmptyOrError; // 当没有图片或图片错误时,显示图标
final BoxFit fit;
final Alignment alignment;

@override
Widget build(BuildContext context) {
Expand All @@ -38,7 +42,8 @@ class CommonImage extends StatelessWidget {
fadeInDuration: fadeInDuration,
errorWidget: (_, __, ___) => _buildDefaultImage(context, isError: true),
placeholder: (_, __) => _buildDefaultImage(context),
fit: BoxFit.cover,
fit: fit,
alignment: alignment,
);
}

Expand All @@ -56,7 +61,8 @@ class CommonImage extends StatelessWidget {
? ResizeImage(fileImage, width: memCacheWidth)
as ImageProvider<Object>
: fileImage,
fit: BoxFit.cover,
fit: fit,
alignment: alignment,
fadeInDuration: fadeInDuration,
placeholder: MemoryImage(kTransparentImage),
imageErrorBuilder: (_, __, ___) =>
Expand Down
3 changes: 3 additions & 0 deletions lib/controllers/theme_controller.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_test_future/models/page_switch_animation.dart';
import 'package:flutter_test_future/utils/settings.dart';
import 'package:flutter_test_future/utils/sp_profile.dart';
import 'package:flutter_test_future/utils/sp_util.dart';
import 'package:flutter_test_future/values/values.dart';
Expand All @@ -12,6 +13,8 @@ class ThemeController extends GetxController {
Rx<bool> useM3 = SPUtil.getBool("useM3", defaultValue: true).obs;
Rx<bool> useCardStyle =
SPUtil.getBool("useCardStyle", defaultValue: true).obs;
Rx<bool> hideMobileBottomLabel =
SettingsUtil.getValue<bool>(SettingsEnum.hideMobileBottomLabel).obs;

Rx<ThemeColor> lightThemeColor = getSelectedTheme();
Rx<ThemeColor> darkThemeColor = getSelectedTheme(dark: true);
Expand Down
41 changes: 38 additions & 3 deletions lib/dao/history_dao.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,16 @@ class HistoryDao {
Log.info('sql: getFirstHistory');

var cols = await SqliteUtil.database.rawQuery('''
select date, anime_id from history
order by date limit 1;
select min(date) min_date, anime_id from history
where date not like '0000%';
''');
if (cols.isEmpty) return null;

var col = cols.first;
var anime = await SqliteUtil.getAnimeByAnimeId(col['anime_id'] as int);
return {
'anime': anime,
'date': col['date'],
'date': col['min_date'],
};
}

Expand All @@ -140,4 +140,39 @@ class HistoryDao {
}
return animes;
}

/// 获取最大观看次数
static Future<int> getMaxReviewNumber(int animeId) async {
final rows = await SqliteUtil.database.rawQuery('''
select max(review_number) max_review_number from history where anime_id = $animeId;
''');
return SqliteUtil.firstRowColumnValue<int>(rows) ?? 1;
}

/// 获取指定回顾序号动漫的观看集数
static Future<int> getAnimeWatchedCount(int animeId, int reviewNumber) async {
final rows = await SqliteUtil.database.rawQuery('''
select count(date) number from history
where anime_id = $animeId and review_number = $reviewNumber;
''');
return SqliteUtil.firstRowColumnValue<int>(rows) ?? 0;
}

/// 获取当前观看次数的最早日期
static Future<String> getWatchedMinDate(int animeId, int reviewNumber) async {
final rows = await SqliteUtil.database.rawQuery('''
select min(date) from history
where anime_id = $animeId and review_number = $reviewNumber and date not like '0000%';
''');
return SqliteUtil.firstRowColumnValue<String>(rows) ?? '';
}

/// 获取当前观看次数的最晚日期
static Future<String> getWatchedMaxDate(int animeId, int reviewNumber) async {
final rows = await SqliteUtil.database.rawQuery('''
select max(date) from history
where anime_id = $animeId and review_number = $reviewNumber and date not like '0000%';
''');
return SqliteUtil.firstRowColumnValue<String>(rows) ?? '';
}
}
33 changes: 14 additions & 19 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:flex_color_scheme/flex_color_scheme.dart';
import 'package:flutter_logkit/logkit.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_test_future/components/classic_refresh_style.dart';
import 'package:flutter_test_future/controllers/backup_service.dart';
import 'package:flutter_test_future/global.dart';
Expand Down Expand Up @@ -98,7 +97,6 @@ class MyApp extends StatefulWidget {

class MyAppState extends State<MyApp> {
final ThemeController themeController = Get.put(ThemeController());
FlexScheme get baseScheme => FlexScheme.blue;
TextStyle get textStyle =>
TextStyle(fontFamilyFallback: themeController.fontFamilyFallback);
ThemeColor get curLightThemeColor => themeController.lightThemeColor.value;
Expand All @@ -114,11 +112,8 @@ class MyAppState extends State<MyApp> {
return GetMaterialApp(
home: LogkitOverlayAttacher(
logger: logger,
child: WindowWrapper(
child: ScreenUtilInit(
designSize: const Size(375, 812),
builder: (context, child) => const MainScreen(),
),
child: const WindowWrapper(
child: MainScreen(),
),
),
debugShowCheckedModeBanner: false,
Expand All @@ -135,10 +130,10 @@ class MyAppState extends State<MyApp> {
child = BotToastInit()(context, child);
// 全局点击空白处隐藏软键盘
child = _buildScaffoldWithHideKeyboardByClickBlank(context, child);
return Theme(
data: _getFixedTheme(context),
child: child,
);
return Obx(() => Theme(
data: _getFixedTheme(context),
child: child ?? const SizedBox(),
));
},
navigatorObservers: [BotToastNavigatorObserver()],
// 后台应用显示名称
Expand Down Expand Up @@ -240,12 +235,11 @@ class MyAppState extends State<MyApp> {
curLightThemeColor.primaryColor;

return FlexThemeData.light(
scheme: baseScheme,
colorScheme: ColorScheme.fromSeed(
seedColor: primary, brightness: Brightness.light),
useMaterial3: themeController.useM3.value,
fontFamilyFallback: textStyle.fontFamilyFallback,
primary: primary,
primaryContainer: primary.withOpacity(0.6),
tertiaryContainer: primary.withOpacity(0.4),
scaffoldBackground: curLightThemeColor.bodyColor,
surface: curLightThemeColor.cardColor,
// BottomNavigationBar
Expand All @@ -259,7 +253,7 @@ class MyAppState extends State<MyApp> {
subThemesData: FlexSubThemesData(
// chip颜色
chipSchemeColor: SchemeColor.primaryContainer,
chipSelectedSchemeColor: SchemeColor.primary,
chipSelectedSchemeColor: SchemeColor.secondaryContainer,
useM2StyleDividerInM3: true,
// 悬浮、按压等颜色不受主颜色影响
interactionEffects: false,
Expand Down Expand Up @@ -306,12 +300,13 @@ class MyAppState extends State<MyApp> {
curDarkThemeColor.primaryColor;

return FlexThemeData.dark(
scheme: baseScheme,
colorScheme: ColorScheme.fromSeed(
seedColor: primary,
onPrimary: Colors.white,
brightness: Brightness.dark),
useMaterial3: themeController.useM3.value,
fontFamilyFallback: textStyle.fontFamilyFallback,
primary: primary,
primaryContainer: primary.withOpacity(0.6),
tertiaryContainer: primary.withOpacity(0.4),
scaffoldBackground: curDarkThemeColor.bodyColor,
surface: curDarkThemeColor.cardColor,
// BottomNavigationBar
Expand All @@ -325,7 +320,7 @@ class MyAppState extends State<MyApp> {
subThemesData: FlexSubThemesData(
// chip颜色
chipSchemeColor: SchemeColor.primaryContainer,
chipSelectedSchemeColor: SchemeColor.tertiaryContainer,
chipSelectedSchemeColor: SchemeColor.secondaryContainer,
// 悬浮、按压等颜色不受主颜色影响
interactionEffects: false,
useTextTheme: true,
Expand Down
4 changes: 4 additions & 0 deletions lib/models/bangumi/bangumi.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export 'character.dart';
export 'images.dart';
export 'person.dart';
export 'person_career.dart';
50 changes: 50 additions & 0 deletions lib/models/bangumi/character.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import 'dart:convert';

import 'bangumi.dart';

class RelatedCharacter {
Images? images;
String? name;
String? relation;
List<RelatedPerson>? actors;
int? type;
int? id;

RelatedCharacter({
this.images,
this.name,
this.relation,
this.actors,
this.type,
this.id,
});

factory RelatedCharacter.fromJson(String str) =>
RelatedCharacter.fromMap(json.decode(str));

String toJson() => json.encode(toMap());

factory RelatedCharacter.fromMap(Map<String, dynamic> json) =>
RelatedCharacter(
images: json["images"] == null ? null : Images.fromMap(json["images"]),
name: json["name"],
relation: json["relation"],
actors: json["actors"] == null
? []
: List<RelatedPerson>.from(
json["actors"]!.map((x) => RelatedPerson.fromMap(x))),
type: json["type"],
id: json["id"],
);

Map<String, dynamic> toMap() => {
"images": images?.toMap(),
"name": name,
"relation": relation,
"actors": actors == null
? []
: List<dynamic>.from(actors!.map((x) => x.toMap())),
"type": type,
"id": id,
};
}
33 changes: 33 additions & 0 deletions lib/models/bangumi/images.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'dart:convert';

class Images {
String? small;
String? grid;
String? large;
String? medium;

Images({
this.small,
this.grid,
this.large,
this.medium,
});

factory Images.fromJson(String str) => Images.fromMap(json.decode(str));

String toJson() => json.encode(toMap());

factory Images.fromMap(Map<String, dynamic> json) => Images(
small: json["small"],
grid: json["grid"],
large: json["large"],
medium: json["medium"],
);

Map<String, dynamic> toMap() => {
"small": small,
"grid": grid,
"large": large,
"medium": medium,
};
}
51 changes: 51 additions & 0 deletions lib/models/bangumi/person.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import 'dart:convert';

import 'bangumi.dart';

class RelatedPerson {
Images? images;
String? name;
String? shortSummary;
List<String>? career;
int? id;
int? type;
bool? locked;

RelatedPerson({
this.images,
this.name,
this.shortSummary,
this.career,
this.id,
this.type,
this.locked,
});

factory RelatedPerson.fromJson(String str) =>
RelatedPerson.fromMap(json.decode(str));

String toJson() => json.encode(toMap());

factory RelatedPerson.fromMap(Map<String, dynamic> json) => RelatedPerson(
images: json["images"] == null ? null : Images.fromMap(json["images"]),
name: json["name"],
shortSummary: json["short_summary"],
career: json["career"] == null
? []
: List<String>.from(json["career"]!.map((x) => x)),
id: json["id"],
type: json["type"],
locked: json["locked"],
);

Map<String, dynamic> toMap() => {
"images": images?.toMap(),
"name": name,
"short_summary": shortSummary,
"career":
career == null ? [] : List<dynamic>.from(career!.map((x) => x)),
"id": id,
"type": type,
"locked": locked,
};
}
9 changes: 9 additions & 0 deletions lib/models/bangumi/person_career.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
enum PersonCareer {
producer,
mangaka,
artist,
seiyu,
writer,
illustrator,
actor
}
Loading

0 comments on commit 40f14a1

Please sign in to comment.