Skip to content

Commit

Permalink
feat: 漫画、小说历史记录
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaoMint committed Jul 30, 2023
1 parent 9e3f8cc commit 334b2d2
Show file tree
Hide file tree
Showing 14 changed files with 340 additions and 100 deletions.
1 change: 1 addition & 0 deletions lib/pages/detail/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class DetailPageController extends GetxController {
),
),
child: WatchPage(
cover: data.value!.cover,
playList: urls,
package: package,
playerIndex: index,
Expand Down
250 changes: 178 additions & 72 deletions lib/pages/home/widgets/home_resent_card.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import 'dart:io';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:fluent_ui/fluent_ui.dart';
import 'package:get/get.dart';
import 'package:miru_app/models/extension.dart';
import 'package:miru_app/models/history.dart';
import 'package:miru_app/pages/detail/view.dart';
import 'package:miru_app/router/router.dart';
import 'package:miru_app/utils/extension.dart';
import 'package:miru_app/utils/extension_runtime.dart';
import 'package:palette_generator/palette_generator.dart';

class HomeRecentCard extends StatefulWidget {
const HomeRecentCard({
Expand All @@ -20,26 +23,193 @@ class HomeRecentCard extends StatefulWidget {
}

class _HomeRecentCardState extends State<HomeRecentCard> {
late ExtensionRuntime? runtime;
String update = "";
late ExtensionRuntime? _runtime;
String _update = "";

PaletteGenerator? _paletteGenerator;

@override
void initState() {
_getUpdate();
_genColor();
super.initState();
}

_getUpdate() async {
runtime = ExtensionUtils.extensions[widget.history.package];
if (runtime == null) {
_runtime = ExtensionUtils.extensions[widget.history.package];
if (_runtime == null) {
return;
}
update = await runtime!.checkUpdate(widget.history.url);
_update = await _runtime!.checkUpdate(widget.history.url);
if (mounted) {
setState(() {});
}
}

_genColor() async {
if (widget.history.type == ExtensionType.bangumi) {
return;
}
_paletteGenerator = await PaletteGenerator.fromImageProvider(
CachedNetworkImageProvider(widget.history.cover),
maximumColorCount: 2,
);

if (mounted) {
setState(() {});
}
}

Widget _bangumiCard() {
return Container(
width: 350,
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(8)),
),
clipBehavior: Clip.antiAlias,
child: Stack(
children: [
Image.file(
File(widget.history.cover),
fit: BoxFit.cover,
width: double.infinity,
height: double.infinity,
),
Positioned(
bottom: 0,
child: Container(
width: 350,
height: 60,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.transparent,
Colors.black.withOpacity(0.8),
],
),
),
child: Padding(
padding: const EdgeInsets.all(10),
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.history.title,
style: const TextStyle(color: Colors.white),
overflow: TextOverflow.ellipsis,
),
Text(
"看到 ${widget.history.episodeTitle}",
style: const TextStyle(
color: Colors.white,
fontSize: 12,
),
),
],
),
),
if (_update.isNotEmpty) ...[
const SizedBox(width: 8),
Text(
_update,
style: const TextStyle(color: Colors.white),
),
]
],
),
),
),
),
],
),
);
}

Widget _coverCard() {
return Container(
width: 350,
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(8)),
// color:
// _paletteGenerator != null ? _paletteGenerator!.colors.first : null,
image: DecorationImage(
image: CachedNetworkImageProvider(widget.history.cover),
fit: BoxFit.cover,
colorFilter: _paletteGenerator != null
? ColorFilter.mode(
_paletteGenerator!.colors.first.withOpacity(0.9),
BlendMode.srcOver,
)
: null,
),
),
clipBehavior: Clip.antiAlias,
child: Container(
height: 60,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.transparent,
Colors.black.withOpacity(0.8),
],
),
),
child: Row(
children: [
Container(
margin: const EdgeInsets.all(10),
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(5)),
),
clipBehavior: Clip.antiAlias,
child: CachedNetworkImage(
imageUrl: widget.history.cover,
width: 130,
height: double.infinity,
fit: BoxFit.cover,
),
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text(
widget.history.title,
style: const TextStyle(color: Colors.white),
overflow: TextOverflow.ellipsis,
),
Text(
"看到 ${widget.history.episodeTitle}",
style: const TextStyle(
color: Colors.white,
fontSize: 12,
),
),
if (_update.isNotEmpty) ...[
const SizedBox(height: 8),
Text(
_update,
style: const TextStyle(color: Colors.white),
),
],
const SizedBox(height: 16),
],
),
),
],
),
),
);
}

