2020-08-10 20:16:15 +02:00
|
|
|
import 'dart:developer' as developer;
|
2020-02-20 10:09:21 +01:00
|
|
|
import 'dart:io';
|
2020-02-09 13:29:09 +01:00
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
2020-07-30 19:19:29 +02:00
|
|
|
import 'package:flutter/rendering.dart';
|
2020-02-22 13:25:06 +01:00
|
|
|
import 'package:flutter/services.dart';
|
2020-02-09 13:29:09 +01:00
|
|
|
import 'package:flutter_html/flutter_html.dart';
|
2020-02-13 03:51:46 +01:00
|
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
2020-07-29 14:06:49 +02:00
|
|
|
import 'package:google_fonts/google_fonts.dart';
|
2020-02-21 16:04:02 +01:00
|
|
|
import 'package:intl/intl.dart';
|
2020-08-10 20:16:15 +02:00
|
|
|
import 'package:linkify/linkify.dart';
|
2020-07-29 14:06:49 +02:00
|
|
|
import 'package:provider/provider.dart';
|
2020-02-25 10:57:12 +01:00
|
|
|
import 'package:tuple/tuple.dart';
|
2020-03-21 17:14:10 +01:00
|
|
|
|
2020-07-26 12:20:42 +02:00
|
|
|
import '../home/audioplayer.dart';
|
|
|
|
import '../local_storage/sqflite_localpodcast.dart';
|
2020-07-07 17:29:21 +02:00
|
|
|
import '../state/audio_state.dart';
|
2020-05-06 18:50:32 +02:00
|
|
|
import '../type/episodebrief.dart';
|
2020-07-22 11:34:32 +02:00
|
|
|
import '../type/play_histroy.dart';
|
2020-07-29 14:06:49 +02:00
|
|
|
import '../util/audiopanel.dart';
|
2020-07-24 16:10:08 +02:00
|
|
|
import '../util/custom_widget.dart';
|
2020-07-26 12:20:42 +02:00
|
|
|
import '../util/extension_helper.dart';
|
2020-07-07 17:29:21 +02:00
|
|
|
import 'episode_download.dart';
|
2020-02-09 13:29:09 +01:00
|
|
|
|
|
|
|
class EpisodeDetail extends StatefulWidget {
|
|
|
|
final EpisodeBrief episodeItem;
|
|
|
|
final String heroTag;
|
2020-03-22 18:03:53 +01:00
|
|
|
final bool hide;
|
2020-04-02 11:52:26 +02:00
|
|
|
EpisodeDetail(
|
|
|
|
{this.episodeItem, this.heroTag = '', this.hide = false, Key key})
|
|
|
|
: super(key: key);
|
2020-02-09 13:29:09 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
_EpisodeDetailState createState() => _EpisodeDetailState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _EpisodeDetailState extends State<EpisodeDetail> {
|
|
|
|
final textstyle = TextStyle(fontSize: 15.0, color: Colors.black);
|
2020-07-29 14:06:49 +02:00
|
|
|
final GlobalKey<AudioPanelState> _playerKey = GlobalKey<AudioPanelState>();
|
2020-02-09 13:29:09 +01:00
|
|
|
double downloadProgress;
|
2020-07-17 16:44:07 +02:00
|
|
|
|
2020-07-17 20:12:41 +02:00
|
|
|
/// Show page title.
|
|
|
|
bool _showTitle;
|
2020-03-01 13:17:06 +01:00
|
|
|
bool _showMenu;
|
2020-02-20 10:09:21 +01:00
|
|
|
String path;
|
2020-02-11 14:01:57 +01:00
|
|
|
|
2020-08-10 15:10:12 +02:00
|
|
|
Future<PlayHistory> _getPosition(EpisodeBrief episode) async {
|
|
|
|
var dbHelper = DBHelper();
|
|
|
|
return await dbHelper.getPosition(episode);
|
|
|
|
}
|
|
|
|
|
2020-03-01 13:17:06 +01:00
|
|
|
ScrollController _controller;
|
|
|
|
_scrollListener() {
|
2020-07-30 19:19:29 +02:00
|
|
|
if (_controller.position.userScrollDirection == ScrollDirection.reverse) {
|
|
|
|
if (_showMenu && mounted) {
|
2020-06-13 15:23:08 +02:00
|
|
|
setState(() {
|
2020-07-30 19:19:29 +02:00
|
|
|
_showMenu = false;
|
2020-06-13 15:23:08 +02:00
|
|
|
});
|
2020-07-26 12:20:42 +02:00
|
|
|
}
|
2020-07-30 19:19:29 +02:00
|
|
|
}
|
|
|
|
if (_controller.position.userScrollDirection == ScrollDirection.forward) {
|
|
|
|
if (!_showMenu && mounted) {
|
2020-06-13 15:23:08 +02:00
|
|
|
setState(() {
|
2020-07-30 19:19:29 +02:00
|
|
|
_showMenu = true;
|
2020-06-13 15:23:08 +02:00
|
|
|
});
|
2020-07-26 12:20:42 +02:00
|
|
|
}
|
2020-06-10 09:42:40 +02:00
|
|
|
}
|
2020-07-17 20:12:41 +02:00
|
|
|
if (_controller.offset > context.textTheme.headline5.fontSize) {
|
|
|
|
if (!_showTitle) setState(() => _showTitle = true);
|
|
|
|
} else if (_showTitle) setState(() => _showTitle = false);
|
2020-03-01 13:17:06 +01:00
|
|
|
}
|
|
|
|
|
2020-02-09 13:29:09 +01:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2020-07-30 19:19:29 +02:00
|
|
|
_showMenu = true;
|
2020-07-17 20:12:41 +02:00
|
|
|
_showTitle = false;
|
2020-08-15 10:24:53 +02:00
|
|
|
//_getSDescription(widget.episodeItem.enclosureUrl);
|
2020-03-01 13:17:06 +01:00
|
|
|
_controller = ScrollController();
|
|
|
|
_controller.addListener(_scrollListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_controller.dispose();
|
|
|
|
super.dispose();
|
2020-02-09 13:29:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-07-07 17:29:21 +02:00
|
|
|
final s = context.s;
|
2020-08-10 15:10:12 +02:00
|
|
|
final audio = context.watch<AudioPlayerNotifier>();
|
2020-02-22 13:25:06 +01:00
|
|
|
return AnnotatedRegion<SystemUiOverlayStyle>(
|
|
|
|
value: SystemUiOverlayStyle(
|
|
|
|
statusBarIconBrightness: Theme.of(context).accentColorBrightness,
|
|
|
|
systemNavigationBarColor: Theme.of(context).primaryColor,
|
2020-03-19 20:58:30 +01:00
|
|
|
systemNavigationBarIconBrightness:
|
|
|
|
Theme.of(context).accentColorBrightness,
|
2020-02-09 13:29:09 +01:00
|
|
|
),
|
2020-07-29 14:06:49 +02:00
|
|
|
child: WillPopScope(
|
|
|
|
onWillPop: () async {
|
|
|
|
if (_playerKey.currentState != null &&
|
|
|
|
_playerKey.currentState.initSize > 100) {
|
|
|
|
_playerKey.currentState.backToMini();
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
child: Scaffold(
|
|
|
|
backgroundColor: Theme.of(context).primaryColor,
|
|
|
|
appBar: AppBar(
|
|
|
|
title: _showTitle
|
|
|
|
? Text(
|
|
|
|
widget.episodeItem.title,
|
|
|
|
maxLines: 1,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
)
|
|
|
|
: Center(),
|
|
|
|
elevation: _showTitle ? 1 : 0,
|
2020-08-10 15:10:12 +02:00
|
|
|
//actions: [
|
|
|
|
// PopupMenuButton(
|
|
|
|
// shape: RoundedRectangleBorder(
|
|
|
|
// borderRadius: BorderRadius.all(Radius.circular(10))),
|
|
|
|
// elevation: 1,
|
|
|
|
// tooltip: s.menu,
|
|
|
|
// itemBuilder: (context) => [
|
|
|
|
// PopupMenuItem(
|
|
|
|
// value: 0,
|
|
|
|
// child: Container(
|
|
|
|
// padding: EdgeInsets.only(left: 10),
|
|
|
|
// child: Row(
|
|
|
|
// crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
// children: <Widget>[
|
|
|
|
// SizedBox(
|
|
|
|
// width: 25,
|
|
|
|
// height: 25,
|
|
|
|
// child: CustomPaint(
|
|
|
|
// painter: ListenedAllPainter(
|
|
|
|
// context.textTheme.bodyText1.color,
|
|
|
|
// stroke: 2)),
|
|
|
|
// ),
|
|
|
|
// Padding(
|
|
|
|
// padding: EdgeInsets.symmetric(horizontal: 5.0),
|
|
|
|
// ),
|
|
|
|
// Text(
|
|
|
|
// s.markListened,
|
|
|
|
// ),
|
|
|
|
// ],
|
|
|
|
// ),
|
|
|
|
// ),
|
|
|
|
// ),
|
|
|
|
// ],
|
|
|
|
// onSelected: (value) async {
|
|
|
|
// switch (value) {
|
|
|
|
// case 0:
|
|
|
|
// await _markListened(widget.episodeItem);
|
|
|
|
// if (mounted) setState(() {});
|
|
|
|
// Fluttertoast.showToast(
|
|
|
|
// msg: s.markListened,
|
|
|
|
// gravity: ToastGravity.BOTTOM,
|
|
|
|
// );
|
|
|
|
// break;
|
|
|
|
// default:
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
// ),
|
|
|
|
//],
|
2020-07-29 14:06:49 +02:00
|
|
|
),
|
|
|
|
body: Stack(
|
|
|
|
children: <Widget>[
|
|
|
|
Container(
|
2020-08-15 10:24:53 +02:00
|
|
|
color: context.primaryColor,
|
2020-07-29 14:06:49 +02:00
|
|
|
child: SingleChildScrollView(
|
|
|
|
scrollDirection: Axis.vertical,
|
|
|
|
controller: _controller,
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 20.0),
|
|
|
|
child: Align(
|
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
child: Text(
|
|
|
|
widget.episodeItem.title,
|
|
|
|
textAlign: TextAlign.left,
|
|
|
|
style: Theme.of(context).textTheme.headline5,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Container(
|
2020-07-17 20:12:41 +02:00
|
|
|
alignment: Alignment.centerLeft,
|
2020-07-29 14:06:49 +02:00
|
|
|
padding: EdgeInsets.only(
|
|
|
|
left: 20.0, right: 20, top: 10, bottom: 10),
|
2020-08-10 20:16:15 +02:00
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
s.published(DateFormat.yMMMd().format(
|
|
|
|
DateTime.fromMillisecondsSinceEpoch(
|
|
|
|
widget.episodeItem.pubDate))),
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).accentColor)),
|
|
|
|
SizedBox(width: 10),
|
|
|
|
if (widget.episodeItem.explicit == 1)
|
|
|
|
Text('E',
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
color: Colors.red))
|
|
|
|
],
|
|
|
|
),
|
2020-07-17 20:12:41 +02:00
|
|
|
),
|
2020-07-29 14:06:49 +02:00
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(
|
2020-08-10 15:10:12 +02:00
|
|
|
left: 20.0, right: 20, top: 5, bottom: 5),
|
2020-07-29 14:06:49 +02:00
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
if (widget.episodeItem.duration != 0)
|
|
|
|
Container(
|
2020-08-10 15:10:12 +02:00
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.cyan[300],
|
|
|
|
borderRadius: BorderRadius.all(
|
|
|
|
Radius.circular(16.0))),
|
|
|
|
height: 32.0,
|
|
|
|
margin: EdgeInsets.only(right: 10.0),
|
|
|
|
padding:
|
|
|
|
EdgeInsets.symmetric(horizontal: 10.0),
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Text(
|
|
|
|
s.minsCount(
|
|
|
|
widget.episodeItem.duration ~/ 60),
|
|
|
|
style: context.textTheme.button)),
|
2020-07-29 14:06:49 +02:00
|
|
|
if (widget.episodeItem.enclosureLength != null &&
|
|
|
|
widget.episodeItem.enclosureLength != 0)
|
|
|
|
Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.lightBlue[300],
|
|
|
|
borderRadius: BorderRadius.all(
|
2020-08-10 15:10:12 +02:00
|
|
|
Radius.circular(16.0))),
|
|
|
|
height: 32.0,
|
2020-07-29 14:06:49 +02:00
|
|
|
margin: EdgeInsets.only(right: 10.0),
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 10.0),
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Text(
|
|
|
|
'${(widget.episodeItem.enclosureLength) ~/ 1000000}MB',
|
2020-08-10 15:10:12 +02:00
|
|
|
style: context.textTheme.button),
|
2020-07-29 14:06:49 +02:00
|
|
|
),
|
2020-08-10 15:10:12 +02:00
|
|
|
FutureBuilder<PlayHistory>(
|
|
|
|
future: _getPosition(widget.episodeItem),
|
|
|
|
builder: (context, snapshot) {
|
2020-08-10 20:16:15 +02:00
|
|
|
if (snapshot.hasError) {
|
|
|
|
developer.log(snapshot.error);
|
|
|
|
}
|
2020-08-10 15:10:12 +02:00
|
|
|
if (snapshot.hasData &&
|
|
|
|
snapshot.data.seekValue < 0.9 &&
|
|
|
|
snapshot.data.seconds > 10) {
|
|
|
|
return OutlineButton(
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius:
|
|
|
|
BorderRadius.circular(100.0),
|
|
|
|
side: BorderSide(
|
|
|
|
color: context.accentColor)),
|
|
|
|
highlightedBorderColor: Colors.green[700],
|
|
|
|
onPressed: () => audio.episodeLoad(
|
|
|
|
widget.episodeItem,
|
|
|
|
startPosition:
|
|
|
|
(snapshot.data.seconds * 1000)
|
|
|
|
.toInt()),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
width: 20,
|
|
|
|
height: 20,
|
|
|
|
child: CustomPaint(
|
|
|
|
painter: ListenedPainter(
|
|
|
|
context.textColor,
|
|
|
|
stroke: 2.0),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(width: 5),
|
|
|
|
Text(snapshot.data.seconds.toTime),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return Center();
|
|
|
|
}
|
|
|
|
}),
|
2020-07-29 14:06:49 +02:00
|
|
|
],
|
|
|
|
),
|
2020-07-17 20:12:41 +02:00
|
|
|
),
|
2020-08-15 10:24:53 +02:00
|
|
|
_ShowNote(episode: widget.episodeItem),
|
|
|
|
// _loaddes
|
|
|
|
// ? _description.length > 0
|
|
|
|
// ? Selector<AudioPlayerNotifier, EpisodeBrief>(
|
|
|
|
// selector: (_, audio) => audio.episode,
|
|
|
|
// builder: (_, data, __) {
|
|
|
|
// var description = _description;
|
|
|
|
// if (data == widget.episodeItem) {
|
|
|
|
// final linkList = linkify(_description,
|
|
|
|
// options:
|
|
|
|
// LinkifyOptions(humanize: false),
|
|
|
|
// linkifiers: [TimeStampLinkifier()]);
|
|
|
|
// for (var element in linkList) {
|
|
|
|
// if (element is TimeStampElement) {
|
|
|
|
// final time = element.timeStamp;
|
|
|
|
// description = description.replaceFirst(
|
|
|
|
// time,
|
|
|
|
// '<a rel="nofollow" href = "skipto:$time">$time</a>');
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// return Html(
|
|
|
|
// padding: EdgeInsets.only(
|
|
|
|
// left: 20.0, right: 20, bottom: 50),
|
|
|
|
// defaultTextStyle: GoogleFonts.martel(
|
|
|
|
// textStyle: TextStyle(
|
|
|
|
// height: 1.8,
|
|
|
|
// ),
|
|
|
|
// ),
|
|
|
|
// data: description,
|
|
|
|
// linkStyle: TextStyle(
|
|
|
|
// color: context.accentColor,
|
|
|
|
// textBaseline:
|
|
|
|
// TextBaseline.ideographic),
|
|
|
|
// onLinkTap: (url) {
|
|
|
|
// if (url.substring(0, 6) == 'skipto') {
|
|
|
|
// final seconds = _getTimeStamp(url);
|
|
|
|
// audio.seekTo(seconds * 1000);
|
|
|
|
// } else {
|
|
|
|
// url.launchUrl;
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
// useRichText: true,
|
|
|
|
// );
|
|
|
|
// })
|
|
|
|
// : Container(
|
|
|
|
// height: context.width,
|
|
|
|
// alignment: Alignment.center,
|
|
|
|
// child: Column(
|
|
|
|
// mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
// children: <Widget>[
|
|
|
|
// Image(
|
|
|
|
// image:
|
|
|
|
// AssetImage('assets/shownote.png'),
|
|
|
|
// height: 100.0,
|
|
|
|
// ),
|
|
|
|
// Padding(padding: EdgeInsets.all(5.0)),
|
|
|
|
// Text(s.noShownote,
|
|
|
|
// textAlign: TextAlign.center,
|
|
|
|
// style: TextStyle(
|
|
|
|
// color: context.textColor
|
|
|
|
// .withOpacity(0.5))),
|
|
|
|
// ],
|
|
|
|
// ),
|
|
|
|
// )
|
|
|
|
// : Center(),
|
2020-07-30 19:19:29 +02:00
|
|
|
Selector<AudioPlayerNotifier, Tuple2<bool, PlayerHeight>>(
|
|
|
|
selector: (_, audio) =>
|
|
|
|
Tuple2(audio.playerRunning, audio.playerHeight),
|
2020-07-29 14:06:49 +02:00
|
|
|
builder: (_, data, __) {
|
2020-07-30 19:19:29 +02:00
|
|
|
var height = kMinPlayerHeight[data.item2.index];
|
2020-07-29 14:06:49 +02:00
|
|
|
return SizedBox(
|
2020-07-30 19:19:29 +02:00
|
|
|
height: data.item1 ? height : 0,
|
2020-07-29 14:06:49 +02:00
|
|
|
);
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
),
|
2020-07-17 20:12:41 +02:00
|
|
|
),
|
2020-02-25 10:57:12 +01:00
|
|
|
),
|
2020-07-30 19:19:29 +02:00
|
|
|
Selector<AudioPlayerNotifier, Tuple2<bool, PlayerHeight>>(
|
|
|
|
selector: (_, audio) =>
|
|
|
|
Tuple2(audio.playerRunning, audio.playerHeight),
|
2020-07-29 14:06:49 +02:00
|
|
|
builder: (_, data, __) {
|
2020-07-30 19:19:29 +02:00
|
|
|
var height = kMinPlayerHeight[data.item2.index];
|
2020-07-29 14:06:49 +02:00
|
|
|
return Container(
|
|
|
|
alignment: Alignment.bottomCenter,
|
2020-07-30 19:19:29 +02:00
|
|
|
padding: EdgeInsets.only(bottom: data.item1 ? height : 0),
|
2020-07-29 14:06:49 +02:00
|
|
|
child: AnimatedContainer(
|
|
|
|
duration: Duration(milliseconds: 400),
|
2020-07-30 19:19:29 +02:00
|
|
|
height: _showMenu ? 50 : 0,
|
2020-07-29 14:06:49 +02:00
|
|
|
child: SingleChildScrollView(
|
|
|
|
scrollDirection: Axis.vertical,
|
2020-08-15 10:24:53 +02:00
|
|
|
child: _MenuBar(
|
2020-07-29 14:06:49 +02:00
|
|
|
episodeItem: widget.episodeItem,
|
|
|
|
heroTag: widget.heroTag,
|
|
|
|
hide: widget.hide),
|
|
|
|
),
|
2020-02-25 10:57:12 +01:00
|
|
|
),
|
2020-07-29 14:06:49 +02:00
|
|
|
);
|
|
|
|
}),
|
2020-08-01 10:00:27 +02:00
|
|
|
Selector<AudioPlayerNotifier, EpisodeBrief>(
|
|
|
|
selector: (_, audio) => audio.episode,
|
|
|
|
builder: (_, data, __) => Container(
|
|
|
|
child: PlayerWidget(
|
|
|
|
playerKey: _playerKey,
|
|
|
|
isPlayingPage: data == widget.episodeItem))),
|
2020-07-29 14:06:49 +02:00
|
|
|
],
|
|
|
|
),
|
2020-02-09 13:29:09 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-15 10:24:53 +02:00
|
|
|
class _MenuBar extends StatefulWidget {
|
2020-02-09 13:29:09 +01:00
|
|
|
final EpisodeBrief episodeItem;
|
|
|
|
final String heroTag;
|
2020-03-22 18:03:53 +01:00
|
|
|
final bool hide;
|
2020-08-15 10:24:53 +02:00
|
|
|
_MenuBar({this.episodeItem, this.heroTag, this.hide, Key key})
|
2020-04-02 11:52:26 +02:00
|
|
|
: super(key: key);
|
2020-02-09 13:29:09 +01:00
|
|
|
@override
|
2020-08-15 10:24:53 +02:00
|
|
|
__MenuBarState createState() => __MenuBarState();
|
2020-02-09 13:29:09 +01:00
|
|
|
}
|
|
|
|
|
2020-08-15 10:24:53 +02:00
|
|
|
class __MenuBarState extends State<_MenuBar> {
|
2020-08-10 15:10:12 +02:00
|
|
|
Future<int> _isListened(EpisodeBrief episode) async {
|
2020-04-11 19:23:12 +02:00
|
|
|
var dbHelper = DBHelper();
|
2020-08-10 15:10:12 +02:00
|
|
|
return await dbHelper.isListened(episode.enclosureUrl);
|
2020-04-11 19:23:12 +02:00
|
|
|
}
|
2020-02-09 13:29:09 +01:00
|
|
|
|
2020-08-10 15:10:12 +02:00
|
|
|
_saveLiked(String url) async {
|
2020-02-09 13:29:09 +01:00
|
|
|
var dbHelper = DBHelper();
|
2020-06-11 17:13:10 +02:00
|
|
|
await dbHelper.setLiked(url);
|
2020-07-17 16:44:07 +02:00
|
|
|
if (mounted) setState(() {});
|
2020-02-09 13:29:09 +01:00
|
|
|
}
|
|
|
|
|
2020-08-10 15:10:12 +02:00
|
|
|
_setUnliked(String url) async {
|
2020-02-09 13:29:09 +01:00
|
|
|
var dbHelper = DBHelper();
|
2020-06-13 15:23:08 +02:00
|
|
|
await dbHelper.setUniked(url);
|
2020-07-17 16:44:07 +02:00
|
|
|
if (mounted) setState(() {});
|
2020-02-09 13:29:09 +01:00
|
|
|
}
|
|
|
|
|
2020-08-10 15:10:12 +02:00
|
|
|
_markListened(EpisodeBrief episode) async {
|
|
|
|
var dbHelper = DBHelper();
|
|
|
|
//var marked = await dbHelper.checkMarked(episode);
|
|
|
|
//if (!marked) {
|
|
|
|
final history = PlayHistory(episode.title, episode.enclosureUrl, 0, 1);
|
|
|
|
await dbHelper.saveHistory(history);
|
|
|
|
//}
|
|
|
|
if (mounted) setState(() {});
|
|
|
|
}
|
|
|
|
|
|
|
|
_markNotListened(String url) async {
|
|
|
|
var dbHelper = DBHelper();
|
|
|
|
await dbHelper.markNotListened(url);
|
|
|
|
if (mounted) setState(() {});
|
|
|
|
}
|
|
|
|
|
2020-04-11 19:23:12 +02:00
|
|
|
Future<bool> _isLiked(EpisodeBrief episode) async {
|
2020-07-26 12:20:42 +02:00
|
|
|
var dbHelper = DBHelper();
|
2020-04-11 19:23:12 +02:00
|
|
|
return await dbHelper.isLiked(episode.enclosureUrl);
|
|
|
|
}
|
|
|
|
|
2020-08-03 15:15:37 +02:00
|
|
|
Widget _buttonOnMenu({Widget child, VoidCallback onTap}) => Material(
|
2020-02-13 03:51:46 +01:00
|
|
|
color: Colors.transparent,
|
|
|
|
child: InkWell(
|
|
|
|
onTap: onTap,
|
2020-08-10 15:10:12 +02:00
|
|
|
child: SizedBox(
|
|
|
|
height: 50,
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 15.0), child: child),
|
|
|
|
),
|
2020-02-13 03:51:46 +01:00
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2020-06-13 15:23:08 +02:00
|
|
|
OverlayEntry _createOverlayEntry() {
|
|
|
|
RenderBox renderBox = context.findRenderObject();
|
|
|
|
var offset = renderBox.localToGlobal(Offset.zero);
|
|
|
|
return OverlayEntry(
|
|
|
|
builder: (constext) => Positioned(
|
|
|
|
left: offset.dx + 50,
|
|
|
|
top: offset.dy - 60,
|
|
|
|
child: Container(
|
|
|
|
width: 70,
|
|
|
|
height: 100,
|
|
|
|
//color: Colors.grey[200],
|
|
|
|
child: HeartOpen(width: 50, height: 80)),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-02-09 13:29:09 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-03-14 04:14:24 +01:00
|
|
|
var audio = Provider.of<AudioPlayerNotifier>(context, listen: false);
|
2020-07-07 17:29:21 +02:00
|
|
|
final s = context.s;
|
2020-02-22 13:25:06 +01:00
|
|
|
return Container(
|
|
|
|
height: 50.0,
|
|
|
|
decoration: BoxDecoration(
|
2020-07-30 11:28:29 +02:00
|
|
|
color: context.scaffoldBackgroundColor,
|
2020-02-22 13:25:06 +01:00
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
2020-06-06 11:05:38 +02:00
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
|
|
|
Hero(
|
|
|
|
tag: widget.episodeItem.enclosureUrl + widget.heroTag,
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 10.0),
|
|
|
|
child: Container(
|
|
|
|
height: 30.0,
|
|
|
|
width: 30.0,
|
2020-07-30 11:28:29 +02:00
|
|
|
color: context.scaffoldBackgroundColor,
|
2020-06-06 11:05:38 +02:00
|
|
|
child: widget.hide
|
2020-04-11 19:23:12 +02:00
|
|
|
? Center()
|
2020-06-06 11:05:38 +02:00
|
|
|
: CircleAvatar(
|
2020-07-30 11:28:29 +02:00
|
|
|
radius: 15,
|
2020-08-15 19:43:45 +02:00
|
|
|
backgroundImage:
|
|
|
|
widget.episodeItem.avatarImage),
|
2020-06-06 11:05:38 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
FutureBuilder<bool>(
|
|
|
|
future: _isLiked(widget.episodeItem),
|
|
|
|
initialData: false,
|
2020-07-26 12:20:42 +02:00
|
|
|
builder: (context, snapshot) {
|
2020-06-10 18:36:53 +02:00
|
|
|
return (!snapshot.data)
|
2020-06-06 11:05:38 +02:00
|
|
|
? _buttonOnMenu(
|
2020-08-03 15:15:37 +02:00
|
|
|
child: Icon(
|
2020-06-06 11:05:38 +02:00
|
|
|
Icons.favorite_border,
|
|
|
|
color: Colors.grey[700],
|
2020-08-03 15:15:37 +02:00
|
|
|
),
|
|
|
|
onTap: () async {
|
2020-08-10 15:10:12 +02:00
|
|
|
await _saveLiked(
|
2020-08-03 15:15:37 +02:00
|
|
|
widget.episodeItem.enclosureUrl);
|
|
|
|
OverlayEntry _overlayEntry;
|
|
|
|
_overlayEntry = _createOverlayEntry();
|
|
|
|
Overlay.of(context).insert(_overlayEntry);
|
|
|
|
await Future.delayed(Duration(seconds: 2));
|
|
|
|
_overlayEntry?.remove();
|
|
|
|
})
|
2020-06-10 18:36:53 +02:00
|
|
|
: _buttonOnMenu(
|
2020-08-03 15:15:37 +02:00
|
|
|
child: Icon(
|
2020-06-10 18:36:53 +02:00
|
|
|
Icons.favorite,
|
|
|
|
color: Colors.red,
|
|
|
|
),
|
2020-08-03 15:15:37 +02:00
|
|
|
onTap: () =>
|
2020-08-10 15:10:12 +02:00
|
|
|
_setUnliked(widget.episodeItem.enclosureUrl));
|
2020-06-06 11:05:38 +02:00
|
|
|
},
|
|
|
|
),
|
|
|
|
DownloadButton(episode: widget.episodeItem),
|
2020-08-03 15:15:37 +02:00
|
|
|
Selector<AudioPlayerNotifier,
|
|
|
|
Tuple2<List<EpisodeBrief>, bool>>(
|
|
|
|
selector: (_, audio) =>
|
|
|
|
Tuple2(audio.queue.playlist, audio.queueUpdate),
|
2020-06-06 11:05:38 +02:00
|
|
|
builder: (_, data, __) {
|
2020-08-15 10:24:53 +02:00
|
|
|
return (data.item1.contains(widget.episodeItem) &&
|
|
|
|
!widget.hide)
|
2020-06-06 11:05:38 +02:00
|
|
|
? _buttonOnMenu(
|
2020-08-03 15:15:37 +02:00
|
|
|
child: Icon(Icons.playlist_add_check,
|
|
|
|
color: context.accentColor),
|
|
|
|
onTap: () {
|
|
|
|
audio.delFromPlaylist(widget.episodeItem);
|
|
|
|
Fluttertoast.showToast(
|
|
|
|
msg: s.toastRemovePlaylist,
|
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
})
|
2020-06-06 11:05:38 +02:00
|
|
|
: _buttonOnMenu(
|
2020-08-03 15:15:37 +02:00
|
|
|
child: Icon(Icons.playlist_add,
|
|
|
|
color: Colors.grey[700]),
|
|
|
|
onTap: () {
|
|
|
|
audio.addToPlaylist(widget.episodeItem);
|
|
|
|
Fluttertoast.showToast(
|
|
|
|
msg: s.toastAddPlaylist,
|
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
});
|
2020-06-06 11:05:38 +02:00
|
|
|
},
|
|
|
|
),
|
2020-08-10 15:10:12 +02:00
|
|
|
FutureBuilder<int>(
|
|
|
|
future: _isListened(widget.episodeItem),
|
|
|
|
initialData: 0,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
return snapshot.data == 0
|
|
|
|
? _buttonOnMenu(
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 12),
|
|
|
|
child: CustomPaint(
|
|
|
|
size: Size(25, 20),
|
|
|
|
painter: ListenedAllPainter(Colors.grey[700],
|
|
|
|
stroke: 2.0),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onTap: () {
|
|
|
|
_markListened(widget.episodeItem);
|
|
|
|
Fluttertoast.showToast(
|
|
|
|
msg: s.markListened,
|
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
})
|
|
|
|
: _buttonOnMenu(
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 12),
|
|
|
|
child: CustomPaint(
|
|
|
|
size: Size(25, 20),
|
|
|
|
painter: ListenedAllPainter(
|
|
|
|
context.accentColor,
|
|
|
|
stroke: 2.0),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onTap: () {
|
|
|
|
_markNotListened(
|
|
|
|
widget.episodeItem.enclosureUrl);
|
|
|
|
Fluttertoast.showToast(
|
|
|
|
msg: s.markNotListened,
|
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
2020-06-06 11:05:38 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2020-04-22 20:10:57 +02:00
|
|
|
Selector<AudioPlayerNotifier, Tuple2<EpisodeBrief, bool>>(
|
2020-06-07 14:47:28 +02:00
|
|
|
selector: (_, audio) => Tuple2(audio.episode, audio.playerRunning),
|
2020-02-25 10:57:12 +01:00
|
|
|
builder: (_, data, __) {
|
2020-08-01 10:00:27 +02:00
|
|
|
return (widget.episodeItem == data.item1 && data.item2)
|
2020-04-22 20:10:57 +02:00
|
|
|
? Container(
|
|
|
|
padding: EdgeInsets.only(right: 30),
|
|
|
|
child: SizedBox(
|
|
|
|
width: 20,
|
|
|
|
height: 15,
|
|
|
|
child: WaveLoader(color: context.accentColor)))
|
|
|
|
: Material(
|
2020-02-25 10:57:12 +01:00
|
|
|
color: Colors.transparent,
|
|
|
|
child: InkWell(
|
|
|
|
onTap: () {
|
|
|
|
audio.episodeLoad(widget.episodeItem);
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
height: 50.0,
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 20.0),
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
2020-07-07 17:29:21 +02:00
|
|
|
Text(s.play,
|
2020-02-25 10:57:12 +01:00
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).accentColor,
|
|
|
|
fontSize: 15,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
)),
|
|
|
|
Icon(
|
|
|
|
Icons.play_arrow,
|
2020-02-22 13:25:06 +01:00
|
|
|
color: Theme.of(context).accentColor,
|
2020-02-25 10:57:12 +01:00
|
|
|
),
|
|
|
|
],
|
2020-02-22 13:25:06 +01:00
|
|
|
),
|
2020-02-25 10:57:12 +01:00
|
|
|
),
|
2020-02-09 13:29:09 +01:00
|
|
|
),
|
2020-04-22 20:10:57 +02:00
|
|
|
);
|
2020-02-25 10:57:12 +01:00
|
|
|
},
|
|
|
|
),
|
2020-02-22 13:25:06 +01:00
|
|
|
],
|
|
|
|
),
|
2020-02-09 13:29:09 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-08-15 10:24:53 +02:00
|
|
|
|
|
|
|
class _ShowNote extends StatelessWidget {
|
|
|
|
final EpisodeBrief episode;
|
|
|
|
const _ShowNote({this.episode, Key key}) : super(key: key);
|
|
|
|
|
|
|
|
int _getTimeStamp(String url) {
|
|
|
|
final time = url.substring(7);
|
|
|
|
final data = time.split(':');
|
|
|
|
var seconds;
|
|
|
|
if (data.length == 3) {
|
|
|
|
seconds = int.tryParse(data[0]) * 3600 +
|
|
|
|
int.tryParse(data[1]) * 60 +
|
|
|
|
int.tryParse(data[2]);
|
|
|
|
} else if (data.length == 2) {
|
|
|
|
seconds = int.tryParse(data[0]) * 60 + int.tryParse(data[1]);
|
|
|
|
}
|
|
|
|
return seconds;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<String> _getSDescription(String url) async {
|
|
|
|
var description;
|
|
|
|
var dbHelper = DBHelper();
|
|
|
|
description = (await dbHelper.getDescription(url))
|
|
|
|
.replaceAll(RegExp(r'\s?<p>(<br>)?</p>\s?'), '')
|
|
|
|
.replaceAll('\r', '')
|
|
|
|
.trim();
|
|
|
|
if (!description.contains('<')) {
|
|
|
|
final linkList = linkify(description,
|
|
|
|
options: LinkifyOptions(humanize: false),
|
|
|
|
linkifiers: [UrlLinkifier(), EmailLinkifier()]);
|
|
|
|
for (var element in linkList) {
|
|
|
|
if (element is UrlElement) {
|
|
|
|
description = description.replaceAll(element.url,
|
|
|
|
'<a rel="nofollow" href = ${element.url}>${element.text}</a>');
|
|
|
|
}
|
|
|
|
if (element is EmailElement) {
|
|
|
|
final address = element.emailAddress;
|
|
|
|
description = description.replaceAll(address,
|
|
|
|
'<a rel="nofollow" href = "mailto:$address">$address</a>');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return description;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
var audio = context.watch<AudioPlayerNotifier>();
|
|
|
|
final s = context.s;
|
|
|
|
return FutureBuilder(
|
|
|
|
future: _getSDescription(episode.enclosureUrl),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
var description = snapshot.data;
|
|
|
|
return description.length > 0
|
|
|
|
? Selector<AudioPlayerNotifier, EpisodeBrief>(
|
|
|
|
selector: (_, audio) => audio.episode,
|
|
|
|
builder: (_, data, __) {
|
|
|
|
if (data == episode) {
|
|
|
|
final linkList = linkify(description,
|
|
|
|
options: LinkifyOptions(humanize: false),
|
|
|
|
linkifiers: [TimeStampLinkifier()]);
|
|
|
|
for (var element in linkList) {
|
|
|
|
if (element is TimeStampElement) {
|
|
|
|
final time = element.timeStamp;
|
|
|
|
description = description.replaceFirst(time,
|
|
|
|
'<a rel="nofollow" href = "skipto:$time">$time</a>');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Html(
|
|
|
|
padding:
|
|
|
|
EdgeInsets.only(left: 20.0, right: 20, bottom: 50),
|
|
|
|
defaultTextStyle: GoogleFonts.martel(
|
|
|
|
textStyle: TextStyle(
|
|
|
|
height: 1.8,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
data: description,
|
|
|
|
linkStyle: TextStyle(
|
|
|
|
color: context.accentColor,
|
|
|
|
textBaseline: TextBaseline.ideographic),
|
|
|
|
onLinkTap: (url) {
|
|
|
|
if (url.substring(0, 6) == 'skipto') {
|
|
|
|
final seconds = _getTimeStamp(url);
|
|
|
|
audio.seekTo(seconds * 1000);
|
|
|
|
} else {
|
|
|
|
url.launchUrl;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
useRichText: true,
|
|
|
|
);
|
|
|
|
})
|
|
|
|
: Container(
|
|
|
|
height: context.width,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
Image(
|
|
|
|
image: AssetImage('assets/shownote.png'),
|
|
|
|
height: 100.0,
|
|
|
|
),
|
|
|
|
Padding(padding: EdgeInsets.all(5.0)),
|
|
|
|
Text(s.noShownote,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
color: context.textColor.withOpacity(0.5))),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return Center();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|