This commit is contained in:
wgh19
2024-05-20 15:16:35 +08:00
parent 2a1a668c25
commit a3868b1969
20 changed files with 2146 additions and 428 deletions

View File

@@ -0,0 +1,210 @@
import 'package:fluent_ui/fluent_ui.dart';
import 'package:pixes/components/animated_image.dart';
import 'package:pixes/components/loading.dart';
import 'package:pixes/components/page_route.dart';
import 'package:pixes/foundation/app.dart';
import 'package:pixes/foundation/image_provider.dart';
import 'package:pixes/network/network.dart';
import 'package:pixes/pages/user_info_page.dart';
import 'package:pixes/utils/translation.dart';
import '../components/md.dart';
import '../components/message.dart';
class CommentsPage extends StatefulWidget {
const CommentsPage(this.id, {this.isNovel = false, super.key});
final String id;
final bool isNovel;
static void show(BuildContext context, String id, {bool isNovel = false}) {
Navigator.of(context)
.push(SideBarRoute(CommentsPage(id, isNovel: isNovel)));
}
@override
State<CommentsPage> createState() => _CommentsPageState();
}
class _CommentsPageState extends MultiPageLoadingState<CommentsPage, Comment> {
bool isCommenting = false;
@override
Widget buildContent(BuildContext context, List<Comment> data) {
return Stack(
children: [
Positioned.fill(child: buildBody(context, data)),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: buildBottom(context),
)
],
);
}
Widget buildBody(BuildContext context, List<Comment> data) {
return ListView.builder(
padding: EdgeInsets.zero,
itemCount: data.length + 2,
itemBuilder: (context, index) {
if (index == 0) {
return Text("Comments".tl, style: const TextStyle(fontSize: 20))
.paddingVertical(16)
.paddingHorizontal(12);
} else if (index == data.length + 1) {
return const SizedBox(
height: 64,
);
}
index--;
var date = data[index].date;
var dateText = "${date.year}/${date.month}/${date.day}";
return Card(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 12),
margin: const EdgeInsets.symmetric(vertical: 4, horizontal: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
SizedBox(
height: 38,
width: 38,
child: ClipRRect(
borderRadius: BorderRadius.circular(38),
child: ColoredBox(
color: ColorScheme.of(context).secondaryContainer,
child: GestureDetector(
onTap: () => context.to(
() => UserInfoPage(data[index].id.toString())),
child: AnimatedImage(
image: CachedImageProvider(data[index].avatar),
width: 38,
height: 38,
fit: BoxFit.cover,
filterQuality: FilterQuality.medium,
),
),
),
),
),
const SizedBox(
width: 8,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
data[index].name,
style: const TextStyle(fontSize: 14),
),
Text(
dateText,
style: TextStyle(
fontSize: 12,
color: ColorScheme.of(context).outline),
)
],
)
],
),
const SizedBox(
height: 8,
),
if (data[index].comment.isNotEmpty)
Text(
data[index].comment,
style: const TextStyle(fontSize: 16),
),
if (data[index].stampUrl != null)
SizedBox(
height: 64,
width: 64,
child: ClipRRect(
borderRadius: BorderRadius.circular(4),
child: AnimatedImage(
image: CachedImageProvider(data[index].stampUrl!),
width: 64,
height: 64,
fit: BoxFit.cover,
),
),
)
],
),
);
});
}
Widget buildBottom(BuildContext context) {
return Card(
padding: EdgeInsets.zero,
backgroundColor:
FluentTheme.of(context).micaBackgroundColor.withOpacity(0.96),
child: SizedBox(
height: 52,
child: TextBox(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
placeholder: "Comment".tl,
foregroundDecoration: BoxDecoration(
border: Border.all(color: Colors.transparent),
),
onSubmitted: (s) {
showToast(context, message: "Sending".tl);
if (isCommenting) return;
setState(() {
isCommenting = true;
});
if (widget.isNovel) {
Network().commentNovel(widget.id, s).then((value) {
if (value.error) {
context.showToast(message: "Network Error");
setState(() {
isCommenting = false;
});
} else {
isCommenting = false;
nextUrl = null;
reset();
}
});
} else {
Network().comment(widget.id, s).then((value) {
if (value.error) {
context.showToast(message: "Network Error");
setState(() {
isCommenting = false;
});
} else {
isCommenting = false;
nextUrl = null;
reset();
}
});
}
},
).paddingVertical(8).paddingHorizontal(12),
).paddingBottom(context.padding.bottom + context.viewInsets.bottom),
);
}
String? nextUrl;
@override
Future<Res<List<Comment>>> loadData(int page) async {
if (nextUrl == "end") {
return Res.error("No more data");
}
var res = widget.isNovel
? await Network().getNovelComments(widget.id, nextUrl)
: await Network().getComments(widget.id, nextUrl);
if (!res.error) {
nextUrl = res.subData;
nextUrl ??= "end";
}
return res;
}
}

View File

