Update discovery page.

This commit is contained in:
stonegate 2020-09-14 22:51:05 +08:00
parent fa171ce307
commit 8ea216468a
6 changed files with 62 additions and 75 deletions

View File

@ -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<List<EpisodeBrief>> _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);

View File

@ -23,9 +23,7 @@ class DiscoveryPageState extends State<DiscoveryPage> {
Genre _selectedGenre;
Genre get selectedGenre => _selectedGenre;
final List<OnlinePodcast> _podcastList = [];
bool _loading;
Future _searchTopPodcast;
int _page;
Future<List<String>> _getSearchHistory() {
final storage = KeyValueStorage(searchHistoryKey);
final history = storage.getStringList();
@ -125,7 +123,6 @@ class DiscoveryPageState extends State<DiscoveryPage> {
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<DiscoveryPage> {
? SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
FutureBuilder<List<String>>(
future: _getSearchHistory(),
@ -147,13 +144,15 @@ class DiscoveryPageState extends State<DiscoveryPage> {
final history = snapshot.data;
return SizedBox(
height: 50,
child: Row(
child: Wrap(
direction: Axis.horizontal,
children: history
.map<Widget>((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<DiscoveryPage> {
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<List<OnlinePodcast>>(
@ -200,8 +205,11 @@ class DiscoveryPageState extends State<DiscoveryPage> {
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<DiscoveryPage> {
);
}),
),
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<Widget>((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) {

View File

@ -108,6 +108,7 @@ class MyHomePageDelegate extends SearchDelegate<int> {
icon: const Icon(Icons.clear),
onPressed: () {
query = '';
showResults(context);
},
),
];
@ -122,18 +123,6 @@ class MyHomePageDelegate extends SearchDelegate<int> {
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<RssResult> {
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<SearchList> {
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<SearchResultDetail>
return _episodeList;
}
_start(DragStartDetails event) {
void _start(DragStartDetails event) {
setState(() {
_startdy = event.localPosition.dy;
_animation =
@ -632,7 +588,7 @@ class _SearchResultDetailState extends State<SearchResultDetail>
_controller.forward();
}
_update(DragUpdateDetails event) {
void _update(DragUpdateDetails event) {
setState(() {
_move = _startdy - event.localPosition.dy;
_animation = Tween<double>(begin: _initSize, end: _initSize + _move)
@ -642,7 +598,7 @@ class _SearchResultDetailState extends State<SearchResultDetail>
_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<GroupList>();
final searchState = context.watch<SearchState>();
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),

View File

@ -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'];

View File

@ -3,7 +3,7 @@ import '../type/searchpodcast.dart';
class SearchState extends ChangeNotifier {
final List<OnlinePodcast> _subscribedList = [];
bool _update;
bool _update = false;
List<OnlinePodcast> get subscribedList => _subscribedList;
bool get update => _update;
OnlinePodcast _selectedPodcast;

View File

@ -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'),
];