Skip to content

Commit

Permalink
feat: 首页收藏分类
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaoMint committed Jul 26, 2023
1 parent 9d638d2 commit 6783895
Show file tree
Hide file tree
Showing 13 changed files with 511 additions and 288 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ Miru App
- [x] Windows 支持
- [x] Android 支持
- [x] ~~Linux 支持~~
- [ ] 字幕
- [ ] BT 种子播放
- [x] 漫画支持
- [x] 小说支持
- [x] 影视支持
- [ ] TMDB 元数据
- [ ] 数据同步
- [x] i18n 国际化
- [x] 扩展设置
- [x] 影视播放进度
- [ ] 漫画小说视频设置
- [ ] 漫画小说历史记录
- [x] 影视播放进度
- [ ] TMDB 元数据
- [ ] 字幕
- [ ] BT 种子播放
- [ ] 数据同步
- [ ] 自动搜寻字幕

## 截图
Expand Down
3 changes: 2 additions & 1 deletion assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"error": "Error",
"retry": "Retry",
"next": "Next",
"previous": "Previous"
"previous": "Previous",
"show-all": "Show all"
},

"home": {
Expand Down
3 changes: 2 additions & 1 deletion assets/i18n/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"error": "错误",
"retry": "重试",
"next": "下一个",
"previous": "上一个"
"previous": "上一个",
"show-all": "显示全部"
},

"home": {
Expand Down
21 changes: 17 additions & 4 deletions lib/pages/home/controller.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import 'package:get/get.dart';
import 'package:miru_app/models/extension.dart';
import 'package:miru_app/models/favorite.dart';
import 'package:miru_app/models/history.dart';
import 'package:miru_app/utils/database.dart';

class HomePageController extends GetxController {
final RxList<History> resents = <History>[].obs;
final RxList<Favorite> favorites = <Favorite>[].obs;
final RxMap<ExtensionType, List<Favorite>> favorites =
<ExtensionType, List<Favorite>>{}.obs;

@override
void onInit() {
Expand All @@ -19,8 +21,19 @@ class HomePageController extends GetxController {
resents.addAll(
await DatabaseUtils.getHistorysByType(),
);
favorites.addAll(
await DatabaseUtils.getFavoritesByType(),
);
favorites.addAll({
ExtensionType.bangumi: await DatabaseUtils.getFavoritesByType(
type: ExtensionType.bangumi,
limit: 20,
),
ExtensionType.manga: await DatabaseUtils.getFavoritesByType(
type: ExtensionType.manga,
limit: 20,
),
ExtensionType.fikushon: await DatabaseUtils.getFavoritesByType(
type: ExtensionType.fikushon,
limit: 20,
),
});
}
}
157 changes: 157 additions & 0 deletions lib/pages/home/pages/favorites_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import 'package:fluent_ui/fluent_ui.dart' as fluent;
import 'package:flutter/material.dart';
import 'package:miru_app/models/index.dart';
import 'package:miru_app/utils/database.dart';
import 'package:miru_app/utils/extension.dart';
import 'package:miru_app/utils/i18n.dart';
import 'package:miru_app/widgets/extension_item_card.dart';
import 'package:miru_app/widgets/platform_widget.dart';
import 'package:miru_app/widgets/progress_ring.dart';

class FavoritesPage extends fluent.StatefulWidget {
const FavoritesPage({Key? key, required this.type}) : super(key: key);
final ExtensionType type;

@override
fluent.State<FavoritesPage> createState() => _FavoritesPageState();
}

class _FavoritesPageState extends fluent.State<FavoritesPage> {
Widget _buildAndroid(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"${ExtensionUtils.typeToString(widget.type)}${"home.favorite".i18n}",
)),
body: FutureBuilder(
future: DatabaseUtils.getFavoritesByType(type: widget.type),
builder: ((context, snapshot) {
if (snapshot.hasError) {
return Center(
child: Text("${snapshot.error}"),
);
}

if (!snapshot.hasData) {
return const SizedBox(
height: 300,
child: Center(
child: ProgressRing(),
),
);
}
final data = snapshot.data;

if (data != null && data.isEmpty) {
return Center(
child: Text("common.no-result".i18n),
);
}
return LayoutBuilder(
builder: (context, constraints) => GridView.builder(
padding: const EdgeInsets.symmetric(horizontal: 16),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: constraints.maxWidth ~/ 120,
childAspectRatio: 0.7,
crossAxisSpacing: 16,
mainAxisSpacing: 16,
),
itemCount: data!.length,
itemBuilder: (context, index) {
final item = data[index];
return ExtensionItemCard(
title: item.title,
url: item.url,
package: item.package,
cover: item.cover,
);
},
),
);
}),
),
);
}

