mirror of
https://github.com/stonega/tsacdop
synced 2025-02-18 04:20:37 +01:00
Fixed bug => save history error.
This commit is contained in:
parent
fda2c2266c
commit
017e15b129
@ -521,7 +521,7 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
child: PlaylistButton()),
|
child: _PlaylistButton()),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Container(height: 2, color: context.primaryColor),
|
Container(height: 2, color: context.primaryColor),
|
||||||
@ -536,19 +536,15 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PlaylistButton extends StatefulWidget {
|
class _PlaylistButton extends StatefulWidget {
|
||||||
PlaylistButton({Key key}) : super(key: key);
|
_PlaylistButton({Key key}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
PlaylistButtonState createState() => PlaylistButtonState();
|
__PlaylistButtonState createState() => __PlaylistButtonState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class PlaylistButtonState extends State<PlaylistButton> {
|
class __PlaylistButtonState extends State<_PlaylistButton> {
|
||||||
bool _loadPlay;
|
bool _loadPlay;
|
||||||
static String _stringForSeconds(int seconds) {
|
|
||||||
if (seconds == null) return null;
|
|
||||||
return '${(seconds ~/ 60)}:${(seconds.truncate() % 60).toString().padLeft(2, '0')}';
|
|
||||||
}
|
|
||||||
|
|
||||||
_getPlaylist() async {
|
_getPlaylist() async {
|
||||||
await Provider.of<AudioPlayerNotifier>(context, listen: false)
|
await Provider.of<AudioPlayerNotifier>(context, listen: false)
|
||||||
@ -567,7 +563,7 @@ class PlaylistButtonState extends State<PlaylistButton> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var audio = Provider.of<AudioPlayerNotifier>(context, listen: false);
|
var audio = context.watch<AudioPlayerNotifier>();
|
||||||
final s = context.s;
|
final s = context.s;
|
||||||
return MyPopupMenuButton<int>(
|
return MyPopupMenuButton<int>(
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
@ -639,7 +635,7 @@ class PlaylistButtonState extends State<PlaylistButton> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text(
|
Text(
|
||||||
_stringForSeconds(data.item3 ~/ 1000),
|
(data.item3 ~/ 1000).toTime,
|
||||||
// style:
|
// style:
|
||||||
// TextStyle(color: Colors.white)
|
// TextStyle(color: Colors.white)
|
||||||
),
|
),
|
||||||
@ -654,7 +650,7 @@ class PlaylistButtonState extends State<PlaylistButton> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Divider(
|
Divider(
|
||||||
height: 2,
|
height: 1,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@ -677,6 +673,9 @@ class PlaylistButtonState extends State<PlaylistButton> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
PopupMenuDivider(
|
||||||
|
height: 1,
|
||||||
|
),
|
||||||
PopupMenuItem(
|
PopupMenuItem(
|
||||||
value: 2,
|
value: 2,
|
||||||
child: Container(
|
child: Container(
|
||||||
@ -692,6 +691,9 @@ class PlaylistButtonState extends State<PlaylistButton> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
PopupMenuDivider(
|
||||||
|
height: 1,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
onSelected: (value) {
|
onSelected: (value) {
|
||||||
if (value == 0) {
|
if (value == 0) {
|
||||||
@ -757,14 +759,14 @@ class _RecentUpdateState extends State<_RecentUpdate>
|
|||||||
await Future.delayed(Duration(seconds: 3));
|
await Future.delayed(Duration(seconds: 3));
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_top = _top + 33;
|
_top = _top + 30;
|
||||||
_loadMore = false;
|
_loadMore = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Episodes loaded first time.
|
/// Episodes loaded first time.
|
||||||
int _top = 99;
|
int _top = 90;
|
||||||
|
|
||||||
/// Load more episodes when scroll to bottom.
|
/// Load more episodes when scroll to bottom.
|
||||||
bool _loadMore;
|
bool _loadMore;
|
||||||
@ -822,8 +824,10 @@ class _RecentUpdateState extends State<_RecentUpdate>
|
|||||||
if (scrollInfo.metrics.pixels ==
|
if (scrollInfo.metrics.pixels ==
|
||||||
scrollInfo.metrics.maxScrollExtent &&
|
scrollInfo.metrics.maxScrollExtent &&
|
||||||
snapshot.data.length == _top) {
|
snapshot.data.length == _top) {
|
||||||
|
if (!_loadMore) {
|
||||||
_loadMoreEpisode();
|
_loadMoreEpisode();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
child: CustomScrollView(
|
child: CustomScrollView(
|
||||||
@ -1060,13 +1064,13 @@ class _MyFavoriteState extends State<_MyFavorite>
|
|||||||
await Future.delayed(Duration(seconds: 3));
|
await Future.delayed(Duration(seconds: 3));
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_top = _top + 33;
|
_top = _top + 30;
|
||||||
_loadMore = false;
|
_loadMore = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int _top = 99;
|
int _top = 90;
|
||||||
bool _loadMore;
|
bool _loadMore;
|
||||||
Layout _layout;
|
Layout _layout;
|
||||||
int _sortBy;
|
int _sortBy;
|
||||||
@ -1110,8 +1114,10 @@ class _MyFavoriteState extends State<_MyFavorite>
|
|||||||
if (scrollInfo.metrics.pixels ==
|
if (scrollInfo.metrics.pixels ==
|
||||||
scrollInfo.metrics.maxScrollExtent &&
|
scrollInfo.metrics.maxScrollExtent &&
|
||||||
snapshot.data.length == _top) {
|
snapshot.data.length == _top) {
|
||||||
|
if (!_loadMore) {
|
||||||
_loadMoreEpisode();
|
_loadMoreEpisode();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
child: CustomScrollView(
|
child: CustomScrollView(
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:fluttertoast/fluttertoast.dart';
|
import 'package:fluttertoast/fluttertoast.dart';
|
||||||
@ -515,6 +513,9 @@ class _HistoryList extends StatefulWidget {
|
|||||||
|
|
||||||
class __HistoryListState extends State<_HistoryList> {
|
class __HistoryListState extends State<_HistoryList> {
|
||||||
var dbHelper = DBHelper();
|
var dbHelper = DBHelper();
|
||||||
|
bool _loadMore = false;
|
||||||
|
Future _getData;
|
||||||
|
|
||||||
Future<List<PlayHistory>> getPlayRecords(int top) async {
|
Future<List<PlayHistory>> getPlayRecords(int top) async {
|
||||||
List<PlayHistory> playHistory;
|
List<PlayHistory> playHistory;
|
||||||
playHistory = await dbHelper.getPlayRecords(top);
|
playHistory = await dbHelper.getPlayRecords(top);
|
||||||
@ -527,41 +528,63 @@ class __HistoryListState extends State<_HistoryList> {
|
|||||||
_loadMoreData() async {
|
_loadMoreData() async {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
_loadMore = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
await Future.delayed(Duration(milliseconds: 500));
|
||||||
_top = _top + 20;
|
_top = _top + 20;
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
_getData = getPlayRecords(_top);
|
||||||
|
_loadMore = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int _top = 20;
|
int _top;
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_top = 20;
|
||||||
|
_getData = getPlayRecords(_top);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final s = context.s;
|
final s = context.s;
|
||||||
final audio = context.watch<AudioPlayerNotifier>();
|
final audio = context.watch<AudioPlayerNotifier>();
|
||||||
return FutureBuilder<List<PlayHistory>>(
|
return FutureBuilder<List<PlayHistory>>(
|
||||||
future: getPlayRecords(_top),
|
future: _getData,
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
return snapshot.hasData
|
return snapshot.hasData
|
||||||
? NotificationListener<ScrollNotification>(
|
? NotificationListener<ScrollNotification>(
|
||||||
onNotification: (scrollInfo) {
|
onNotification: (scrollInfo) {
|
||||||
if (scrollInfo.metrics.pixels ==
|
if (scrollInfo.metrics.pixels ==
|
||||||
scrollInfo.metrics.maxScrollExtent &&
|
scrollInfo.metrics.maxScrollExtent &&
|
||||||
snapshot.data.length == _top) _loadMoreData();
|
snapshot.data.length == _top) {
|
||||||
|
if (!_loadMore) {
|
||||||
|
_loadMoreData();
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
scrollDirection: Axis.vertical,
|
scrollDirection: Axis.vertical,
|
||||||
itemCount: snapshot.data.length,
|
itemCount: snapshot.data.length + 1,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
|
if (index == snapshot.data.length) {
|
||||||
|
return SizedBox(
|
||||||
|
height: 2,
|
||||||
|
child: _loadMore
|
||||||
|
? LinearProgressIndicator()
|
||||||
|
: Center());
|
||||||
|
} else {
|
||||||
final seekValue = snapshot.data[index].seekValue;
|
final seekValue = snapshot.data[index].seekValue;
|
||||||
final seconds = snapshot.data[index].seconds;
|
final seconds = snapshot.data[index].seconds;
|
||||||
final date = snapshot
|
final date = snapshot
|
||||||
.data[index].playdate.millisecondsSinceEpoch;
|
.data[index].playdate.millisecondsSinceEpoch;
|
||||||
final episode = snapshot.data[index].episode;
|
final episode = snapshot.data[index].episode;
|
||||||
var c =
|
final c = episode.backgroudColor(context);
|
||||||
(Theme.of(context).brightness == Brightness.light)
|
|
||||||
? episode.primaryColor.colorizedark()
|
|
||||||
: episode.primaryColor.colorizeLight();
|
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
height: 90.0,
|
height: 90.0,
|
||||||
child: Column(
|
child: Column(
|
||||||
@ -609,7 +632,8 @@ class __HistoryListState extends State<_HistoryList> {
|
|||||||
},
|
},
|
||||||
child: Stack(children: [
|
child: Stack(children: [
|
||||||
ShaderMask(
|
ShaderMask(
|
||||||
shaderCallback: (bounds) {
|
shaderCallback:
|
||||||
|
(bounds) {
|
||||||
return LinearGradient(
|
return LinearGradient(
|
||||||
begin: Alignment
|
begin: Alignment
|
||||||
.centerLeft,
|
.centerLeft,
|
||||||
@ -625,7 +649,8 @@ class __HistoryListState extends State<_HistoryList> {
|
|||||||
],
|
],
|
||||||
tileMode:
|
tileMode:
|
||||||
TileMode.mirror,
|
TileMode.mirror,
|
||||||
).createShader(bounds);
|
).createShader(
|
||||||
|
bounds);
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
height: 25,
|
height: 25,
|
||||||
@ -633,13 +658,13 @@ class __HistoryListState extends State<_HistoryList> {
|
|||||||
Alignment.center,
|
Alignment.center,
|
||||||
padding: EdgeInsets
|
padding: EdgeInsets
|
||||||
.symmetric(
|
.symmetric(
|
||||||
horizontal: 20),
|
horizontal:
|
||||||
|
20),
|
||||||
decoration:
|
decoration:
|
||||||
BoxDecoration(
|
BoxDecoration(
|
||||||
borderRadius:
|
borderRadius:
|
||||||
BorderRadius.all(
|
BorderRadius.all(
|
||||||
Radius
|
Radius.circular(
|
||||||
.circular(
|
|
||||||
20.0)),
|
20.0)),
|
||||||
color: context
|
color: context
|
||||||
.accentColor,
|
.accentColor,
|
||||||
@ -647,8 +672,8 @@ class __HistoryListState extends State<_HistoryList> {
|
|||||||
child: Text(
|
child: Text(
|
||||||
seconds.toTime,
|
seconds.toTime,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color:
|
color: Colors
|
||||||
Colors.white),
|
.white),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -674,7 +699,8 @@ class __HistoryListState extends State<_HistoryList> {
|
|||||||
color: context
|
color: context
|
||||||
.accentColor),
|
.accentColor),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
audio.delFromPlaylist(
|
audio
|
||||||
|
.delFromPlaylist(
|
||||||
episode);
|
episode);
|
||||||
Fluttertoast
|
Fluttertoast
|
||||||
.showToast(
|
.showToast(
|
||||||
@ -687,7 +713,8 @@ class __HistoryListState extends State<_HistoryList> {
|
|||||||
})
|
})
|
||||||
: IconButton(
|
: IconButton(
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
Icons.playlist_add,
|
Icons
|
||||||
|
.playlist_add,
|
||||||
color: Colors
|
color: Colors
|
||||||
.grey[700]),
|
.grey[700]),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
@ -722,13 +749,16 @@ class __HistoryListState extends State<_HistoryList> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
: Center(
|
: Center(
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: 25,
|
height: 25,
|
||||||
width: 25,
|
width: 25,
|
||||||
child: CircularProgressIndicator()),
|
child: CircularProgressIndicator(
|
||||||
|
strokeWidth: 2,
|
||||||
|
)),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -235,30 +235,27 @@ class DBHelper {
|
|||||||
[_milliseconds, 1, id]);
|
[_milliseconds, 1, id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<int> saveHistory(PlayHistory history) async {
|
Future<void> saveHistory(PlayHistory history) async {
|
||||||
var dbClient = await database;
|
var dbClient = await database;
|
||||||
var _milliseconds = DateTime.now().millisecondsSinceEpoch;
|
final milliseconds = DateTime.now().millisecondsSinceEpoch;
|
||||||
var recent = await getPlayHistory(1);
|
var recent = await getPlayHistory(1);
|
||||||
if (recent.length == 1) {
|
if (recent.isNotEmpty && recent.first.url == history.url) {
|
||||||
if (recent.first.url == history.url) {
|
|
||||||
await dbClient.rawDelete("DELETE FROM PlayHistory WHERE add_date = ?",
|
await dbClient.rawDelete("DELETE FROM PlayHistory WHERE add_date = ?",
|
||||||
[recent.first.playdate.millisecondsSinceEpoch]);
|
[recent.first.playdate.millisecondsSinceEpoch]);
|
||||||
}
|
}
|
||||||
}
|
await dbClient.transaction((txn) async {
|
||||||
var result = await dbClient.transaction((txn) async {
|
|
||||||
return await txn.rawInsert(
|
return await txn.rawInsert(
|
||||||
"""REPLACE INTO PlayHistory (title, enclosure_url, seconds, seek_value, add_date, listen_time)
|
"""INSERT INTO PlayHistory (title, enclosure_url, seconds, seek_value, add_date, listen_time)
|
||||||
VALUES (?, ?, ?, ?, ?, ?) """,
|
VALUES (?, ?, ?, ?, ?, ?) """,
|
||||||
[
|
[
|
||||||
history.title,
|
history.title,
|
||||||
history.url,
|
history.url,
|
||||||
history.seconds,
|
history.seconds,
|
||||||
history.seekValue,
|
history.seekValue,
|
||||||
_milliseconds,
|
milliseconds,
|
||||||
history.seekValue > 0.95 ? 1 : 0
|
history.seekValue > 0.95 ? 1 : 0
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<PlayHistory>> getPlayHistory(int top) async {
|
Future<List<PlayHistory>> getPlayHistory(int top) async {
|
||||||
|
@ -267,7 +267,7 @@ class AudioPlayerNotifier extends ChangeNotifier {
|
|||||||
await lastWorkStorage.saveInt(0);
|
await lastWorkStorage.saveInt(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
playlistLoad() async {
|
Future<void> playlistLoad() async {
|
||||||
await _queue.getPlaylist();
|
await _queue.getPlaylist();
|
||||||
_backgroundAudioDuration = 0;
|
_backgroundAudioDuration = 0;
|
||||||
_backgroundAudioPosition = 0;
|
_backgroundAudioPosition = 0;
|
||||||
@ -442,12 +442,14 @@ class AudioPlayerNotifier extends ChangeNotifier {
|
|||||||
await dbHelper.saveHistory(history);
|
await dbHelper.saveHistory(history);
|
||||||
}
|
}
|
||||||
if (event is Map && event['playerRunning'] == false) {
|
if (event is Map && event['playerRunning'] == false) {
|
||||||
|
if (_playerRunning) {
|
||||||
_playerRunning = false;
|
_playerRunning = false;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
final history = PlayHistory(_episode.title, _episode.enclosureUrl,
|
final history = PlayHistory(_episode.title, _episode.enclosureUrl,
|
||||||
_lastPostion ~/ 1000, _seekSliderValue);
|
_lastPostion ~/ 1000, _seekSliderValue);
|
||||||
await dbHelper.saveHistory(history);
|
await dbHelper.saveHistory(history);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//double s = _currentSpeed ?? 1.0;
|
//double s = _currentSpeed ?? 1.0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user