tsacdop-podcast-app-android/lib/home/search_podcast.dart

1008 lines
37 KiB
Dart
Raw Normal View History

2020-02-11 14:48:11 +01:00
import 'dart:async';
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';
import 'package:flutter/services.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:fluttertoast/fluttertoast.dart';
2020-07-26 15:48:30 +02:00
import 'package:webfeed/webfeed.dart';
2020-07-26 12:20:42 +02:00
import 'package:provider/provider.dart';
import '../service/api_search.dart';
import '../state/podcast_group.dart';
2020-07-26 12:20:42 +02:00
import '../type/searchepisodes.dart';
import '../type/searchpodcast.dart';
import '../util/extension_helper.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-06-02 16:05:49 +02:00
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,
);
static Future getRss(String url) async {
try {
2020-07-26 12:20:42 +02:00
var options = BaseOptions(
connectTimeout: 10000,
receiveTimeout: 10000,
);
2020-07-26 12:20:42 +02:00
var response = await Dio(options).get(url);
return RssFeed.parse(response.data);
} catch (e) {
2020-07-26 12:20:42 +02:00
rethrow;
}
}
RegExp rssExp = RegExp(r'^(https?):\/\/(.*)');
2020-07-04 16:42:56 +02:00
Widget invalidRss(BuildContext context) => Container(
height: 50,
alignment: Alignment.center,
2020-07-04 16:42:56 +02:00
child: Text(context.s.searchInvalidRss),
);
@override
ThemeData appBarTheme(BuildContext context) => Theme.of(context);
2020-02-09 13:29:09 +01:00
@override
Widget buildLeading(BuildContext context) {
return IconButton(
2020-07-04 16:42:56 +02:00
tooltip: context.s.back,
2020-02-09 13:29:09 +01:00
icon: AnimatedIcon(
icon: AnimatedIcons.menu_arrow,
progress: transitionAnimation,
),
onPressed: () {
close(context, 1);
},
);
}
@override
Widget buildSuggestions(BuildContext context) {
return Center(
child: Container(
padding: EdgeInsets.only(top: 100),
child: Image(
image: context.brightness == Brightness.light
? AssetImage('assets/listennotes.png')
: AssetImage('assets/listennotes_light.png'),
height: 20,
),
));
2020-02-09 13:29:09 +01:00
}
@override
List<Widget> buildActions(BuildContext context) {
return <Widget>[
if (query.isEmpty)
2020-02-11 14:01:57 +01:00
Center()
2020-02-09 13:29:09 +01:00
else
IconButton(
2020-07-04 16:42:56 +02:00
tooltip: context.s.clear,
2020-02-09 13:29:09 +01:00
icon: const Icon(Icons.clear),
onPressed: () {
query = '';
},
),
];
}
@override
Widget buildResults(BuildContext context) {
2020-07-26 12:20:42 +02:00
if (query.isEmpty) {
2020-02-09 13:29:09 +01:00
return Container(
height: 10,
width: 10,
margin: EdgeInsets.only(top: 400),
2020-02-11 14:01:57 +01:00
child: SizedBox(
height: 10,
2020-02-11 14:48:11 +01:00
child: Image.asset(
2020-02-11 14:01:57 +01:00
'assets/listennote.png',
fit: BoxFit.fill,
),
2020-02-09 13:29:09 +01:00
),
);
2020-07-26 12:20:42 +02:00
} else if (rssExp.stringMatch(query) != null) {
return FutureBuilder(
future: getRss(rssExp.stringMatch(query)),
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) {
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 {
return Container(
padding: EdgeInsets.only(top: 200),
alignment: Alignment.topCenter,
child: CircularProgressIndicator(),
);
2020-07-26 12:20:42 +02:00
}
},
);
2020-07-26 12:20:42 +02:00
} else {
2020-06-02 16:05:49 +02:00
return SearchList(
query: query,
);
2020-07-26 12:20:42 +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;
bool _isSubscribed = false;
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) {
var subscribeWorker = Provider.of<GroupList>(context, listen: false);
final s = context.s;
_subscribePodcast(OnlinePodcast podcast) {
2020-07-26 12:20:42 +02:00
var item = SubscribeItem(podcast.rss, podcast.title,
imgUrl: podcast.image, group: 'Home');
subscribeWorker.setSubscribeItem(item);
}
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-08-14 14:12:44 +02:00
!_isSubscribed
? OutlineButton(
highlightedBorderColor: 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: () {
_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: () {})
],
),
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-08-14 14:12:44 +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)))
],
)
]),
),
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 14:39:25 +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) {
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-26 12:20:42 +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
}
}
class SearchList extends StatefulWidget {
final String query;
SearchList({this.query, Key key}) : super(key: key);
@override
_SearchListState createState() => _SearchListState();
}
class _SearchListState extends State<SearchList> {
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;
bool _loading;
OnlinePodcast _selectedPodcast;
Future _searchFuture;
2020-07-26 12:20:42 +02:00
final List<OnlinePodcast> _subscribed = [];
2020-06-02 16:05:49 +02:00
@override
void initState() {
super.initState();
_searchFuture = _getList(widget.query, _nextOffset);
2020-06-02 16:05:49 +02:00
}
Future<List<OnlinePodcast>> _getList(
String searchText, int nextOffset) async {
2020-07-26 12:20:42 +02:00
var searchEngine = SearchEngine();
2020-07-22 14:39:25 +02:00
var searchResult = await searchEngine.searchPodcasts(
searchText: searchText, nextOffset: nextOffset);
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) {
return Stack(
alignment: Alignment.bottomCenter,
children: [
FutureBuilder<List>(
future: _searchFuture,
2020-07-26 12:20:42 +02:00
builder: (context, snapshot) {
if (!snapshot.hasData && widget.query != null) {
return Container(
padding: EdgeInsets.only(top: 200),
alignment: Alignment.topCenter,
child: CircularProgressIndicator(),
);
2020-07-26 12:20:42 +02:00
}
var content = snapshot.data;
return CustomScrollView(
slivers: [
SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) {
return SearchResult(
onlinePodcast: content[index],
isSubscribed: _subscribed.contains(content[index]),
onSelect: (onlinePodcast) {
setState(() {
_selectedPodcast = onlinePodcast;
});
},
onSubscribe: (onlinePodcast) {
setState(() {
_subscribed.add(onlinePodcast);
});
},
);
},
childCount: content.length,
),
),
SliverToBoxAdapter(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.only(top: 10.0, bottom: 20.0),
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: _loading
? SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
))
: Text(context.s.loadMore),
onPressed: () => _loading
? null
: setState(
() {
_loading = true;
_nextOffset = _offset;
_searchFuture =
_getList(widget.query, _nextOffset);
},
),
),
)
],
),
)
],
);
},
),
if (_selectedPodcast != null)
Positioned.fill(
child: GestureDetector(
onTap: () => setState(() => _selectedPodcast = null),
child: Container(
2020-07-30 11:29:48 +02:00
color: context.scaffoldBackgroundColor.withOpacity(0.9),
2020-06-02 16:05:49 +02:00
),
),
),
if (_selectedPodcast != null)
LayoutBuilder(
builder: (context, constrants) => SearchResultDetail(
_selectedPodcast,
maxHeight: constrants.maxHeight,
2020-08-01 17:10:43 +02:00
isSubscribed: _subscribed.contains(_selectedPodcast),
onClose: (option) {
setState(() => _selectedPodcast = null);
},
onSubscribe: (onlinePodcast) {
setState(() {
_subscribed.add(onlinePodcast);
});
},
),
),
],
2020-06-02 16:05:49 +02:00
);
2020-02-09 13:29:09 +01:00
}
}
class SearchResult extends StatelessWidget {
2020-02-09 13:29:09 +01:00
final OnlinePodcast onlinePodcast;
final ValueChanged<OnlinePodcast> onSelect;
final ValueChanged<OnlinePodcast> onSubscribe;
final bool isSubscribed;
SearchResult(
{this.onlinePodcast,
this.onSelect,
this.onSubscribe,
this.isSubscribed,
Key key})
: super(key: key);
2020-02-09 13:29:09 +01:00
@override
Widget build(BuildContext context) {
var subscribeWorker = Provider.of<GroupList>(context, listen: false);
2020-07-04 16:42:56 +02:00
final s = context.s;
subscribePodcast(OnlinePodcast podcast) {
2020-07-26 12:20:42 +02:00
var item = SubscribeItem(podcast.rss, podcast.title,
2020-07-14 20:34:28 +02:00
imgUrl: podcast.image, group: 'Home');
subscribeWorker.setSubscribeItem(item);
onSubscribe(podcast);
2020-02-11 14:48:11 +01:00
}
2020-02-11 14:01:57 +01:00
2020-02-09 13:29:09 +01:00
return Container(
decoration: BoxDecoration(
border: Border(
bottom: Divider.createBorderSide(context),
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
ListTile(
contentPadding: EdgeInsets.symmetric(horizontal: 20.0),
onTap: () {
onSelect(onlinePodcast);
},
leading: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(20.0)),
child: CachedNetworkImage(
height: 40.0,
width: 40.0,
fit: BoxFit.fitWidth,
alignment: Alignment.center,
imageUrl: onlinePodcast.image,
progressIndicatorBuilder: (context, url, downloadProgress) =>
Container(
height: 40,
width: 40,
alignment: Alignment.center,
color: context.primaryColorDark,
child: SizedBox(
width: 20,
height: 2,
child: LinearProgressIndicator(
value: downloadProgress.progress),
),
),
errorWidget: (context, url, error) => Container(
2020-06-02 16:05:49 +02:00
width: 40,
height: 40,
alignment: Alignment.center,
color: context.primaryColorDark,
child: Icon(Icons.error)),
),
),
title: Text(onlinePodcast.title),
subtitle: Text(onlinePodcast.publisher ?? ''),
trailing: !isSubscribed
? OutlineButton(
highlightedBorderColor: 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: () {
subscribePodcast(onlinePodcast);
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: () {}),
),
],
),
);
}
}
class SearchResultDetail extends StatefulWidget {
SearchResultDetail(this.onlinePodcast,
{this.onClose,
this.maxHeight,
this.onSubscribe,
this.episodeList,
2020-08-01 17:10:43 +02:00
this.isSubscribed,
Key key})
: super(key: key);
final OnlinePodcast onlinePodcast;
final ValueChanged<bool> onClose;
final ValueChanged<OnlinePodcast> onSubscribe;
final double maxHeight;
final List<OnlineEpisode> episodeList;
2020-08-01 17:10:43 +02:00
final bool isSubscribed;
@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 = [];
Future _searchFuture;
/// Episodes list load more.
bool _loading = false;
@override
void initState() {
super.initState();
_searchFuture = _getEpisodes(
id: widget.onlinePodcast.id, nextEpisodeDate: _nextEpisdoeDate);
_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();
}
Future<List<OnlineEpisode>> _getEpisodes(
{String id, int nextEpisodeDate}) async {
2020-07-26 12:20:42 +02:00
var searchEngine = SearchEngine();
var searchResult = await searchEngine.fetchEpisode(
id: id, nextEpisodeDate: nextEpisodeDate);
_nextEpisdoeDate = searchResult.nextEpisodeDate;
_episodeList.addAll(searchResult.episodes.cast());
_loading = false;
return _episodeList;
}
_start(DragStartDetails event) {
setState(() {
_startdy = event.localPosition.dy;
_animation =
Tween<double>(begin: _initSize, end: _initSize).animate(_controller);
});
_controller.forward();
}
_update(DragUpdateDetails event) {
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();
}
_end() {
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();
if (_animation.value < _minHeight - 50) widget.onClose(true);
}
}
}
@override
Widget build(BuildContext context) {
var subscribeWorker = Provider.of<GroupList>(context, listen: false);
final s = context.s;
subscribePodcast(OnlinePodcast podcast) {
2020-07-26 12:20:42 +02:00
var item = SubscribeItem(podcast.rss, podcast.title,
imgUrl: podcast.image, group: 'Home');
subscribeWorker.setSubscribeItem(item);
widget.onSubscribe(podcast);
}
return GestureDetector(
2020-07-26 12:20:42 +02:00
onVerticalDragStart: _start,
onVerticalDragUpdate: _update,
onVerticalDragEnd: (event) => _end(),
2020-07-30 11:29:48 +02:00
child: Container(
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
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(
'${widget.onlinePodcast.interval.toInterval(context)} | '
'${widget.onlinePodcast.latestPubDate.toDate(context)}',
maxLines: 1,
overflow: TextOverflow.fade,
style: TextStyle(color: context.accentColor),
),
2020-08-01 17:10:43 +02:00
!widget.isSubscribed
2020-07-30 11:29:48 +02:00
? OutlineButton(
highlightedBorderColor:
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: () {
subscribePodcast(
widget.onlinePodcast);
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: () {})
],
),
),
),
2020-07-30 11:29:48 +02:00
CachedNetworkImage(
height: 120.0,
width: 120.0,
fit: BoxFit.fitWidth,
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,
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-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),
Container(
padding: const EdgeInsets.only(
2020-07-30 11:29:48 +02:00
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)))
],
)
]),
),
),
),
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(
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: () => _loading
? null
: setState(
() {
_loading = true;
_searchFuture = _getEpisodes(
id: widget.onlinePodcast.id,
nextEpisodeDate:
_nextEpisdoeDate);
},
),
),
2020-07-30 11:29:48 +02:00
),
);
2020-07-30 11:29:48 +02:00
}
return ListTile(
title: Text(content[index].title),
subtitle: Text(
'${content[index].length.toTime} | '
'${content[index].pubDate.toDate(context)}',
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-02-09 13:29:09 +01:00
),
);
}
}