Widget _buildDesktop(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(left: 16, right: 16, top: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
flex: 2,
child: Text(
"${ExtensionUtils.typeToString(widget.type)}${"home.favorite".i18n}",
style: fluent.FluentTheme.of(context).typography.subtitle,
),
),
const Spacer(),
],
),
const SizedBox(height: 16),
Expanded(
child: FutureBuilder(
future: DatabaseUtils.getFavoritesByType(type: widget.type),
builder: ((context, snapshot) {
if (snapshot.hasError) {
return Center(
child: Text(
snapshot.error.toString(),
),
);
}

if (!snapshot.hasData) {
return const Center(
child: CircularProgressIndicator(),
);
}

final data = snapshot.data;

if (data == null) {
return const Center(
child: Text('No data'),
);
}

return LayoutBuilder(
builder: ((context, constraints) => GridView.builder(
padding: const EdgeInsets.all(8),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: constraints.maxWidth ~/ 160,
childAspectRatio: 0.6,
crossAxisSpacing: 16,
mainAxisSpacing: 16,
),
itemCount: data.length,
itemBuilder: (context, index) {
final item = data[index];
return ExtensionItemCard(
title: item.title,
url: item.url,
package: item.package,
cover: item.cover,
);
},
)),
);
}),
),
)
],
),
);
}

@override
Widget build(BuildContext context) {
return PlatformBuildWidget(
androidBuilder: _buildAndroid,
desktopBuilder: _buildDesktop,
);
}
}
15 changes: 13 additions & 2 deletions lib/pages/home/view.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:miru_app/models/extension.dart';
import 'package:miru_app/pages/home/controller.dart';
import 'package:miru_app/pages/home/widgets/home_favorites.dart';
import 'package:miru_app/pages/home/widgets/home_recent.dart';
Expand Down Expand Up @@ -58,10 +59,20 @@ class _HomePageState extends State<HomePage> {
),
const SizedBox(height: 16),
],
if (c.favorites.isNotEmpty)
if (c.favorites.isNotEmpty) ...[
HomeFavorites(
data: c.favorites,
type: ExtensionType.bangumi,
data: c.favorites[ExtensionType.bangumi]!,
),
HomeFavorites(
type: ExtensionType.manga,
data: c.favorites[ExtensionType.manga]!,
),
HomeFavorites(
type: ExtensionType.fikushon,
data: c.favorites[ExtensionType.fikushon]!,
),
]
],
),
),
Expand Down
82 changes: 36 additions & 46 deletions lib/pages/home/widgets/home_favorites.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:miru_app/models/extension.dart';
import 'package:miru_app/models/favorite.dart';
import 'package:miru_app/utils/i18n.dart';
import 'package:miru_app/pages/home/pages/favorites_page.dart';
import 'package:miru_app/router/router.dart';
import 'package:miru_app/utils/extension.dart';
import 'package:miru_app/widgets/extension_item_card.dart';
import 'package:miru_app/widgets/horizontal_list.dart';

class HomeFavorites extends StatefulWidget {
const HomeFavorites({
Key? key,
required this.type,
required this.data,
}) : super(key: key);
final ExtensionType type;
final List<Favorite> data;

@override
Expand All @@ -19,52 +26,35 @@ class HomeFavorites extends StatefulWidget {
class _HomeFavoritesState extends State<HomeFavorites> {
@override
Widget build(BuildContext context) {
return Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"home.favorite".i18n,
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
// IconButton(
// icon: const Icon(FluentIcons.filter),
// onPressed: () {
// // _filterDialog(context);
// })
],
),
const SizedBox(height: 16),
LayoutBuilder(
builder: (context, constraints) {
final crossAxisCount =
constraints.maxWidth ~/ (Platform.isAndroid ? 120 : 160);
final childAspectRatio = Platform.isAndroid ? 0.7 : 0.6;
return GridView.builder(
// 取消滚动
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: crossAxisCount,
childAspectRatio: childAspectRatio,
crossAxisSpacing: 16,
mainAxisSpacing: 16,
),
itemCount: widget.data.length,
itemBuilder: (context, index) {
return ExtensionItemCard(
key: ValueKey(widget.data[index].cover),
title: widget.data[index].title,
url: widget.data[index].url,
package: widget.data[index].package,
cover: widget.data[index].cover,
);
},
if (widget.data.isEmpty) {
return const SizedBox.shrink();
}
return SizedBox(
child: HorizontalList(
title: ExtensionUtils.typeToString(widget.type),
onClickMore: () {
if (Platform.isAndroid) {
Get.to(FavoritesPage(type: widget.type));
} else {
router.push(
Uri(
path: '/favorites',
queryParameters: {'type': widget.type.index.toString()},
).toString(),
);
},
)
],
}
},
itemCount: widget.data.length,
itemBuilder: (context, index) {
return ExtensionItemCard(
key: ValueKey(widget.data[index].cover),
title: widget.data[index].title,
url: widget.data[index].url,
package: widget.data[index].package,
cover: widget.data[index].cover,
);
},
),
);
}
}
Loading

0 comments on commit 6783895

Please sign in to comment.