diff --git a/android/app/build.gradle b/android/app/build.gradle index 997272b7f..e7f004cc0 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -86,8 +86,8 @@ android { applicationId packageName minSdkVersion 21 targetSdkVersion 30 - versionCode 33 - versionName "0.2.2 X" + versionCode 34 + versionName "0.2.2 theocracy" } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 diff --git a/android/app/src/main/kotlin/com/perol/pixez/MainActivity.kt b/android/app/src/main/kotlin/com/perol/pixez/MainActivity.kt index 482a184a1..a8cbbeabd 100644 --- a/android/app/src/main/kotlin/com/perol/pixez/MainActivity.kt +++ b/android/app/src/main/kotlin/com/perol/pixez/MainActivity.kt @@ -281,7 +281,7 @@ class MainActivity : FlutterActivity() { MethodChannel(flutterEngine.dartExecutor.binaryMessenger, ENCODE_CHANNEL).setMethodCallHandler { call, result -> if (call.method == "getBatteryLevel") { val name = call.argument("name")!! - val path = call.argument("flutter.store_path")!! + val path = call.argument("path")!! val delay = call.argument("delay")!! GlobalScope.launch(Dispatchers.Main) { withContext(Dispatchers.IO) { diff --git a/lib/constants.dart b/lib/constants.dart index e17e5acf0..70ec3b283 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -18,5 +18,5 @@ class Constants { static String tagName = "0.2.2"; // static bool isGooglePlay = // bool.fromEnvironment("IS_GOOGLEPLAY", defaultValue: false);//为何没用啊咕鸽? - static bool isGooglePlay = false; + static bool isGooglePlay =true; } diff --git a/lib/generated/intl/messages_zh-CN.dart b/lib/generated/intl/messages_zh-CN.dart index dbb37b991..ded4fcce2 100644 --- a/lib/generated/intl/messages_zh-CN.dart +++ b/lib/generated/intl/messages_zh-CN.dart @@ -60,7 +60,7 @@ class MessageLookup extends MessageLookupByLibrary { "create_folder" : MessageLookupByLibrary.simpleMessage("创建文件夹"), "crosscount" : MessageLookupByLibrary.simpleMessage("列数"), "current_password" : MessageLookupByLibrary.simpleMessage("当前密码"), - "dark" : MessageLookupByLibrary.simpleMessage("dark"), + "dark" : MessageLookupByLibrary.simpleMessage("深色"), "date_asc" : MessageLookupByLibrary.simpleMessage("日期升序"), "date_desc" : MessageLookupByLibrary.simpleMessage("日期降序"), "date_duration" : MessageLookupByLibrary.simpleMessage("日期间隔"), @@ -102,7 +102,7 @@ class MessageLookup extends MessageLookupByLibrary { "large_preview_zoom_quality" : MessageLookupByLibrary.simpleMessage("大图预览缩放"), "latest_version" : MessageLookupByLibrary.simpleMessage("最新版本"), "let_go_and_load_more" : MessageLookupByLibrary.simpleMessage("松手加载更多"), - "light" : MessageLookupByLibrary.simpleMessage("light"), + "light" : MessageLookupByLibrary.simpleMessage("浅色"), "link" : MessageLookupByLibrary.simpleMessage("链接"), "load_image_failed_click_to_reload" : MessageLookupByLibrary.simpleMessage("图片加载失败,点击重试"), "loading_failed_retry_message" : MessageLookupByLibrary.simpleMessage("加载失败,点击重试"), diff --git a/lib/l10n/intl_zh_CN.arb b/lib/l10n/intl_zh_CN.arb index f44904f53..df0e55c37 100644 --- a/lib/l10n/intl_zh_CN.arb +++ b/lib/l10n/intl_zh_CN.arb @@ -182,8 +182,8 @@ "special_shaped_screen": "异形屏", "platform_special_setting": "平台特殊设置", "system": "跟随系统", - "light": "light", - "dark": "dark", + "light": "浅色", + "dark": "深色", "theme_mode": "深色模式", "create_folder": "创建文件夹", "old_way": "传统方式", diff --git a/lib/page/about/about_page.dart b/lib/page/about/about_page.dart index 9b03e877f..ac6ea86a6 100644 --- a/lib/page/about/about_page.dart +++ b/lib/page/about/about_page.dart @@ -192,7 +192,6 @@ class _AboutPageState extends State { builder: (BuildContext context) { return Container( height: 200.0, - color: Color(0xfff1f1f1), child: Center( child: Text("这里空空的,这个设计师显然没有什么话要说"), ), diff --git a/lib/page/comment/comment_page.dart b/lib/page/comment/comment_page.dart index a4e86950d..af6de78d5 100644 --- a/lib/page/comment/comment_page.dart +++ b/lib/page/comment/comment_page.dart @@ -40,7 +40,6 @@ class _CommentPageState extends State { RefreshController easyRefreshController; CommentStore _store; - @override void initState() { _editController = TextEditingController(); @@ -141,7 +140,9 @@ class _CommentPageState extends State { Padding( padding: const EdgeInsets.only(top: 8.0), - child: Text(comment.date.toString().toShortTime()), + child: Text(comment.date + .toString() + .toShortTime()), ) ], ), @@ -179,28 +180,36 @@ class _CommentPageState extends State { child: Padding( padding: const EdgeInsets.only(bottom: 2.0, right: 8.0), - child: TextField( - controller: _editController, - decoration: InputDecoration( - labelText: - "Reply to ${parentCommentName == null ? "illust" : parentCommentName}", - suffixIcon: IconButton( - icon: Icon(Icons.reply), - onPressed: () async { - final client = apiClient; - String txt = _editController.text.trim(); - try { - if (txt.isNotEmpty) - Response reponse = await client - .postIllustComment(widget.id, txt, - parent_comment_id: - parentCommentId); - _editController.clear(); - _store.fetch(); - } catch (e) { - print(e); - } - })), + child: Theme( + data: Theme.of(context).copyWith( + primaryColor: Theme.of(context).accentColor), + child: TextField( + controller: _editController, + decoration: InputDecoration( + labelText: + "Reply to ${parentCommentName == null ? "illust" : parentCommentName}", + suffixIcon: IconButton( + icon: Icon( + Icons.reply, + ), + onPressed: () async { + final client = apiClient; + String txt = + _editController.text.trim(); + try { + if (txt.isNotEmpty) + Response reponse = + await client.postIllustComment( + widget.id, txt, + parent_comment_id: + parentCommentId); + _editController.clear(); + _store.fetch(); + } catch (e) { + print(e); + } + })), + ), ), ), ), diff --git a/lib/page/hello/recom/recom_spotlight_page.dart b/lib/page/hello/recom/recom_spotlight_page.dart index 90852f4d4..821d9c26f 100644 --- a/lib/page/hello/recom/recom_spotlight_page.dart +++ b/lib/page/hello/recom/recom_spotlight_page.dart @@ -28,6 +28,7 @@ import 'package:pixez/models/illust.dart'; import 'package:pixez/network/api_client.dart'; import 'package:pixez/page/hello/ranking/rank_page.dart'; import 'package:pixez/page/hello/recom/recom_user_road.dart'; +import 'package:pixez/page/hello/recom/recom_user_store.dart'; import 'package:pixez/page/hello/recom/spotlight_store.dart'; import 'package:pixez/page/spotlight/spotlight_page.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; @@ -46,10 +47,12 @@ class _RecomSpolightPageState extends State with AutomaticKeepAliveClientMixin { SpotlightStore spotlightStore; LightingStore _lightingStore; + RecomUserStore _recomUserStore; @override void initState() { _easyRefreshController = RefreshController(initialRefresh: true); + _recomUserStore = RecomUserStore(); spotlightStore = SpotlightStore(null); _lightingStore = LightingStore(() => apiClient.getRecommend(), _easyRefreshController); @@ -61,6 +64,7 @@ class _RecomSpolightPageState extends State Future fetchT() async { await spotlightStore.fetch(); await _lightingStore.fetch(); + await _recomUserStore.fetch(); } @override diff --git a/lib/page/hello/recom/recom_user_page.dart b/lib/page/hello/recom/recom_user_page.dart index cd0d41071..d31d3b00f 100644 --- a/lib/page/hello/recom/recom_user_page.dart +++ b/lib/page/hello/recom/recom_user_page.dart @@ -38,15 +38,17 @@ class _RecomUserPageState extends State { void initState() { _refreshController = RefreshController(initialRefresh: widget.recomUserStore == null); - _recomUserStore = RecomUserStore(controller: _refreshController); + _recomUserStore = + widget.recomUserStore ?? RecomUserStore(controller: _refreshController); if (widget.recomUserStore != null) { - _recomUserStore.users = widget.recomUserStore.users; + _recomUserStore.controller = _refreshController; } super.initState(); } @override void dispose() { + _recomUserStore?.controller = null; _refreshController?.dispose(); super.dispose(); } @@ -69,22 +71,35 @@ class _RecomUserPageState extends State { enablePullUp: true, onRefresh: () => _recomUserStore.fetch(), onLoading: () => _recomUserStore.next(), + footer: CustomFooter( + builder: (BuildContext context, LoadStatus mode) { + Widget body; + if (mode == LoadStatus.idle) { + body = Text(I18n.of(context).pull_up_to_load_more); + } else if (mode == LoadStatus.loading) { + body = CircularProgressIndicator(); + } else if (mode == LoadStatus.failed) { + body = Text(I18n.of(context).loading_failed_retry_message); + } else if (mode == LoadStatus.canLoading) { + body = Text(I18n.of(context).let_go_and_load_more); + } else { + body = Text(I18n.of(context).no_more_data); + } + return Container( + height: 55.0, + child: Center(child: body), + ); + }, + ), child: _recomUserStore.users.isNotEmpty - ? AnimationLimiter( - child: ListView.builder( - itemCount: _recomUserStore.users.length, - itemBuilder: (context, index) { - final data = _recomUserStore.users[index]; - return AnimationConfiguration.staggeredList( - position: index, - child: SlideAnimation( - child: PainterCard( - user: data, - ), - ), - ); - }), - ) + ? ListView.builder( + itemCount: _recomUserStore.users.length, + itemBuilder: (context, index) { + final data = _recomUserStore.users[index]; + return PainterCard( + user: data, + ); + }) : Container(), ), ); diff --git a/lib/page/hello/recom/recom_user_road.dart b/lib/page/hello/recom/recom_user_road.dart index 4002c2dcb..af5899ece 100644 --- a/lib/page/hello/recom/recom_user_road.dart +++ b/lib/page/hello/recom/recom_user_road.dart @@ -1,10 +1,15 @@ import 'package:flutter/material.dart'; +import 'package:flutter_staggered_animations/flutter_staggered_animations.dart'; import 'package:pixez/component/pixiv_image.dart'; import 'package:pixez/generated/l10n.dart'; import 'package:pixez/page/hello/recom/recom_user_page.dart'; import 'package:pixez/page/hello/recom/recom_user_store.dart'; class RecomUserRoad extends StatefulWidget { + final RecomUserStore recomUserStore; + + const RecomUserRoad({Key key, @required this.recomUserStore}) + : super(key: key); @override _RecomUserRoadState createState() => _RecomUserRoadState(); } @@ -13,7 +18,8 @@ class _RecomUserRoadState extends State { RecomUserStore _recomUserStore; @override void initState() { - _recomUserStore = RecomUserStore()..fetch(); + _recomUserStore = widget.recomUserStore ?? RecomUserStore() + ..fetch(); super.initState(); } @@ -22,7 +28,9 @@ class _RecomUserRoadState extends State { return InkWell( onTap: () { Navigator.of(context).push(MaterialPageRoute(builder: (context) { - return RecomUserPage(); + return RecomUserPage( + recomUserStore: _recomUserStore, + ); })); }, child: Container( @@ -40,21 +48,18 @@ class _RecomUserRoadState extends State { topLeft: Radius.circular(16.0)), color: Colors.transparent), child: _recomUserStore.users.isNotEmpty - ? ListView.builder( - itemCount: _recomUserStore.users.length + 1, - scrollDirection: Axis.horizontal, - itemBuilder: (context, index) { - if (index == 0) { - return Center( - child: Padding( - padding: EdgeInsets.only(right: 10.0), - child: Visibility( - visible: false, - child: - Text(I18n.of(context).painter)))); - } - return _buildUserList(index - 1); - }, + ? AnimationLimiter( + child: ListView.builder( + itemCount: _recomUserStore.users.length, + scrollDirection: Axis.horizontal, + itemBuilder: (context, index) { + return AnimationConfiguration.staggeredList( + position: index, + child: SlideAnimation( + horizontalOffset: 50.0, + child: _buildUserList(index))); + }, + ), ) : Container(), ), diff --git a/lib/page/hello/setting/setting_page.dart b/lib/page/hello/setting/setting_page.dart index 5c9385adb..5aa1a44b7 100644 --- a/lib/page/hello/setting/setting_page.dart +++ b/lib/page/hello/setting/setting_page.dart @@ -43,7 +43,6 @@ class SettingPage extends StatefulWidget { } class _SettingPageState extends State { - @override void initState() { super.initState(); @@ -242,22 +241,14 @@ class _SettingPageState extends State { Divider(), Column( children: [ - OpenContainer( - transitionType: ContainerTransitionType.fade, - closedColor: Colors.transparent, - closedElevation: 0.0, - openElevation: 0.0, - openBuilder: - (BuildContext context, VoidCallback _) { - return AboutPage(); - }, - closedShape: const RoundedRectangleBorder(), - closedBuilder: - (BuildContext _, VoidCallback openContainer) { - return ListTile( - leading: Icon(Icons.message), - title: Text(I18n.of(context).about), - ); + ListTile( + leading: Icon(Icons.message), + title: Text(I18n.of(context).about), + onTap: () { + Navigator.of(context) + .push(MaterialPageRoute(builder: (context) { + return AboutPage(); + })); }, ), Observer(builder: (context) { diff --git a/lib/page/search/suggest/search_suggestion_page.dart b/lib/page/search/suggest/search_suggestion_page.dart index 225d914db..cf5bf25c7 100644 --- a/lib/page/search/suggest/search_suggestion_page.dart +++ b/lib/page/search/suggest/search_suggestion_page.dart @@ -28,16 +28,16 @@ class SearchSuggestionPage extends StatefulWidget { final String preword; const SearchSuggestionPage({Key key, this.preword}) : super(key: key); + @override _SearchSuggestionPageState createState() => _SearchSuggestionPageState(); } -class _SearchSuggestionPageState extends State - with SingleTickerProviderStateMixin { +class _SearchSuggestionPageState extends State { TextEditingController _filter; - TabController _tabController; SuggestionStore _suggestionStore; SauceStore _sauceStore; + @override void initState() { _suggestionStore = SuggestionStore(); @@ -55,142 +55,91 @@ class _SearchSuggestionPageState extends State } }); _filter = TextEditingController(text: widget.preword ?? ''); - _tabController = TabController(length: 3, vsync: this); super.initState(); } @override void dispose() { _filter?.dispose(); - _tabController?.dispose(); super.dispose(); } + bool idV = false; + @override Widget build(BuildContext context) { - return Scaffold( - appBar: _buildAppBar(context), - body: Container( - child: Suggestions( - suggestionStore: _suggestionStore, - )), - floatingActionButton: FloatingActionButton( - onPressed: () { - _sauceStore.findImage(); - }, - child: Icon(Icons.add_photo_alternate), - ), - ); + return Observer(builder: (context) { + return Scaffold( + appBar: _buildAppBar(context), + body: Container( + child: CustomScrollView( + slivers: [ + SliverVisibility( + sliver: SliverList( + delegate: SliverChildBuilderDelegate((context, index) { + if (index == 0) + return ListTile( + title: Text(_filter.text ?? ''), + subtitle: Text(I18n.of(context).illust_id), + onTap: () { + Navigator.of(context).push(MaterialPageRoute( + builder: (context) => IllustPage( + id: int.tryParse(_filter.text), + ))); + }, + ); + return ListTile( + title: Text(_filter.text ?? ''), + subtitle: Text(I18n.of(context).painter_id), + onTap: () { + Navigator.of(context).push(MaterialPageRoute( + builder: (context) => UsersPage( + id: int.tryParse(_filter.text), + ))); + }, + ); + }, childCount: 2), + ), + visible: idV, + ), + if (_suggestionStore.autoWords != null && + _suggestionStore.autoWords.tags.isNotEmpty) + SliverList( + delegate: SliverChildBuilderDelegate((context, index) { + final tags = _suggestionStore.autoWords.tags; + return ListTile( + onTap: () { + FocusScope.of(context).unfocus(); + Navigator.of(context, rootNavigator: true) + .push(MaterialPageRoute(builder: (context) { + return ResultPage( + word: tags[index].name, + translatedName: tags[index].translated_name ?? '', + ); + })); + }, + title: Text(tags[index].name), + subtitle: Text(tags[index].translated_name ?? ""), + ); + }, childCount: _suggestionStore.autoWords.tags.length), + ), + ], + )), + floatingActionButton: FloatingActionButton( + onPressed: () { + _sauceStore.findImage(); + }, + child: Icon(Icons.add_photo_alternate), + ), + ); + }); } FocusNode focusNode = FocusNode(); AppBar _buildAppBar(context) { return AppBar( - title: TextField( - controller: _filter, - focusNode: focusNode, - autofocus: true, - onTap: () { - FocusScope.of(context).requestFocus(focusNode); - }, - onChanged: (query) { - if (query.startsWith('https://')) { - Uri uri = Uri.parse(query); - if (!uri.host.contains('pixiv')) { - return; - } - final segment = uri.pathSegments; - if (segment.length == 1 && query.contains("/member.php?id=")) { - final id = uri.queryParameters['id']; - Navigator.of(context, rootNavigator: true) - .push(MaterialPageRoute( - builder: (BuildContext context) => UsersPage( - id: int.parse(id), - ))); - _filter.clear(); - } - if (segment.length == 2) { - if (segment[0] == 'artworks') { - Navigator.of(context, rootNavigator: true).push( - MaterialPageRoute( - builder: (BuildContext context) => - IllustPage(id: int.parse(segment[1])))); - _filter.clear(); - } - if (segment[0] == 'users') { - Navigator.of(context, rootNavigator: true) - .push(MaterialPageRoute(builder: (BuildContext context) { - return UsersPage( - id: int.parse(segment[1]), - ); - })); - _filter.clear(); - } - } - } - var word = query.trim(); - if (word.isEmpty) return; - _suggestionStore.fetch(word); - }, - onSubmitted: (s) { - var word = s.trim(); - if (word.isEmpty) return; - switch (_tabController.index) { - case 0: - { - Navigator.of(context, rootNavigator: true) - .push(MaterialPageRoute( - builder: (context) => ResultPage( - word: word, - ))); - } - break; - case 1: - { - var id = int.tryParse(word); - if (id != null) { - Navigator.of(context, rootNavigator: true).push( - MaterialPageRoute(builder: (_) => IllustPage(id: id))); - } else { - _filter.clear(); - } - } - break; - case 2: - { - var id = int.tryParse(word); - if (id != null) { - Navigator.of(context, rootNavigator: true) - .push(MaterialPageRoute( - builder: (_) => UsersPage( - id: id, - ))); - } else { - _filter.clear(); - } - } - break; - } - }, - decoration: InputDecoration( - hintText: I18n.of(context).search_word_or_paste_link, - )), - bottom: TabBar( - indicatorSize: TabBarIndicatorSize.label, - controller: _tabController, - tabs: [ - Tab( - child: Text(I18n.of(context).key_word), - ), - Tab( - child: Text(I18n.of(context).illust_id), - ), - Tab( - child: Text(I18n.of(context).painter_id), - ), - ], - ), + title: _textField(context, TextInputType.text, focusNode), actions: [ IconButton( icon: Icon(Icons.close), @@ -201,10 +150,77 @@ class _SearchSuggestionPageState extends State ], ); } + + TextField _textField( + BuildContext context, TextInputType inputType, FocusNode node) { + return TextField( + controller: _filter, + focusNode: node, + keyboardType: inputType, + autofocus: true, + onTap: () { + FocusScope.of(context).requestFocus(node); + }, + onChanged: (query) { + bool isNum = int.tryParse(query) != null; + setState(() { + idV = isNum; + }); + if (query.startsWith('https://')) { + Uri uri = Uri.parse(query); + if (!uri.host.contains('pixiv')) { + return; + } + final segment = uri.pathSegments; + if (segment.length == 1 && query.contains("/member.php?id=")) { + final id = uri.queryParameters['id']; + Navigator.of(context, rootNavigator: true).push(MaterialPageRoute( + builder: (BuildContext context) => UsersPage( + id: int.parse(id), + ))); + _filter.clear(); + } + if (segment.length == 2) { + if (segment[0] == 'artworks') { + Navigator.of(context, rootNavigator: true).push( + MaterialPageRoute( + builder: (BuildContext context) => + IllustPage(id: int.parse(segment[1])))); + _filter.clear(); + } + if (segment[0] == 'users') { + Navigator.of(context, rootNavigator: true) + .push(MaterialPageRoute(builder: (BuildContext context) { + return UsersPage( + id: int.parse(segment[1]), + ); + })); + _filter.clear(); + } + } + } + var word = query.trim(); + if (word.isEmpty) return; + if (isNum && word.length > 5) return; //超过五个数字应该就不需要给建议了吧 + _suggestionStore.fetch(word); + }, + onSubmitted: (s) { + var word = s.trim(); + if (word.isEmpty) return; + Navigator.of(context, rootNavigator: true).push(MaterialPageRoute( + builder: (context) => ResultPage( + word: word, + ))); + }, + decoration: InputDecoration( + hintText: I18n.of(context).search_word_or_paste_link, + )); + } } class Suggestions extends StatefulWidget { final SuggestionStore suggestionStore; + const Suggestions({Key key, this.suggestionStore}) : super(key: key); @override diff --git a/lib/page/theme/theme_page.dart b/lib/page/theme/theme_page.dart index 038ee3df7..d39275a0b 100644 --- a/lib/page/theme/theme_page.dart +++ b/lib/page/theme/theme_page.dart @@ -123,7 +123,7 @@ class ThemePage extends StatefulWidget { _ThemePageState createState() => _ThemePageState(); } -class _ThemePageState extends State { +class _ThemePageState extends State with TickerProviderStateMixin { final skinList = [ ThemeData( brightness: Brightness.light, @@ -182,11 +182,8 @@ class _ThemePageState extends State { } } - int index = 0; - @override void initState() { - index = ThemeMode.values.indexOf(userSetting.themeMode); super.initState(); } @@ -200,22 +197,26 @@ class _ThemePageState extends State { body: ListView( children: [ Observer(builder: (context) { - return Padding( - padding: const EdgeInsets.all(8.0), - child: CupertinoSlidingSegmentedControl( - groupValue: index, - onValueChanged: (value) { - userSetting.setThemeMode(value); - setState(() { - this.index=value; - }); - }, - children: { - 0: Text(I18n.of(context).system), - 1: Text(I18n.of(context).light), - 2: Text(I18n.of(context).dark), - }, - ), + return Card( + child: TabBar( + controller: TabController( + length: 3, + initialIndex: + ThemeMode.values.indexOf(userSetting.themeMode), + vsync: this, + ), + onTap: (i) { + userSetting.setThemeMode(i); + }, + tabs: [ + Tab( + text: I18n.of(context).system, + ), + Tab( + text: I18n.of(context).light, + ), + Tab(text: I18n.of(context).dark) + ]), ); }), Card(