2020-02-11 14:48:11 +01:00
|
|
|
import 'dart:async';
|
2020-04-18 06:48:02 +02:00
|
|
|
import 'dart:math' as math;
|
2020-02-11 14:01:57 +01:00
|
|
|
|
2020-07-26 12:20:42 +02:00
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
2020-02-09 13:29:09 +01:00
|
|
|
import 'package:dio/dio.dart';
|
2020-07-26 12:20:42 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2020-02-21 16:04:02 +01:00
|
|
|
import 'package:flutter/services.dart';
|
2020-07-22 11:34:32 +02:00
|
|
|
import 'package:flutter_html/flutter_html.dart';
|
2020-02-12 17:10:03 +01:00
|
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
2020-07-26 12:20:42 +02:00
|
|
|
import 'package:provider/provider.dart';
|
2020-09-14 11:51:04 +02:00
|
|
|
import 'package:webfeed/webfeed.dart';
|
2020-04-22 20:10:57 +02:00
|
|
|
|
2020-09-14 11:51:04 +02:00
|
|
|
import '../local_storage/key_value_storage.dart';
|
2020-09-23 16:19:07 +02:00
|
|
|
import '../service/search_api.dart';
|
2020-07-14 17:45:45 +02:00
|
|
|
import '../state/podcast_group.dart';
|
2020-09-14 11:51:04 +02:00
|
|
|
import '../state/search_state.dart';
|
2020-09-23 16:19:07 +02:00
|
|
|
import '../type/search_api/searchepisodes.dart';
|
|
|
|
import '../type/search_api/searchpodcast.dart';
|
2020-09-29 19:25:44 +02:00
|
|
|
import '../util/custom_widget.dart';
|
2020-07-22 11:34:32 +02:00
|
|
|
import '../util/extension_helper.dart';
|
2020-09-14 11:51:04 +02:00
|
|
|
import 'pocast_discovery.dart';
|
2020-02-09 13:29:09 +01:00
|
|
|
|
2020-04-29 19:32:45 +02:00
|
|
|
class MyHomePageDelegate extends SearchDelegate<int> {
|
|
|
|
final String searchFieldLabel;
|
2020-09-14 11:51:04 +02:00
|
|
|
final GlobalKey<DiscoveryPageState> _discoveryKey =
|
|
|
|
GlobalKey<DiscoveryPageState>();
|
2020-04-29 19:32:45 +02:00
|
|
|
MyHomePageDelegate({this.searchFieldLabel})
|
2020-05-26 09:21:14 +02:00
|
|
|
: super(
|
2020-06-02 16:05:49 +02:00
|
|
|
searchFieldLabel: searchFieldLabel,
|
|
|
|
);
|
2020-09-29 19:25:44 +02:00
|
|
|
var _searchEngine;
|
|
|
|
static Future _getRss(String url) async {
|
2020-04-18 06:48:02 +02:00
|
|
|
try {
|
2020-09-29 19:25:44 +02:00
|
|
|
final options = BaseOptions(
|
|
|
|
connectTimeout: 30000,
|
|
|
|
receiveTimeout: 90000,
|
2020-04-18 06:48:02 +02:00
|
|
|
);
|
2020-07-26 12:20:42 +02:00
|
|
|
var response = await Dio(options).get(url);
|
2020-07-22 11:34:32 +02:00
|
|
|
return RssFeed.parse(response.data);
|
2020-04-18 06:48:02 +02:00
|
|
|
} catch (e) {
|
2020-07-26 12:20:42 +02:00
|
|
|
rethrow;
|
2020-04-18 06:48:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-29 19:25:44 +02:00
|
|
|
Future<SearchEngine> _getSearchEngine() async {
|
|
|
|
final storage = KeyValueStorage(searchEngineKey);
|
2020-10-01 13:42:52 +02:00
|
|
|
final index = await storage.getInt();
|
2020-09-29 19:25:44 +02:00
|
|
|
if (_searchEngine == null) {
|
|
|
|
_searchEngine = SearchEngine.values[index];
|
|
|
|
}
|
|
|
|
return _searchEngine;
|
|
|
|
}
|
|
|
|
|
2020-04-18 06:48:02 +02:00
|
|
|
RegExp rssExp = RegExp(r'^(https?):\/\/(.*)');
|
2020-09-29 19:25:44 +02:00
|
|
|
|
2020-07-04 16:42:56 +02:00
|
|
|
Widget invalidRss(BuildContext context) => Container(
|
2020-04-18 06:48:02 +02:00
|
|
|
height: 50,
|
|
|
|
alignment: Alignment.center,
|
2020-07-04 16:42:56 +02:00
|
|
|
child: Text(context.s.searchInvalidRss),
|
2020-04-18 06:48:02 +02:00
|
|
|
);
|
|
|
|
|
2020-09-14 11:51:04 +02:00
|
|
|
@override
|
|
|
|
void close(BuildContext context, int result) {
|
|
|
|
final selectedPodcast = context.read<SearchState>().selectedPodcast;
|
|
|
|
if (selectedPodcast != null) {
|
|
|
|
context.read<SearchState>().clearSelect();
|
|
|
|
} else {
|
|
|
|
if (_discoveryKey.currentState?.selectedGenre != null) {
|
|
|
|
_discoveryKey.currentState.backToHome();
|
|
|
|
} else {
|
|
|
|
context.read<SearchState>().clearList();
|
|
|
|
super.close(context, result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-22 13:25:06 +01:00
|
|
|
@override
|
2020-02-23 14:20:07 +01:00
|
|
|
ThemeData appBarTheme(BuildContext context) => Theme.of(context);
|
2020-02-09 13:29:09 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget buildLeading(BuildContext context) {
|
2020-09-14 11:51:04 +02:00
|
|
|
return WillPopScope(
|
|
|
|
onWillPop: () async {
|
|
|
|
close(context, null);
|
|
|
|
return false;
|
2020-02-09 13:29:09 +01:00
|
|
|
},
|
2020-09-14 11:51:04 +02:00
|
|
|
child: IconButton(
|
|
|
|
tooltip: context.s.back,
|
2020-10-09 17:59:29 +02:00
|
|
|
splashRadius: 25,
|
2020-09-14 11:51:04 +02:00
|
|
|
icon: AnimatedIcon(
|
|
|
|
icon: AnimatedIcons.menu_arrow,
|
|
|
|
progress: transitionAnimation,
|
|
|
|
),
|
|
|
|
onPressed: () {
|
|
|
|
close(context, 1);
|
|
|
|
},
|
|
|
|
),
|
2020-02-09 13:29:09 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget buildSuggestions(BuildContext context) {
|
2020-09-14 11:51:04 +02:00
|
|
|
return DiscoveryPage(
|
|
|
|
key: _discoveryKey,
|
|
|
|
onTap: (history) {
|
|
|
|
query = history;
|
|
|
|
showResults(context);
|
|
|
|
},
|
|
|
|
);
|
2020-02-09 13:29:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
List<Widget> buildActions(BuildContext context) {
|
|
|
|
return <Widget>[
|
2020-09-29 19:25:44 +02:00
|
|
|
if (query.isNotEmpty)
|
2020-02-09 13:29:09 +01:00
|
|
|
IconButton(
|
2020-07-04 16:42:56 +02:00
|
|
|
tooltip: context.s.clear,
|
2020-10-09 17:59:29 +02:00
|
|
|
splashRadius: 25,
|
2020-02-09 13:29:09 +01:00
|
|
|
icon: const Icon(Icons.clear),
|
|
|
|
onPressed: () {
|
|
|
|
query = '';
|
2020-09-14 16:51:05 +02:00
|
|
|
showResults(context);
|
2020-02-09 13:29:09 +01:00
|
|
|
},
|
|
|
|
),
|
2020-09-29 19:25:44 +02:00
|
|
|
FutureBuilder<SearchEngine>(
|
|
|
|
future: _getSearchEngine(),
|
|
|
|
initialData: SearchEngine.podcastIndex,
|
|
|
|
builder: (context, snapshot) => PopupMenuButton<SearchEngine>(
|
|
|
|
shape:
|
|
|
|
RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
|
|
|
elevation: 1,
|
2020-09-30 18:15:41 +02:00
|
|
|
icon: SizedBox(
|
|
|
|
height: 30,
|
|
|
|
width: 30,
|
|
|
|
child: CircleAvatar(
|
|
|
|
backgroundImage: snapshot.data == SearchEngine.podcastIndex
|
|
|
|
? AssetImage('assets/podcastindex_logo.png')
|
|
|
|
: AssetImage('assets/listennotes_logo.png'),
|
|
|
|
maxRadius: 25,
|
|
|
|
),
|
|
|
|
),
|
2020-09-29 19:25:44 +02:00
|
|
|
onSelected: (value) {
|
|
|
|
_searchEngine = value;
|
|
|
|
showSuggestions(context);
|
|
|
|
if (query != '') {
|
|
|
|
showResults(context);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
itemBuilder: (context) => [
|
|
|
|
PopupMenuItem(
|
2020-10-01 10:51:45 +02:00
|
|
|
value: SearchEngine.podcastIndex,
|
2020-09-29 19:25:44 +02:00
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.only(left: 10),
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
2020-10-01 10:51:45 +02:00
|
|
|
Text('Podcastindex'),
|
2020-09-29 19:25:44 +02:00
|
|
|
Spacer(),
|
2020-10-01 10:51:45 +02:00
|
|
|
if (_searchEngine == SearchEngine.podcastIndex)
|
2020-09-29 19:25:44 +02:00
|
|
|
DotIndicator()
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
PopupMenuItem(
|
2020-10-01 10:51:45 +02:00
|
|
|
value: SearchEngine.listenNotes,
|
2020-09-29 19:25:44 +02:00
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.only(left: 10),
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
2020-10-01 10:51:45 +02:00
|
|
|
Text('ListenNotes'),
|
2020-09-29 19:25:44 +02:00
|
|
|
Spacer(),
|
2020-10-01 10:51:45 +02:00
|
|
|
if (_searchEngine == SearchEngine.listenNotes)
|
2020-09-29 19:25:44 +02:00
|
|
|
DotIndicator()
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2020-09-30 18:15:41 +02:00
|
|
|
SizedBox(width: 10),
|
2020-02-09 13:29:09 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget buildResults(BuildContext context) {
|
2020-07-26 12:20:42 +02:00
|
|
|
if (query.isEmpty) {
|
2020-09-14 11:51:04 +02:00
|
|
|
return DiscoveryPage(
|
|
|
|
key: _discoveryKey,
|
|
|
|
onTap: (history) {
|
|
|
|
query = history;
|
|
|
|
showResults(context);
|
|
|
|
});
|
2020-07-26 12:20:42 +02:00
|
|
|
} else if (rssExp.stringMatch(query) != null) {
|
2020-04-18 06:48:02 +02:00
|
|
|
return FutureBuilder(
|
2020-09-29 19:25:44 +02:00
|
|
|
future: _getRss(rssExp.stringMatch(query)),
|
2020-04-18 06:48:02 +02:00
|
|
|
builder: (context, snapshot) {
|
2020-07-26 12:20:42 +02:00
|
|
|
if (snapshot.hasError) {
|
2020-07-04 16:42:56 +02:00
|
|
|
return invalidRss(context);
|
2020-07-26 12:20:42 +02:00
|
|
|
} else if (snapshot.hasData) {
|
2020-07-22 11:34:32 +02:00
|
|
|
return RssResult(
|
|
|
|
url: rssExp.stringMatch(query),
|
|
|
|
rssFeed: snapshot.data,
|
2020-02-09 13:29:09 +01:00
|
|
|
);
|
2020-07-26 12:20:42 +02:00
|
|
|
} else {
|
2020-04-18 06:48:02 +02:00
|
|
|
return Container(
|
|
|
|
padding: EdgeInsets.only(top: 200),
|
|
|
|
alignment: Alignment.topCenter,
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
);
|
2020-07-26 12:20:42 +02:00
|
|
|
}
|
2020-04-18 06:48:02 +02:00
|
|
|
},
|
|
|
|
);
|
2020-07-26 12:20:42 +02:00
|
|
|
} else {
|
2020-09-29 19:25:44 +02:00
|
|
|
switch (_searchEngine) {
|
|
|
|
case SearchEngine.listenNotes:
|
|
|
|
return _ListenNotesSearch(query: query);
|
|
|
|
break;
|
|
|
|
case SearchEngine.podcastIndex:
|
|
|
|
return _PodcastIndexSearch(query: query);
|
|
|
|
default:
|
|
|
|
return Center();
|
|
|
|
break;
|
|
|
|
}
|
2020-07-26 12:20:42 +02:00
|
|
|
}
|
2020-07-22 11:34:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class RssResult extends StatefulWidget {
|
|
|
|
RssResult({this.url, this.rssFeed, Key key}) : super(key: key);
|
|
|
|
final RssFeed rssFeed;
|
|
|
|
final String url;
|
|
|
|
@override
|
|
|
|
_RssResultState createState() => _RssResultState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _RssResultState extends State<RssResult> {
|
|
|
|
OnlinePodcast _onlinePodcast;
|
|
|
|
int _loadItems;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
var p = widget.rssFeed;
|
|
|
|
_loadItems = 10;
|
|
|
|
_onlinePodcast = OnlinePodcast(
|
|
|
|
rss: widget.url,
|
|
|
|
title: p.title,
|
|
|
|
publisher: p.author,
|
|
|
|
description: p.description,
|
|
|
|
image: p.itunes.image.href,
|
|
|
|
count: p.items.length);
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final s = context.s;
|
|
|
|
var items = widget.rssFeed.items;
|
|
|
|
return DefaultTabController(
|
|
|
|
length: 2,
|
|
|
|
child: Column(
|
|
|
|
children: [
|
2020-08-14 14:12:44 +02:00
|
|
|
SizedBox(
|
|
|
|
height: 140,
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 20),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
|
|
|
child: Text(_onlinePodcast.title,
|
|
|
|
maxLines: 2,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
style: context.textTheme.headline5),
|
2020-07-22 11:34:32 +02:00
|
|
|
),
|
2020-09-14 16:51:05 +02:00
|
|
|
SubscribeButton(_onlinePodcast),
|
2020-08-14 14:12:44 +02:00
|
|
|
],
|
2020-07-22 11:34:32 +02:00
|
|
|
),
|
2020-08-14 14:12:44 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
CachedNetworkImage(
|
|
|
|
height: 120.0,
|
|
|
|
width: 120.0,
|
|
|
|
fit: BoxFit.fitWidth,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
imageUrl: _onlinePodcast.image,
|
|
|
|
progressIndicatorBuilder: (context, url, downloadProgress) =>
|
|
|
|
Container(
|
|
|
|
height: 120,
|
|
|
|
width: 120,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
color: context.primaryColorDark,
|
|
|
|
child: SizedBox(
|
|
|
|
width: 40,
|
|
|
|
height: 2,
|
|
|
|
child: LinearProgressIndicator(
|
|
|
|
value: downloadProgress.progress),
|
2020-07-24 19:56:42 +02:00
|
|
|
),
|
2020-08-14 14:12:44 +02:00
|
|
|
),
|
|
|
|
errorWidget: (context, url, error) => Container(
|
|
|
|
width: 120,
|
|
|
|
height: 120,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
color: context.primaryColorDark,
|
|
|
|
child: Icon(Icons.error)),
|
2020-07-22 11:34:32 +02:00
|
|
|
),
|
2020-08-14 14:12:44 +02:00
|
|
|
],
|
|
|
|
),
|
2020-07-22 11:34:32 +02:00
|
|
|
),
|
2020-08-14 14:12:44 +02:00
|
|
|
Container(
|
|
|
|
height: 50,
|
|
|
|
color: context.scaffoldBackgroundColor,
|
|
|
|
child: TabBar(
|
|
|
|
indicatorColor: context.accentColor,
|
|
|
|
labelColor: context.textColor,
|
|
|
|
indicatorWeight: 3,
|
|
|
|
indicatorSize: TabBarIndicatorSize.label,
|
|
|
|
tabs: [
|
|
|
|
Text(s.homeToprightMenuAbout),
|
|
|
|
Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
Text(s.episode(2)),
|
|
|
|
SizedBox(width: 2),
|
|
|
|
Container(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
left: 5, right: 5, top: 2, bottom: 2),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: context.accentColor,
|
|
|
|
borderRadius: BorderRadius.circular(100)),
|
|
|
|
child: Text(_onlinePodcast.count.toString(),
|
|
|
|
style: TextStyle(color: Colors.white)))
|
|
|
|
],
|
|
|
|
)
|
|
|
|
]),
|
2020-07-22 11:34:32 +02:00
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: TabBarView(children: [
|
2020-07-22 14:39:25 +02:00
|
|
|
ListView(
|
|
|
|
children: [
|
2020-07-24 19:56:42 +02:00
|
|
|
Align(
|
|
|
|
alignment: Alignment.topLeft,
|
|
|
|
child: Html(
|
|
|
|
onLinkTap: (url) {
|
|
|
|
url.launchUrl;
|
|
|
|
},
|
|
|
|
linkStyle: TextStyle(
|
|
|
|
color: context.accentColor,
|
|
|
|
// decoration: TextDecoration.underline,
|
|
|
|
textBaseline: TextBaseline.ideographic),
|
|
|
|
shrinkToFit: true,
|
|
|
|
data: _onlinePodcast.description,
|
|
|
|
padding:
|
|
|
|
EdgeInsets.only(left: 20.0, right: 20, bottom: 20),
|
|
|
|
defaultTextStyle: TextStyle(
|
|
|
|
height: 1.8,
|
|
|
|
),
|
2020-07-22 14:39:25 +02:00
|
|
|
),
|
2020-07-22 11:34:32 +02:00
|
|
|
),
|
2020-07-22 14:39:25 +02:00
|
|
|
],
|
2020-07-22 11:34:32 +02:00
|
|
|
),
|
|
|
|
ListView.builder(
|
|
|
|
itemCount: math.min(_loadItems + 1, items.length),
|
|
|
|
itemBuilder: (context, index) {
|
2020-07-26 12:20:42 +02:00
|
|
|
if (index == _loadItems) {
|
2020-07-22 11:34:32 +02:00
|
|
|
return Container(
|
|
|
|
padding: const EdgeInsets.only(top: 10.0, bottom: 20.0),
|
|
|
|
alignment: Alignment.center,
|
2020-08-01 17:10:43 +02:00
|
|
|
child: OutlineButton(
|
|
|
|
highlightedBorderColor: context.accentColor,
|
|
|
|
splashColor: context.accentColor.withOpacity(0.5),
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius:
|
|
|
|
BorderRadius.all(Radius.circular(100))),
|
|
|
|
child: Text(context.s.loadMore),
|
|
|
|
onPressed: () => setState(
|
|
|
|
() => _loadItems += 10,
|
2020-07-22 11:34:32 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2020-07-26 12:20:42 +02:00
|
|
|
}
|
2020-07-22 11:34:32 +02:00
|
|
|
return ListTile(
|
|
|
|
title: Text(items[index].title),
|
|
|
|
subtitle: Text('${items[index].pubDate}',
|
|
|
|
style: TextStyle(color: context.accentColor)),
|
|
|
|
);
|
|
|
|
})
|
|
|
|
]),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
2020-06-02 16:05:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-29 19:25:44 +02:00
|
|
|
class _ListenNotesSearch extends StatefulWidget {
|
2020-06-02 16:05:49 +02:00
|
|
|
final String query;
|
2020-09-29 19:25:44 +02:00
|
|
|
_ListenNotesSearch({this.query, Key key}) : super(key: key);
|
2020-06-02 16:05:49 +02:00
|
|
|
|
|
|
|
@override
|
2020-09-29 19:25:44 +02:00
|
|
|
__ListenNotesSearchState createState() => __ListenNotesSearchState();
|
2020-06-02 16:05:49 +02:00
|
|
|
}
|
|
|
|
|
2020-09-29 19:25:44 +02:00
|
|
|
class __ListenNotesSearchState extends State<_ListenNotesSearch> {
|
2020-07-22 11:34:32 +02:00
|
|
|
int _nextOffset = 0;
|
2020-07-26 12:20:42 +02:00
|
|
|
final List<OnlinePodcast> _podcastList = [];
|
2020-06-02 16:05:49 +02:00
|
|
|
int _offset;
|
2020-10-01 11:32:39 +02:00
|
|
|
bool _loading = false;
|
|
|
|
bool _loadError = false;
|
2020-07-22 11:34:32 +02:00
|
|
|
Future _searchFuture;
|
2020-09-14 11:51:04 +02:00
|
|
|
|
2020-06-02 16:05:49 +02:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2020-09-29 19:25:44 +02:00
|
|
|
_searchFuture = _getListenNotesList(widget.query, _nextOffset);
|
2020-06-02 16:05:49 +02:00
|
|
|
}
|
|
|
|
|
2020-09-14 11:51:04 +02:00
|
|
|
Future<void> _saveHistory(String query) async {
|
|
|
|
final storage = KeyValueStorage(searchHistoryKey);
|
|
|
|
final history = await storage.getStringList();
|
|
|
|
if (!history.contains(query)) {
|
2020-09-14 16:51:05 +02:00
|
|
|
if (history.length >= 6) {
|
2020-09-14 11:51:04 +02:00
|
|
|
history.removeLast();
|
|
|
|
}
|
|
|
|
history.insert(0, query);
|
|
|
|
await storage.saveStringList(history);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-29 19:25:44 +02:00
|
|
|
Future<List<OnlinePodcast>> _getListenNotesList(
|
2020-07-22 11:34:32 +02:00
|
|
|
String searchText, int nextOffset) async {
|
2020-09-14 11:51:04 +02:00
|
|
|
if (nextOffset == 0) _saveHistory(searchText);
|
2020-09-23 16:19:07 +02:00
|
|
|
final searchEngine = ListenNotesSearch();
|
2020-10-01 11:32:39 +02:00
|
|
|
var searchResult;
|
|
|
|
try {
|
|
|
|
searchResult = await searchEngine.searchPodcasts(
|
|
|
|
searchText: searchText, nextOffset: nextOffset);
|
|
|
|
} catch (e) {
|
2020-10-01 11:47:25 +02:00
|
|
|
_loadError = true;
|
2020-10-01 11:32:39 +02:00
|
|
|
_loading = false;
|
|
|
|
return [];
|
|
|
|
}
|
2020-06-02 16:05:49 +02:00
|
|
|
_offset = searchResult.nextOffset;
|
|
|
|
_podcastList.addAll(searchResult.results.cast());
|
|
|
|
_loading = false;
|
|
|
|
return _podcastList;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-09-14 11:51:04 +02:00
|
|
|
return PodcastSlideup(
|
2020-09-29 19:25:44 +02:00
|
|
|
searchEngine: SearchEngine.listenNotes,
|
2020-09-14 11:51:04 +02:00
|
|
|
child: FutureBuilder<List>(
|
|
|
|
future: _searchFuture,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (!snapshot.hasData && widget.query != null) {
|
|
|
|
return Container(
|
|
|
|
padding: EdgeInsets.only(top: 200),
|
|
|
|
alignment: Alignment.topCenter,
|
|
|
|
child: CircularProgressIndicator(),
|
2020-07-22 11:34:32 +02:00
|
|
|
);
|
2020-09-14 11:51:04 +02:00
|
|
|
}
|
2020-10-01 11:32:39 +02:00
|
|
|
if (snapshot.data.isEmpty) {
|
|
|
|
if (_loadError) {
|
|
|
|
return Container(
|
|
|
|
padding: EdgeInsets.only(top: 200),
|
|
|
|
alignment: Alignment.topCenter,
|
|
|
|
child: Text('Network error.',
|
|
|
|
style: context.textTheme.headline6
|
|
|
|
.copyWith(color: Colors.red)),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return Container(
|
|
|
|
padding: EdgeInsets.only(top: 200),
|
|
|
|
alignment: Alignment.topCenter,
|
|
|
|
child: Text('No result.',
|
|
|
|
style: context.textTheme.headline6
|
|
|
|
.copyWith(color: context.accentColor)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-09-14 11:51:04 +02:00
|
|
|
var content = snapshot.data;
|
|
|
|
return CustomScrollView(
|
|
|
|
slivers: [
|
|
|
|
SliverList(
|
|
|
|
delegate: SliverChildBuilderDelegate(
|
|
|
|
(context, index) {
|
|
|
|
return SearchResult(onlinePodcast: content[index]);
|
|
|
|
},
|
|
|
|
childCount: content.length,
|
|
|
|
),
|
2020-06-02 16:05:49 +02:00
|
|
|
),
|
2020-09-14 11:51:04 +02:00
|
|
|
SliverToBoxAdapter(
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 10.0, bottom: 20.0),
|
|
|
|
child: OutlineButton(
|
|
|
|
highlightedBorderColor: context.accentColor,
|
|
|
|
splashColor: context.accentColor.withOpacity(0.5),
|
|
|
|
shape: RoundedRectangleBorder(
|
2020-09-29 19:25:44 +02:00
|
|
|
borderRadius: BorderRadius.circular(100)),
|
2020-09-14 11:51:04 +02:00
|
|
|
child: _loading
|
|
|
|
? SizedBox(
|
|
|
|
height: 20,
|
|
|
|
width: 20,
|
|
|
|
child: CircularProgressIndicator(
|
|
|
|
strokeWidth: 2,
|
|
|
|
))
|
|
|
|
: Text(context.s.loadMore),
|
|
|
|
onPressed: () => _loading
|
|
|
|
? null
|
|
|
|
: setState(
|
|
|
|
() {
|
|
|
|
_loading = true;
|
|
|
|
_nextOffset = _offset;
|
2020-09-29 19:25:44 +02:00
|
|
|
_searchFuture = _getListenNotesList(
|
|
|
|
widget.query, _nextOffset);
|
2020-09-14 11:51:04 +02:00
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2020-09-30 18:15:41 +02:00
|
|
|
),
|
|
|
|
SliverToBoxAdapter(
|
|
|
|
child: SizedBox(
|
|
|
|
height: 20,
|
|
|
|
child: Center(
|
|
|
|
child: Image(
|
|
|
|
image: context.brightness == Brightness.light
|
|
|
|
? AssetImage('assets/listennotes.png')
|
|
|
|
: AssetImage('assets/listennotes_light.png'),
|
|
|
|
height: 15,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
))
|
2020-09-14 11:51:04 +02:00
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2020-06-02 16:05:49 +02:00
|
|
|
);
|
2020-02-09 13:29:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-29 19:25:44 +02:00
|
|
|
class _PodcastIndexSearch extends StatefulWidget {
|
|
|
|
final String query;
|
|
|
|
_PodcastIndexSearch({this.query, Key key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
__PodcastIndexSearchState createState() => __PodcastIndexSearchState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class __PodcastIndexSearchState extends State<_PodcastIndexSearch> {
|
|
|
|
int _limit;
|
|
|
|
bool _loading;
|
2020-10-01 11:32:39 +02:00
|
|
|
bool _loadError;
|
2020-09-29 19:25:44 +02:00
|
|
|
Future _searchFuture;
|
|
|
|
List _podcastList = [];
|
2020-09-30 18:15:41 +02:00
|
|
|
final _searchEngine = PodcastsIndexSearch();
|
2020-09-29 19:25:44 +02:00
|
|
|
|
|
|
|
Future<void> _saveHistory(String query) async {
|
|
|
|
final storage = KeyValueStorage(searchHistoryKey);
|
|
|
|
final history = await storage.getStringList();
|
|
|
|
if (!history.contains(query)) {
|
|
|
|
if (history.length >= 6) {
|
|
|
|
history.removeLast();
|
|
|
|
}
|
|
|
|
history.insert(0, query);
|
|
|
|
await storage.saveStringList(history);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_loading = false;
|
2020-10-01 11:32:39 +02:00
|
|
|
_loadError = false;
|
2020-09-29 19:25:44 +02:00
|
|
|
_limit = 10;
|
|
|
|
_searchFuture = _getPodcatsIndexList(widget.query, limit: _limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<List<OnlinePodcast>> _getPodcatsIndexList(String searchText,
|
|
|
|
{int limit}) async {
|
2020-09-30 18:15:41 +02:00
|
|
|
if (_limit == 10) _saveHistory(searchText);
|
2020-10-01 11:32:39 +02:00
|
|
|
var searchResult;
|
|
|
|
try {
|
|
|
|
searchResult = await _searchEngine.searchPodcasts(
|
|
|
|
searchText: searchText, limit: limit);
|
|
|
|
} catch (e) {
|
|
|
|
_loadError = true;
|
|
|
|
_loading = false;
|
|
|
|
return [];
|
|
|
|
}
|
2020-09-29 19:25:44 +02:00
|
|
|
var list = searchResult.feeds.cast();
|
|
|
|
_podcastList = <OnlinePodcast>[
|
|
|
|
for (var podcast in list) podcast.toOnlinePodcast
|
|
|
|
];
|
|
|
|
_loading = false;
|
|
|
|
return _podcastList;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return PodcastSlideup(
|
|
|
|
searchEngine: SearchEngine.podcastIndex,
|
|
|
|
child: FutureBuilder<List>(
|
|
|
|
future: _searchFuture,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (!snapshot.hasData && widget.query != null) {
|
|
|
|
return Container(
|
|
|
|
padding: EdgeInsets.only(top: 200),
|
|
|
|
alignment: Alignment.topCenter,
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
);
|
|
|
|
}
|
2020-10-01 11:32:39 +02:00
|
|
|
if (snapshot.data.isEmpty) {
|
|
|
|
if (_loadError) {
|
|
|
|
return Container(
|
|
|
|
padding: EdgeInsets.only(top: 200),
|
|
|
|
alignment: Alignment.topCenter,
|
|
|
|
child: Text('Network error.',
|
|
|
|
style: context.textTheme.headline6
|
|
|
|
.copyWith(color: Colors.red)),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return Container(
|
|
|
|
padding: EdgeInsets.only(top: 200),
|
|
|
|
alignment: Alignment.topCenter,
|
|
|
|
child: Text('No result found.',
|
|
|
|
style: context.textTheme.headline6
|
|
|
|
.copyWith(color: context.accentColor)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-09-29 19:25:44 +02:00
|
|
|
var content = snapshot.data;
|
|
|
|
return CustomScrollView(
|
|
|
|
slivers: [
|
|
|
|
SliverList(
|
|
|
|
delegate: SliverChildBuilderDelegate(
|
|
|
|
(context, index) {
|
|
|
|
return SearchResult(onlinePodcast: content[index]);
|
|
|
|
},
|
|
|
|
childCount: content.length,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SliverToBoxAdapter(
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 10.0, bottom: 20.0),
|
|
|
|
child: OutlineButton(
|
|
|
|
highlightedBorderColor: context.accentColor,
|
|
|
|
splashColor: context.accentColor.withOpacity(0.5),
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(100)),
|
|
|
|
child: _loading
|
|
|
|
? SizedBox(
|
|
|
|
height: 20,
|
|
|
|
width: 20,
|
|
|
|
child: CircularProgressIndicator(
|
|
|
|
strokeWidth: 2,
|
|
|
|
))
|
|
|
|
: Text(context.s.loadMore),
|
|
|
|
onPressed: () => _loading
|
|
|
|
? null
|
|
|
|
: setState(
|
|
|
|
() {
|
|
|
|
_loading = true;
|
|
|
|
_limit += 10;
|
|
|
|
_searchFuture = _getPodcatsIndexList(
|
|
|
|
widget.query,
|
|
|
|
limit: _limit);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2020-09-30 18:15:41 +02:00
|
|
|
),
|
|
|
|
SliverToBoxAdapter(
|
|
|
|
child: SizedBox(
|
|
|
|
height: 20,
|
|
|
|
child: Center(
|
|
|
|
child: Image(
|
|
|
|
image: AssetImage('assets/podcastindex.png'),
|
|
|
|
height: 15,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
))
|
2020-09-29 19:25:44 +02:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-22 11:34:32 +02:00
|
|
|
class SearchResult extends StatelessWidget {
|
2020-02-09 13:29:09 +01:00
|
|
|
final OnlinePodcast onlinePodcast;
|
2020-09-14 11:51:04 +02:00
|
|
|
SearchResult({this.onlinePodcast, Key key}) : super(key: key);
|
2020-02-09 13:29:09 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-09-14 11:51:04 +02:00
|
|
|
var searchState = context.watch<SearchState>();
|
|
|
|
return Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
|
|
|
ListTile(
|
2020-08-27 10:35:18 +02:00
|
|
|
contentPadding: EdgeInsets.fromLTRB(20, 10, 20, 10),
|
2020-02-21 16:04:02 +01:00
|
|
|
onTap: () {
|
2020-09-14 11:51:04 +02:00
|
|
|
searchState.selectedPodcast = onlinePodcast;
|
2020-02-21 16:04:02 +01:00
|
|
|
},
|
2020-02-20 16:44:42 +01:00
|
|
|
leading: ClipRRect(
|
2020-08-27 10:35:18 +02:00
|
|
|
borderRadius: BorderRadius.circular(25.0),
|
2020-06-03 14:39:15 +02:00
|
|
|
child: CachedNetworkImage(
|
2020-08-27 10:35:18 +02:00
|
|
|
height: 50.0,
|
|
|
|
width: 50.0,
|
2020-02-20 16:44:42 +01:00
|
|
|
fit: BoxFit.fitWidth,
|
|
|
|
alignment: Alignment.center,
|
2020-07-22 11:34:32 +02:00
|
|
|
imageUrl: onlinePodcast.image,
|
2020-06-03 14:39:15 +02:00
|
|
|
progressIndicatorBuilder: (context, url, downloadProgress) =>
|
|
|
|
Container(
|
2020-08-27 10:35:18 +02:00
|
|
|
height: 50,
|
|
|
|
width: 50,
|
2020-06-03 14:39:15 +02:00
|
|
|
alignment: Alignment.center,
|
|
|
|
color: context.primaryColorDark,
|
|
|
|
child: SizedBox(
|
|
|
|
width: 20,
|
|
|
|
height: 2,
|
|
|
|
child: LinearProgressIndicator(
|
|
|
|
value: downloadProgress.progress),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
errorWidget: (context, url, error) => Container(
|
2020-08-27 10:35:18 +02:00
|
|
|
width: 50,
|
|
|
|
height: 50,
|
2020-06-02 16:05:49 +02:00
|
|
|
alignment: Alignment.center,
|
|
|
|
color: context.primaryColorDark,
|
|
|
|
child: Icon(Icons.error)),
|
2020-02-20 16:44:42 +01:00
|
|
|
),
|
|
|
|
),
|
2020-07-22 11:34:32 +02:00
|
|
|
title: Text(onlinePodcast.title),
|
2020-09-29 19:25:44 +02:00
|
|
|
subtitle: Text(
|
|
|
|
onlinePodcast.publisher ?? '',
|
|
|
|
maxLines: 3,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
),
|
2020-09-14 11:51:04 +02:00
|
|
|
trailing: SubscribeButton(onlinePodcast)),
|
|
|
|
],
|
2020-07-22 11:34:32 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-14 11:51:04 +02:00
|
|
|
/// Search podcast detail widget
|
2020-07-22 11:34:32 +02:00
|
|
|
class SearchResultDetail extends StatefulWidget {
|
|
|
|
SearchResultDetail(this.onlinePodcast,
|
2020-09-29 19:25:44 +02:00
|
|
|
{this.maxHeight, this.isSubscribed, this.searchEngine, Key key})
|
2020-07-22 11:34:32 +02:00
|
|
|
: super(key: key);
|
|
|
|
final OnlinePodcast onlinePodcast;
|
|
|
|
final double maxHeight;
|
2020-08-01 17:10:43 +02:00
|
|
|
final bool isSubscribed;
|
2020-09-29 19:25:44 +02:00
|
|
|
final SearchEngine searchEngine;
|
2020-07-22 11:34:32 +02:00
|
|
|
@override
|
|
|
|
_SearchResultDetailState createState() => _SearchResultDetailState();
|
|
|
|
}
|
|
|
|
|
|
|
|
enum SlideDirection { up, down }
|
|
|
|
|
|
|
|
class _SearchResultDetailState extends State<SearchResultDetail>
|
|
|
|
with SingleTickerProviderStateMixin {
|
|
|
|
/// Animation value.
|
|
|
|
double _initSize;
|
|
|
|
|
|
|
|
/// Gesture tap start position.
|
|
|
|
double _startdy;
|
|
|
|
|
|
|
|
/// Height of first open.
|
|
|
|
double _minHeight;
|
|
|
|
|
|
|
|
/// Gesture move.
|
|
|
|
double _move = 0;
|
|
|
|
|
|
|
|
AnimationController _controller;
|
|
|
|
Animation _animation;
|
|
|
|
|
|
|
|
/// Gesture scroll direction.
|
|
|
|
SlideDirection _slideDirection;
|
|
|
|
|
|
|
|
/// Search offset.
|
|
|
|
int _nextEpisdoeDate = DateTime.now().millisecondsSinceEpoch;
|
|
|
|
|
|
|
|
/// Search result.
|
2020-07-26 12:20:42 +02:00
|
|
|
final List<OnlineEpisode> _episodeList = [];
|
2020-07-22 11:34:32 +02:00
|
|
|
|
|
|
|
Future _searchFuture;
|
|
|
|
|
|
|
|
/// Episodes list load more.
|
|
|
|
bool _loading = false;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2020-09-29 19:25:44 +02:00
|
|
|
|
|
|
|
_searchFuture = widget.searchEngine == SearchEngine.listenNotes
|
|
|
|
? _getListenNotesEpisodes(
|
|
|
|
id: widget.onlinePodcast.id, nextEpisodeDate: _nextEpisdoeDate)
|
|
|
|
: _getIndexEpisodes(id: widget.onlinePodcast.rss);
|
2020-07-22 11:34:32 +02:00
|
|
|
_minHeight = widget.maxHeight / 2;
|
|
|
|
_initSize = _minHeight;
|
|
|
|
_slideDirection = SlideDirection.up;
|
|
|
|
_controller =
|
|
|
|
AnimationController(vsync: this, duration: Duration(milliseconds: 200))
|
|
|
|
..addListener(() {
|
|
|
|
if (mounted) setState(() {});
|
|
|
|
});
|
|
|
|
_animation =
|
|
|
|
Tween<double>(begin: 170, end: _minHeight).animate(_controller);
|
|
|
|
_controller.forward();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_controller.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
2020-09-29 19:25:44 +02:00
|
|
|
Future<List<OnlineEpisode>> _getListenNotesEpisodes(
|
2020-07-22 11:34:32 +02:00
|
|
|
{String id, int nextEpisodeDate}) async {
|
2020-09-23 16:19:07 +02:00
|
|
|
var searchEngine = ListenNotesSearch();
|
2020-07-22 11:34:32 +02:00
|
|
|
var searchResult = await searchEngine.fetchEpisode(
|
|
|
|
id: id, nextEpisodeDate: nextEpisodeDate);
|
|
|
|
_nextEpisdoeDate = searchResult.nextEpisodeDate;
|
|
|
|
_episodeList.addAll(searchResult.episodes.cast());
|
|
|
|
_loading = false;
|
|
|
|
return _episodeList;
|
|
|
|
}
|
|
|
|
|
2020-09-29 19:25:44 +02:00
|
|
|
Future<List<OnlineEpisode>> _getIndexEpisodes(
|
|
|
|
{String id, int nextEpisodeDate}) async {
|
|
|
|
var searchEngine = PodcastsIndexSearch();
|
|
|
|
var searchResult = await searchEngine.fetchEpisode(rssUrl: id);
|
|
|
|
var episodes = searchResult.items.cast();
|
|
|
|
for (var episode in episodes) {
|
|
|
|
_episodeList.add(episode.toOnlineWEpisode);
|
|
|
|
}
|
|
|
|
_loading = false;
|
|
|
|
return _episodeList;
|
|
|
|
}
|
|
|
|
|
2020-09-14 16:51:05 +02:00
|
|
|
void _start(DragStartDetails event) {
|
2020-07-22 11:34:32 +02:00
|
|
|
setState(() {
|
|
|
|
_startdy = event.localPosition.dy;
|
|
|
|
_animation =
|
|
|
|
Tween<double>(begin: _initSize, end: _initSize).animate(_controller);
|
|
|
|
});
|
|
|
|
_controller.forward();
|
|
|
|
}
|
|
|
|
|
2020-09-14 16:51:05 +02:00
|
|
|
void _update(DragUpdateDetails event) {
|
2020-07-22 11:34:32 +02:00
|
|
|
setState(() {
|
|
|
|
_move = _startdy - event.localPosition.dy;
|
|
|
|
_animation = Tween<double>(begin: _initSize, end: _initSize + _move)
|
|
|
|
.animate(_controller);
|
|
|
|
_slideDirection = _move > 0 ? SlideDirection.up : SlideDirection.down;
|
|
|
|
});
|
|
|
|
_controller.forward();
|
|
|
|
}
|
|
|
|
|
2020-09-14 16:51:05 +02:00
|
|
|
void _end() {
|
2020-07-22 11:34:32 +02:00
|
|
|
if (_slideDirection == SlideDirection.up) {
|
|
|
|
if (_move > 20) {
|
|
|
|
setState(() {
|
|
|
|
_animation =
|
|
|
|
Tween<double>(begin: _animation.value, end: widget.maxHeight)
|
|
|
|
.animate(_controller);
|
|
|
|
_initSize = widget.maxHeight;
|
|
|
|
});
|
|
|
|
_controller.forward();
|
|
|
|
} else {
|
|
|
|
setState(() {
|
|
|
|
_animation = Tween<double>(begin: _animation.value, end: _minHeight)
|
|
|
|
.animate(_controller);
|
|
|
|
_initSize = _minHeight;
|
|
|
|
});
|
|
|
|
_controller.forward();
|
|
|
|
}
|
|
|
|
} else if (_slideDirection == SlideDirection.down) {
|
|
|
|
if (_move > -50) {
|
|
|
|
setState(() {
|
|
|
|
_animation = Tween<double>(
|
|
|
|
begin: _animation.value,
|
|
|
|
end: _animation.value > _minHeight
|
|
|
|
? widget.maxHeight
|
|
|
|
: _minHeight)
|
|
|
|
.animate(_controller);
|
|
|
|
_initSize =
|
|
|
|
_animation.value > _minHeight ? widget.maxHeight : _minHeight;
|
|
|
|
});
|
|
|
|
_controller.forward();
|
|
|
|
} else {
|
|
|
|
setState(() {
|
|
|
|
_animation = Tween<double>(
|
|
|
|
begin: _animation.value,
|
|
|
|
end: _animation.value > _minHeight - 50 ? _minHeight : 1)
|
|
|
|
.animate(_controller);
|
|
|
|
_initSize = _animation.value > _minHeight - 50 ? _minHeight : 100;
|
|
|
|
});
|
|
|
|
_controller.forward();
|
2020-09-14 11:51:04 +02:00
|
|
|
if (_animation.value < _minHeight - 50) {
|
|
|
|
context.read<SearchState>().clearSelect();
|
|
|
|
}
|
2020-07-22 11:34:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final s = context.s;
|
|
|
|
return GestureDetector(
|
2020-07-26 12:20:42 +02:00
|
|
|
onVerticalDragStart: _start,
|
|
|
|
onVerticalDragUpdate: _update,
|
2020-07-22 11:34:32 +02:00
|
|
|
onVerticalDragEnd: (event) => _end(),
|
2020-07-30 11:29:48 +02:00
|
|
|
child: Container(
|
|
|
|
decoration: BoxDecoration(
|
2020-09-29 19:25:44 +02:00
|
|
|
color: context.primaryColor,
|
2020-07-30 11:29:48 +02:00
|
|
|
boxShadow: [
|
|
|
|
BoxShadow(
|
|
|
|
offset: Offset(0, -0.5),
|
|
|
|
blurRadius: 1,
|
|
|
|
color: Theme.of(context).brightness == Brightness.light
|
|
|
|
? Colors.grey[400].withOpacity(0.5)
|
|
|
|
: Colors.grey[800],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
height: _animation.value,
|
|
|
|
child: DefaultTabController(
|
|
|
|
length: 2,
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
height: math.min(_animation.value, 120),
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
|
|
child: SizedBox(
|
|
|
|
height: 120,
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 20),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding:
|
|
|
|
const EdgeInsets.symmetric(vertical: 8),
|
|
|
|
child: Text(widget.onlinePodcast.title,
|
|
|
|
maxLines: 1,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
style: context.textTheme.headline5),
|
|
|
|
),
|
|
|
|
Text(
|
2020-09-29 19:25:44 +02:00
|
|
|
widget.onlinePodcast.interval
|
|
|
|
.toInterval(context) !=
|
|
|
|
''
|
|
|
|
? '${widget.onlinePodcast.interval.toInterval(context)} | '
|
|
|
|
'${widget.onlinePodcast.latestPubDate.toDate(context)}'
|
|
|
|
: '${widget.onlinePodcast.latestPubDate.toDate(context)}',
|
2020-07-30 11:29:48 +02:00
|
|
|
maxLines: 1,
|
|
|
|
overflow: TextOverflow.fade,
|
|
|
|
style: TextStyle(color: context.accentColor),
|
|
|
|
),
|
2020-09-14 11:51:04 +02:00
|
|
|
SubscribeButton(widget.onlinePodcast),
|
2020-07-30 11:29:48 +02:00
|
|
|
],
|
|
|
|
),
|
2020-07-22 11:34:32 +02:00
|
|
|
),
|
|
|
|
),
|
2020-07-30 11:29:48 +02:00
|
|
|
CachedNetworkImage(
|
|
|
|
height: 120.0,
|
|
|
|
width: 120.0,
|
|
|
|
fit: BoxFit.fitWidth,
|
2020-07-22 11:34:32 +02:00
|
|
|
alignment: Alignment.center,
|
2020-07-30 11:29:48 +02:00
|
|
|
imageUrl: widget.onlinePodcast.image,
|
|
|
|
progressIndicatorBuilder:
|
|
|
|
(context, url, downloadProgress) => Container(
|
2020-07-22 14:39:25 +02:00
|
|
|
height: 120,
|
2020-07-30 11:29:48 +02:00
|
|
|
width: 120,
|
2020-07-22 11:34:32 +02:00
|
|
|
alignment: Alignment.center,
|
|
|
|
color: context.primaryColorDark,
|
2020-07-30 11:29:48 +02:00
|
|
|
child: SizedBox(
|
|
|
|
width: 40,
|
|
|
|
height: 2,
|
|
|
|
child: LinearProgressIndicator(
|
|
|
|
value: downloadProgress.progress),
|
|
|
|
),
|
2020-07-22 14:39:25 +02:00
|
|
|
),
|
2020-07-30 11:29:48 +02:00
|
|
|
errorWidget: (context, url, error) => Container(
|
|
|
|
width: 120,
|
|
|
|
height: 120,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
color: context.primaryColorDark,
|
|
|
|
child: Icon(Icons.error)),
|
2020-07-22 14:39:25 +02:00
|
|
|
),
|
|
|
|
],
|
2020-07-22 11:34:32 +02:00
|
|
|
),
|
2020-07-30 11:29:48 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (_animation.value > 120)
|
|
|
|
SizedBox(
|
|
|
|
height: math.min(_animation.value - 120, 50),
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
|
|
child: SizedBox(
|
|
|
|
height: 50,
|
|
|
|
child: TabBar(
|
|
|
|
indicatorColor: context.accentColor,
|
|
|
|
labelColor: context.textColor,
|
|
|
|
indicatorWeight: 3,
|
|
|
|
indicatorSize: TabBarIndicatorSize.label,
|
|
|
|
tabs: [
|
|
|
|
Text(s.homeToprightMenuAbout),
|
|
|
|
Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
Text(s.episode(2)),
|
|
|
|
SizedBox(width: 2),
|
2020-09-29 19:25:44 +02:00
|
|
|
if (widget.onlinePodcast.count > 0)
|
|
|
|
Container(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
left: 5, right: 5, top: 2, bottom: 2),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: context.accentColor,
|
|
|
|
borderRadius:
|
|
|
|
BorderRadius.circular(100)),
|
|
|
|
child: Text(
|
|
|
|
widget.onlinePodcast.count.toString(),
|
|
|
|
style:
|
|
|
|
TextStyle(color: Colors.white)))
|
2020-07-30 11:29:48 +02:00
|
|
|
],
|
|
|
|
)
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: TabBarView(children: [
|
|
|
|
ListView(
|
|
|
|
physics: _animation.value != widget.maxHeight
|
|
|
|
? NeverScrollableScrollPhysics()
|
|
|
|
: null,
|
|
|
|
children: [
|
|
|
|
Html(
|
|
|
|
onLinkTap: (url) {
|
|
|
|
url.launchUrl;
|
|
|
|
},
|
|
|
|
linkStyle: TextStyle(
|
|
|
|
color: context.accentColor,
|
|
|
|
textBaseline: TextBaseline.ideographic),
|
|
|
|
shrinkToFit: true,
|
|
|
|
data: widget.onlinePodcast.description,
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
left: 20.0, right: 20, bottom: 20),
|
|
|
|
defaultTextStyle: TextStyle(
|
|
|
|
height: 1.8,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
FutureBuilder<List<OnlineEpisode>>(
|
|
|
|
future: _searchFuture,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
var content = snapshot.data;
|
|
|
|
return ListView.builder(
|
|
|
|
physics: _animation.value != widget.maxHeight
|
|
|
|
? NeverScrollableScrollPhysics()
|
|
|
|
: null,
|
|
|
|
itemCount: content.length + 1,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
if (index == content.length) {
|
|
|
|
return Container(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
top: 10.0, bottom: 20.0),
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: SizedBox(
|
|
|
|
child: OutlineButton(
|
2020-09-29 19:25:44 +02:00
|
|
|
highlightedBorderColor:
|
|
|
|
context.accentColor,
|
|
|
|
splashColor: context.accentColor
|
|
|
|
.withOpacity(0.5),
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.all(
|
|
|
|
Radius.circular(100))),
|
|
|
|
child: _loading
|
|
|
|
? SizedBox(
|
|
|
|
height: 20,
|
|
|
|
width: 20,
|
|
|
|
child:
|
|
|
|
CircularProgressIndicator(
|
|
|
|
strokeWidth: 2,
|
|
|
|
))
|
|
|
|
: Text(context.s.loadMore),
|
|
|
|
onPressed: () {
|
|
|
|
if (widget.searchEngine ==
|
|
|
|
SearchEngine.listenNotes) {
|
|
|
|
_loading
|
|
|
|
? null
|
|
|
|
: setState(
|
|
|
|
() {
|
|
|
|
_loading = true;
|
|
|
|
_searchFuture =
|
|
|
|
_getListenNotesEpisodes(
|
|
|
|
id: widget
|
|
|
|
.onlinePodcast
|
|
|
|
.id,
|
|
|
|
nextEpisodeDate:
|
|
|
|
_nextEpisdoeDate);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}),
|
2020-07-30 11:29:48 +02:00
|
|
|
),
|
2020-07-22 11:34:32 +02:00
|
|
|
);
|
2020-07-30 11:29:48 +02:00
|
|
|
}
|
|
|
|
return ListTile(
|
|
|
|
title: Text(content[index].title),
|
|
|
|
subtitle: Text(
|
2020-09-29 19:25:44 +02:00
|
|
|
content[index].length == 0
|
|
|
|
? '${content[index].pubDate.toDate(context)}'
|
|
|
|
: '${content[index].length.toTime} | '
|
|
|
|
'${content[index].pubDate.toDate(context)}',
|
2020-07-30 11:29:48 +02:00
|
|
|
style:
|
|
|
|
TextStyle(color: context.accentColor)),
|
|
|
|
);
|
|
|
|
},
|
2020-07-16 16:37:19 +02:00
|
|
|
);
|
2020-07-30 11:29:48 +02:00
|
|
|
}
|
|
|
|
return Center(
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
);
|
|
|
|
})
|
|
|
|
]),
|
|
|
|
)
|
|
|
|
],
|
2020-02-09 13:29:09 +01:00
|
|
|
),
|
2020-07-22 11:34:32 +02:00
|
|
|
),
|
2020-02-09 13:29:09 +01:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-09-14 11:51:04 +02:00
|
|
|
|
|
|
|
class SubscribeButton extends StatelessWidget {
|
|
|
|
SubscribeButton(this.onlinePodcast, {Key key}) : super(key: key);
|
|
|
|
final OnlinePodcast onlinePodcast;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final subscribeWorker = context.watch<GroupList>();
|
|
|
|
final searchState = context.watch<SearchState>();
|
|
|
|
final s = context.s;
|
2020-09-14 16:51:05 +02:00
|
|
|
void subscribePodcast(OnlinePodcast podcast) {
|
2020-09-14 11:51:04 +02:00
|
|
|
var item = SubscribeItem(podcast.rss, podcast.title,
|
|
|
|
imgUrl: podcast.image, group: 'Home');
|
|
|
|
subscribeWorker.setSubscribeItem(item);
|
|
|
|
searchState.addPodcast(podcast);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Consumer<SearchState>(builder: (_, searchState, __) {
|
|
|
|
final subscribed = searchState.isSubscribed(onlinePodcast);
|
|
|
|
return !subscribed
|
2020-09-29 19:25:44 +02:00
|
|
|
? ButtonTheme(
|
|
|
|
height: 32,
|
|
|
|
child: OutlineButton(
|
|
|
|
highlightedBorderColor: context.accentColor,
|
|
|
|
borderSide: BorderSide(color: context.accentColor),
|
|
|
|
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: () {
|
|
|
|
Fluttertoast.showToast(
|
|
|
|
msg: s.podcastSubscribed,
|
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
subscribePodcast(onlinePodcast);
|
|
|
|
searchState.addPodcast(onlinePodcast);
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
: ButtonTheme(
|
|
|
|
height: 32,
|
|
|
|
child: 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: () {}),
|
|
|
|
);
|
2020-09-14 11:51:04 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class PodcastSlideup extends StatelessWidget {
|
2020-09-29 19:25:44 +02:00
|
|
|
const PodcastSlideup({this.child, this.searchEngine, Key key})
|
|
|
|
: super(key: key);
|
2020-09-14 11:51:04 +02:00
|
|
|
final Widget child;
|
2020-09-29 19:25:44 +02:00
|
|
|
final SearchEngine searchEngine;
|
2020-09-14 11:51:04 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Consumer<SearchState>(builder: (_, searchState, __) {
|
|
|
|
final selectedPodcast = searchState.selectedPodcast;
|
|
|
|
final subscribed = searchState.subscribedList;
|
|
|
|
return Stack(
|
|
|
|
alignment: Alignment.bottomCenter,
|
|
|
|
children: [
|
|
|
|
child,
|
|
|
|
if (selectedPodcast != null)
|
|
|
|
Positioned.fill(
|
|
|
|
child: GestureDetector(
|
|
|
|
onTap: searchState.clearSelect,
|
|
|
|
child: Container(
|
|
|
|
color: context.scaffoldBackgroundColor.withOpacity(0.9),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (selectedPodcast != null)
|
|
|
|
LayoutBuilder(
|
|
|
|
builder: (context, constrants) => SearchResultDetail(
|
|
|
|
selectedPodcast,
|
|
|
|
maxHeight: constrants.maxHeight,
|
|
|
|
isSubscribed: subscribed.contains(selectedPodcast),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class PodcastAvatar extends StatelessWidget {
|
|
|
|
const PodcastAvatar(this.podcast, {Key key}) : super(key: key);
|
|
|
|
final OnlinePodcast podcast;
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return SizedBox(
|
|
|
|
height: 50,
|
|
|
|
child: ClipRRect(
|
|
|
|
borderRadius: BorderRadius.circular(25.0),
|
|
|
|
child: CachedNetworkImage(
|
|
|
|
height: 50.0,
|
|
|
|
width: 50.0,
|
|
|
|
fit: BoxFit.fitWidth,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
imageUrl: podcast.image,
|
|
|
|
progressIndicatorBuilder: (context, url, downloadProgress) =>
|
|
|
|
Container(
|
|
|
|
height: 50,
|
|
|
|
width: 50,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
color: context.primaryColorDark,
|
|
|
|
child: SizedBox(
|
|
|
|
width: 20,
|
|
|
|
height: 2,
|
|
|
|
child: LinearProgressIndicator(value: downloadProgress.progress),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
errorWidget: (context, url, error) => Container(
|
|
|
|
width: 50,
|
|
|
|
height: 50,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
color: context.primaryColorDark,
|
|
|
|
child: Icon(Icons.error)),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|