2020-02-11 14:01:57 +01:00
|
|
|
import 'dart:io';
|
|
|
|
import 'dart:async';
|
|
|
|
|
2020-02-09 13:29:09 +01:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2020-02-11 14:01:57 +01:00
|
|
|
import 'package:provider/provider.dart';
|
2020-02-20 10:09:21 +01:00
|
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
2020-03-14 04:14:24 +01:00
|
|
|
import 'package:tuple/tuple.dart';
|
|
|
|
import 'package:line_icons/line_icons.dart';
|
2020-04-18 06:48:02 +02:00
|
|
|
|
2020-05-06 18:50:32 +02:00
|
|
|
import '../type/episodebrief.dart';
|
|
|
|
import '../state/podcast_group.dart';
|
2020-06-03 14:39:15 +02:00
|
|
|
import '../state/subscribe_podcast.dart';
|
2020-06-10 09:42:40 +02:00
|
|
|
import '../state/download_state.dart';
|
2020-05-06 18:50:32 +02:00
|
|
|
import '../type/podcastlocal.dart';
|
|
|
|
import '../state/audiostate.dart';
|
|
|
|
import '../util/custompaint.dart';
|
|
|
|
import '../util/pageroute.dart';
|
|
|
|
import '../util/colorize.dart';
|
|
|
|
import '../util/context_extension.dart';
|
2020-04-18 06:48:02 +02:00
|
|
|
import '../local_storage/sqflite_localpodcast.dart';
|
2020-06-10 09:42:40 +02:00
|
|
|
import '../local_storage/key_value_storage.dart';
|
2020-04-18 06:48:02 +02:00
|
|
|
import '../episodes/episodedetail.dart';
|
|
|
|
import '../podcasts/podcastdetail.dart';
|
|
|
|
import '../podcasts/podcastmanage.dart';
|
2020-02-09 13:29:09 +01:00
|
|
|
|
|
|
|
class ScrollPodcasts extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_ScrollPodcastsState createState() => _ScrollPodcastsState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ScrollPodcastsState extends State<ScrollPodcasts> {
|
2020-02-20 10:09:21 +01:00
|
|
|
int _groupIndex;
|
2020-04-22 20:10:57 +02:00
|
|
|
|
2020-04-23 19:46:36 +02:00
|
|
|
Future<int> getPodcastUpdateCounts(String id) async {
|
2020-04-22 20:10:57 +02:00
|
|
|
var dbHelper = DBHelper();
|
2020-04-23 19:46:36 +02:00
|
|
|
return await dbHelper.getPodcastUpdateCounts(id);
|
2020-04-22 20:10:57 +02:00
|
|
|
}
|
|
|
|
|
2020-02-16 09:25:53 +01:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2020-02-20 10:09:21 +01:00
|
|
|
_groupIndex = 0;
|
2020-02-16 09:25:53 +01:00
|
|
|
}
|
|
|
|
|
2020-04-29 19:32:45 +02:00
|
|
|
Widget _circleContainer(BuildContext context) => Container(
|
|
|
|
margin: EdgeInsets.symmetric(horizontal: 10),
|
|
|
|
height: 50,
|
|
|
|
width: 50,
|
|
|
|
decoration:
|
|
|
|
BoxDecoration(shape: BoxShape.circle, color: context.primaryColor),
|
|
|
|
);
|
|
|
|
|
2020-02-09 13:29:09 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-02-15 08:53:26 +01:00
|
|
|
double _width = MediaQuery.of(context).size.width;
|
2020-02-20 10:09:21 +01:00
|
|
|
return Consumer<GroupList>(builder: (_, groupList, __) {
|
|
|
|
var groups = groupList.groups;
|
|
|
|
bool isLoading = groupList.isLoading;
|
|
|
|
return isLoading
|
|
|
|
? Container(
|
2020-03-21 17:14:10 +01:00
|
|
|
height: (_width - 20) / 3 + 140,
|
2020-02-20 10:09:21 +01:00
|
|
|
)
|
2020-02-23 14:20:07 +01:00
|
|
|
: groups[_groupIndex].podcastList.length == 0
|
2020-03-25 16:33:48 +01:00
|
|
|
? Container(
|
|
|
|
height: (_width - 20) / 3 + 140,
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
|
|
|
GestureDetector(
|
|
|
|
onVerticalDragEnd: (event) {
|
|
|
|
if (event.primaryVelocity > 200) {
|
|
|
|
if (groups.length == 1) {
|
|
|
|
Fluttertoast.showToast(
|
|
|
|
msg: 'Add some groups',
|
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
if (mounted)
|
|
|
|
setState(() {
|
|
|
|
(_groupIndex != 0)
|
|
|
|
? _groupIndex--
|
|
|
|
: _groupIndex = groups.length - 1;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else if (event.primaryVelocity < -200) {
|
|
|
|
if (groups.length == 1) {
|
|
|
|
Fluttertoast.showToast(
|
|
|
|
msg: 'Add some groups',
|
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
} else {
|
2020-02-23 14:20:07 +01:00
|
|
|
setState(() {
|
2020-03-25 16:33:48 +01:00
|
|
|
(_groupIndex < groups.length - 1)
|
|
|
|
? _groupIndex++
|
|
|
|
: _groupIndex = 0;
|
2020-02-23 14:20:07 +01:00
|
|
|
});
|
2020-03-25 16:33:48 +01:00
|
|
|
}
|
2020-02-23 14:20:07 +01:00
|
|
|
}
|
2020-03-25 16:33:48 +01:00
|
|
|
},
|
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
Container(
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
Container(
|
|
|
|
padding: EdgeInsets.symmetric(
|
|
|
|
horizontal: 15.0),
|
|
|
|
child: Text(
|
|
|
|
groups[_groupIndex].name,
|
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.bodyText1
|
|
|
|
.copyWith(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.accentColor),
|
|
|
|
)),
|
|
|
|
Spacer(),
|
|
|
|
Container(
|
|
|
|
height: 30,
|
|
|
|
padding:
|
|
|
|
EdgeInsets.symmetric(horizontal: 15),
|
|
|
|
alignment: Alignment.bottomRight,
|
|
|
|
child: InkWell(
|
|
|
|
onTap: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
SlideLeftRoute(
|
|
|
|
page: PodcastManage()),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
height: 30,
|
|
|
|
padding: EdgeInsets.all(5.0),
|
|
|
|
child: Text(
|
|
|
|
'See All',
|
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.bodyText1
|
|
|
|
.copyWith(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.accentColor),
|
|
|
|
)),
|
|
|
|
),
|
2020-02-23 14:20:07 +01:00
|
|
|
),
|
2020-03-25 16:33:48 +01:00
|
|
|
],
|
|
|
|
),
|
2020-02-23 14:20:07 +01:00
|
|
|
),
|
2020-03-25 16:33:48 +01:00
|
|
|
Container(
|
2020-04-29 19:32:45 +02:00
|
|
|
height: 70,
|
|
|
|
color:
|
|
|
|
Theme.of(context).scaffoldBackgroundColor,
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
_circleContainer(context),
|
|
|
|
_circleContainer(context),
|
|
|
|
_circleContainer(context)
|
|
|
|
],
|
|
|
|
)),
|
2020-03-25 16:33:48 +01:00
|
|
|
],
|
|
|
|
)),
|
|
|
|
Container(
|
|
|
|
height: (_width - 20) / 3 + 40,
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
margin: EdgeInsets.symmetric(horizontal: 15),
|
2020-04-29 19:32:45 +02:00
|
|
|
child: Center(
|
|
|
|
child: _groupIndex == 0
|
|
|
|
? Text.rich(TextSpan(
|
|
|
|
style: context.textTheme.headline6
|
|
|
|
.copyWith(height: 2),
|
|
|
|
children: [
|
|
|
|
TextSpan(
|
|
|
|
text: 'Welcome to Tsacdop\n',
|
|
|
|
style: context.textTheme.headline6
|
|
|
|
.copyWith(
|
|
|
|
color: context.accentColor)),
|
|
|
|
TextSpan(
|
|
|
|
text: 'Get started\n',
|
|
|
|
style: context.textTheme.headline6
|
|
|
|
.copyWith(
|
|
|
|
color: context.accentColor)),
|
|
|
|
TextSpan(text: 'Tap '),
|
|
|
|
WidgetSpan(
|
|
|
|
child:
|
|
|
|
Icon(Icons.add_circle_outline)),
|
|
|
|
TextSpan(text: ' to subscribe podcasts')
|
|
|
|
],
|
|
|
|
))
|
|
|
|
: Text('No podcast in this group',
|
|
|
|
style: TextStyle(
|
|
|
|
color: context.textTheme.bodyText2.color
|
|
|
|
.withOpacity(0.5)))),
|
2020-03-25 16:33:48 +01:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2020-02-23 14:20:07 +01:00
|
|
|
)
|
|
|
|
: DefaultTabController(
|
|
|
|
length: groups[_groupIndex].podcastList.length,
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
|
|
|
GestureDetector(
|
|
|
|
onVerticalDragEnd: (event) {
|
|
|
|
if (event.primaryVelocity > 200) {
|
|
|
|
if (groups.length == 1) {
|
|
|
|
Fluttertoast.showToast(
|
|
|
|
msg: 'Add some groups',
|
|
|
|
gravity: ToastGravity.BOTTOM,
|
2020-02-20 10:09:21 +01:00
|
|
|
);
|
2020-02-23 14:20:07 +01:00
|
|
|
} else {
|
|
|
|
if (mounted)
|
|
|
|
setState(() {
|
|
|
|
(_groupIndex != 0)
|
|
|
|
? _groupIndex--
|
|
|
|
: _groupIndex = groups.length - 1;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else if (event.primaryVelocity < -200) {
|
|
|
|
if (groups.length == 1) {
|
|
|
|
Fluttertoast.showToast(
|
|
|
|
msg: 'Add some groups',
|
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
setState(() {
|
|
|
|
(_groupIndex < groups.length - 1)
|
|
|
|
? _groupIndex++
|
|
|
|
: _groupIndex = 0;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
Container(
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
Container(
|
|
|
|
padding: EdgeInsets.symmetric(
|
|
|
|
horizontal: 15.0),
|
|
|
|
child: Text(
|
|
|
|
groups[_groupIndex].name,
|
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.bodyText1
|
2020-03-14 04:14:24 +01:00
|
|
|
.copyWith(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.accentColor),
|
2020-02-23 14:20:07 +01:00
|
|
|
)),
|
|
|
|
Spacer(),
|
|
|
|
Container(
|
2020-03-25 16:33:48 +01:00
|
|
|
height: 30.0,
|
2020-02-23 14:20:07 +01:00
|
|
|
padding:
|
|
|
|
EdgeInsets.symmetric(horizontal: 15),
|
|
|
|
alignment: Alignment.bottomRight,
|
|
|
|
child: InkWell(
|
|
|
|
onTap: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
SlideLeftRoute(page: PodcastManage()),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
height: 30,
|
|
|
|
padding: EdgeInsets.all(5.0),
|
|
|
|
child: Text(
|
|
|
|
'See All',
|
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.bodyText1
|
|
|
|
.copyWith(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.accentColor),
|
|
|
|
)),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
height: 70,
|
|
|
|
width: _width,
|
|
|
|
alignment: Alignment.centerLeft,
|
2020-04-11 19:23:12 +02:00
|
|
|
color: context.scaffoldBackgroundColor,
|
2020-02-23 14:20:07 +01:00
|
|
|
child: TabBar(
|
|
|
|
labelPadding: EdgeInsets.only(
|
|
|
|
top: 5.0,
|
|
|
|
bottom: 10.0,
|
|
|
|
left: 6.0,
|
|
|
|
right: 6.0),
|
|
|
|
indicator: CircleTabIndicator(
|
2020-03-01 13:17:06 +01:00
|
|
|
color: Theme.of(context).accentColor,
|
|
|
|
radius: 3),
|
2020-02-23 14:20:07 +01:00
|
|
|
isScrollable: true,
|
|
|
|
tabs: groups[_groupIndex]
|
|
|
|
.podcasts
|
2020-04-11 19:23:12 +02:00
|
|
|
.map<Widget>((PodcastLocal podcastLocal) {
|
2020-02-23 14:20:07 +01:00
|
|
|
return Tab(
|
|
|
|
child: ClipRRect(
|
|
|
|
borderRadius: BorderRadius.all(
|
|
|
|
Radius.circular(25.0)),
|
2020-03-19 20:58:30 +01:00
|
|
|
child: Stack(
|
|
|
|
alignment: Alignment.bottomCenter,
|
|
|
|
children: <Widget>[
|
|
|
|
LimitedBox(
|
|
|
|
maxHeight: 50,
|
|
|
|
maxWidth: 50,
|
|
|
|
child: Image.file(File(
|
|
|
|
"${podcastLocal.imagePath}")),
|
|
|
|
),
|
2020-04-22 20:10:57 +02:00
|
|
|
FutureBuilder<int>(
|
2020-04-23 19:46:36 +02:00
|
|
|
future: getPodcastUpdateCounts(
|
2020-04-22 20:10:57 +02:00
|
|
|
podcastLocal.id),
|
|
|
|
initialData: 0,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
return snapshot.data > 0
|
|
|
|
? Container(
|
|
|
|
alignment:
|
|
|
|
Alignment.center,
|
|
|
|
height: 10,
|
|
|
|
width: 40,
|
|
|
|
color: Colors.black54,
|
|
|
|
child: Text('New',
|
|
|
|
style: TextStyle(
|
|
|
|
color:
|
|
|
|
Colors.red,
|
|
|
|
fontSize: 8,
|
|
|
|
fontStyle:
|
|
|
|
FontStyle
|
|
|
|
.italic)),
|
|
|
|
)
|
|
|
|
: Center();
|
|
|
|
}),
|
2020-03-19 20:58:30 +01:00
|
|
|
],
|
2020-02-23 14:20:07 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}).toList(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2020-02-09 13:29:09 +01:00
|
|
|
),
|
2020-02-23 14:20:07 +01:00
|
|
|
),
|
2020-04-18 06:48:02 +02:00
|
|
|
Container(
|
|
|
|
height: (_width - 20) / 3 + 40,
|
|
|
|
margin: EdgeInsets.only(left: 10, right: 10),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Theme.of(context).scaffoldBackgroundColor,
|
|
|
|
),
|
|
|
|
child: TabBarView(
|
|
|
|
children: groups[_groupIndex]
|
|
|
|
.podcasts
|
|
|
|
.map<Widget>((PodcastLocal podcastLocal) {
|
|
|
|
return Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Theme.of(context).brightness ==
|
|
|
|
Brightness.light
|
|
|
|
? Theme.of(context).primaryColor
|
|
|
|
: Colors.black12),
|
|
|
|
margin: EdgeInsets.symmetric(horizontal: 5.0),
|
|
|
|
key: ObjectKey(podcastLocal.title),
|
|
|
|
child: PodcastPreview(
|
|
|
|
podcastLocal: podcastLocal,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}).toList(),
|
2020-02-23 14:20:07 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2020-02-20 10:09:21 +01:00
|
|
|
),
|
2020-02-23 14:20:07 +01:00
|
|
|
);
|
2020-02-20 10:09:21 +01:00
|
|
|
});
|
2020-02-09 13:29:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-10 18:36:53 +02:00
|
|
|
class PodcastPreview extends StatelessWidget {
|
2020-02-09 13:29:09 +01:00
|
|
|
final PodcastLocal podcastLocal;
|
|
|
|
PodcastPreview({this.podcastLocal, Key key}) : super(key: key);
|
|
|
|
|
|
|
|
Future<List<EpisodeBrief>> _getRssItemTop(PodcastLocal podcastLocal) async {
|
|
|
|
var dbHelper = DBHelper();
|
2020-03-01 13:17:06 +01:00
|
|
|
List<EpisodeBrief> episodes = await dbHelper.getRssItemTop(podcastLocal.id);
|
2020-02-09 13:29:09 +01:00
|
|
|
return episodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-03-01 13:17:06 +01:00
|
|
|
Color _c = (Theme.of(context).brightness == Brightness.light)
|
2020-06-10 18:36:53 +02:00
|
|
|
? podcastLocal.primaryColor.colorizedark()
|
|
|
|
: podcastLocal.primaryColor.colorizeLight();
|
2020-02-09 13:29:09 +01:00
|
|
|
return Column(
|
|
|
|
children: <Widget>[
|
|
|
|
Expanded(
|
2020-06-03 14:39:15 +02:00
|
|
|
child: Selector<SubscribeWorker, bool>(
|
|
|
|
selector: (_, worker) => worker.created,
|
|
|
|
builder: (context, created, child) {
|
|
|
|
return FutureBuilder<List<EpisodeBrief>>(
|
2020-06-10 18:36:53 +02:00
|
|
|
future: _getRssItemTop(podcastLocal),
|
2020-06-03 14:39:15 +02:00
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasError) {
|
|
|
|
print(snapshot.error);
|
|
|
|
Center();
|
|
|
|
}
|
|
|
|
return (snapshot.hasData)
|
|
|
|
? ShowEpisode(
|
|
|
|
episodes: snapshot.data,
|
2020-06-10 18:36:53 +02:00
|
|
|
podcastLocal: podcastLocal,
|
2020-06-03 14:39:15 +02:00
|
|
|
)
|
|
|
|
: Container(
|
|
|
|
padding: EdgeInsets.all(5.0),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}),
|
2020-02-09 13:29:09 +01:00
|
|
|
),
|
|
|
|
Container(
|
|
|
|
height: 40,
|
2020-06-03 14:39:15 +02:00
|
|
|
padding: EdgeInsets.only(left: 10.0),
|
2020-02-09 13:29:09 +01:00
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
2020-02-21 16:04:02 +01:00
|
|
|
Expanded(
|
|
|
|
flex: 4,
|
2020-06-10 18:36:53 +02:00
|
|
|
child: Text(podcastLocal.title,
|
2020-02-21 16:04:02 +01:00
|
|
|
maxLines: 1,
|
|
|
|
overflow: TextOverflow.visible,
|
|
|
|
style: TextStyle(fontWeight: FontWeight.bold, color: _c)),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
flex: 1,
|
|
|
|
child: Container(
|
|
|
|
alignment: Alignment.centerRight,
|
|
|
|
child: Material(
|
|
|
|
color: Colors.transparent,
|
2020-06-03 14:39:15 +02:00
|
|
|
child: Selector<AudioPlayerNotifier, bool>(
|
|
|
|
selector: (_, audio) => audio.playerRunning,
|
|
|
|
builder: (_, playerRunning, __) => IconButton(
|
|
|
|
icon: Icon(Icons.arrow_forward),
|
|
|
|
tooltip: 'See All',
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
SlideLeftHideRoute(
|
|
|
|
transitionPage: PodcastDetail(
|
2020-06-10 18:36:53 +02:00
|
|
|
podcastLocal: podcastLocal,
|
2020-06-03 14:39:15 +02:00
|
|
|
hide: playerRunning,
|
|
|
|
),
|
|
|
|
page: PodcastDetail(
|
2020-06-10 18:36:53 +02:00
|
|
|
podcastLocal: podcastLocal,
|
2020-06-03 14:39:15 +02:00
|
|
|
)),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2020-02-21 16:04:02 +01:00
|
|
|
),
|
|
|
|
),
|
2020-02-14 12:52:03 +01:00
|
|
|
),
|
2020-02-09 13:29:09 +01:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ShowEpisode extends StatelessWidget {
|
2020-03-31 18:36:20 +02:00
|
|
|
final List<EpisodeBrief> episodes;
|
2020-02-09 13:29:09 +01:00
|
|
|
final PodcastLocal podcastLocal;
|
2020-03-31 18:36:20 +02:00
|
|
|
ShowEpisode({Key key, this.episodes, this.podcastLocal}) : super(key: key);
|
2020-04-11 19:23:12 +02:00
|
|
|
String _stringForSeconds(double seconds) {
|
|
|
|
if (seconds == null) return null;
|
|
|
|
return '${(seconds ~/ 60)}:${(seconds.truncate() % 60).toString().padLeft(2, '0')}';
|
|
|
|
}
|
2020-03-19 20:58:30 +01:00
|
|
|
|
2020-06-10 09:42:40 +02:00
|
|
|
Future<int> _isListened(EpisodeBrief episode) async {
|
|
|
|
DBHelper dbHelper = DBHelper();
|
|
|
|
return await dbHelper.isListened(episode.enclosureUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<bool> _isLiked(EpisodeBrief episode) async {
|
|
|
|
DBHelper dbHelper = DBHelper();
|
|
|
|
return await dbHelper.isLiked(episode.enclosureUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<List<int>> _getEpisodeMenu() async {
|
|
|
|
KeyValueStorage popupMenuStorage = KeyValueStorage(episodePopupMenuKey);
|
|
|
|
List<int> list = await popupMenuStorage.getMenu();
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<bool> _isDownloaded(EpisodeBrief episode) async {
|
|
|
|
DBHelper dbHelper = DBHelper();
|
|
|
|
return await dbHelper.isDownloaded(episode.enclosureUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
_markListened(EpisodeBrief episode) async {
|
|
|
|
DBHelper dbHelper = DBHelper();
|
|
|
|
bool marked = await dbHelper.checkMarked(episode);
|
|
|
|
if (!marked) {
|
|
|
|
final PlayHistory history =
|
|
|
|
PlayHistory(episode.title, episode.enclosureUrl, 0, 1);
|
|
|
|
await dbHelper.saveHistory(history);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-11 17:13:10 +02:00
|
|
|
_saveLiked(String url) async {
|
2020-06-10 09:42:40 +02:00
|
|
|
var dbHelper = DBHelper();
|
2020-06-11 17:13:10 +02:00
|
|
|
await dbHelper.setLiked(url);
|
2020-06-10 09:42:40 +02:00
|
|
|
}
|
|
|
|
|
2020-06-11 17:13:10 +02:00
|
|
|
_setUnliked(String url) async {
|
2020-06-10 09:42:40 +02:00
|
|
|
var dbHelper = DBHelper();
|
2020-06-11 17:13:10 +02:00
|
|
|
await dbHelper.setUniked(url);
|
2020-06-10 09:42:40 +02:00
|
|
|
}
|
|
|
|
|
2020-04-22 20:10:57 +02:00
|
|
|
_showPopupMenu(Offset offset, EpisodeBrief episode, BuildContext context,
|
|
|
|
bool isPlaying, bool isInPlaylist) async {
|
|
|
|
var audio = Provider.of<AudioPlayerNotifier>(context, listen: false);
|
|
|
|
double left = offset.dx;
|
|
|
|
double top = offset.dy;
|
2020-06-10 09:42:40 +02:00
|
|
|
bool isLiked, isDownload;
|
|
|
|
int isListened;
|
|
|
|
var downloader = Provider.of<DownloadState>(context, listen: false);
|
|
|
|
List<int> menuList = await _getEpisodeMenu();
|
|
|
|
if (menuList.contains(3)) isListened = await _isListened(episode);
|
|
|
|
if (menuList.contains(2)) isLiked = await _isLiked(episode);
|
|
|
|
if (menuList.contains(4)) isDownload = await _isDownloaded(episode);
|
2020-04-22 20:10:57 +02:00
|
|
|
await showMenu<int>(
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(10))),
|
|
|
|
context: context,
|
|
|
|
position: RelativeRect.fromLTRB(left, top, context.width - left, 0),
|
|
|
|
items: <PopupMenuEntry<int>>[
|
|
|
|
PopupMenuItem(
|
|
|
|
value: 0,
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
children: <Widget>[
|
|
|
|
Icon(
|
|
|
|
LineIcons.play_circle_solid,
|
|
|
|
color: Theme.of(context).accentColor,
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 2),
|
|
|
|
),
|
|
|
|
!isPlaying ? Text('Play') : Text('Playing'),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2020-06-10 09:42:40 +02:00
|
|
|
menuList.contains(1)
|
|
|
|
? PopupMenuItem(
|
|
|
|
value: 1,
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
Icon(
|
|
|
|
LineIcons.clock_solid,
|
|
|
|
color: Colors.red,
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 2),
|
|
|
|
),
|
|
|
|
!isInPlaylist ? Text('Later') : Text('Remove')
|
|
|
|
],
|
|
|
|
))
|
|
|
|
: null,
|
|
|
|
menuList.contains(2)
|
|
|
|
? PopupMenuItem(
|
|
|
|
value: 2,
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
Icon(LineIcons.heart, color: Colors.red, size: 21),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 2),
|
|
|
|
),
|
|
|
|
isLiked
|
|
|
|
? Text(
|
|
|
|
'Unlike',
|
|
|
|
)
|
|
|
|
: Text('Like')
|
|
|
|
],
|
|
|
|
))
|
|
|
|
: null,
|
|
|
|
menuList.contains(3)
|
|
|
|
? PopupMenuItem(
|
|
|
|
value: 3,
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
SizedBox(
|
|
|
|
width: 23,
|
|
|
|
height: 23,
|
|
|
|
child: CustomPaint(
|
|
|
|
painter:
|
|
|
|
ListenedAllPainter(Colors.blue, stroke: 1.5)),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 2),
|
|
|
|
),
|
2020-06-10 18:36:53 +02:00
|
|
|
isListened > 0
|
2020-06-10 09:42:40 +02:00
|
|
|
? Text('Listened',
|
|
|
|
style: TextStyle(
|
|
|
|
color: context.textColor.withOpacity(0.5)))
|
|
|
|
: Text('Mark\nListened')
|
|
|
|
],
|
|
|
|
))
|
|
|
|
: null,
|
|
|
|
menuList.contains(4)
|
|
|
|
? PopupMenuItem(
|
|
|
|
value: 4,
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
Icon(LineIcons.download_solid, color: Colors.green),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 2),
|
|
|
|
),
|
|
|
|
isDownload
|
|
|
|
? Text('Downloaded',
|
|
|
|
style: TextStyle(
|
|
|
|
color: context.textColor.withOpacity(0.5)))
|
|
|
|
: Text('Download')
|
|
|
|
],
|
|
|
|
))
|
|
|
|
: null,
|
2020-04-22 20:10:57 +02:00
|
|
|
],
|
|
|
|
elevation: 5.0,
|
2020-06-10 09:42:40 +02:00
|
|
|
).then((value) async {
|
|
|
|
switch (value) {
|
|
|
|
case 0:
|
|
|
|
if (!isPlaying) audio.episodeLoad(episode);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (!isInPlaylist) {
|
|
|
|
audio.addToPlaylist(episode);
|
|
|
|
Fluttertoast.showToast(
|
|
|
|
msg: 'Added to playlist',
|
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
audio.delFromPlaylist(episode);
|
|
|
|
Fluttertoast.showToast(
|
|
|
|
msg: 'Removed from playlist',
|
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (isLiked) {
|
|
|
|
await _setUnliked(episode.enclosureUrl);
|
|
|
|
audio.setEpisodeState = true;
|
|
|
|
Fluttertoast.showToast(
|
|
|
|
msg: 'Unliked',
|
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
await _saveLiked(episode.enclosureUrl);
|
|
|
|
audio.setEpisodeState = true;
|
|
|
|
Fluttertoast.showToast(
|
|
|
|
msg: 'Liked',
|
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
2020-06-10 18:36:53 +02:00
|
|
|
if (isListened < 1) {
|
2020-06-10 09:42:40 +02:00
|
|
|
await _markListened(episode);
|
|
|
|
audio.setEpisodeState = true;
|
|
|
|
Fluttertoast.showToast(
|
|
|
|
msg: 'Mark listened',
|
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
if (!isDownload) downloader.startTask(episode);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2020-04-22 20:10:57 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-03-03 17:04:23 +01:00
|
|
|
|
2020-04-22 20:10:57 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
double _width = context.width;
|
|
|
|
Offset offset;
|
2020-02-09 13:29:09 +01:00
|
|
|
return CustomScrollView(
|
2020-04-06 14:18:08 +02:00
|
|
|
physics: NeverScrollableScrollPhysics(),
|
2020-02-09 13:29:09 +01:00
|
|
|
primary: false,
|
|
|
|
slivers: <Widget>[
|
|
|
|
SliverPadding(
|
|
|
|
padding: const EdgeInsets.all(5.0),
|
|
|
|
sliver: SliverGrid(
|
|
|
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
2020-04-02 11:52:26 +02:00
|
|
|
childAspectRatio: 1.5,
|
|
|
|
crossAxisCount: 2,
|
2020-02-09 13:29:09 +01:00
|
|
|
mainAxisSpacing: 6.0,
|
|
|
|
crossAxisSpacing: 6.0,
|
|
|
|
),
|
|
|
|
delegate: SliverChildBuilderDelegate(
|
|
|
|
(BuildContext context, int index) {
|
2020-03-03 17:04:23 +01:00
|
|
|
Color _c = (Theme.of(context).brightness == Brightness.light)
|
|
|
|
? podcastLocal.primaryColor.colorizedark()
|
|
|
|
: podcastLocal.primaryColor.colorizeLight();
|
2020-03-14 04:14:24 +01:00
|
|
|
return Selector<AudioPlayerNotifier,
|
|
|
|
Tuple2<EpisodeBrief, List<String>>>(
|
|
|
|
selector: (_, audio) => Tuple2(
|
|
|
|
audio?.episode,
|
|
|
|
audio.queue.playlist.map((e) => e.enclosureUrl).toList(),
|
|
|
|
),
|
|
|
|
builder: (_, data, __) => Container(
|
2020-02-09 13:29:09 +01:00
|
|
|
decoration: BoxDecoration(
|
2020-02-25 10:57:12 +01:00
|
|
|
borderRadius: BorderRadius.all(Radius.circular(5.0)),
|
|
|
|
color: Theme.of(context).scaffoldBackgroundColor,
|
|
|
|
),
|
2020-02-09 13:29:09 +01:00
|
|
|
alignment: Alignment.center,
|
2020-03-14 04:14:24 +01:00
|
|
|
child: Material(
|
|
|
|
color: Colors.transparent,
|
|
|
|
child: InkWell(
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(5.0)),
|
|
|
|
onTapDown: (details) => offset = Offset(
|
|
|
|
details.globalPosition.dx,
|
|
|
|
details.globalPosition.dy),
|
|
|
|
onLongPress: () => _showPopupMenu(
|
|
|
|
offset,
|
2020-03-31 18:36:20 +02:00
|
|
|
episodes[index],
|
2020-03-14 04:14:24 +01:00
|
|
|
context,
|
2020-03-31 18:36:20 +02:00
|
|
|
data.item1 == episodes[index],
|
|
|
|
data.item2.contains(episodes[index].enclosureUrl)),
|
2020-03-14 04:14:24 +01:00
|
|
|
onTap: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
ScaleRoute(
|
|
|
|
page: EpisodeDetail(
|
2020-03-31 18:36:20 +02:00
|
|
|
episodeItem: episodes[index],
|
2020-03-14 04:14:24 +01:00
|
|
|
heroTag: 'scroll',
|
|
|
|
//unique hero tag
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.all(10.0),
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
2020-02-09 13:29:09 +01:00
|
|
|
children: <Widget>[
|
2020-03-14 04:14:24 +01:00
|
|
|
Expanded(
|
|
|
|
flex: 2,
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Hero(
|
2020-03-31 18:36:20 +02:00
|
|
|
tag: episodes[index].enclosureUrl +
|
2020-03-14 04:14:24 +01:00
|
|
|
'scroll',
|
|
|
|
child: Container(
|
|
|
|
height: _width / 18,
|
|
|
|
width: _width / 18,
|
|
|
|
child: CircleAvatar(
|
|
|
|
backgroundImage: FileImage(File(
|
|
|
|
"${podcastLocal.imagePath}")),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Spacer(),
|
2020-04-18 06:48:02 +02:00
|
|
|
Selector<AudioPlayerNotifier,
|
|
|
|
Tuple2<EpisodeBrief, bool>>(
|
|
|
|
selector: (_, audio) => Tuple2(
|
|
|
|
audio.episode, audio.playerRunning),
|
2020-04-11 19:59:52 +02:00
|
|
|
builder: (_, data, __) {
|
|
|
|
return (episodes[index]
|
2020-04-18 06:48:02 +02:00
|
|
|
.enclosureUrl ==
|
|
|
|
data.item1
|
|
|
|
?.enclosureUrl &&
|
|
|
|
data.item2)
|
2020-04-11 19:59:52 +02:00
|
|
|
? Container(
|
|
|
|
height: 20,
|
|
|
|
width: 20,
|
|
|
|
margin: EdgeInsets.symmetric(
|
|
|
|
horizontal: 2),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
shape: BoxShape.circle,
|
|
|
|
),
|
|
|
|
child: WaveLoader(
|
|
|
|
color:
|
|
|
|
context.accentColor))
|
|
|
|
: Center();
|
|
|
|
}),
|
2020-04-02 11:52:26 +02:00
|
|
|
episodes[index].isNew == 1
|
2020-03-19 20:58:30 +01:00
|
|
|
? Text(
|
|
|
|
'New',
|
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.red,
|
|
|
|
fontStyle: FontStyle.italic),
|
|
|
|
)
|
|
|
|
: Center(),
|
2020-03-14 04:14:24 +01:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
flex: 5,
|
2020-02-09 13:29:09 +01:00
|
|
|
child: Container(
|
2020-03-14 04:14:24 +01:00
|
|
|
padding: EdgeInsets.only(top: 2.0),
|
|
|
|
alignment: Alignment.topLeft,
|
|
|
|
child: Text(
|
2020-03-31 18:36:20 +02:00
|
|
|
episodes[index].title,
|
2020-03-14 04:14:24 +01:00
|
|
|
style: TextStyle(
|
2020-04-02 11:52:26 +02:00
|
|
|
//fontSize: _width / 32,
|
|
|
|
),
|
2020-03-14 04:14:24 +01:00
|
|
|
maxLines: 4,
|
|
|
|
overflow: TextOverflow.fade,
|
2020-02-09 13:29:09 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2020-03-14 04:14:24 +01:00
|
|
|
Expanded(
|
|
|
|
flex: 1,
|
2020-04-02 11:52:26 +02:00
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
Container(
|
|
|
|
alignment: Alignment.bottomLeft,
|
|
|
|
child: Text(
|
|
|
|
episodes[index].dateToString(),
|
|
|
|
//podcast[index].pubDate.substring(4, 16),
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: _width / 35,
|
|
|
|
color: _c,
|
|
|
|
fontStyle: FontStyle.italic,
|
|
|
|
),
|
|
|
|
),
|
2020-03-14 04:14:24 +01:00
|
|
|
),
|
2020-04-02 11:52:26 +02:00
|
|
|
Spacer(),
|
|
|
|
episodes[index].duration != 0
|
|
|
|
? Container(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Text(
|
2020-04-11 19:23:12 +02:00
|
|
|
_stringForSeconds(
|
2020-04-18 06:48:02 +02:00
|
|
|
episodes[index]
|
|
|
|
.duration
|
|
|
|
.toDouble())
|
|
|
|
.toString(),
|
2020-04-02 11:52:26 +02:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: _width / 35,
|
2020-04-11 19:23:12 +02:00
|
|
|
// color: _c,
|
|
|
|
// fontStyle: FontStyle.italic,
|
2020-04-02 11:52:26 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: Center(),
|
2020-04-18 06:48:02 +02:00
|
|
|
episodes[index].duration == 0 ||
|
|
|
|
episodes[index].enclosureLength ==
|
|
|
|
null ||
|
|
|
|
episodes[index].enclosureLength ==
|
|
|
|
0
|
|
|
|
? Center()
|
|
|
|
: Text(
|
|
|
|
'|',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: _width / 35,
|
|
|
|
// color: _c,
|
|
|
|
// fontStyle: FontStyle.italic,
|
|
|
|
),
|
|
|
|
),
|
2020-04-11 19:23:12 +02:00
|
|
|
episodes[index].enclosureLength != null &&
|
|
|
|
episodes[index].enclosureLength !=
|
|
|
|
0
|
|
|
|
? Container(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Text(
|
|
|
|
((episodes[index]
|
|
|
|
.enclosureLength) ~/
|
|
|
|
1000000)
|
|
|
|
.toString() +
|
|
|
|
'MB',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: _width / 35),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: Center(),
|
2020-04-02 11:52:26 +02:00
|
|
|
],
|
2020-03-14 04:14:24 +01:00
|
|
|
)),
|
2020-02-09 13:29:09 +01:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2020-03-14 04:14:24 +01:00
|
|
|
),
|
2020-02-09 13:29:09 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2020-04-02 11:52:26 +02:00
|
|
|
childCount: (episodes.length > 2) ? 2 : episodes.length,
|
2020-02-09 13:29:09 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Circle Indicator
|
|
|
|
class CircleTabIndicator extends Decoration {
|
|
|
|
final BoxPainter _painter;
|
|
|
|
CircleTabIndicator({@required Color color, @required double radius})
|
|
|
|
: _painter = _CirclePainter(color, radius);
|
|
|
|
@override
|
|
|
|
BoxPainter createBoxPainter([onChanged]) => _painter;
|
|
|
|
}
|
|
|
|
|
|
|
|
class _CirclePainter extends BoxPainter {
|
|
|
|
final Paint _paint;
|
|
|
|
final double radius;
|
|
|
|
|
|
|
|
_CirclePainter(Color color, this.radius)
|
|
|
|
: _paint = Paint()
|
|
|
|
..color = color
|
|
|
|
..isAntiAlias = true;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void paint(Canvas canvas, Offset offset, ImageConfiguration cfg) {
|
|
|
|
final Offset circleOffset =
|
|
|
|
offset + Offset(cfg.size.width / 2, cfg.size.height - radius);
|
|
|
|
canvas.drawCircle(circleOffset, radius, _paint);
|
|
|
|
}
|
|
|
|
}
|