diff --git a/assets/tr.json b/assets/tr.json index 636fa53..9dc809b 100644 --- a/assets/tr.json +++ b/assets/tr.json @@ -10,7 +10,7 @@ "History": "历史", "Ranking": "排行", "Settings": "设置", - "Artworks": "插画", + "Artworks": "作品", "Mangas": "漫画", "Users": "用户", "Search artwork": "搜索作品", @@ -173,7 +173,8 @@ "Use an external browser: You can sign in using Google. However, some browsers may not be compatible with the application": "使用外部浏览器: 可以使用Google登录. 但是, 一些浏览器可能与应用程序不兼容", "External browser": "外部浏览器", "Show comments": "显示评论", - "Show original image": "显示原图" + "Show original image": "显示原图", + "Illustrations": "插画" }, "zh_TW": { "Search": "搜索", @@ -349,6 +350,7 @@ "Use an external browser: You can sign in using Google. However, some browsers may not be compatible with the application": "使用外部瀏覽器: 可以使用Google登錄. 但是, 一些瀏覽器可能與應用程序不兼容", "External browser": "外部瀏覽器", "Show comments": "顯示評論", - "Show original image": "顯示原圖" + "Show original image": "顯示原圖", + "Illustrations": "插畫" } } \ No newline at end of file diff --git a/lib/components/md.dart b/lib/components/md.dart index fe12845..442346e 100644 --- a/lib/components/md.dart +++ b/lib/components/md.dart @@ -4,6 +4,7 @@ typedef MdIcons = md.Icons; typedef MdTheme = md.Theme; typedef MdThemeData = md.ThemeData; typedef MdColorScheme = md.ColorScheme; +typedef TextField = md.TextField; class ColorScheme { static md.ColorScheme of(md.BuildContext context) { diff --git a/lib/network/network.dart b/lib/network/network.dart index 82b4d23..38cff76 100644 --- a/lib/network/network.dart +++ b/lib/network/network.dart @@ -387,9 +387,9 @@ class Network { } } - Future>> getUserIllusts(String uid) async { + Future>> getUserIllusts(String uid, String? type) async { var res = await apiGet( - "/v1/user/illusts?filter=for_android&user_id=$uid&type=illust"); + "/v1/user/illusts?filter=for_android&user_id=$uid${type != null ? "&type=$type" : ""}"); if (res.success) { return Res( (res.data["illusts"] as List).map((e) => Illust.fromJson(e)).toList(), @@ -574,7 +574,7 @@ class Network { } } - Future> sendHistory(List ids) async{ + Future> sendHistory(List ids) async { var res = await apiPost("/v2/user/browsing-history/illust/add", data: {"illust_ids": ids}); if (res.success) { diff --git a/lib/pages/image_page.dart b/lib/pages/image_page.dart index 735e5be..2998595 100644 --- a/lib/pages/image_page.dart +++ b/lib/pages/image_page.dart @@ -92,7 +92,7 @@ class _ImagePageState extends State with WindowListener { void showMenu() { menuController.showFlyout( barrierColor: Colors.transparent, - position: Offset(context.size!.width, 0), + position: App.isMobile ? Offset(context.size!.width, 0) : null, builder: (context) => MenuFlyout( items: [ MenuFlyoutItem( @@ -100,10 +100,11 @@ class _ImagePageState extends State with WindowListener { onPressed: () async { var file = await getFile(); if (file != null) { - var fileName = file.path.split('/').last; + var fileName = widget.urls[currentPage].split('/').last; if (!fileName.contains('.')) { fileName += getExtensionName(); } + print(fileName); saveFile(file, fileName); } }), @@ -113,7 +114,8 @@ class _ImagePageState extends State with WindowListener { onPressed: () async { var file = await getFile(); if (file != null) { - var fileName = file.path.split('/').last; + var fileName = + widget.urls[currentPage].split('/').last; if (!fileName.contains('.')) { fileName += getExtensionName(); } @@ -130,7 +132,7 @@ class _ImagePageState extends State with WindowListener { var file = await getFile(); if (file != null) { var ext = getExtensionName(); - var fileName = file.path.split('/').last; + var fileName = widget.urls[currentPage].split('/').last; if (!fileName.contains('.')) { fileName += ext; } diff --git a/lib/pages/main_page.dart b/lib/pages/main_page.dart index dfb6cdc..c4526cc 100644 --- a/lib/pages/main_page.dart +++ b/lib/pages/main_page.dart @@ -2,6 +2,7 @@ import "dart:async"; import "package:fluent_ui/fluent_ui.dart"; import "package:flutter/foundation.dart"; +import "package:flutter/services.dart"; import "package:pixes/appdata.dart"; import "package:pixes/components/md.dart"; import "package:pixes/foundation/app.dart"; @@ -64,13 +65,17 @@ class MainPage extends StatefulWidget { State createState() => _MainPageState(); } -class _MainPageState extends State with WindowListener { +class _MainPageState extends State + with WindowListener + implements PopEntry { final navigatorKey = GlobalKey(); int index = 4; int windowButtonKey = 0; + ModalRoute? _route; + @override void initState() { StateController.put(TitleBarController()); @@ -80,10 +85,22 @@ class _MainPageState extends State with WindowListener { super.initState(); } + @override + void didChangeDependencies() { + super.didChangeDependencies(); + final ModalRoute? nextRoute = ModalRoute.of(context); + if (nextRoute != _route) { + _route?.unregisterPopEntry(this); + _route = nextRoute; + _route?.registerPopEntry(this); + } + } + @override void dispose() { StateController.remove(); windowManager.removeListener(this); + ModalRoute.of(context)!.unregisterPopEntry(this); super.dispose(); } @@ -151,7 +168,7 @@ class _MainPageState extends State with WindowListener { ), PaneItemSeparator(), PaneItemHeader( - header: Text('${"Artwork".tl}/${"Manga".tl}') + header: Text('${"Illustrations".tl}/${"Manga".tl}') .paddingBottom(4) .paddingLeft(8)), PaneItem( @@ -209,10 +226,7 @@ class _MainPageState extends State with WindowListener { ), ], ), - paneBodyBuilder: (pane, child) => NavigatorPopHandler( - key: const Key("navigator"), - onPop: () => navigatorKey.currentState?.pop(), - child: MediaQuery.removePadding( + paneBodyBuilder: (pane, child) => MediaQuery.removePadding( context: context, removeTop: true, child: Navigator( @@ -220,7 +234,7 @@ class _MainPageState extends State with WindowListener { onGenerateRoute: (settings) => AppPageRoute( builder: (context) => const RecommendationPage()), ), - ))), + )), ); } @@ -315,6 +329,25 @@ class _MainPageState extends State with WindowListener { : null, ); } + + final popValue = ValueNotifier(false); + + @override + ValueListenable get canPopNotifier => popValue; + + @override + PopInvokedCallback? get onPopInvoked => onPop; + + void onPop(bool value) { + print("ok"); + if (App.rootNavigatorKey.currentState?.canPop() ?? false) { + App.rootNavigatorKey.currentState?.pop(); + } else if (App.mainNavigatorKey?.currentState?.canPop() ?? false) { + App.mainNavigatorKey?.currentState?.pop(); + } else { + SystemNavigator.pop(); + } + } } class _BackButton extends StatefulWidget { diff --git a/lib/pages/recommendation_page.dart b/lib/pages/recommendation_page.dart index dc75317..7c97135 100644 --- a/lib/pages/recommendation_page.dart +++ b/lib/pages/recommendation_page.dart @@ -45,7 +45,7 @@ class _RecommendationPageState extends State { title: "Explore".tl, action: SegmentedButton( options: [ - SegmentedButtonOption(0, "Artworks".tl), + SegmentedButtonOption(0, "Illustrations".tl), SegmentedButtonOption(1, "Mangas".tl), SegmentedButtonOption(2, "Users".tl), ], diff --git a/lib/pages/user_info_page.dart b/lib/pages/user_info_page.dart index 9193d5f..131f1dc 100644 --- a/lib/pages/user_info_page.dart +++ b/lib/pages/user_info_page.dart @@ -63,7 +63,7 @@ class _UserInfoPageState extends LoadingState { _RelatedUsers(widget.id), buildInformation(), buildArtworkHeader(), - if (page == 2) + if (page == 4) _UserNovels(widget.id) else _UserArtworks( @@ -228,8 +228,10 @@ class _UserInfoPageState extends LoadingState { SegmentedButton( options: [ SegmentedButtonOption(0, "Artworks".tl), - SegmentedButtonOption(1, "Bookmarks".tl), - SegmentedButtonOption(2, "Novels".tl), + SegmentedButtonOption(1, "Illustrations".tl), + SegmentedButtonOption(2, "Mangas".tl), + SegmentedButtonOption(3, "Bookmarks".tl), + SegmentedButtonOption(4, "Novels".tl), ], value: page, onPressed: (value) { @@ -239,15 +241,24 @@ class _UserInfoPageState extends LoadingState { }, ), const Spacer(), - if (page != 2) + if (page != 4) BatchDownloadButton( request: () { - if (page == 0) { - return Network().getUserIllusts(data!.id.toString()); - } else { - return Network() - .getUserBookmarks(data!.id.toString()); + switch (page) { + case 0: + return Network() + .getUserIllusts(data!.id.toString(), null); + case 1: + return Network() + .getUserIllusts(data!.id.toString(), "illust"); + case 2: + return Network() + .getUserIllusts(data!.id.toString(), "manga"); + case 3: + return Network() + .getUserBookmarks(data!.id.toString()); } + throw "Invalid page"; }, ), ], @@ -269,14 +280,14 @@ class _UserInfoPageState extends LoadingState { margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 2), padding: EdgeInsets.zero, child: ListTile( - leading: icon == null - ? null - : Icon( - icon, - size: 20, - ), - title: Text(title), - subtitle: SelectableText(content), + title: Row( + children: [ + Icon(icon, size: 20), + const SizedBox(width: 8), + Text(title) + ], + ), + subtitle: SelectableText(content).paddingLeft(icon == null ? 0 : 28), trailing: trailing, ), ); @@ -409,8 +420,9 @@ class _UserArtworksState extends MultiPageLoadingState<_UserArtworks, Illust> { return Res.error("No more data"); } var res = nextUrl == null - ? (widget.type == 0 - ? await Network().getUserIllusts(widget.uid) + ? (widget.type != 3 + ? await Network().getUserIllusts( + widget.uid, [null, "illust", "manga"][widget.type]) : await Network().getUserBookmarks(widget.uid)) : await Network().getIllustsWithNextUrl(nextUrl!); if (!res.error) { @@ -422,7 +434,7 @@ class _UserArtworksState extends MultiPageLoadingState<_UserArtworks, Illust> { } class _UserNovels extends StatefulWidget { - const _UserNovels(this.uid, {super.key}); + const _UserNovels(this.uid); final String uid; @@ -534,7 +546,7 @@ class _RelatedUsersState return UserPreviewWidget(data[index]).fixWidth(342); }, )); - if (MediaQuery.of(context).size.width > 500) { + if (App.isDesktop) { content = ScrollbarTheme.merge( data: const ScrollbarThemeData( thickness: 6, @@ -542,7 +554,21 @@ class _RelatedUsersState mainAxisMargin: 4, hoveringPadding: EdgeInsets.zero, padding: EdgeInsets.zero, - hoveringMainAxisMargin: 4), + hoveringMainAxisMargin: 4, + crossAxisMargin: 0, + hoveringCrossAxisMargin: 0), + child: content); + } else { + content = ScrollbarTheme.merge( + data: const ScrollbarThemeData( + thickness: 4, + hoveringThickness: 4, + mainAxisMargin: 4, + hoveringPadding: EdgeInsets.zero, + padding: EdgeInsets.zero, + hoveringMainAxisMargin: 4, + crossAxisMargin: 0, + hoveringCrossAxisMargin: 0), child: content); } return MediaQuery.removePadding(