@@ -14,6 +14,7 @@ import 'package:pixes/foundation/app.dart';
import 'package:pixes/foundation/image_provider.dart';
import 'package:pixes/network/download.dart';
import 'package:pixes/network/network.dart';
import 'package:pixes/pages/comments_page.dart';
import 'package:pixes/pages/image_page.dart';
import 'package:pixes/pages/search_page.dart';
import 'package:pixes/pages/user_info_page.dart';
@@ -672,7 +673,7 @@ class _BottomBarState extends State<_BottomBar> with TickerProviderStateMixin{
yield const SizedBox(width: 8,);
yield Button(
onPressed: () => _CommentsPage.show(context, widget.illust.id.toString()),
onPressed: () => CommentsPage.show(context, widget.illust.id.toString()),
child: SizedBox(
height: 28,
child: Row(
@@ -866,165 +867,6 @@ class _BottomBarState extends State<_BottomBar> with TickerProviderStateMixin{
}
}
class _CommentsPage extends StatefulWidget {
const _CommentsPage(this.id);
final String id;
static void show(BuildContext context, String id) {
Navigator.of(context).push(SideBarRoute(_CommentsPage(id)));
}
@override
State<_CommentsPage> createState() => _CommentsPageState();
}
class _CommentsPageState extends MultiPageLoadingState<_CommentsPage, Comment> {
bool isCommenting = false;
@override
Widget buildContent(BuildContext context, List<Comment> data) {
return Stack(
children: [
Positioned.fill(child: buildBody(context, data)),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: buildBottom(context),
)
],
);
}
Widget buildBody(BuildContext context, List<Comment> data) {
return ListView.builder(
padding: EdgeInsets.zero,
itemCount: data.length + 2,
itemBuilder: (context, index) {
if(index == 0) {
return Text("Comments".tl, style: const TextStyle(fontSize: 20)).paddingVertical(16).paddingHorizontal(12);
} else if(index == data.length + 1) {
return const SizedBox(height: 64,);
}
index--;
var date = data[index].date;
var dateText = "${date.year}/${date.month}/${date.day}";
return Card(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 12),
margin: const EdgeInsets.symmetric(vertical: 4, horizontal: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
SizedBox(
height: 38,
width: 38,
child: ClipRRect(
borderRadius: BorderRadius.circular(38),
child: ColoredBox(
color: ColorScheme.of(context).secondaryContainer,
child: GestureDetector(
onTap: () => context.to(() => UserInfoPage(data[index].id.toString())),
child: AnimatedImage(
image: CachedImageProvider(data[index].avatar),
width: 38,
height: 38,
fit: BoxFit.cover,
filterQuality: FilterQuality.medium,
),
),
),
),
),
const SizedBox(width: 8,),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(data[index].name, style: const TextStyle(fontSize: 14),),
Text(dateText, style: TextStyle(fontSize: 12, color: ColorScheme.of(context).outline),)
],
)
],
),
const SizedBox(height: 8,),
if(data[index].comment.isNotEmpty)
Text(data[index].comment, style: const TextStyle(fontSize: 16),),
if(data[index].stampUrl != null)
SizedBox(
height: 64,
width: 64,
child: ClipRRect(
borderRadius: BorderRadius.circular(4),
child: AnimatedImage(
image: CachedImageProvider(data[index].stampUrl!),
width: 64,
height: 64,
fit: BoxFit.cover,
),
),
)
],
),
);
}
);
}
Widget buildBottom(BuildContext context) {
return Card(
padding: EdgeInsets.zero,
backgroundColor: FluentTheme.of(context).micaBackgroundColor.withOpacity(0.96),
child: SizedBox(
height: 52,
child: TextBox(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
placeholder: "Comment".tl,
foregroundDecoration: BoxDecoration(
border: Border.all(color: Colors.transparent),
),
onSubmitted: (s) {
showToast(context, message: "Sending".tl);
if(isCommenting) return;
setState(() {
isCommenting = true;
});
Network().comment(widget.id, s).then((value) {
if(value.error) {
context.showToast(message: "Network Error");
setState(() {
isCommenting = false;
});
} else {
isCommenting = false;
nextUrl = null;
reset();
}
});
},
).paddingVertical(8).paddingHorizontal(12),
).paddingBottom(context.padding.bottom + context.viewInsets.bottom),
);
}
String? nextUrl;
@override
Future<Res<List<Comment>>> loadData(int page) async{
if(nextUrl == "end") {
return Res.error("No more data");
}
var res = await Network().getComments(widget.id, nextUrl);
if(!res.error) {
nextUrl = res.subData;
nextUrl ??= "end";
}
return res;
}
}
class IllustPageWithId extends StatefulWidget {
const IllustPageWithId(this.id, {super.key});

View File

@@ -11,6 +11,9 @@ import "package:pixes/pages/bookmarks.dart";
import "package:pixes/pages/downloaded_page.dart";
import "package:pixes/pages/following_artworks.dart";
import "package:pixes/pages/history.dart";
import "package:pixes/pages/novel_bookmarks_page.dart";
import "package:pixes/pages/novel_ranking_page.dart";
import "package:pixes/pages/novel_recommendation_page.dart";
import "package:pixes/pages/ranking.dart";
import "package:pixes/pages/recommendation_page.dart";
import "package:pixes/pages/login_page.dart";
@@ -45,6 +48,7 @@ class _MainPageState extends State<MainPage> with WindowListener {
void initState() {
windowManager.addListener(this);
listenMouseSideButtonToBack(navigatorKey);
App.mainNavigatorKey = navigatorKey;
super.initState();
}
@@ -93,24 +97,37 @@ class _MainPageState extends State<MainPage> with WindowListener {
items: [
UserPane(),
PaneItem(
icon: const Icon(MdIcons.search, size: 20,),
icon: const Icon(
MdIcons.search,
size: 20,
),
title: Text('Search'.tl),
body: const SizedBox.shrink(),
),
PaneItem(
icon: const Icon(MdIcons.downloading, size: 20,),
icon: const Icon(
MdIcons.downloading,
size: 20,
),
title: Text('Downloading'.tl),
body: const SizedBox.shrink(),
),
PaneItem(
icon: const Icon(MdIcons.download, size: 20,),
icon: const Icon(
MdIcons.download,
size: 20,
),
title: Text('Downloaded'.tl),
body: const SizedBox.shrink(),
),
PaneItemSeparator(),
PaneItemHeader(header: Text("Artwork".tl).paddingBottom(4).paddingLeft(8)),
PaneItemHeader(
header: Text("Artwork".tl).paddingBottom(4).paddingLeft(8)),
PaneItem(
icon: const Icon(MdIcons.explore_outlined, size: 20,),
icon: const Icon(
MdIcons.explore_outlined,
size: 20,
),
title: Text('Explore'.tl),
body: const SizedBox.shrink(),
),
@@ -134,8 +151,26 @@ class _MainPageState extends State<MainPage> with WindowListener {
title: Text('Ranking'.tl),
body: const SizedBox.shrink(),
),
],
footerItems: [
PaneItemSeparator(),
PaneItemHeader(
header: Text("Novel".tl).paddingBottom(4).paddingLeft(8)),
PaneItem(
icon: const Icon(MdIcons.featured_play_list_outlined, size: 20),
title: Text('Recommendation'.tl),
body: const SizedBox.shrink(),
),
PaneItem(
icon:
const Icon(MdIcons.collections_bookmark_outlined, size: 20),
title: Text('Bookmarks'.tl),
body: const SizedBox.shrink(),
),
PaneItem(
icon: const Icon(MdIcons.leaderboard_outlined, size: 20),
title: Text('Ranking'.tl),
body: const SizedBox.shrink(),
),
PaneItemSeparator(),
PaneItem(
icon: const Icon(MdIcons.settings_outlined, size: 20),
title: Text('Settings'.tl),
@@ -168,6 +203,9 @@ class _MainPageState extends State<MainPage> with WindowListener {
() => const FollowingArtworksPage(),
() => const HistoryPage(),
() => const RankingPage(),
() => const NovelRecommendationPage(),
() => const NovelBookmarksPage(),
() => const NovelRankingPage(),
() => const SettingsPage(),
];
@@ -204,7 +242,7 @@ class _MainPageState extends State<MainPage> with WindowListener {
style: TextStyle(fontSize: 13),
),
Spacer(),
if(kDebugMode)
if (kDebugMode)
Padding(
padding: EdgeInsets.only(right: 138),
child: Button(onPressed: debug, child: Text("Debug")),
@@ -216,9 +254,11 @@ class _MainPageState extends State<MainPage> with WindowListener {
);
}(),
leading: _BackButton(navigatorKey),
actions: App.isDesktop ? WindowButtons(
key: ValueKey(windowButtonKey),
) : null,
actions: App.isDesktop
? WindowButtons(
key: ValueKey(windowButtonKey),
)
: null,
);
}
}
@@ -248,11 +288,11 @@ class _BackButtonState extends State<_BackButton> {
void loop() {
timer = Timer.periodic(const Duration(milliseconds: 100), (timer) {
if(!mounted) {
if (!mounted) {
timer.cancel();
} else {
bool enabled = navigatorKey.currentState?.canPop() == true;
if(enabled != this.enabled) {
if (enabled != this.enabled) {
setState(() {
this.enabled = enabled;
});
@@ -293,18 +333,19 @@ class _BackButtonState extends State<_BackButton> {
title: const Text("Back"),
body: const SizedBox.shrink(),
enabled: enabled,
).build(
context,
false,
onPressed,
displayMode: PaneDisplayMode.compact,
).paddingTop(2),
)
.build(
context,
false,
onPressed,
displayMode: PaneDisplayMode.compact,
)
.paddingTop(2),
),
);
}
}
class WindowButtons extends StatelessWidget {
const WindowButtons({super.key});
@@ -458,7 +499,8 @@ class UserPane extends PaneItem {
child: Image(
height: 48,
width: 48,
image: CachedImageProvider(appdata.account!.user.profile),
image:
CachedImageProvider(appdata.account!.user.profile),
fit: BoxFit.fill,
),
),
@@ -481,7 +523,9 @@ class UserPane extends PaneItem {
fontSize: 16, fontWeight: FontWeight.w500),
),
Text(
kDebugMode ? "<hide due to debug>" : appdata.account!.user.email,
kDebugMode
? "<hide due to debug>"
: appdata.account!.user.email,
style: const TextStyle(fontSize: 12),
)
],

View File

@@ -0,0 +1,53 @@
import 'package:fluent_ui/fluent_ui.dart';
import 'package:pixes/appdata.dart';
import 'package:pixes/components/grid.dart';
import 'package:pixes/components/loading.dart';
import 'package:pixes/components/novel.dart';
import 'package:pixes/components/title_bar.dart';
import 'package:pixes/foundation/widget_utils.dart';
import 'package:pixes/network/network.dart';
import 'package:pixes/utils/translation.dart';
class NovelBookmarksPage extends StatefulWidget {
const NovelBookmarksPage({super.key});
@override
State<NovelBookmarksPage> createState() => _NovelBookmarksPageState();
}
class _NovelBookmarksPageState
extends MultiPageLoadingState<NovelBookmarksPage, Novel> {
@override
Widget buildContent(BuildContext context, List<Novel> data) {
return Column(
children: [
TitleBar(title: "Bookmarks".tl),
Expanded(
child: GridViewWithFixedItemHeight(
itemCount: data.length,
itemHeight: 164,
minCrossAxisExtent: 400,
builder: (context, index) {
if (index == data.length - 1) {
nextPage();
}
return NovelWidget(data[index]);
},
).paddingHorizontal(8),
)
],
);
}
String? nextUrl;
@override
Future<Res<List<Novel>>> loadData(int page) async {
if (nextUrl == "end") return Res.error("No more data");
var res = nextUrl == null
? await Network().getBookmarkedNovels(appdata.account!.user.id)
: await Network().getNovelsWithNextUrl(nextUrl!);
nextUrl = res.subData ?? "end";
return res;
}
}

669
lib/pages/novel_page.dart Normal file
View File

@@ -0,0 +1,669 @@
import 'dart:collection';
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/gestures.dart';
import 'package:pixes/components/animated_image.dart';
import 'package:pixes/components/grid.dart';
import 'package:pixes/components/loading.dart';
import 'package:pixes/components/md.dart';
import 'package:pixes/components/novel.dart';
import 'package:pixes/components/title_bar.dart';
import 'package:pixes/foundation/app.dart';
import 'package:pixes/foundation/image_provider.dart';
import 'package:pixes/network/network.dart';
import 'package:pixes/pages/comments_page.dart';
import 'package:pixes/pages/novel_reading_page.dart';
import 'package:pixes/pages/search_page.dart';
import 'package:pixes/pages/user_info_page.dart';
import 'package:pixes/utils/app_links.dart';
import 'package:pixes/utils/translation.dart';
import 'package:url_launcher/url_launcher_string.dart';
const kFluentButtonPadding = 28.0;
class NovelPage extends StatefulWidget {
const NovelPage(this.novel, {super.key});
final Novel novel;
@override
State<NovelPage> createState() => _NovelPageState();
}
class _NovelPageState extends State<NovelPage> {
final scrollController = ScrollController();
@override
Widget build(BuildContext context) {
return Scrollbar(
controller: scrollController,
child: ScrollConfiguration(
behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false),
child: CustomScrollView(
controller: scrollController,
slivers: [
SliverToBoxAdapter(
child: buildTop(),
),
SliverToBoxAdapter(
child: buildActions(),
),
SliverToBoxAdapter(
child: buildDescription(),
),
if (widget.novel.seriesId != null)
NovelSeriesWidget(
widget.novel.seriesId!, widget.novel.seriesTitle!)
],
),
).padding(const EdgeInsets.symmetric(horizontal: 16)));
}
Widget buildTop() {
return Card(
child: SizedBox(
height: 128,
child: Row(
children: [
Container(
width: 96,
height: double.infinity,
decoration: BoxDecoration(
color: ColorScheme.of(context).secondaryContainer,
borderRadius: BorderRadius.circular(4),
),
clipBehavior: Clip.antiAlias,
child: AnimatedImage(
fit: BoxFit.cover,
filterQuality: FilterQuality.medium,
width: double.infinity,
height: double.infinity,
image: CachedImageProvider(widget.novel.image)),
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(widget.novel.title,
maxLines: 3,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
)),
const SizedBox(height: 4),
const Spacer(),
if (widget.novel.seriesId != null)
Text(
overflow: TextOverflow.ellipsis,
"${"Series".tl}: ${widget.novel.seriesTitle!}",
style: TextStyle(
color: ColorScheme.of(context).primary,
fontSize: 12,
),
).paddingVertical(4)
],
),
),
],
),
)).paddingTop(12);
}
Widget buildStats() {
return Container(
height: 74,
constraints: const BoxConstraints(maxWidth: 560),
padding: const EdgeInsets.only(bottom: 10),
child: Row(
children: [
const SizedBox(
width: 2,
),
Expanded(
child: Container(
height: 68,
decoration: BoxDecoration(
border: Border.all(
color: ColorScheme.of(context).outlineVariant,
width: 0.6),
borderRadius: BorderRadius.circular(4)),
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
child: Row(
children: [
Column(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(
FluentIcons.view,
size: 20,
),
Text(
"Views".tl,
style: const TextStyle(fontSize: 12),
)
],
),
const SizedBox(
width: 12,
),
Text(
widget.novel.totalViews.toString(),
style: TextStyle(
color: ColorScheme.of(context).primary,
fontWeight: FontWeight.w500,
fontSize: 18),
)
],
),
),
),
const SizedBox(
width: 16,
),
Expanded(
child: Container(
height: 68,
decoration: BoxDecoration(
border: Border.all(
color: ColorScheme.of(context).outlineVariant, width: 0.6),
borderRadius: BorderRadius.circular(4)),
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
child: Row(
children: [
Column(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(
FluentIcons.six_point_star,
size: 20,
),
Text(
"Favorites".tl,
style: const TextStyle(fontSize: 12),
)
],
),
const SizedBox(
width: 12,
),
Text(
widget.novel.totalBookmarks.toString(),
style: TextStyle(
color: ColorScheme.of(context).primary,
fontWeight: FontWeight.w500,
fontSize: 18),
)
],
),
)),
const SizedBox(
width: 2,
),
],
),
);
}
Widget buildAuthor() {
return ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 560),
child: Card(
margin: const EdgeInsets.only(left: 2, right: 2, bottom: 12),
borderColor: ColorScheme.of(context).outlineVariant.withOpacity(0.52),
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
context.to(() => UserInfoPage(widget.novel.author.id.toString()));
},
child: SizedBox(
height: 38,
child: Row(
children: [
Container(
width: 36,
height: 36,
decoration: BoxDecoration(
color: ColorScheme.of(context).secondaryContainer,
borderRadius: BorderRadius.circular(36),
),
clipBehavior: Clip.antiAlias,
child: AnimatedImage(
fit: BoxFit.cover,
width: 36,
height: 36,
filterQuality: FilterQuality.medium,
image: CachedImageProvider(widget.novel.author.avatar),
),
),
const SizedBox(width: 12),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(widget.novel.author.name,
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
)),
Text(
widget.novel.createDate.toString().substring(0, 10),
style: const TextStyle(
fontSize: 12,
color: Colors.grey,
),
),
],
),
const Spacer(),
const Icon(MdIcons.chevron_right)
],
),
),
),
),
);
}
bool isAddingFavorite = false;
Widget buildActions() {
void favorite() async {
if (isAddingFavorite) return;
setState(() {
isAddingFavorite = true;
});
var res = widget.novel.isBookmarked
? await Network().deleteFavoriteNovel(widget.novel.id.toString())
: await Network().favoriteNovel(widget.novel.id.toString());
if (res.error) {
if (mounted) {
context.showToast(message: res.errorMessage ?? "Network Error");
}
} else {
widget.novel.isBookmarked = !widget.novel.isBookmarked;
}
setState(() {
isAddingFavorite = false;
});
}
return LayoutBuilder(builder: (context, constraints) {
final width = constraints.maxWidth;
return Card(
margin: const EdgeInsets.only(top: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (width < 560) buildAuthor().toAlign(Alignment.centerLeft),
if (width < 560) buildStats().toAlign(Alignment.centerLeft),
if (width >= 560)
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 1132),
child: Row(
children: [
Expanded(child: buildAuthor()),
const SizedBox(width: 12),
Expanded(child: buildStats()),
],
),
).toAlign(Alignment.centerLeft),
LayoutBuilder(
builder: (context, constrains) {
var width = constrains.maxWidth;
bool shouldFillSpace = width < 500;
return Row(
children: [
FilledButton(
child: Row(
children: [
const Icon(MdIcons.menu_book_outlined, size: 18),
const SizedBox(width: 12),
Text("Read".tl),
const Spacer(),
const Icon(MdIcons.chevron_right, size: 18)
.paddingTop(2),
],
)
.fixWidth(shouldFillSpace
? width / 2 - 4 - kFluentButtonPadding
: 220)
.fixHeight(32),
onPressed: () {
context.to(() => NovelReadingPage(widget.novel));
}),
const SizedBox(width: 16),
Button(
onPressed: favorite,
child: Row(
children: [
if (isAddingFavorite)
const SizedBox(
width: 18,
height: 18,
child: ProgressRing(
strokeWidth: 2,
),
)
else if (widget.novel.isBookmarked)
Icon(
MdIcons.favorite,
size: 18,
color: ColorScheme.of(context).error,
)
else
const Icon(MdIcons.favorite_outline, size: 18),
const SizedBox(width: 12),
Text("Favorite".tl)
],
)
.fixWidth(shouldFillSpace
? width / 4 - 4 - kFluentButtonPadding
: 64)
.fixHeight(32),
),
const SizedBox(width: 8),
Button(
child: Row(
children: [
const Icon(MdIcons.comment, size: 18),
const SizedBox(width: 12),
Text("Comments".tl)
],
)
.fixWidth(shouldFillSpace
? width / 4 - 4 - kFluentButtonPadding
: 64)
.fixHeight(32),
onPressed: () {
CommentsPage.show(context, widget.novel.id.toString(),
isNovel: true);
}),
],
);
},
).paddingHorizontal(2),
SelectableText(
"ID: ${widget.novel.id}",
style: TextStyle(
fontSize: 13, color: ColorScheme.of(context).outline),
).paddingTop(8).paddingLeft(2),
],
),
);
});
}
Widget buildDescription() {
return Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Description".tl,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 8),
SelectableText.rich(
TextSpan(children: buildDescriptionText().toList())),
const SizedBox(height: 12),
SizedBox(
width: double.infinity,
child: Wrap(
crossAxisAlignment: WrapCrossAlignment.start,
children: [
for (final tag in widget.novel.tags)
MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: () {
context.to(() => SearchNovelResultPage(tag.name));
},
child: Container(
margin: const EdgeInsets.only(right: 8, bottom: 6),
padding: const EdgeInsets.symmetric(
horizontal: 10, vertical: 6),
decoration: BoxDecoration(
color: ColorScheme.of(context).primaryContainer,
borderRadius: BorderRadius.circular(4),
),
child: Text(
tag.name,
style: const TextStyle(fontSize: 12),
),
),
),
),
],
),
),
const SizedBox(height: 12),
Button(
child: Row(
children: [
const Icon(MdIcons.bookmark_outline, size: 18),
const SizedBox(width: 12),
Text("Related".tl)
],
).fixWidth(64).fixHeight(32),
onPressed: () {
context
.to(() => _RelatedNovelsPage(widget.novel.id.toString()));
}),
],
),
).paddingTop(12);
}
Iterable<TextSpan> buildDescriptionText() sync* {
var text = widget.novel.caption;
text = text.replaceAll("<br />", "\n");
text = text.replaceAll('\n\n', '\n');
var labels = Queue<String>();
var buffer = StringBuffer();
var style = const TextStyle();
String? link;
Map<String, String> attributes = {};
for (int i = 0; i < text.length; i++) {
if (text[i] == '<' && text[i + 1] != '/') {
var label =
text.substring(i + 1, text.indexOf('>', i)).split(' ').first;
labels.addLast(label);
for (var part
in text.substring(i + 1, text.indexOf('>', i)).split(' ')) {
var kv = part.split('=');
if (kv.length >= 2) {
attributes[kv[0]] =
kv.join('=').substring(kv[0].length + 2).replaceAll('"', '');
}
}
i = text.indexOf('>', i);
} else if (text[i] == '<' && text[i + 1] == '/') {
var label = text.substring(i + 2, text.indexOf('>', i));
if (label == labels.last) {
switch (label) {
case "strong":
style = style.copyWith(fontWeight: FontWeight.bold);
case "a":
style = style.copyWith(color: ColorScheme.of(context).primary);
link = attributes["href"];
}
labels.removeLast();
}
i = text.indexOf('>', i);
} else {
buffer.write(text[i]);
}
if (i + 1 >= text.length ||
(labels.isEmpty &&
(text[i + 1] == '<' || (i != 0 && text[i - 1] == '>')))) {
var content = buffer.toString();
var url = link;
yield TextSpan(
text: content,
style: style,
recognizer: url != null
? (TapGestureRecognizer()
..onTap = () {
if (!handleLink(Uri.parse(url))) {
launchUrlString(url);
}
})
: null);
buffer.clear();
link = null;
attributes.clear();
style = const TextStyle();
}
}
}
}
class NovelSeriesWidget extends StatefulWidget {
const NovelSeriesWidget(this.seriesId, this.title, {super.key});
final int seriesId;
final String title;
@override
State<NovelSeriesWidget> createState() => _NovelSeriesWidgetState();
}
class _NovelSeriesWidgetState
extends MultiPageLoadingState<NovelSeriesWidget, Novel> {
@override
Widget? buildFrame(BuildContext context, Widget child) {
return DecoratedSliver(
decoration: BoxDecoration(
color: FluentTheme.of(context).cardColor,
borderRadius: BorderRadius.circular(4),
border: Border.all(
color: ColorScheme.of(context).outlineVariant.withOpacity(0.6),
width: 0.5,
)),
sliver: SliverMainAxisGroup(slivers: [
SliverToBoxAdapter(
child: Text(widget.title.trim(),
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
)).paddingTop(16).paddingLeft(12).paddingRight(12),
),
const SliverPadding(padding: EdgeInsets.only(top: 8)),
child
]),
).sliverPadding(const EdgeInsets.only(top: 16));
}
@override
Widget buildLoading(BuildContext context) {
return SliverToBoxAdapter(
child: const Center(
child: ProgressRing(),
).fixHeight(124),
);
}
@override
Widget buildError(BuildContext context, String error) {
return SliverToBoxAdapter(
child: Center(
child: Text(error),
).fixHeight(124),
);
}
@override
Widget buildContent(BuildContext context, final List<Novel> data) {
return SliverGridViewWithFixedItemHeight(
itemHeight: 164,
minCrossAxisExtent: 400,
delegate: SliverChildBuilderDelegate(
(context, index) {
if (index == data.length - 1) {
nextPage();
}
return NovelWidget(data[index]);
},
childCount: data.length,
),
).sliverPadding(const EdgeInsets.symmetric(horizontal: 8));
}
String? nextUrl;
@override
Future<Res<List<Novel>>> loadData(page) async {
if (nextUrl == "end") {
return Res.error("No more data");
}
var res =
await Network().getNovelSeries(widget.seriesId.toString(), nextUrl);
if (!res.error) {
nextUrl = res.subData;
nextUrl ??= "end";
}
return res;
}
}
class NovelPageWithId extends StatefulWidget {
const NovelPageWithId(this.id, {super.key});
final String id;
@override
State<NovelPageWithId> createState() => _NovelPageWithIdState();
}
class _NovelPageWithIdState extends LoadingState<NovelPageWithId, Novel> {
@override
Future<Res<Novel>> loadData() async {
return Network().getNovelDetail(widget.id);
}
@override
Widget buildContent(BuildContext context, Novel data) {
return NovelPage(data);
}
}
class _RelatedNovelsPage extends StatefulWidget {
const _RelatedNovelsPage(this.id, {super.key});
final String id;
@override
State<_RelatedNovelsPage> createState() => __RelatedNovelsPageState();
}
class __RelatedNovelsPageState
extends LoadingState<_RelatedNovelsPage, List<Novel>> {
@override
Widget buildContent(BuildContext context, List<Novel> data) {
return Column(
children: [
TitleBar(title: "Related Novels".tl),
Expanded(
child: GridViewWithFixedItemHeight(
itemHeight: 164,
itemCount: data.length,
minCrossAxisExtent: 400,
builder: (context, index) {
return NovelWidget(data[index]);
},
)),
],
);
}
@override
Future<Res<List<Novel>>> loadData() async {
return Network().relatedNovels(widget.id);
}
}

