From 8ea216468aba7b286229d4d035e91672de5f4f91 Mon Sep 17 00:00:00 2001 From: stonegate Date: Mon, 14 Sep 2020 22:51:05 +0800 Subject: [PATCH] Update discovery page. --- lib/home/home.dart | 9 +++-- lib/home/pocast_discovery.dart | 48 ++++++++++++++++++++------ lib/home/search_podcast.dart | 62 +++++----------------------------- lib/service/api_search.dart | 2 +- lib/state/search_state.dart | 2 +- lib/type/search_genre.dart | 14 ++++---- 6 files changed, 62 insertions(+), 75 deletions(-) diff --git a/lib/home/home.dart b/lib/home/home.dart index f104911..cd7849f 100644 --- a/lib/home/home.dart +++ b/lib/home/home.dart @@ -8,7 +8,6 @@ import 'package:flutter/services.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:line_icons/line_icons.dart'; import 'package:provider/provider.dart'; -import 'package:tsacdop/state/search_state.dart'; import 'package:tuple/tuple.dart'; import '../local_storage/key_value_storage.dart'; @@ -1282,7 +1281,7 @@ class _MyDownload extends StatefulWidget { class _MyDownloadState extends State<_MyDownload> with AutomaticKeepAliveClientMixin { Layout _layout; - int _sortBy = 0; + int _sortBy; bool _hideListened; Future> _getDownloadedEpisodes(int sortBy, {bool hideListened}) async { @@ -1299,6 +1298,12 @@ class _MyDownloadState extends State<_MyDownload> return episodes; } + @override + void initState() { + super.initState(); + _sortBy = 0; + } + @override Widget build(BuildContext context) { super.build(context); diff --git a/lib/home/pocast_discovery.dart b/lib/home/pocast_discovery.dart index f9c0613..e42f497 100644 --- a/lib/home/pocast_discovery.dart +++ b/lib/home/pocast_discovery.dart @@ -23,9 +23,7 @@ class DiscoveryPageState extends State { Genre _selectedGenre; Genre get selectedGenre => _selectedGenre; final List _podcastList = []; - bool _loading; Future _searchTopPodcast; - int _page; Future> _getSearchHistory() { final storage = KeyValueStorage(searchHistoryKey); final history = storage.getStringList(); @@ -125,7 +123,6 @@ class DiscoveryPageState extends State { final podcastTopList = searchResult.podcasts.map((e) => e?.toOnlinePodcast).toList(); _podcastList.addAll(podcastTopList.cast()); - _loading = false; return _podcastList; } @@ -137,7 +134,7 @@ class DiscoveryPageState extends State { ? SingleChildScrollView( child: Column( mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, children: [ FutureBuilder>( future: _getSearchHistory(), @@ -147,13 +144,15 @@ class DiscoveryPageState extends State { final history = snapshot.data; return SizedBox( height: 50, - child: Row( + child: Wrap( + direction: Axis.horizontal, children: history .map((e) => Padding( - padding: const EdgeInsets.all(8.0), + padding: const EdgeInsets.fromLTRB( + 8, 8, 0, 8), child: FlatButton.icon( - color: Colors.accents[ - math.Random().nextInt(10)] + color: Colors + .accents[history.indexOf(e)] .withAlpha(70), shape: RoundedRectangleBorder( borderRadius: @@ -175,6 +174,12 @@ class DiscoveryPageState extends State { height: 1, ); }), + Padding( + padding: EdgeInsets.fromLTRB(20, 10, 10, 4), + child: Text('Popular', + style: context.textTheme.headline6 + .copyWith(color: context.accentColor)), + ), SizedBox( height: 200, child: FutureBuilder>( @@ -200,8 +205,11 @@ class DiscoveryPageState extends State { BorderRadius.circular(10), clipBehavior: Clip.hardEdge, child: InkWell( - onTap: () => searchState - .selectedPodcast = podcast, + onTap: () { + searchState.selectedPodcast = + podcast; + widget.onTap(''); + }, child: Padding( padding: const EdgeInsets.all(4.0), @@ -254,12 +262,22 @@ class DiscoveryPageState extends State { ); }), ), + Padding( + padding: EdgeInsets.fromLTRB(20, 10, 10, 4), + child: Text('Categories', + style: context.textTheme.headline6 + .copyWith(color: context.accentColor)), + ), ListView( shrinkWrap: true, physics: NeverScrollableScrollPhysics(), children: genres .map((e) => ListTile( - onTap: () => setState(() => _selectedGenre = e), + contentPadding: EdgeInsets.fromLTRB(20, 0, 20, 0), + onTap: () { + widget.onTap(''); + setState(() => _selectedGenre = e); + }, title: Text(e.name), )) .toList(), @@ -331,6 +349,14 @@ class __TopPodcastListState extends State<_TopPodcastList> { final content = snapshot.data; return CustomScrollView( slivers: [ + SliverToBoxAdapter( + child: Padding( + padding: EdgeInsets.fromLTRB(20, 10, 10, 4), + child: Text(widget.genre.name, + style: context.textTheme.headline6 + .copyWith(color: context.accentColor)), + ), + ), SliverList( delegate: SliverChildBuilderDelegate( (context, index) { diff --git a/lib/home/search_podcast.dart b/lib/home/search_podcast.dart index 7f3698f..c0ac3e9 100644 --- a/lib/home/search_podcast.dart +++ b/lib/home/search_podcast.dart @@ -108,6 +108,7 @@ class MyHomePageDelegate extends SearchDelegate { icon: const Icon(Icons.clear), onPressed: () { query = ''; + showResults(context); }, ), ]; @@ -122,18 +123,6 @@ class MyHomePageDelegate extends SearchDelegate { query = history; showResults(context); }); - // return Container( - // height: 10, - // width: 10, - // margin: EdgeInsets.only(top: 400), - // child: SizedBox( - // height: 10, - // child: Image.asset( - // 'assets/listennotes.png', - // fit: BoxFit.fill, - // ), - // ), - // ); } else if (rssExp.stringMatch(query) != null) { return FutureBuilder( future: getRss(rssExp.stringMatch(query)), @@ -222,40 +211,7 @@ class _RssResultState extends State { overflow: TextOverflow.ellipsis, style: context.textTheme.headline5), ), - !_isSubscribed - ? OutlineButton( - highlightedBorderColor: context.accentColor, - borderSide: BorderSide( - color: context.accentColor, width: 2), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(100.0), - side: - BorderSide(color: context.accentColor)), - splashColor: - context.accentColor.withOpacity(0.5), - child: Text(s.subscribe, - style: - TextStyle(color: context.accentColor)), - onPressed: () { - _subscribePodcast(_onlinePodcast); - setState(() { - _isSubscribed = true; - }); - Fluttertoast.showToast( - msg: s.podcastSubscribed, - gravity: ToastGravity.BOTTOM, - ); - }) - : OutlineButton( - color: context.accentColor.withOpacity(0.5), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(100.0), - side: BorderSide(color: Colors.grey[500])), - highlightedBorderColor: Colors.grey[500], - disabledTextColor: Colors.grey[500], - child: Text(s.subscribe), - disabledBorderColor: Colors.grey[500], - onPressed: () {}) + SubscribeButton(_onlinePodcast), ], ), ), @@ -400,7 +356,7 @@ class _SearchListState extends State { final storage = KeyValueStorage(searchHistoryKey); final history = await storage.getStringList(); if (!history.contains(query)) { - if (history.length == 10) { + if (history.length >= 6) { history.removeLast(); } history.insert(0, query); @@ -623,7 +579,7 @@ class _SearchResultDetailState extends State return _episodeList; } - _start(DragStartDetails event) { + void _start(DragStartDetails event) { setState(() { _startdy = event.localPosition.dy; _animation = @@ -632,7 +588,7 @@ class _SearchResultDetailState extends State _controller.forward(); } - _update(DragUpdateDetails event) { + void _update(DragUpdateDetails event) { setState(() { _move = _startdy - event.localPosition.dy; _animation = Tween(begin: _initSize, end: _initSize + _move) @@ -642,7 +598,7 @@ class _SearchResultDetailState extends State _controller.forward(); } - _end() { + void _end() { if (_slideDirection == SlideDirection.up) { if (_move > 20) { setState(() { @@ -920,7 +876,7 @@ class SubscribeButton extends StatelessWidget { final subscribeWorker = context.watch(); final searchState = context.watch(); final s = context.s; - subscribePodcast(OnlinePodcast podcast) { + void subscribePodcast(OnlinePodcast podcast) { var item = SubscribeItem(podcast.rss, podcast.title, imgUrl: podcast.image, group: 'Home'); subscribeWorker.setSubscribeItem(item); @@ -940,12 +896,12 @@ class SubscribeButton extends StatelessWidget { child: Text(s.subscribe, style: TextStyle(color: context.accentColor)), onPressed: () { - subscribePodcast(onlinePodcast); - searchState.addPodcast(onlinePodcast); Fluttertoast.showToast( msg: s.podcastSubscribed, gravity: ToastGravity.BOTTOM, ); + subscribePodcast(onlinePodcast); + searchState.addPodcast(onlinePodcast); }) : OutlineButton( color: context.accentColor.withOpacity(0.5), diff --git a/lib/service/api_search.dart b/lib/service/api_search.dart index 2c5b177..04ea042 100644 --- a/lib/service/api_search.dart +++ b/lib/service/api_search.dart @@ -3,9 +3,9 @@ import 'dart:convert'; import 'package:dio/dio.dart'; import '../.env.dart'; +import '../type/search_top_podcast.dart'; import '../type/searchepisodes.dart'; import '../type/searchpodcast.dart'; -import '../type/search_top_podcast.dart'; class SearchEngine { final apiKey = environment['apiKey']; diff --git a/lib/state/search_state.dart b/lib/state/search_state.dart index cc4e481..0246fb1 100644 --- a/lib/state/search_state.dart +++ b/lib/state/search_state.dart @@ -3,7 +3,7 @@ import '../type/searchpodcast.dart'; class SearchState extends ChangeNotifier { final List _subscribedList = []; - bool _update; + bool _update = false; List get subscribedList => _subscribedList; bool get update => _update; OnlinePodcast _selectedPodcast; diff --git a/lib/type/search_genre.dart b/lib/type/search_genre.dart index a5822e7..87ef91b 100644 --- a/lib/type/search_genre.dart +++ b/lib/type/search_genre.dart @@ -5,25 +5,25 @@ class Genre { } var genres = [ + Genre(id: '100', name: 'Arts'), + Genre(id: '99', name: 'News'), Genre(id: '144', name: 'Personal Finance'), Genre(id: '151', name: 'Locally Focused'), + Genre(id: '107', name: 'Science'), + Genre(id: '77', name: 'Sports'), + Genre(id: '134', name: 'Music'), + Genre(id: '125', name: 'History'), Genre(id: '68', name: 'TV & Film'), Genre(id: '127', name: 'Technology'), Genre(id: '135', name: 'True Crime'), - Genre(id: '100', name: 'Arts'), Genre(id: '93', name: 'Business'), Genre(id: '67', name: 'Comedy'), Genre(id: '111', name: 'Education'), Genre(id: '168', name: 'Fiction'), - Genre(id: '117', name: 'Government'), Genre(id: '88', name: 'Health & Fitness'), - Genre(id: '125', name: 'History'), Genre(id: '132', name: 'Kids & Family'), Genre(id: '82', name: 'Leisure'), - Genre(id: '134', name: 'Music'), - Genre(id: '99', name: 'News'), Genre(id: '69', name: 'Religion & Spirituality'), - Genre(id: '107', name: 'Science'), Genre(id: '122', name: 'Society & Culture'), - Genre(id: '77', name: 'Sports'), + Genre(id: '117', name: 'Government'), ];