@override
Widget build(BuildContext context) {
return Padding(
Expand Down Expand Up @@ -67,73 +237,9 @@ class _HomeRecentCardState extends State<HomeRecentCard> {
).toString(),
);
},
child: Container(
width: 350,
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(8)),
),
clipBehavior: Clip.antiAlias,
child: Stack(
children: [
Image.file(
File(widget.history.cover),
fit: BoxFit.cover,
width: double.infinity,
height: double.infinity,
),
Positioned(
bottom: 0,
child: Container(
width: 350,
height: 60,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.transparent,
Colors.black.withOpacity(0.8),
],
),
),
child: Padding(
padding: const EdgeInsets.all(10),
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.history.title,
style: const TextStyle(color: Colors.white),
overflow: TextOverflow.ellipsis,
),
Text(
"看到 ${widget.history.episodeTitle}",
style: const TextStyle(
color: Colors.white,
fontSize: 12,
),
),
],
),
),
if (update.isNotEmpty) ...[
const SizedBox(width: 8),
Text(
update,
style: const TextStyle(color: Colors.white),
),
]
],
),
),
),
),
],
),
),
child: widget.history.type == ExtensionType.bangumi
? _bangumiCard()
: _coverCard(),
),
),
);
Expand Down
22 changes: 22 additions & 0 deletions lib/pages/watch/reader_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import 'dart:async';

import 'package:get/get.dart';
import 'package:miru_app/models/extension.dart';
import 'package:miru_app/models/history.dart';
import 'package:miru_app/pages/home/controller.dart';
import 'package:miru_app/utils/database.dart';
import 'package:miru_app/utils/extension_runtime.dart';

class ReaderController<T> extends GetxController {
Expand All @@ -11,6 +14,7 @@ class ReaderController<T> extends GetxController {
final int playIndex;
final int episodeGroupId;
final ExtensionRuntime runtime;
final String cover;

ReaderController({
required this.title,
Expand All @@ -19,6 +23,7 @@ class ReaderController<T> extends GetxController {
required this.playIndex,
required this.episodeGroupId,
required this.runtime,
required this.cover,
});

late Rx<T?> watchData = Rx(null);
Expand Down Expand Up @@ -54,4 +59,21 @@ class ReaderController<T> extends GetxController {
isShowControlPanel.value = false;
});
}

addHistory(String progress, String totalProgress) async {
await DatabaseUtils.putHistory(
History()
..url = detailUrl
..episodeId = index.value
..type = runtime.extension.type
..episodeGroupId = episodeGroupId
..package = runtime.extension.package
..episodeTitle = playList[index.value].name
..title = title
..progress = progress
..totalProgress = totalProgress
..cover = cover,
);
await Get.find<HomePageController>().onRefresh();
}
}
4 changes: 4 additions & 0 deletions lib/pages/watch/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ class WatchPage extends StatelessWidget {
required this.playerIndex,
required this.episodeGroupId,
required this.detailUrl,
required this.cover,
}) : super(key: key);
final List<ExtensionEpisode> playList;
final int playerIndex;
final String title;
final String package;
final String detailUrl;
final int episodeGroupId;
final String cover;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -68,6 +70,7 @@ class WatchPage extends StatelessWidget {
playerIndex: playerIndex,
episodeGroupId: episodeGroupId,
runtime: runtime,
cover: cover,
);
default:
return NovelReader(
Expand All @@ -77,6 +80,7 @@ class WatchPage extends StatelessWidget {
playerIndex: playerIndex,
title: title,
detailUrl: detailUrl,
cover: cover,
);
}
}
Expand Down
Loading

0 comments on commit 334b2d2

Please sign in to comment.