From 3fe4954201ed1ef59c2fcb0087a8a07464539fa0 Mon Sep 17 00:00:00 2001 From: wgh19 Date: Sun, 14 Apr 2024 11:58:19 +0800 Subject: [PATCH] fix #486 --- lib/views/me_page.dart | 69 +++++++++++++++++++++++---- lib/views/show_image_page.dart | 15 ++++++ lib/views/widgets/avatar.dart | 30 +++++++++++- lib/views/widgets/show_user_info.dart | 28 ----------- 4 files changed, 104 insertions(+), 38 deletions(-) delete mode 100644 lib/views/widgets/show_user_info.dart diff --git a/lib/views/me_page.dart b/lib/views/me_page.dart index 24ac880a..4e38c470 100644 --- a/lib/views/me_page.dart +++ b/lib/views/me_page.dart @@ -1,6 +1,7 @@ import 'package:fl_chart/fl_chart.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; +import 'package:pica_comic/comic_source/comic_source.dart'; import 'package:pica_comic/foundation/history.dart'; import 'package:pica_comic/foundation/image_loader/cached_image.dart'; import 'package:pica_comic/network/download.dart'; @@ -449,6 +450,7 @@ class MePage extends StatelessWidget { buildHistory(), if(shouldShowTwoPanel) Row( + crossAxisAlignment: CrossAxisAlignment.start, children: [ Expanded( child: Column( @@ -550,11 +552,30 @@ class MePage extends StatelessWidget { } Widget buildAccount(double width){ + var accounts = findAccounts(); + + Widget buildItem(String name){ + return Container( + height: 24, + padding: const EdgeInsets.symmetric(horizontal: 12), + decoration: BoxDecoration( + color: Theme.of(App.globalContext!).colorScheme.secondaryContainer, + borderRadius: BorderRadius.circular(12), + ), + child: Text(name, style: const TextStyle(fontSize: 12),).paddingTop(4), + ); + } + return _MePageCard( icon: const Icon(Icons.switch_account), title: "账号管理".tl, - description: "已登录 @a 个账号".tlParams({"a": calcAccounts().toString()}), + description: "已登录 @a 个账号".tlParams({"a": accounts.length.toString()}), onTap: () => showAdaptiveWidget(App.globalContext!, AccountsPage()), + child: Wrap( + spacing: 8, + runSpacing: 8, + children: accounts.map((e) => buildItem(e)).toList(), + ).paddingHorizontal(12).paddingBottom(12) ); } @@ -577,22 +598,48 @@ class MePage extends StatelessWidget { } Widget buildTools(double width){ + Widget buildItem(String name){ + return Container( + height: 24, + padding: const EdgeInsets.symmetric(horizontal: 12), + decoration: BoxDecoration( + color: Theme.of(App.globalContext!).colorScheme.primaryContainer, + borderRadius: BorderRadius.circular(12), + ), + child: Text(name, style: const TextStyle(fontSize: 12),).paddingTop(4), + ); + } + return _MePageCard( icon: const Icon(Icons.build_circle), title: "工具".tl, description: "使用工具发现更多漫画".tl, onTap: openTool, + child: Wrap( + spacing: 8, + runSpacing: 8, + children: [ + buildItem("Eh订阅".tl), + buildItem("图片搜索".tl), + buildItem("打开链接".tl), + ], + ).paddingHorizontal(12).paddingBottom(12), ); } - int calcAccounts(){ - int count = 0; - if(appdata.picacgAccount != "") count++; - if(appdata.ehAccount != "") count++; - if(appdata.jmName != "") count++; - if(appdata.htName != "") count++; - if(NhentaiNetwork().logged) count++; - return count; + List findAccounts(){ + var result = []; + if(appdata.picacgAccount != "") result.add("Picacg"); + if(appdata.ehAccount != "") result.add("ehentai"); + if(appdata.jmName != "") result.add("jm"); + if(appdata.htName != "") result.add("紳士漫畫"); + if(NhentaiNetwork().logged) result.add("nhentai"); + for(var source in ComicSource.sources) { + if(source.isLogin){ + result.add(source.name); + } + } + return result; } } @@ -602,12 +649,14 @@ class _MePageCard extends StatelessWidget { required this.title, required this.description, required this.onTap, + this.child, }); final Widget icon; final String title; final String description; final VoidCallback onTap; + final Widget? child; @override Widget build(BuildContext context) { @@ -627,6 +676,8 @@ class _MePageCard extends StatelessWidget { mouseCursor: SystemMouseCursors.click, ), Text(description).paddingHorizontal(16).paddingBottom(16).paddingTop(8), + if(child != null) + child! ], ), ), diff --git a/lib/views/show_image_page.dart b/lib/views/show_image_page.dart index dfbc2df8..1c233417 100644 --- a/lib/views/show_image_page.dart +++ b/lib/views/show_image_page.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; import 'package:photo_view/photo_view.dart'; import 'package:pica_comic/foundation/image_loader/cached_image.dart'; +import 'package:pica_comic/foundation/image_manager.dart'; +import 'package:pica_comic/tools/save_image.dart'; import 'package:pica_comic/tools/translations.dart'; class ShowImagePage extends StatelessWidget { @@ -42,6 +44,19 @@ class ShowImagePageWithHero extends StatelessWidget { return Scaffold( appBar: AppBar( title: Text("图片".tl), + actions: [ + Tooltip( + message: "保存".tl, + child: IconButton( + icon: const Icon(Icons.download), + onPressed: () async{ + var file = await ImageManager().getFile(url); + if(file != null){ + saveImage(file); + } + } + )) + ], ), body: Hero( tag: tag, diff --git a/lib/views/widgets/avatar.dart b/lib/views/widgets/avatar.dart index ca48bbe0..47412666 100644 --- a/lib/views/widgets/avatar.dart +++ b/lib/views/widgets/avatar.dart @@ -1,7 +1,8 @@ import 'package:flutter/material.dart'; +import 'package:pica_comic/foundation/app.dart'; import 'package:pica_comic/foundation/image_loader/cached_image.dart'; +import 'package:pica_comic/views/show_image_page.dart'; import 'package:pica_comic/views/widgets/animated_image.dart'; -import 'package:pica_comic/views/widgets/show_user_info.dart'; import '../../base.dart'; class Avatar extends StatelessWidget { @@ -29,6 +30,8 @@ class Avatar extends StatelessWidget { onTap: () { if (couldBeShown) { showUserInfo(context, avatarUrl, frame, name, slogan, level); + } else if(avatarUrl != null && avatarUrl != "DEFAULT AVATAR URL"){ + App.globalTo(() => ShowImagePageWithHero(avatarUrl!, "avatar")); } }, child: Container( @@ -76,3 +79,28 @@ class Avatar extends StatelessWidget { ); } } + +void showUserInfo(BuildContext context, String? avatarUrl, String? frameUrl, String name, String? slogan, int level){ + showDialog(context: context, builder: (dialogContext){ + return SimpleDialog( + contentPadding: const EdgeInsets.all(20), + children: [ + Align( + alignment: Alignment.center, + child: Column( + children: [ + Avatar(size: 80, avatarUrl: avatarUrl, frame: frameUrl,), + Text(name,style: const TextStyle(fontSize: 16,fontWeight: FontWeight.w600),), + Text("Lv${level.toString()}"), + const SizedBox(height: 10,width: 0,), + SizedBox(width: 400,child: Align( + alignment: Alignment.center, + child: Text(slogan??""), + ),) + ], + ), + ) + ], + ); + }); +} diff --git a/lib/views/widgets/show_user_info.dart b/lib/views/widgets/show_user_info.dart deleted file mode 100644 index ca151e51..00000000 --- a/lib/views/widgets/show_user_info.dart +++ /dev/null @@ -1,28 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:pica_comic/tools/translations.dart'; -import 'avatar.dart'; - -void showUserInfo(BuildContext context, String? avatarUrl, String? frameUrl, String name, String? slogan, int level){ - showDialog(context: context, builder: (dialogContext){ - return SimpleDialog( - contentPadding: const EdgeInsets.all(20), - children: [ - Align( - alignment: Alignment.center, - child: Column( - children: [ - Avatar(size: 80,avatarUrl: avatarUrl,frame: frameUrl,), - Text(name,style: const TextStyle(fontSize: 16,fontWeight: FontWeight.w600),), - Text("Lv${level.toString()}"), - const SizedBox(height: 10,width: 0,), - SizedBox(width: 400,child: Align( - alignment: Alignment.center, - child: Text(slogan??"无".tl), - ),) - ], - ), - ) - ], - ); - }); -} \ No newline at end of file