2020-02-11 14:01:57 +01:00
|
|
|
import 'dart:async';
|
2020-08-23 11:42:13 +02:00
|
|
|
import 'dart:math' as math;
|
2020-02-11 14:01:57 +01:00
|
|
|
|
2020-09-15 13:48:22 +02:00
|
|
|
import 'package:connectivity/connectivity.dart';
|
2020-02-09 13:29:09 +01:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2020-07-26 12:20:42 +02:00
|
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
2020-06-30 21:14:36 +02:00
|
|
|
import 'package:focused_menu/focused_menu.dart';
|
|
|
|
import 'package:focused_menu/modals.dart';
|
2020-07-07 17:29:21 +02:00
|
|
|
import 'package:intl/intl.dart';
|
2020-07-26 12:20:42 +02:00
|
|
|
import 'package:line_icons/line_icons.dart';
|
2020-09-15 13:48:22 +02:00
|
|
|
import 'package:permission_handler/permission_handler.dart';
|
2020-02-11 14:01:57 +01:00
|
|
|
import 'package:provider/provider.dart';
|
2020-09-18 19:56:07 +02:00
|
|
|
import 'package:tsacdop/podcasts/podcastlist.dart';
|
2020-09-15 13:48:22 +02:00
|
|
|
import 'package:tsacdop/util/general_dialog.dart';
|
2020-03-14 04:14:24 +01:00
|
|
|
import 'package:tuple/tuple.dart';
|
2020-04-18 06:48:02 +02:00
|
|
|
|
2020-07-26 12:20:42 +02:00
|
|
|
import '../episodes/episode_detail.dart';
|
|
|
|
import '../local_storage/key_value_storage.dart';
|
|
|
|
import '../local_storage/sqflite_localpodcast.dart';
|
|
|
|
import '../podcasts/podcast_detail.dart';
|
|
|
|
import '../podcasts/podcast_manage.dart';
|
|
|
|
import '../state/audio_state.dart';
|
|
|
|
import '../state/download_state.dart';
|
|
|
|
import '../state/podcast_group.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-05-06 18:50:32 +02:00
|
|
|
import '../type/podcastlocal.dart';
|
2020-07-24 16:10:08 +02:00
|
|
|
import '../util/custom_widget.dart';
|
2020-07-22 11:34:32 +02:00
|
|
|
import '../util/extension_helper.dart';
|
2020-07-26 12:20:42 +02:00
|
|
|
import '../util/pageroute.dart';
|
2020-02-09 13:29:09 +01:00
|
|
|
|
|
|
|
class ScrollPodcasts extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_ScrollPodcastsState createState() => _ScrollPodcastsState();
|
|
|
|
}
|
|
|
|
|
2020-08-19 12:09:50 +02:00
|
|
|
class _ScrollPodcastsState extends State<ScrollPodcasts>
|
|
|
|
with SingleTickerProviderStateMixin {
|
|
|
|
int _groupIndex = 0;
|
|
|
|
AnimationController _controller;
|
|
|
|
TweenSequence _slideTween;
|
2020-09-14 17:18:13 +02:00
|
|
|
TweenSequence<double> _getSlideTween(double value) => TweenSequence<double>([
|
2020-08-19 12:09:50 +02:00
|
|
|
TweenSequenceItem(
|
2020-08-20 14:50:27 +02:00
|
|
|
tween: Tween<double>(begin: 0.0, end: value), weight: 3 / 5),
|
|
|
|
TweenSequenceItem(tween: ConstantTween<double>(value), weight: 1 / 5),
|
2020-08-19 12:26:48 +02:00
|
|
|
TweenSequenceItem(
|
|
|
|
tween: Tween<double>(begin: -value, end: 0), weight: 1 / 5)
|
2020-08-19 12:09:50 +02:00
|
|
|
]);
|
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-08-19 12:09:50 +02:00
|
|
|
_controller =
|
2020-08-23 11:42:13 +02:00
|
|
|
AnimationController(vsync: this, duration: Duration(milliseconds: 150))
|
2020-08-19 12:09:50 +02:00
|
|
|
..addListener(() {
|
|
|
|
if (mounted) setState(() {});
|
|
|
|
})
|
|
|
|
..addStatusListener((status) {
|
|
|
|
if (status == AnimationStatus.completed) _controller.reset();
|
|
|
|
});
|
|
|
|
_slideTween = _getSlideTween(0.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_controller.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
2020-08-23 11:42:13 +02:00
|
|
|
Future<int> _getPodcastUpdateCounts(String id) async {
|
2020-08-19 12:09:50 +02:00
|
|
|
var dbHelper = DBHelper();
|
|
|
|
return await dbHelper.getPodcastUpdateCounts(id);
|
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-09-14 17:18:13 +02:00
|
|
|
final width = MediaQuery.of(context).size.width;
|
2020-07-04 16:42:56 +02:00
|
|
|
final s = context.s;
|
2020-07-25 15:17:01 +02:00
|
|
|
return Selector<GroupList, Tuple3<List<PodcastGroup>, bool, bool>>(
|
|
|
|
selector: (_, groupList) =>
|
|
|
|
Tuple3(groupList.groups, groupList.created, groupList.isLoading),
|
|
|
|
builder: (_, data, __) {
|
|
|
|
var groups = data.item1;
|
2020-07-26 12:20:42 +02:00
|
|
|
var import = data.item2;
|
|
|
|
var isLoading = data.item3;
|
2020-07-25 15:17:01 +02:00
|
|
|
return isLoading
|
|
|
|
? Container(
|
2020-08-23 11:42:13 +02:00
|
|
|
height: (width - 20) / 3 + 140,
|
2020-07-25 15:17:01 +02:00
|
|
|
)
|
|
|
|
: groups[_groupIndex].podcastList.length == 0
|
|
|
|
? Container(
|
2020-08-23 11:42:13 +02:00
|
|
|
height: (width - 20) / 3 + 140,
|
2020-07-25 15:17:01 +02:00
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
|
|
|
GestureDetector(
|
|
|
|
onVerticalDragEnd: (event) {
|
|
|
|
if (event.primaryVelocity > 200) {
|
|
|
|
if (groups.length == 1) {
|
|
|
|
Fluttertoast.showToast(
|
|
|
|
msg: s.addSomeGroups,
|
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
} else {
|
2020-07-26 12:20:42 +02:00
|
|
|
if (mounted) {
|
2020-07-25 15:17:01 +02:00
|
|
|
setState(() {
|
|
|
|
(_groupIndex != 0)
|
|
|
|
? _groupIndex--
|
|
|
|
: _groupIndex = groups.length - 1;
|
|
|
|
});
|
2020-07-26 12:20:42 +02:00
|
|
|
}
|
2020-07-25 15:17:01 +02:00
|
|
|
}
|
|
|
|
} else if (event.primaryVelocity < -200) {
|
|
|
|
if (groups.length == 1) {
|
|
|
|
Fluttertoast.showToast(
|
|
|
|
msg: s.addSomeGroups,
|
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
} else {
|
2020-08-19 12:09:50 +02:00
|
|
|
if (mounted) {
|
|
|
|
setState(() {
|
|
|
|
(_groupIndex < groups.length - 1)
|
|
|
|
? _groupIndex++
|
|
|
|
: _groupIndex = 0;
|
|
|
|
});
|
|
|
|
}
|
2020-07-25 15:17:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
2020-08-20 14:50:27 +02:00
|
|
|
SizedBox(
|
|
|
|
height: 30,
|
2020-07-25 15:17:01 +02:00
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
2020-08-20 14:50:27 +02:00
|
|
|
Padding(
|
2020-07-25 15:17:01 +02:00
|
|
|
padding: EdgeInsets.symmetric(
|
|
|
|
horizontal: 15.0),
|
|
|
|
child: Text(
|
|
|
|
groups[_groupIndex].name,
|
2020-08-19 12:09:50 +02:00
|
|
|
style: context.textTheme.bodyText1
|
2020-07-25 15:17:01 +02:00
|
|
|
.copyWith(
|
2020-08-19 12:09:50 +02:00
|
|
|
color: context.accentColor),
|
2020-07-25 15:17:01 +02:00
|
|
|
)),
|
|
|
|
Spacer(),
|
2020-08-20 14:50:27 +02:00
|
|
|
Padding(
|
2020-07-25 15:17:01 +02:00
|
|
|
padding: EdgeInsets.symmetric(
|
|
|
|
horizontal: 15),
|
|
|
|
child: InkWell(
|
|
|
|
onTap: () {
|
2020-07-26 12:20:42 +02:00
|
|
|
if (!import) {
|
2020-07-25 15:17:01 +02:00
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
SlideLeftRoute(
|
|
|
|
page: PodcastManage()),
|
|
|
|
);
|
2020-07-26 12:20:42 +02:00
|
|
|
}
|
2020-07-25 15:17:01 +02:00
|
|
|
},
|
2020-09-18 19:56:07 +02:00
|
|
|
onLongPress: () {
|
|
|
|
if (!import) {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
SlideLeftRoute(
|
|
|
|
page: PodcastList()),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
2020-08-20 14:50:27 +02:00
|
|
|
borderRadius:
|
|
|
|
BorderRadius.circular(5),
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(5.0),
|
2020-07-25 15:17:01 +02:00
|
|
|
child: Text(
|
|
|
|
s.homeGroupsSeeAll,
|
|
|
|
style: context.textTheme.bodyText1
|
|
|
|
.copyWith(
|
|
|
|
color: import
|
|
|
|
? context
|
|
|
|
.primaryColorDark
|
|
|
|
: context
|
|
|
|
.accentColor),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
height: 70,
|
2020-08-19 12:09:50 +02:00
|
|
|
color: context.scaffoldBackgroundColor,
|
2020-07-25 15:17:01 +02:00
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
_circleContainer(context),
|
|
|
|
_circleContainer(context),
|
|
|
|
_circleContainer(context)
|
|
|
|
],
|
|
|
|
)),
|
|
|
|
],
|
|
|
|
)),
|
|
|
|
Container(
|
2020-08-23 11:42:13 +02:00
|
|
|
height: (width - 20) / 3 + 40,
|
2020-07-25 15:17:01 +02:00
|
|
|
color: context.primaryColor,
|
|
|
|
margin: EdgeInsets.symmetric(horizontal: 15),
|
|
|
|
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)),
|
2020-07-26 12:20:42 +02:00
|
|
|
TextSpan(text: ' to search podcasts')
|
2020-07-25 15:17:01 +02:00
|
|
|
],
|
|
|
|
))
|
|
|
|
: Text(s.noPodcastGroup,
|
|
|
|
style: TextStyle(
|
|
|
|
color: context
|
|
|
|
.textTheme.bodyText2.color
|
|
|
|
.withOpacity(0.5)))),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: DefaultTabController(
|
|
|
|
length: groups[_groupIndex].podcastList.length,
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
|
|
|
GestureDetector(
|
2020-08-19 12:09:50 +02:00
|
|
|
onVerticalDragEnd: (event) async {
|
2020-03-25 16:33:48 +01:00
|
|
|
if (event.primaryVelocity > 200) {
|
|
|
|
if (groups.length == 1) {
|
|
|
|
Fluttertoast.showToast(
|
2020-07-04 16:42:56 +02:00
|
|
|
msg: s.addSomeGroups,
|
2020-03-25 16:33:48 +01:00
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
} else {
|
2020-07-26 12:20:42 +02:00
|
|
|
if (mounted) {
|
2020-08-19 12:09:50 +02:00
|
|
|
setState(
|
|
|
|
() => _slideTween = _getSlideTween(20));
|
|
|
|
_controller.forward();
|
|
|
|
await Future.delayed(
|
2020-08-20 14:50:27 +02:00
|
|
|
Duration(milliseconds: 50));
|
2020-08-19 12:09:50 +02:00
|
|
|
if (mounted) {
|
|
|
|
setState(() {
|
|
|
|
(_groupIndex != 0)
|
|
|
|
? _groupIndex--
|
|
|
|
: _groupIndex = groups.length - 1;
|
|
|
|
});
|
|
|
|
}
|
2020-07-26 12:20:42 +02:00
|
|
|
}
|
2020-03-25 16:33:48 +01:00
|
|
|
}
|
|
|
|
} else if (event.primaryVelocity < -200) {
|
|
|
|
if (groups.length == 1) {
|
|
|
|
Fluttertoast.showToast(
|
2020-07-04 16:42:56 +02:00
|
|
|
msg: s.addSomeGroups,
|
2020-03-25 16:33:48 +01:00
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
} else {
|
2020-08-19 12:09:50 +02:00
|
|
|
setState(
|
|
|
|
() => _slideTween = _getSlideTween(-20));
|
|
|
|
await Future.delayed(
|
2020-08-20 14:50:27 +02:00
|
|
|
Duration(milliseconds: 50));
|
2020-08-19 12:09:50 +02:00
|
|
|
_controller.forward();
|
|
|
|
if (mounted) {
|
|
|
|
setState(() {
|
|
|
|
(_groupIndex < groups.length - 1)
|
|
|
|
? _groupIndex++
|
|
|
|
: _groupIndex = 0;
|
|
|
|
});
|
|
|
|
}
|
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>[
|
2020-08-20 14:50:27 +02:00
|
|
|
SizedBox(
|
|
|
|
height: 30,
|
2020-03-25 16:33:48 +01:00
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
2020-08-20 14:50:27 +02:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(
|
2020-03-25 16:33:48 +01:00
|
|
|
horizontal: 15.0),
|
|
|
|
child: Text(
|
|
|
|
groups[_groupIndex].name,
|
2020-07-25 15:17:01 +02:00
|
|
|
style: context.textTheme.bodyText1
|
2020-03-25 16:33:48 +01:00
|
|
|
.copyWith(
|
2020-08-20 14:50:27 +02:00
|
|
|
color: context.accentColor),
|
2020-03-25 16:33:48 +01:00
|
|
|
)),
|
|
|
|
Spacer(),
|
2020-08-20 14:50:27 +02:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
horizontal: 15),
|
2020-03-25 16:33:48 +01:00
|
|
|
child: InkWell(
|
2020-08-20 14:50:27 +02:00
|
|
|
onTap: () {
|
|
|
|
if (!import) {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
SlideLeftRoute(
|
|
|
|
page: PodcastManage()),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
2020-09-18 19:56:07 +02:00
|
|
|
onLongPress: () {
|
|
|
|
if (!import) {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
SlideLeftRoute(
|
|
|
|
page: PodcastList()),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
2020-08-20 14:50:27 +02:00
|
|
|
borderRadius:
|
|
|
|
BorderRadius.circular(5),
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(5.0),
|
|
|
|
child: Text(
|
|
|
|
s.homeGroupsSeeAll,
|
|
|
|
style: context.textTheme.bodyText1
|
|
|
|
.copyWith(
|
|
|
|
color: import
|
|
|
|
? context
|
|
|
|
.primaryColorDark
|
|
|
|
: context
|
|
|
|
.accentColor),
|
|
|
|
),
|
|
|
|
)),
|
|
|
|
)
|
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-07-25 15:17:01 +02:00
|
|
|
height: 70,
|
2020-08-23 11:42:13 +02:00
|
|
|
width: width,
|
2020-07-25 15:17:01 +02:00
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
color: context.scaffoldBackgroundColor,
|
|
|
|
child: TabBar(
|
|
|
|
labelPadding: EdgeInsets.only(
|
|
|
|
top: 5.0,
|
|
|
|
bottom: 10.0,
|
|
|
|
left: 6.0,
|
|
|
|
right: 6.0),
|
|
|
|
indicator: CircleTabIndicator(
|
|
|
|
color: context.accentColor, radius: 3),
|
|
|
|
isScrollable: true,
|
|
|
|
tabs: groups[_groupIndex]
|
|
|
|
.podcasts
|
2020-07-26 12:20:42 +02:00
|
|
|
.map<Widget>((podcastLocal) {
|
2020-08-15 19:43:45 +02:00
|
|
|
final color =
|
|
|
|
podcastLocal.backgroudColor(context);
|
2020-07-25 15:17:01 +02:00
|
|
|
return Tab(
|
2020-08-19 12:09:50 +02:00
|
|
|
child: Transform.translate(
|
|
|
|
offset: Offset(
|
|
|
|
0,
|
|
|
|
_slideTween
|
|
|
|
.animate(_controller)
|
|
|
|
.value),
|
2020-08-23 11:42:13 +02:00
|
|
|
child: LimitedBox(
|
|
|
|
maxHeight: 50,
|
|
|
|
maxWidth: 50,
|
|
|
|
child: CircleAvatar(
|
|
|
|
backgroundColor:
|
|
|
|
color.withOpacity(0.5),
|
|
|
|
backgroundImage:
|
|
|
|
podcastLocal.avatarImage,
|
|
|
|
child: FutureBuilder<int>(
|
|
|
|
future: _getPodcastUpdateCounts(
|
|
|
|
podcastLocal.id),
|
|
|
|
initialData: 0,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
return snapshot.data > 0
|
|
|
|
? Align(
|
|
|
|
alignment: Alignment
|
|
|
|
.bottomRight,
|
|
|
|
child: Container(
|
2020-08-19 12:09:50 +02:00
|
|
|
alignment: Alignment
|
2020-08-23 11:42:13 +02:00
|
|
|
.center,
|
|
|
|
height: 10,
|
|
|
|
width: 10,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color:
|
|
|
|
Colors.red,
|
|
|
|
border: Border.all(
|
|
|
|
color: context
|
|
|
|
.primaryColor,
|
|
|
|
width: 2),
|
|
|
|
shape: BoxShape
|
|
|
|
.circle),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: Center();
|
|
|
|
}),
|
2020-08-19 12:09:50 +02:00
|
|
|
),
|
2020-07-25 15:17:01 +02:00
|
|
|
),
|
2020-02-23 14:20:07 +01:00
|
|
|
),
|
2020-07-25 15:17:01 +02:00
|
|
|
);
|
|
|
|
}).toList(),
|
|
|
|
),
|
2020-02-23 14:20:07 +01:00
|
|
|
),
|
2020-07-25 15:17:01 +02:00
|
|
|
],
|
|
|
|
),
|
2020-04-18 06:48:02 +02:00
|
|
|
),
|
2020-07-25 15:17:01 +02:00
|
|
|
Container(
|
2020-08-23 11:42:13 +02:00
|
|
|
height: (width - 20) / 3 + 40,
|
|
|
|
margin: const EdgeInsets.symmetric(horizontal: 10),
|
2020-07-25 15:17:01 +02:00
|
|
|
decoration: BoxDecoration(
|
2020-08-23 11:42:13 +02:00
|
|
|
color: context.scaffoldBackgroundColor,
|
2020-07-25 15:17:01 +02:00
|
|
|
),
|
2020-07-29 18:37:51 +02:00
|
|
|
child: ScrollConfiguration(
|
|
|
|
behavior: NoGrowBehavior(),
|
|
|
|
child: TabBarView(
|
|
|
|
children: groups[_groupIndex]
|
|
|
|
.podcasts
|
|
|
|
.map<Widget>((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-07-25 15:17:01 +02:00
|
|
|
),
|
2020-02-23 14:20:07 +01:00
|
|
|
),
|
2020-07-25 15:17:01 +02: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-07-26 12:20:42 +02:00
|
|
|
var episodes = await dbHelper.getRssItemTop(podcastLocal.id);
|
2020-02-09 13:29:09 +01:00
|
|
|
return episodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-08-15 19:43:45 +02:00
|
|
|
final c = podcastLocal.backgroudColor(context);
|
2020-02-09 13:29:09 +01:00
|
|
|
return Column(
|
|
|
|
children: <Widget>[
|
|
|
|
Expanded(
|
2020-07-14 17:45:45 +02:00
|
|
|
child: Selector<GroupList, bool>(
|
2020-06-03 14:39:15 +02:00
|
|
|
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) {
|
|
|
|
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
|
|
|
)
|
2020-08-23 11:42:13 +02:00
|
|
|
: Padding(
|
|
|
|
padding: const EdgeInsets.all(5.0),
|
2020-06-03 14:39:15 +02:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}),
|
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,
|
2020-08-23 11:42:13 +02:00
|
|
|
overflow: TextOverflow.ellipsis,
|
2020-08-15 19:43:45 +02:00
|
|
|
style: TextStyle(fontWeight: FontWeight.bold, color: c)),
|
2020-02-21 16:04:02 +01:00
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
flex: 1,
|
2020-08-23 11:42:13 +02:00
|
|
|
child: Align(
|
2020-02-21 16:04:02 +01:00
|
|
|
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),
|
2020-07-04 16:42:56 +02:00
|
|
|
tooltip: context.s.homeGroupsSeeAll,
|
2020-06-03 14:39:15 +02:00
|
|
|
onPressed: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
2020-07-30 11:28:29 +02:00
|
|
|
SlideLeftRoute(
|
2020-06-03 14:39:15 +02:00
|
|
|
page: PodcastDetail(
|
2020-07-30 11:28:29 +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-09-15 13:48:22 +02:00
|
|
|
final DBHelper _dbHelper = DBHelper();
|
2020-03-31 18:36:20 +02:00
|
|
|
ShowEpisode({Key key, this.episodes, this.podcastLocal}) : super(key: key);
|
2020-08-23 11:42:13 +02:00
|
|
|
String stringForSeconds(double seconds) {
|
2020-04-11 19:23:12 +02:00
|
|
|
if (seconds == null) return null;
|
|
|
|
return '${(seconds ~/ 60)}:${(seconds.truncate() % 60).toString().padLeft(2, '0')}';
|
|
|
|
}
|
2020-03-19 20:58:30 +01:00
|
|
|
|
2020-07-07 17:29:21 +02:00
|
|
|
String _dateToString(BuildContext context, {int pubDate}) {
|
|
|
|
final s = context.s;
|
2020-07-26 12:20:42 +02:00
|
|
|
var date = DateTime.fromMillisecondsSinceEpoch(pubDate, isUtc: true);
|
2020-07-07 17:29:21 +02:00
|
|
|
var difference = DateTime.now().toUtc().difference(date);
|
|
|
|
if (difference.inHours < 24) {
|
|
|
|
return s.hoursAgo(difference.inHours);
|
|
|
|
} else if (difference.inDays < 7) {
|
|
|
|
return s.daysAgo(difference.inDays);
|
|
|
|
} else {
|
|
|
|
return DateFormat.yMMMd().format(
|
|
|
|
DateTime.fromMillisecondsSinceEpoch(pubDate, isUtc: true).toLocal());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-07 19:36:40 +02:00
|
|
|
Future<Tuple5<int, bool, bool, bool, List<int>>> _initData(
|
2020-07-04 16:42:56 +02:00
|
|
|
EpisodeBrief episode) async {
|
2020-07-26 12:20:42 +02:00
|
|
|
var menuList = await _getEpisodeMenu();
|
|
|
|
var tapToOpen = await _getTapToOpenPopupMenu();
|
|
|
|
var listened = await _isListened(episode);
|
2020-07-07 19:36:40 +02:00
|
|
|
|
2020-07-26 12:20:42 +02:00
|
|
|
var liked = await _isLiked(episode);
|
|
|
|
var downloaded = await _isDownloaded(episode);
|
2020-07-07 19:36:40 +02:00
|
|
|
|
|
|
|
return Tuple5(listened, liked, downloaded, tapToOpen, menuList);
|
2020-06-30 21:14:36 +02:00
|
|
|
}
|
|
|
|
|
2020-06-10 09:42:40 +02:00
|
|
|
Future<int> _isListened(EpisodeBrief episode) async {
|
2020-09-15 13:48:22 +02:00
|
|
|
return await _dbHelper.isListened(episode.enclosureUrl);
|
2020-06-10 09:42:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<bool> _isLiked(EpisodeBrief episode) async {
|
2020-07-26 12:20:42 +02:00
|
|
|
var dbHelper = DBHelper();
|
2020-06-10 09:42:40 +02:00
|
|
|
return await dbHelper.isLiked(episode.enclosureUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<List<int>> _getEpisodeMenu() async {
|
2020-07-26 12:20:42 +02:00
|
|
|
var popupMenuStorage = KeyValueStorage(episodePopupMenuKey);
|
|
|
|
var list = await popupMenuStorage.getMenu();
|
2020-06-10 09:42:40 +02:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<bool> _isDownloaded(EpisodeBrief episode) async {
|
2020-07-26 12:20:42 +02:00
|
|
|
var dbHelper = DBHelper();
|
2020-06-10 09:42:40 +02:00
|
|
|
return await dbHelper.isDownloaded(episode.enclosureUrl);
|
|
|
|
}
|
|
|
|
|
2020-07-07 19:36:40 +02:00
|
|
|
Future<bool> _getTapToOpenPopupMenu() async {
|
2020-07-26 12:20:42 +02:00
|
|
|
var tapToOpenPopupMenuStorage = KeyValueStorage(tapToOpenPopupMenuKey);
|
|
|
|
var boo = await tapToOpenPopupMenuStorage.getInt(defaultValue: 0);
|
2020-07-07 19:36:40 +02:00
|
|
|
return boo == 1;
|
|
|
|
}
|
|
|
|
|
2020-09-15 13:48:22 +02:00
|
|
|
Future<void> _markListened(EpisodeBrief episode) async {
|
2020-07-26 12:20:42 +02:00
|
|
|
var dbHelper = DBHelper();
|
|
|
|
var marked = await dbHelper.checkMarked(episode);
|
2020-06-10 09:42:40 +02:00
|
|
|
if (!marked) {
|
2020-07-26 12:20:42 +02:00
|
|
|
final history = PlayHistory(episode.title, episode.enclosureUrl, 0, 1);
|
2020-06-10 09:42:40 +02:00
|
|
|
await dbHelper.saveHistory(history);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-15 13:48:22 +02:00
|
|
|
Future<void> _saveLiked(String url) async {
|
2020-06-10 09:42:40 +02:00
|
|
|
var dbHelper = DBHelper();
|
2020-06-30 21:14:36 +02:00
|
|
|
await dbHelper.setLiked(url);
|
2020-06-10 09:42:40 +02:00
|
|
|
}
|
|
|
|
|
2020-09-15 13:48:22 +02:00
|
|
|
Future<void> _setUnliked(String url) async {
|
2020-06-10 09:42:40 +02:00
|
|
|
var dbHelper = DBHelper();
|
2020-06-30 21:14:36 +02:00
|
|
|
await dbHelper.setUniked(url);
|
2020-04-22 20:10:57 +02:00
|
|
|
}
|
2020-03-03 17:04:23 +01:00
|
|
|
|
2020-09-15 13:48:22 +02:00
|
|
|
Future<void> _requestDownload(BuildContext context,
|
|
|
|
{EpisodeBrief episode}) async {
|
|
|
|
final permissionReady = await _checkPermmison();
|
|
|
|
final downloadUsingData = await KeyValueStorage(downloadUsingDataKey)
|
|
|
|
.getBool(defaultValue: true, reverse: true);
|
|
|
|
final result = await Connectivity().checkConnectivity();
|
|
|
|
final usingData = result == ConnectivityResult.mobile;
|
|
|
|
var dataConfirm = true;
|
|
|
|
if (permissionReady) {
|
|
|
|
if (downloadUsingData && usingData) {
|
|
|
|
dataConfirm = await _useDataConfirm(context);
|
|
|
|
}
|
|
|
|
if (dataConfirm) {
|
|
|
|
Provider.of<DownloadState>(context, listen: false).startTask(episode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<bool> _checkPermmison() async {
|
|
|
|
var permission = await Permission.storage.status;
|
|
|
|
if (permission != PermissionStatus.granted) {
|
|
|
|
var permissions = await [Permission.storage].request();
|
|
|
|
if (permissions[Permission.storage] == PermissionStatus.granted) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<bool> _useDataConfirm(BuildContext context) async {
|
|
|
|
var ifUseData = false;
|
|
|
|
final s = context.s;
|
|
|
|
await generalDialog(
|
|
|
|
context,
|
|
|
|
title: Text(s.cellularConfirm),
|
|
|
|
content: Text(s.cellularConfirmDes),
|
|
|
|
actions: <Widget>[
|
|
|
|
FlatButton(
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
child: Text(
|
|
|
|
s.cancel,
|
|
|
|
style: TextStyle(color: Colors.grey[600]),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
FlatButton(
|
|
|
|
onPressed: () {
|
|
|
|
ifUseData = true;
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
child: Text(
|
|
|
|
s.confirm,
|
|
|
|
style: TextStyle(color: Colors.red),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
return ifUseData;
|
|
|
|
}
|
|
|
|
|
2020-04-22 20:10:57 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-07-26 12:20:42 +02:00
|
|
|
var _width = context.width;
|
2020-07-04 16:42:56 +02:00
|
|
|
final s = context.s;
|
2020-06-30 21:14:36 +02:00
|
|
|
var audio = Provider.of<AudioPlayerNotifier>(context, listen: false);
|
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(
|
2020-07-26 12:20:42 +02:00
|
|
|
(context, index) {
|
2020-08-15 19:43:45 +02:00
|
|
|
final c = podcastLocal.backgroudColor(context);
|
2020-03-14 04:14:24 +01:00
|
|
|
return Selector<AudioPlayerNotifier,
|
2020-06-30 21:14:36 +02:00
|
|
|
Tuple2<EpisodeBrief, List<String>>>(
|
|
|
|
selector: (_, audio) => Tuple2(
|
|
|
|
audio?.episode,
|
|
|
|
audio.queue.playlist
|
|
|
|
.map((e) => e.enclosureUrl)
|
|
|
|
.toList(),
|
|
|
|
),
|
|
|
|
builder: (_, data, __) => FutureBuilder<
|
2020-07-07 19:36:40 +02:00
|
|
|
Tuple5<int, bool, bool, bool, List<int>>>(
|
2020-06-30 21:14:36 +02:00
|
|
|
future: _initData(episodes[index]),
|
2020-07-07 19:36:40 +02:00
|
|
|
initialData: Tuple5(0, false, false, false, []),
|
2020-07-26 12:20:42 +02:00
|
|
|
builder: (context, snapshot) {
|
2020-09-15 13:48:22 +02:00
|
|
|
final isListened = snapshot.data.item1;
|
|
|
|
final isLiked = snapshot.data.item2;
|
|
|
|
final isDownloaded = snapshot.data.item3;
|
|
|
|
final tapToOpen = snapshot.data.item4;
|
|
|
|
final menuList = snapshot.data.item5;
|
2020-06-30 21:14:36 +02:00
|
|
|
return Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius:
|
|
|
|
BorderRadius.all(Radius.circular(5.0)),
|
|
|
|
color: Theme.of(context).scaffoldBackgroundColor,
|
|
|
|
),
|
|
|
|
alignment: Alignment.center,
|
2020-07-04 16:42:56 +02:00
|
|
|
child: FocusedMenuHolder(
|
2020-06-30 21:14:36 +02:00
|
|
|
blurSize: 0.0,
|
|
|
|
menuItemExtent: 45,
|
|
|
|
menuBoxDecoration: BoxDecoration(
|
|
|
|
color: Colors.transparent,
|
|
|
|
borderRadius:
|
|
|
|
BorderRadius.all(Radius.circular(15.0))),
|
|
|
|
duration: Duration(milliseconds: 100),
|
2020-07-07 19:36:40 +02:00
|
|
|
tapMode: tapToOpen
|
|
|
|
? TapMode.onTap
|
|
|
|
: TapMode.onLongPress,
|
2020-06-30 21:14:36 +02:00
|
|
|
animateMenuItems: false,
|
|
|
|
blurBackgroundColor:
|
|
|
|
context.brightness == Brightness.light
|
|
|
|
? Colors.white38
|
|
|
|
: Colors.black38,
|
|
|
|
bottomOffsetHeight: 10,
|
|
|
|
menuOffset: 6,
|
|
|
|
menuItems: <FocusedMenuItem>[
|
|
|
|
FocusedMenuItem(
|
|
|
|
backgroundColor:
|
|
|
|
context.brightness == Brightness.light
|
|
|
|
? context.primaryColor
|
2020-07-25 12:32:05 +02:00
|
|
|
: context.dialogBackgroundColor,
|
2020-06-30 21:14:36 +02:00
|
|
|
title: Text(data.item1 != episodes[index]
|
2020-07-04 16:42:56 +02:00
|
|
|
? s.play
|
|
|
|
: s.playing),
|
2020-06-30 21:14:36 +02:00
|
|
|
trailingIcon: Icon(
|
|
|
|
LineIcons.play_circle_solid,
|
2020-07-25 12:32:05 +02:00
|
|
|
color: context.accentColor,
|
2020-03-14 04:14:24 +01:00
|
|
|
),
|
2020-06-30 21:14:36 +02:00
|
|
|
onPressed: () {
|
2020-07-26 12:20:42 +02:00
|
|
|
if (data.item1 != episodes[index]) {
|
2020-06-30 21:14:36 +02:00
|
|
|
audio.episodeLoad(episodes[index]);
|
2020-07-26 12:20:42 +02:00
|
|
|
}
|
2020-06-30 21:14:36 +02:00
|
|
|
}),
|
2020-07-04 16:42:56 +02:00
|
|
|
menuList.contains(1)
|
2020-06-30 21:14:36 +02:00
|
|
|
? FocusedMenuItem(
|
|
|
|
backgroundColor: context.brightness ==
|
|
|
|
Brightness.light
|
|
|
|
? context.primaryColor
|
2020-07-25 12:32:05 +02:00
|
|
|
: context.dialogBackgroundColor,
|
2020-06-30 21:14:36 +02:00
|
|
|
title: data.item2.contains(
|
|
|
|
episodes[index].enclosureUrl)
|
2020-07-04 16:42:56 +02:00
|
|
|
? Text(s.remove)
|
|
|
|
: Text(s.later),
|
2020-06-30 21:14:36 +02:00
|
|
|
trailingIcon: Icon(
|
|
|
|
LineIcons.clock_solid,
|
|
|
|
color: Colors.cyan,
|
2020-04-02 11:52:26 +02:00
|
|
|
),
|
2020-06-30 21:14:36 +02:00
|
|
|
onPressed: () {
|
|
|
|
if (!data.item2.contains(
|
|
|
|
episodes[index].enclosureUrl)) {
|
|
|
|
audio
|
|
|
|
.addToPlaylist(episodes[index]);
|
|
|
|
Fluttertoast.showToast(
|
2020-07-04 16:42:56 +02:00
|
|
|
msg: s.toastAddPlaylist,
|
2020-06-30 21:14:36 +02:00
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
audio.delFromPlaylist(
|
|
|
|
episodes[index]);
|
|
|
|
Fluttertoast.showToast(
|
2020-07-04 16:42:56 +02:00
|
|
|
msg: s.toastRemovePlaylist,
|
2020-06-30 21:14:36 +02:00
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
: null,
|
2020-07-04 16:42:56 +02:00
|
|
|
menuList.contains(2)
|
2020-06-30 21:14:36 +02:00
|
|
|
? FocusedMenuItem(
|
|
|
|
backgroundColor: context.brightness ==
|
|
|
|
Brightness.light
|
|
|
|
? context.primaryColor
|
2020-07-25 12:32:05 +02:00
|
|
|
: context.dialogBackgroundColor,
|
2020-06-30 21:14:36 +02:00
|
|
|
title: isLiked
|
2020-07-04 16:42:56 +02:00
|
|
|
? Text(s.unlike)
|
|
|
|
: Text(s.like),
|
2020-06-30 21:14:36 +02:00
|
|
|
trailingIcon: Icon(LineIcons.heart,
|
|
|
|
color: Colors.red, size: 21),
|
|
|
|
onPressed: () async {
|
|
|
|
if (isLiked) {
|
|
|
|
await _setUnliked(
|
|
|
|
episodes[index].enclosureUrl);
|
|
|
|
audio.setEpisodeState = true;
|
|
|
|
Fluttertoast.showToast(
|
2020-07-04 16:42:56 +02:00
|
|
|
msg: s.unliked,
|
2020-06-30 21:14:36 +02:00
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
await _saveLiked(
|
|
|
|
episodes[index].enclosureUrl);
|
|
|
|
audio.setEpisodeState = true;
|
|
|
|
Fluttertoast.showToast(
|
2020-07-04 16:42:56 +02:00
|
|
|
msg: s.liked,
|
2020-06-30 21:14:36 +02:00
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
: null,
|
2020-07-04 16:42:56 +02:00
|
|
|
menuList.contains(3)
|
2020-06-30 21:14:36 +02:00
|
|
|
? FocusedMenuItem(
|
|
|
|
backgroundColor: context.brightness ==
|
|
|
|
Brightness.light
|
|
|
|
? context.primaryColor
|
2020-07-25 12:32:05 +02:00
|
|
|
: context.dialogBackgroundColor,
|
2020-06-30 21:14:36 +02:00
|
|
|
title: isListened > 0
|
2020-07-04 16:42:56 +02:00
|
|
|
? Text(s.listened,
|
2020-06-30 21:14:36 +02:00
|
|
|
style: TextStyle(
|
|
|
|
color: context.textColor
|
|
|
|
.withOpacity(0.5)))
|
|
|
|
: Text(
|
2020-07-04 16:42:56 +02:00
|
|
|
s.markListened,
|
2020-06-30 21:14:36 +02:00
|
|
|
maxLines: 1,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
),
|
|
|
|
trailingIcon: SizedBox(
|
|
|
|
width: 23,
|
|
|
|
height: 23,
|
|
|
|
child: CustomPaint(
|
|
|
|
painter: ListenedAllPainter(
|
|
|
|
Colors.blue,
|
|
|
|
stroke: 1.5)),
|
|
|
|
),
|
|
|
|
onPressed: () async {
|
|
|
|
if (isListened < 1) {
|
|
|
|
await _markListened(
|
|
|
|
episodes[index]);
|
|
|
|
audio.setEpisodeState = true;
|
|
|
|
Fluttertoast.showToast(
|
2020-07-04 16:42:56 +02:00
|
|
|
msg: s.markListened,
|
2020-06-30 21:14:36 +02:00
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
: null,
|
2020-07-04 16:42:56 +02:00
|
|
|
menuList.contains(4)
|
2020-06-30 21:14:36 +02:00
|
|
|
? FocusedMenuItem(
|
|
|
|
backgroundColor: context.brightness ==
|
|
|
|
Brightness.light
|
|
|
|
? context.primaryColor
|
2020-07-25 12:32:05 +02:00
|
|
|
: context.dialogBackgroundColor,
|
2020-06-30 21:14:36 +02:00
|
|
|
title: isDownloaded
|
2020-07-04 16:42:56 +02:00
|
|
|
? Text(s.downloaded,
|
2020-06-30 21:14:36 +02:00
|
|
|
style: TextStyle(
|
|
|
|
color: context.textColor
|
|
|
|
.withOpacity(0.5)))
|
2020-07-04 16:42:56 +02:00
|
|
|
: Text(s.download),
|
2020-06-30 21:14:36 +02:00
|
|
|
trailingIcon: Icon(
|
|
|
|
LineIcons.download_solid,
|
|
|
|
color: Colors.green),
|
|
|
|
onPressed: () {
|
2020-07-26 12:20:42 +02:00
|
|
|
if (!isDownloaded) {
|
2020-09-15 13:48:22 +02:00
|
|
|
_requestDownload(context,
|
|
|
|
episode: episodes[index]);
|
|
|
|
// downloader
|
|
|
|
// .startTask(episodes[index]);
|
2020-07-26 12:20:42 +02:00
|
|
|
}
|
2020-06-30 21:14:36 +02:00
|
|
|
})
|
|
|
|
: null
|
|
|
|
],
|
|
|
|
action: () => Navigator.push(
|
|
|
|
context,
|
|
|
|
ScaleRoute(
|
|
|
|
page: EpisodeDetail(
|
|
|
|
episodeItem: episodes[index],
|
|
|
|
heroTag: 'scroll',
|
|
|
|
//unique hero tag
|
|
|
|
)),
|
2020-02-09 13:29:09 +01:00
|
|
|
),
|
2020-06-30 21:14:36 +02:00
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.all(10.0),
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
Expanded(
|
|
|
|
flex: 2,
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment:
|
|
|
|
MainAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Hero(
|
2020-07-26 12:20:42 +02:00
|
|
|
tag:
|
|
|
|
'${episodes[index].enclosureUrl}scroll',
|
2020-06-30 21:14:36 +02:00
|
|
|
child: Container(
|
|
|
|
height: _width / 18,
|
|
|
|
width: _width / 18,
|
|
|
|
child: CircleAvatar(
|
2020-08-15 19:43:45 +02:00
|
|
|
backgroundImage:
|
|
|
|
podcastLocal.avatarImage,
|
2020-06-30 21:14:36 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Spacer(),
|
|
|
|
Selector<AudioPlayerNotifier,
|
|
|
|
Tuple2<EpisodeBrief, bool>>(
|
|
|
|
selector: (_, audio) => Tuple2(
|
|
|
|
audio.episode,
|
|
|
|
audio.playerRunning),
|
|
|
|
builder: (_, data, __) {
|
|
|
|
return (episodes[index]
|
|
|
|
.enclosureUrl ==
|
|
|
|
data.item1
|
|
|
|
?.enclosureUrl &&
|
|
|
|
data.item2)
|
|
|
|
? Container(
|
|
|
|
height: 20,
|
|
|
|
width: 20,
|
|
|
|
margin: EdgeInsets
|
|
|
|
.symmetric(
|
|
|
|
horizontal: 2),
|
|
|
|
decoration:
|
|
|
|
BoxDecoration(
|
|
|
|
shape:
|
|
|
|
BoxShape.circle,
|
|
|
|
),
|
|
|
|
child: WaveLoader(
|
|
|
|
color: context
|
|
|
|
.accentColor))
|
|
|
|
: Center();
|
|
|
|
}),
|
|
|
|
episodes[index].isNew == 1
|
|
|
|
? Text(
|
|
|
|
'New',
|
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.red,
|
|
|
|
fontStyle:
|
|
|
|
FontStyle.italic),
|
|
|
|
)
|
|
|
|
: Center(),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
flex: 5,
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.only(top: 2.0),
|
|
|
|
alignment: Alignment.topLeft,
|
2020-04-02 11:52:26 +02:00
|
|
|
child: Text(
|
2020-06-30 21:14:36 +02:00
|
|
|
episodes[index].title,
|
2020-04-02 11:52:26 +02:00
|
|
|
style: TextStyle(
|
2020-06-30 21:14:36 +02:00
|
|
|
//fontSize: _width / 32,
|
|
|
|
),
|
|
|
|
maxLines: 4,
|
|
|
|
overflow: TextOverflow.fade,
|
2020-04-02 11:52:26 +02:00
|
|
|
),
|
2020-03-14 04:14:24 +01:00
|
|
|
),
|
2020-06-30 21:14:36 +02:00
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
flex: 1,
|
|
|
|
child: Row(
|
2020-08-01 09:30:24 +02:00
|
|
|
crossAxisAlignment:
|
|
|
|
CrossAxisAlignment.center,
|
2020-06-30 21:14:36 +02:00
|
|
|
children: <Widget>[
|
2020-08-01 09:30:24 +02:00
|
|
|
Text(
|
|
|
|
_dateToString(context,
|
|
|
|
pubDate:
|
|
|
|
episodes[index].pubDate),
|
|
|
|
overflow: TextOverflow.visible,
|
|
|
|
style: TextStyle(
|
2020-09-14 17:18:13 +02:00
|
|
|
height: 1,
|
2020-08-01 09:30:24 +02:00
|
|
|
fontSize: _width / 35,
|
2020-08-15 19:43:45 +02:00
|
|
|
color: c,
|
2020-08-01 09:30:24 +02:00
|
|
|
fontStyle: FontStyle.italic,
|
2020-04-02 11:52:26 +02:00
|
|
|
),
|
2020-04-18 06:48:02 +02:00
|
|
|
),
|
2020-06-30 21:14:36 +02:00
|
|
|
Spacer(),
|
2020-09-14 17:18:13 +02:00
|
|
|
if (episodes[index].duration != 0)
|
|
|
|
Align(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Text(
|
|
|
|
episodes[index]
|
|
|
|
.duration
|
|
|
|
.toTime,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: _width / 35,
|
|
|
|
// color: _c,
|
|
|
|
// fontStyle: FontStyle.italic,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2020-06-30 21:14:36 +02:00
|
|
|
episodes[index].duration == 0 ||
|
|
|
|
episodes[index]
|
|
|
|
.enclosureLength ==
|
|
|
|
null ||
|
|
|
|
episodes[index]
|
|
|
|
.enclosureLength ==
|
|
|
|
0
|
|
|
|
? Center()
|
|
|
|
: Text(
|
|
|
|
'|',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: _width / 35,
|
|
|
|
),
|
|
|
|
),
|
2020-09-14 17:18:13 +02:00
|
|
|
if (episodes[index]
|
|
|
|
.enclosureLength !=
|
|
|
|
null &&
|
|
|
|
episodes[index]
|
|
|
|
.enclosureLength !=
|
|
|
|
0)
|
|
|
|
Container(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Text(
|
|
|
|
'${(episodes[index].enclosureLength) ~/ 1000000}MB',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: _width / 35),
|
|
|
|
),
|
|
|
|
),
|
2020-06-30 21:14:36 +02:00
|
|
|
],
|
|
|
|
)),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}));
|
2020-02-09 13:29:09 +01:00
|
|
|
},
|
2020-08-23 11:42:13 +02:00
|
|
|
childCount: math.min(episodes.length, 2),
|
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) {
|
2020-07-26 12:20:42 +02:00
|
|
|
final circleOffset =
|
2020-02-09 13:29:09 +01:00
|
|
|
offset + Offset(cfg.size.width / 2, cfg.size.height - radius);
|
|
|
|
canvas.drawCircle(circleOffset, radius, _paint);
|
|
|
|
}
|
|
|
|
}
|