View File

@@ -0,0 +1,102 @@
import 'package:fluent_ui/fluent_ui.dart';
import 'package:pixes/components/loading.dart';
import 'package:pixes/components/novel.dart';
import 'package:pixes/components/title_bar.dart';
import 'package:pixes/foundation/app.dart';
import 'package:pixes/network/network.dart';
import 'package:pixes/utils/translation.dart';
import '../components/grid.dart';
class NovelRankingPage extends StatefulWidget {
const NovelRankingPage({super.key});
@override
State<NovelRankingPage> createState() => _NovelRankingPageState();
}
class _NovelRankingPageState extends State<NovelRankingPage> {
String type = "day";
/// mode: day, day_male, day_female, week_rookie, week, week_ai
static const types = {
"day": "Daily",
"week": "Weekly",
"day_male": "For male",
"day_female": "For female",
"week_rookie": "Rookies",
};
@override
Widget build(BuildContext context) {
return ScaffoldPage(
padding: EdgeInsets.zero,
content: Column(
children: [
buildHeader(),
Expanded(
child: _OneRankingPage(type, key: Key(type),),
),
],
),
);
}
Widget buildHeader() {
return TitleBar(
title: "Ranking".tl,
action: DropDownButton(
title: Text(types[type]!.tl),
items: types.entries.map((e) => MenuFlyoutItem(
text: Text(e.value.tl),
onPressed: () {
setState(() {
type = e.key;
});
},
)).toList(),
),
);
}
}
class _OneRankingPage extends StatefulWidget {
const _OneRankingPage(this.type, {super.key});
final String type;
@override
State<_OneRankingPage> createState() => _OneRankingPageState();
}
class _OneRankingPageState extends MultiPageLoadingState<_OneRankingPage, Novel> {
@override
Widget buildContent(BuildContext context, final List<Novel> data) {
return GridViewWithFixedItemHeight(
itemCount: data.length,
itemHeight: 164,
minCrossAxisExtent: 400,
builder: (context, index) {
if (index == data.length - 1) {
nextPage();
}
return NovelWidget(data[index]);
},
).paddingHorizontal(8);
}
String? nextUrl;
@override
Future<Res<List<Novel>>> loadData(page) async{
if(nextUrl == "end") {
return Res.error("No more data");
}
var res = await Network().getNovelRanking(widget.type, null);
if(!res.error) {
nextUrl = res.subData;
nextUrl ??= "end";
}
return res;
}
}

View File

@@ -0,0 +1,49 @@
import 'package:fluent_ui/fluent_ui.dart';
import 'package:pixes/components/loading.dart';
import 'package:pixes/network/network.dart';
class NovelReadingPage extends StatefulWidget {
const NovelReadingPage(this.novel, {super.key});
final Novel novel;
@override
State<NovelReadingPage> createState() => _NovelReadingPageState();
}
class _NovelReadingPageState extends LoadingState<NovelReadingPage, String> {
@override
Widget buildContent(BuildContext context, String data) {
return ScaffoldPage(
padding: EdgeInsets.zero,
content: SelectionArea(
child: SingleChildScrollView(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(widget.novel.title,
style: const TextStyle(
fontSize: 24.0, fontWeight: FontWeight.bold)),
const SizedBox(height: 12.0),
const Divider(
style: DividerThemeData(horizontalMargin: EdgeInsets.all(0)),
),
const SizedBox(height: 12.0),
Text(data,
style: const TextStyle(
fontSize: 16.0,
height: 1.6,
)),
],
),
),
),
);
}
@override
Future<Res<String>> loadData() {
return Network().getNovelContent(widget.novel.id.toString());
}
}

View File

@@ -0,0 +1,46 @@
import 'package:fluent_ui/fluent_ui.dart';
import 'package:pixes/components/grid.dart';
import 'package:pixes/components/loading.dart';
import 'package:pixes/components/novel.dart';
import 'package:pixes/components/title_bar.dart';
import 'package:pixes/foundation/app.dart';
import 'package:pixes/network/network.dart';
import 'package:pixes/utils/translation.dart';
class NovelRecommendationPage extends StatefulWidget {
const NovelRecommendationPage({super.key});
@override
State<NovelRecommendationPage> createState() =>
_NovelRecommendationPageState();
}
class _NovelRecommendationPageState
extends MultiPageLoadingState<NovelRecommendationPage, Novel> {
@override
Widget buildContent(BuildContext context, List<Novel> data) {
return Column(
children: [
TitleBar(title: "Recommendation".tl),
Expanded(
child: GridViewWithFixedItemHeight(
itemCount: data.length,
itemHeight: 164,
minCrossAxisExtent: 400,
builder: (context, index) {
if (index == data.length - 1) {
nextPage();
}
return NovelWidget(data[index]);
},
).paddingHorizontal(8),
)
],
);
}
@override
Future<Res<List<Novel>>> loadData(int page) {
return Network().getRecommendNovels();
}
}

View File

@@ -3,6 +3,7 @@ import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:pixes/appdata.dart';
import 'package:pixes/components/loading.dart';
import 'package:pixes/components/message.dart';
import 'package:pixes/components/novel.dart';
import 'package:pixes/components/page_route.dart';
import 'package:pixes/components/user_preview.dart';
import 'package:pixes/foundation/app.dart';
@@ -39,11 +40,11 @@ class _SearchPageState extends State<SearchPage> {
];
void search() {
switch(searchType) {
switch (searchType) {
case 0:
context.to(() => SearchResultPage(text));
case 1:
showToast(context, message: "Not implemented");
context.to(() => SearchNovelResultPage(text));
case 2:
context.to(() => SearchUserResultPage(text));
case 3:
@@ -62,7 +63,9 @@ class _SearchPageState extends State<SearchPage> {
content: Column(
children: [
buildSearchBar(),
const SizedBox(height: 8,),
const SizedBox(
height: 8,
),
const Expanded(
child: _TrendingTagsView(),
)
@@ -130,7 +133,9 @@ class _SearchPageState extends State<SearchPage> {
},
),
),
const SizedBox(width: 4,),
const SizedBox(
width: 4,
),
Button(
child: const SizedBox(
height: 42,
@@ -139,7 +144,9 @@ class _SearchPageState extends State<SearchPage> {
),
),
onPressed: () {
Navigator.of(context).push(SideBarRoute(const SearchSettings()));
Navigator.of(context).push(SideBarRoute(SearchSettings(
isNovel: searchType == 1,
)));
},
)
],
@@ -169,12 +176,13 @@ class _TrendingTagsView extends StatefulWidget {
State<_TrendingTagsView> createState() => _TrendingTagsViewState();
}
class _TrendingTagsViewState extends LoadingState<_TrendingTagsView, List<TrendingTag>> {
class _TrendingTagsViewState
extends LoadingState<_TrendingTagsView, List<TrendingTag>> {
@override
Widget buildContent(BuildContext context, List<TrendingTag> data) {
return MasonryGridView.builder(
padding: const EdgeInsets.symmetric(horizontal: 8.0)
+ EdgeInsets.only(bottom: context.padding.bottom),
padding: const EdgeInsets.symmetric(horizontal: 8.0) +
EdgeInsets.only(bottom: context.padding.bottom),
gridDelegate: const SliverSimpleGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 240,
),
@@ -189,7 +197,7 @@ class _TrendingTagsViewState extends LoadingState<_TrendingTagsView, List<Trendi
final illust = tag.illust;
var text = tag.tag.name;
if(tag.tag.translatedName != null) {
if (tag.tag.translatedName != null) {
text += "/${tag.tag.translatedName}";
}
@@ -206,18 +214,19 @@ class _TrendingTagsViewState extends LoadingState<_TrendingTagsView, List<Trendi
child: MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: (){
onTap: () {
context.to(() => SearchResultPage(tag.tag.name));
},
child: Stack(
children: [
Positioned.fill(child: ClipRRect(
Positioned.fill(
child: ClipRRect(
borderRadius: BorderRadius.circular(4.0),
child: AnimatedImage(
image: CachedImageProvider(illust.images.first.medium),
fit: BoxFit.cover,
width: width-16.0,
height: height-16.0,
width: width - 16.0,
height: height - 16.0,
),
)),
Positioned(
@@ -226,10 +235,14 @@ class _TrendingTagsViewState extends LoadingState<_TrendingTagsView, List<Trendi
right: 0,
child: Container(
decoration: BoxDecoration(
color: FluentTheme.of(context).micaBackgroundColor.withOpacity(0.84),
borderRadius: BorderRadius.circular(4)
),
child: Text(text).paddingHorizontal(4).paddingVertical(6).paddingBottom(2),
color: FluentTheme.of(context)
.micaBackgroundColor
.withOpacity(0.84),
borderRadius: BorderRadius.circular(4)),
child: Text(text)
.paddingHorizontal(4)
.paddingVertical(6)
.paddingBottom(2),
),
)
],
@@ -248,10 +261,12 @@ class _TrendingTagsViewState extends LoadingState<_TrendingTagsView, List<Trendi
}
class SearchSettings extends StatefulWidget {
const SearchSettings({this.onChanged, super.key});
const SearchSettings({this.onChanged, this.isNovel = false, super.key});
final void Function()? onChanged;
final bool isNovel;
@override
State<SearchSettings> createState() => _SearchSettingsState();
}
@@ -264,113 +279,139 @@ class _SearchSettingsState extends State<SearchSettings> {
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 12),
child: Text("Search Settings".tl, style: const TextStyle(fontSize: 18),),
child: Text(
"Search Settings".tl,
style: const TextStyle(fontSize: 18),
),
).toAlign(Alignment.centerLeft),
buildItem(title: "Match".tl, child: DropDownButton(
title: Text(appdata.searchOptions.matchType.toString().tl),
items: KeywordMatchType.values.map((e) =>
MenuFlyoutItem(
text: Text(e.toString().tl),
onPressed: () {
if(appdata.searchOptions.matchType != e) {
setState(() => appdata.searchOptions.matchType = e);
widget.onChanged?.call();
}
}
)
).toList(),
)),
buildItem(title: "Favorite number".tl, child: DropDownButton(
title: Text(appdata.searchOptions.favoriteNumber.toString().tl),
items: FavoriteNumber.values.map((e) =>
MenuFlyoutItem(
text: Text(e.toString().tl),
onPressed: () {
if(appdata.searchOptions.favoriteNumber != e) {
setState(() => appdata.searchOptions.favoriteNumber = e);
widget.onChanged?.call();
}
}
)
).toList(),
)),
buildItem(title: "Sort".tl, child: DropDownButton(
title: Text(appdata.searchOptions.sort.toString().tl),
items: SearchSort.values.map((e) =>
MenuFlyoutItem(
text: Text(e.toString().tl),
onPressed: () {
if(appdata.searchOptions.sort != e) {
setState(() => appdata.searchOptions.sort = e);
widget.onChanged?.call();
}
}
)
).toList(),
)),
Card(
padding: EdgeInsets.zero,
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
child: SizedBox(
width: double.infinity,
child: Column(
children: [
Text("Start Time".tl, style: const TextStyle(fontSize: 16),)
.paddingVertical(8)
.toAlign(Alignment.centerLeft)
.paddingLeft(16),
DatePicker(
selected: appdata.searchOptions.startTime,
onChanged: (t) {
if(appdata.searchOptions.startTime != t) {
setState(() => appdata.searchOptions.startTime = t);
widget.onChanged?.call();
}
},
),
const SizedBox(height: 8,)
],
),
)),
Card(
padding: EdgeInsets.zero,
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
child: SizedBox(
width: double.infinity,
child: Column(
children: [
Text("End Time".tl, style: const TextStyle(fontSize: 16),)
.paddingVertical(8)
.toAlign(Alignment.centerLeft)
.paddingLeft(16),
DatePicker(
selected: appdata.searchOptions.endTime,
onChanged: (t) {
if(appdata.searchOptions.endTime != t) {
setState(() => appdata.searchOptions.endTime = t);
widget.onChanged?.call();
}
},
),
const SizedBox(height: 8,)
],
),
buildItem(
title: "Match".tl,
child: DropDownButton(
title: Text(appdata.searchOptions.matchType.toString().tl),
items: KeywordMatchType.values
.map((e) => MenuFlyoutItem(
text: Text(e.toString().tl),
onPressed: () {
if (appdata.searchOptions.matchType != e) {
setState(() => appdata.searchOptions.matchType = e);
widget.onChanged?.call();
}
}))
.toList(),
)),
buildItem(title: "Age limit".tl, child: DropDownButton(
title: Text(appdata.searchOptions.ageLimit.toString().tl),
items: AgeLimit.values.map((e) =>
MenuFlyoutItem(
text: Text(e.toString().tl),
onPressed: () {
if(appdata.searchOptions.ageLimit != e) {
setState(() => appdata.searchOptions.ageLimit = e);
widget.onChanged?.call();
}
}
)
).toList(),
)),
SizedBox(height: context.padding.bottom,)
if (!widget.isNovel)
buildItem(
title: "Favorite number".tl,
child: DropDownButton(
title:
Text(appdata.searchOptions.favoriteNumber.toString().tl),
items: FavoriteNumber.values
.map((e) => MenuFlyoutItem(
text: Text(e.toString().tl),
onPressed: () {
if (appdata.searchOptions.favoriteNumber != e) {
setState(() =>
appdata.searchOptions.favoriteNumber = e);
widget.onChanged?.call();
}
}))
.toList(),
)),
buildItem(
title: "Sort".tl,
child: DropDownButton(
title: Text(appdata.searchOptions.sort.toString().tl),
items: SearchSort.values
.map((e) => MenuFlyoutItem(
text: Text(e.toString().tl),
onPressed: () {
if (appdata.searchOptions.sort != e) {
setState(() => appdata.searchOptions.sort = e);
widget.onChanged?.call();
}
}))
.toList(),
)),
if (!widget.isNovel)
Card(
padding: EdgeInsets.zero,
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
child: SizedBox(
width: double.infinity,
child: Column(
children: [
Text(
"Start Time".tl,
style: const TextStyle(fontSize: 16),
)
.paddingVertical(8)
.toAlign(Alignment.centerLeft)
.paddingLeft(16),
DatePicker(
selected: appdata.searchOptions.startTime,
onChanged: (t) {
if (appdata.searchOptions.startTime != t) {
setState(() => appdata.searchOptions.startTime = t);
widget.onChanged?.call();
}
},
),
const SizedBox(
height: 8,
)
],
),
)),
if (!widget.isNovel)
Card(
padding: EdgeInsets.zero,
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
child: SizedBox(
width: double.infinity,
child: Column(
children: [
Text(
"End Time".tl,
style: const TextStyle(fontSize: 16),
)
.paddingVertical(8)
.toAlign(Alignment.centerLeft)
.paddingLeft(16),
DatePicker(
selected: appdata.searchOptions.endTime,
onChanged: (t) {
if (appdata.searchOptions.endTime != t) {
setState(() => appdata.searchOptions.endTime = t);
widget.onChanged?.call();
}
},
),
const SizedBox(
height: 8,
)
],
),
)),
if (!widget.isNovel)
buildItem(
title: "Age limit".tl,
child: DropDownButton(
title: Text(appdata.searchOptions.ageLimit.toString().tl),
items: AgeLimit.values
.map((e) => MenuFlyoutItem(
text: Text(e.toString().tl),
onPressed: () {
if (appdata.searchOptions.ageLimit != e) {
setState(
() => appdata.searchOptions.ageLimit = e);
widget.onChanged?.call();
}
}))
.toList(),
)),
SizedBox(
height: context.padding.bottom,
)
],
),
);
@@ -388,7 +429,6 @@ class _SearchSettingsState extends State<SearchSettings> {
}
}
class SearchResultPage extends StatefulWidget {
const SearchResultPage(this.keyword, {super.key});
@@ -398,7 +438,8 @@ class SearchResultPage extends StatefulWidget {
State<SearchResultPage> createState() => _SearchResultPageState();
}
class _SearchResultPageState extends MultiPageLoadingState<SearchResultPage, Illust> {
class _SearchResultPageState
extends MultiPageLoadingState<SearchResultPage, Illust> {
late String keyword = widget.keyword;
late String oldKeyword = widget.keyword;
@@ -406,7 +447,7 @@ class _SearchResultPageState extends MultiPageLoadingState<SearchResultPage, Ill
late final controller = TextEditingController(text: widget.keyword);
void search() {
if(keyword != oldKeyword) {
if (keyword != oldKeyword) {
oldKeyword = keyword;
reset();
}
@@ -423,21 +464,23 @@ class _SearchResultPageState extends MultiPageLoadingState<SearchResultPage, Ill
),
delegate: SliverChildBuilderDelegate(
(context, index) {
if(index == data.length - 1){
if (index == data.length - 1) {
nextPage();
}
return IllustWidget(data[index], onTap: () {
context.to(() => IllustGalleryPage(
illusts: data,
initialPage: index,
nextUrl: nextUrl
));
},);
return IllustWidget(
data[index],
onTap: () {
context.to(() => IllustGalleryPage(
illusts: data, initialPage: index, nextUrl: nextUrl));
},
);
},
childCount: data.length,
),
).sliverPaddingHorizontal(8),
SliverPadding(padding: EdgeInsets.only(bottom: context.padding.bottom),)
SliverPadding(
padding: EdgeInsets.only(bottom: context.padding.bottom),
)
],
);
}
@@ -481,7 +524,9 @@ class _SearchResultPageState extends MultiPageLoadingState<SearchResultPage, Ill
),
),
),
const SizedBox(width: 4,),
const SizedBox(
width: 4,
),
Button(
child: const SizedBox(
height: 42,
@@ -489,12 +534,13 @@ class _SearchResultPageState extends MultiPageLoadingState<SearchResultPage, Ill
child: Icon(FluentIcons.settings),
),
),
onPressed: () async{
onPressed: () async {
bool isChanged = false;
await Navigator.of(context).push(
SideBarRoute(SearchSettings(
onChanged: () => isChanged = true,)));
if(isChanged) {
await Navigator.of(context)
.push(SideBarRoute(SearchSettings(
onChanged: () => isChanged = true,
)));
if (isChanged) {
reset();
}
},
@@ -513,14 +559,14 @@ class _SearchResultPageState extends MultiPageLoadingState<SearchResultPage, Ill
String? nextUrl;
@override
Future<Res<List<Illust>>> loadData(page) async{
if(nextUrl == "end") {
Future<Res<List<Illust>>> loadData(page) async {
if (nextUrl == "end") {
return Res.error("No more data");
}
var res = nextUrl == null
? await Network().search(keyword, appdata.searchOptions)
: await Network().getIllustsWithNextUrl(nextUrl!);
if(!res.error) {
if (!res.error) {
nextUrl = res.subData;
nextUrl ??= "end";
}
@@ -537,30 +583,31 @@ class SearchUserResultPage extends StatefulWidget {
State<SearchUserResultPage> createState() => _SearchUserResultPageState();
}
class _SearchUserResultPageState extends MultiPageLoadingState<SearchUserResultPage, UserPreview> {
class _SearchUserResultPageState
extends MultiPageLoadingState<SearchUserResultPage, UserPreview> {
@override
Widget buildContent(BuildContext context, final List<UserPreview> data) {
return CustomScrollView(
slivers: [
SliverToBoxAdapter(
child: Text("${"Search".tl}: ${widget.keyword}",
style: const TextStyle(fontSize: 22, fontWeight: FontWeight.bold),)
.paddingVertical(12).paddingHorizontal(16),
child: Text(
"${"Search".tl}: ${widget.keyword}",
style: const TextStyle(fontSize: 22, fontWeight: FontWeight.bold),
).paddingVertical(12).paddingHorizontal(16),
),
SliverGridViewWithFixedItemHeight(
delegate: SliverChildBuilderDelegate(
(context, index) {
if(index == data.length - 1){
nextPage();
}
return UserPreviewWidget(data[index]);
},
childCount: data.length
),
delegate: SliverChildBuilderDelegate((context, index) {
if (index == data.length - 1) {
nextPage();
}
return UserPreviewWidget(data[index]);
}, childCount: data.length),
minCrossAxisExtent: 440,
itemHeight: 136,
).sliverPaddingHorizontal(8),
SliverPadding(padding: EdgeInsets.only(bottom: context.padding.bottom),)
SliverPadding(
padding: EdgeInsets.only(bottom: context.padding.bottom),
)
],
);
}
@@ -568,12 +615,12 @@ class _SearchUserResultPageState extends MultiPageLoadingState<SearchUserResultP
String? nextUrl;
@override
Future<Res<List<UserPreview>>> loadData(page) async{
if(nextUrl == "end") {
Future<Res<List<UserPreview>>> loadData(page) async {
if (nextUrl == "end") {
return Res.error("No more data");
}
var res = await Network().searchUsers(widget.keyword, nextUrl);
if(!res.error) {
if (!res.error) {
nextUrl = res.subData;
nextUrl ??= "end";
}
@@ -581,3 +628,141 @@ class _SearchUserResultPageState extends MultiPageLoadingState<SearchUserResultP
}
}
class SearchNovelResultPage extends StatefulWidget {
const SearchNovelResultPage(this.keyword, {super.key});
final String keyword;
@override
State<SearchNovelResultPage> createState() => _SearchNovelResultPageState();
}
class _SearchNovelResultPageState
extends MultiPageLoadingState<SearchNovelResultPage, Novel> {
late String keyword = widget.keyword;
late String oldKeyword = widget.keyword;
late final controller = TextEditingController(text: widget.keyword);
void search() {
if (keyword != oldKeyword) {
oldKeyword = keyword;
reset();
}
}
@override
Widget buildContent(BuildContext context, final List<Novel> data) {
return CustomScrollView(
slivers: [
buildSearchBar(),
SliverGridViewWithFixedItemHeight(
itemHeight: 164,
minCrossAxisExtent: 400,
delegate: SliverChildBuilderDelegate(
(context, index) {
if (index == data.length - 1) {
nextPage();
}
return NovelWidget(data[index]);
},
childCount: data.length,
),
).sliverPaddingHorizontal(8),
SliverPadding(
padding: EdgeInsets.only(bottom: context.padding.bottom),
)
],
);
}
Widget buildSearchBar() {
return SliverToBoxAdapter(
child: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 560),
child: SizedBox(
height: 42,
width: double.infinity,
child: LayoutBuilder(
builder: (context, constrains) {
return SizedBox(
height: 42,
width: constrains.maxWidth,
child: Row(
children: [
Expanded(
child: TextBox(
controller: controller,
placeholder: "Search artworks".tl,
onChanged: (s) => keyword = s,
onSubmitted: (s) => search(),
foregroundDecoration: BoxDecoration(
border: Border.all(
color: ColorScheme.of(context)
.outlineVariant
.withOpacity(0.6)),
borderRadius: BorderRadius.circular(4)),
suffix: MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: search,
child: const Icon(
FluentIcons.search,
size: 16,
).paddingHorizontal(12),
),
),
),
),
const SizedBox(
width: 4,
),
Button(
child: const SizedBox(
height: 42,
child: Center(
child: Icon(FluentIcons.settings),
),
),
onPressed: () async {
bool isChanged = false;
await Navigator.of(context)
.push(SideBarRoute(SearchSettings(
onChanged: () => isChanged = true,
isNovel: true,
)));
if (isChanged) {
reset();
}
},
)
],
),
);
},
),
).paddingHorizontal(16),
),
),
).sliverPadding(const EdgeInsets.only(top: 12));
}
String? nextUrl;
@override
Future<Res<List<Novel>>> loadData(page) async {
if (nextUrl == "end") {
return Res.error("No more data");
}
var res = nextUrl == null
? await Network().searchNovels(keyword, appdata.searchOptions)
: await Network().getNovelsWithNextUrl(nextUrl!);
if (!res.error) {
nextUrl = res.subData;
nextUrl ??= "end";
}
return res;
}
}

View File

@@ -3,8 +3,10 @@ import 'package:flutter/gestures.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:pixes/appdata.dart';
import 'package:pixes/components/batch_download.dart';
import 'package:pixes/components/grid.dart';
import 'package:pixes/components/loading.dart';
import 'package:pixes/components/md.dart';
import 'package:pixes/components/novel.dart';
import 'package:pixes/components/segmented_button.dart';
import 'package:pixes/components/user_preview.dart';
import 'package:pixes/foundation/app.dart';
@@ -43,11 +45,14 @@ class _UserInfoPageState extends LoadingState<UserInfoPage, UserDetails> {
_RelatedUsers(widget.id),
buildInformation(),
buildArtworkHeader(),
_UserArtworks(
data.id.toString(),
page,
key: ValueKey(data.id + page),
),
if (page == 2)
_UserNovels(widget.id)
else
_UserArtworks(
data.id.toString(),
page,
key: ValueKey(data.id + page),
),
SliverPadding(
padding: EdgeInsets.only(bottom: context.padding.bottom)),
],
@@ -204,6 +209,7 @@ class _UserInfoPageState extends LoadingState<UserInfoPage, UserDetails> {
options: [
SegmentedButtonOption(0, "Artworks".tl),
SegmentedButtonOption(1, "Bookmarks".tl),
SegmentedButtonOption(2, "Novels".tl),
],
value: page,
onPressed: (value) {
@@ -213,15 +219,17 @@ class _UserInfoPageState extends LoadingState<UserInfoPage, UserDetails> {
},
),
const Spacer(),
BatchDownloadButton(
request: () {
if (page == 0) {
return Network().getUserIllusts(data!.id.toString());
} else {
return Network().getUserBookmarks(data!.id.toString());
}
},
),
if (page != 2)
BatchDownloadButton(
request: () {
if (page == 0) {
return Network().getUserIllusts(data!.id.toString());
} else {
return Network()
.getUserBookmarks(data!.id.toString());
}
},
),
],
).paddingHorizontal(16))
.paddingTop(12),
@@ -392,6 +400,81 @@ class _UserArtworksState extends MultiPageLoadingState<_UserArtworks, Illust> {
}
}
class _UserNovels extends StatefulWidget {
const _UserNovels(this.uid, {super.key});
final String uid;
@override
State<_UserNovels> createState() => _UserNovelsState();
}
class _UserNovelsState extends MultiPageLoadingState<_UserNovels, Novel> {
@override
Widget buildLoading(BuildContext context) {
return const SliverToBoxAdapter(
child: SizedBox(
child: Center(
child: ProgressRing(),
),
),
);
}
@override
Widget buildError(context, error) {
return SliverToBoxAdapter(
child: SizedBox(
child: Center(
child: Row(
children: [
const Icon(FluentIcons.info),
const SizedBox(
width: 4,
),
Text(error)
],
),
),
),
);
}
@override
Widget buildContent(BuildContext context, List<Novel> data) {
return SliverGridViewWithFixedItemHeight(
itemHeight: 164,
minCrossAxisExtent: 400,
delegate: SliverChildBuilderDelegate(
(context, index) {
if (index == data.length - 1) {
nextPage();
}
return NovelWidget(data[index]);
},
childCount: data.length,
),
).sliverPaddingHorizontal(8);
}
String? nextUrl;
@override
Future<Res<List<Novel>>> loadData(page) async {
if (nextUrl == "end") {
return Res.error("No more data");
}
var res = nextUrl == null
? await Network().getUserNovels(widget.uid)
: await Network().getNovelsWithNextUrl(nextUrl!);
if (!res.error) {
nextUrl = res.subData;
nextUrl ??= "end";
}
return res;
}
}
class _RelatedUsers extends StatefulWidget {
const _RelatedUsers(this.uid);