1
0
mirror of https://github.com/stonega/tsacdop synced 2025-02-03 08:57:33 +01:00

Save size in saveMediaId

Change setting ui
This commit is contained in:
stonegate 2020-06-13 21:23:08 +08:00
parent 0b20c24984
commit 9740113dfe
13 changed files with 158 additions and 133 deletions

View File

@ -15,6 +15,7 @@ import 'package:google_fonts/google_fonts.dart';
import '../state/audiostate.dart';
import '../type/episodebrief.dart';
import '../local_storage/sqflite_localpodcast.dart';
import '../local_storage/key_value_storage.dart';
import '../util/context_extension.dart';
import '../util/custompaint.dart';
import 'episodedownload.dart';
@ -52,14 +53,16 @@ class _EpisodeDetailState extends State<EpisodeDetail> {
ScrollController _controller;
_scrollListener() {
if (_controller.offset > _controller.position.maxScrollExtent * 0.8) {
setState(() {
_showMenu = true;
});
if (!_showMenu)
setState(() {
_showMenu = true;
});
} else if (_controller.offset <
_controller.position.maxScrollExtent * 0.8) {
setState(() {
_showMenu = false;
});
if (_showMenu)
setState(() {
_showMenu = false;
});
}
}
@ -267,7 +270,7 @@ class _EpisodeDetailState extends State<EpisodeDetail> {
? (_description.contains('<'))
? Html(
padding: EdgeInsets.only(
left: 20.0, right: 20, bottom: 20),
left: 20.0, right: 20, bottom: 50),
defaultTextStyle:
// GoogleFonts.libreBaskerville(
GoogleFonts.martel(
@ -290,7 +293,7 @@ class _EpisodeDetailState extends State<EpisodeDetail> {
padding: EdgeInsets.only(
left: 20.0,
right: 20.0,
bottom: 20.0),
bottom: 50.0),
alignment: Alignment.topLeft,
child: SelectableLinkify(
onOpen: (link) {
@ -398,7 +401,7 @@ class _MenuBarState extends State<MenuBar> {
setUnliked(String url) async {
var dbHelper = DBHelper();
await dbHelper.setUniked(url);
await dbHelper.setUniked(url);
setState(() {});
}
@ -423,24 +426,25 @@ class _MenuBarState extends State<MenuBar> {
),
);
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)),
),
);
}
@override
Widget build(BuildContext context) {
var audio = Provider.of<AudioPlayerNotifier>(context, listen: false);
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)),
),
);
}
return Container(
height: 50.0,

View File

@ -899,6 +899,7 @@ class DBHelper {
var dbClient = await database;
List<EpisodeBrief> episodes = [];
List<Map> list;
//Ordered by date
if (mode == 0)
list = await dbClient.rawQuery(
"""SELECT E.title, E.enclosure_url, E.enclosure_length, E.download_date,
@ -908,6 +909,7 @@ class DBHelper {
WHERE E.enclosure_url != E.media_id
ORDER BY E.download_date DESC""",
);
//Ordered by date
else if (mode == 1)
list = await dbClient.rawQuery(
"""SELECT E.title, E.enclosure_url, E.enclosure_length, E.download_date,
@ -917,6 +919,7 @@ class DBHelper {
WHERE E.enclosure_url != E.media_id
ORDER BY E.download_date ASC""",
);
//Ordered by size
else if (mode == 2)
list = await dbClient.rawQuery(
"""SELECT E.title, E.enclosure_url, E.enclosure_length, E.download_date,
@ -926,24 +929,12 @@ class DBHelper {
WHERE E.enclosure_url != E.media_id
ORDER BY E.enclosure_length DESC""",
);
for (int x = 0; x < list.length; x++) {
int size;
if (list[x]['enclosure_length'] == null ||
list[x]['enclosure_length'] == 0) {
String uri = list[x]['media_id'];
FileStat fileStat = await File(uri.substring(6)).stat();
size = fileStat.size;
await dbClient.rawUpdate(
"UPDATE Episodes SET enclosure_length = ?, WHERE media_id = ?",
[size, uri]);
} else
size = list[x]['enclosure_length'];
episodes.add(
EpisodeBrief(
list[x]['title'],
list[x]['enclosure_url'],
size,
list[x]['enclosure_length'],
list[x]['milliseconds'],
list[x]['feed_title'],
list[x]['primaryColor'],
@ -1115,12 +1106,12 @@ class DBHelper {
return count;
}
Future<int> saveMediaId(String url, String path, String id) async {
Future<int> saveMediaId(String url, String path, String id, int size) async {
var dbClient = await database;
int milliseconds = DateTime.now().millisecondsSinceEpoch;
int count = await dbClient.rawUpdate(
"UPDATE Episodes SET media_id = ?, download_date = ?, downloaded = ? WHERE enclosure_url = ?",
[path, milliseconds, id, url]);
"UPDATE Episodes SET enclosure_length = ?, media_id = ?, download_date = ?, downloaded = ? WHERE enclosure_url = ?",
[size, path, milliseconds, id, url]);
return count;
}

View File

@ -366,8 +366,8 @@ class _PodcastCardState extends State<PodcastCard>
color: snapshot.data
? Colors.white
: null),
height: _value == 0 ? 1 : 18 * _value,
width: _value == 0 ? 1 : 18 * _value,
height: _value == 0 ? 1 : 20 * _value,
width: _value == 0 ? 1 : 20 * _value,
decoration: BoxDecoration(
border: snapshot.data
? Border.all(

View File

@ -43,13 +43,14 @@ class _DownloadsManageState extends State<DownloadsManage> {
_size = 0;
_fileNum = 0;
var dir = await getExternalStorageDirectory();
print(dir.path);
dir.list().forEach((d) {
var fileDir = Directory(d.path);
fileDir.list().forEach((file) async {
await File(file.path).stat().then((value) {
_size += value.size;
_fileNum += 1;
setState(() {});
if (mounted) setState(() {});
});
});
});
@ -59,19 +60,16 @@ class _DownloadsManageState extends State<DownloadsManage> {
setState(() => _clearing = true);
await Future.forEach(_selectedList, (EpisodeBrief episode) async {
var downloader = Provider.of<DownloadState>(context, listen: false);
await downloader.removeTask(episode);
// await FlutterDownloader.remove(
// taskId: episode.downloaded, shouldDeleteContent: true);
// var dbHelper = DBHelper();
// await dbHelper.delDownloaded(episode.enclosureUrl);
setState(() {});
await downloader.delTask(episode);
if (mounted) setState(() {});
});
await Future.delayed(Duration(seconds: 1));
setState(() {
_clearing = false;
});
if (mounted)
setState(() {
_clearing = false;
});
await Future.delayed(Duration(seconds: 1));
setState(() => _selectedList = []);
if (mounted) setState(() => _selectedList = []);
_getStorageSize();
}
@ -245,13 +243,16 @@ class _DownloadsManageState extends State<DownloadsManage> {
EdgeInsets.symmetric(horizontal: 5),
),
Text('Listened Only'),
Checkbox(
value: _onlyListened,
onChanged: (value) {
setState(() {
_onlyListened = value;
});
}),
Transform.scale(
scale: 0.8,
child: Checkbox(
value: _onlyListened,
onChanged: (value) {
setState(() {
_onlyListened = value;
});
}),
),
],
),
),
@ -277,8 +278,7 @@ class _DownloadsManageState extends State<DownloadsManage> {
future: _isListened(_episodes[index]),
initialData: 0,
builder: (context, snapshot) {
return (_onlyListened &&
snapshot.data > 0)
return (_onlyListened && snapshot.data == 0)
? Center()
: Column(
children: <Widget>[

View File

@ -39,7 +39,7 @@ class Libries extends StatelessWidget {
),
Container(
height: 30.0,
padding: EdgeInsets.symmetric(horizontal: 80),
padding: EdgeInsets.symmetric(horizontal: 70),
alignment: Alignment.centerLeft,
child: Text('Google',
style: Theme.of(context)
@ -61,7 +61,7 @@ class Libries extends StatelessWidget {
),
Container(
height: 30.0,
padding: EdgeInsets.symmetric(horizontal: 80),
padding: EdgeInsets.symmetric(horizontal: 70),
alignment: Alignment.centerLeft,
child: Text('Fonts',
style: Theme.of(context)
@ -83,7 +83,7 @@ class Libries extends StatelessWidget {
),
Container(
height: 30.0,
padding: EdgeInsets.symmetric(horizontal: 80),
padding: EdgeInsets.symmetric(horizontal: 70),
alignment: Alignment.centerLeft,
child: Text('Plugins',
style: Theme.of(context)

View File

@ -56,9 +56,12 @@ class PlaySetting extends StatelessWidget {
subtitle: Text('Autoplay next episode in playlist'),
trailing: Selector<AudioPlayerNotifier, bool>(
selector: (_, audio) => audio.autoPlay,
builder: (_, data, __) => Switch(
value: data,
onChanged: (boo) => audio.autoPlaySwitch = boo),
builder: (_, data, __) => Transform.scale(
scale: 0.9,
child: Switch(
value: data,
onChanged: (boo) => audio.autoPlaySwitch = boo),
),
),
),
Divider(height: 2),

View File

@ -128,10 +128,13 @@ class _StorageSettingState extends State<StorageSetting>
title: Text('Ask before using cellular data'),
subtitle: Text(
'Ask to confirm when using cellular data to download episodes.'),
trailing: Switch(
value: data,
onChanged: (value) =>
settings.downloadUsingData = value,
trailing: Transform.scale(
scale: 0.9,
child: Switch(
value: data,
onChanged: (value) =>
settings.downloadUsingData = value,
),
),
);
},
@ -152,12 +155,15 @@ class _StorageSettingState extends State<StorageSetting>
Text('Auto download using cellular data'),
subtitle: Text(
'You can set podcast auto download in group manage page.'),
trailing: Switch(
value: snapshot.data,
onChanged: (value) async {
await _setAudtDownloadNetwork(value);
setState(() {});
},
trailing: Transform.scale(
scale: 0.9,
child: Switch(
value: snapshot.data,
onChanged: (value) async {
await _setAudtDownloadNetwork(value);
setState(() {});
},
),
),
);
}),

View File

@ -71,15 +71,18 @@ class SyncingSetting extends StatelessWidget {
title: Text('Enable syncing'),
subtitle: Text(
'Refresh all podcasts in the background to get leatest episodes'),
trailing: Switch(
value: data.item1,
onChanged: (boo) async {
settings.autoUpdate = boo;
if (boo)
settings.setWorkManager(data.item2);
else
settings.cancelWork();
}),
trailing: Transform.scale(
scale: 0.9,
child: Switch(
value: data.item1,
onChanged: (boo) async {
settings.autoUpdate = boo;
if (boo)
settings.setWorkManager(data.item2);
else
settings.cancelWork();
}),
),
),
Divider(height: 2),
ListTile(

View File

@ -126,11 +126,14 @@ class ThemeSetting extends StatelessWidget {
Text('Turn on if you think the night is not dark enough'),
trailing: Selector<SettingState, bool>(
selector: (_, setting) => setting.realDark,
builder: (_, data, __) => Switch(
value: data,
onChanged: (boo) async {
settings.setRealDark = boo;
}),
builder: (_, data, __) => Transform.scale(
scale: 0.9,
child: Switch(
value: data,
onChanged: (boo) async {
settings.setRealDark = boo;
}),
),
),
),
Divider(height: 2),

View File

@ -92,7 +92,7 @@ class Playlist {
savePlaylist() async {
List<String> urls = [];
urls.addAll(_playlist.map((e) => e.enclosureUrl));
await storage.saveStringList(urls);
await storage.saveStringList(urls.toSet().toList());
}
addToPlayList(EpisodeBrief episodeBrief) async {
@ -104,15 +104,16 @@ class Playlist {
}
addToPlayListAt(EpisodeBrief episodeBrief, int index) async {
_playlist.insert(index, episodeBrief);
await savePlaylist();
dbHelper.removeEpisodeNewMark(episodeBrief.enclosureUrl);
if (!_playlist.contains(episodeBrief)) {
_playlist.insert(index, episodeBrief);
await savePlaylist();
dbHelper.removeEpisodeNewMark(episodeBrief.enclosureUrl);
}
}
Future<int> delFromPlaylist(EpisodeBrief episodeBrief) async {
int index = _playlist.indexOf(episodeBrief);
_playlist
.removeWhere((item) => item.enclosureUrl == episodeBrief.enclosureUrl);
_playlist.removeWhere((episode) => episode == episodeBrief);
await savePlaylist();
return index;
}

View File

@ -91,8 +91,11 @@ class AutoDownloader {
String filePath = 'file://' +
path.join(completeTask.first.savedDir,
Uri.encodeComponent(completeTask.first.filename));
await dbHelper.saveMediaId(
episodeTask.episode.enclosureUrl, filePath, episodeTask.taskId);
FileStat fileStat = await File(
path.join(completeTask.first.savedDir, completeTask.first.filename))
.stat();
await dbHelper.saveMediaId(episodeTask.episode.enclosureUrl, filePath,
episodeTask.taskId, fileStat.size);
_episodeTasks.removeWhere((element) =>
element.episode.enclosureUrl == episodeTask.episode.enclosureUrl);
if (_episodeTasks.length == 0) _unbindBackgroundIsolate();
@ -200,8 +203,12 @@ class DownloadState extends ChangeNotifier {
String filePath = 'file://' +
path.join(completeTask.first.savedDir,
Uri.encodeComponent(completeTask.first.filename));
dbHelper.saveMediaId(
episodeTask.episode.enclosureUrl, filePath, episodeTask.taskId);
print(filePath);
FileStat fileStat = await File(
path.join(completeTask.first.savedDir, completeTask.first.filename))
.stat();
dbHelper.saveMediaId(episodeTask.episode.enclosureUrl, filePath,
episodeTask.taskId, fileStat.size);
EpisodeBrief episode =
await dbHelper.getRssItemWithUrl(episodeTask.episode.enclosureUrl);
_removeTask(episodeTask.episode);
@ -231,33 +238,36 @@ class DownloadState extends ChangeNotifier {
}
Future startTask(EpisodeBrief episode, {bool showNotification = true}) async {
final dir = await getExternalStorageDirectory();
String localPath = path.join(dir.path, episode.feedTitle);
final saveDir = Directory(localPath);
bool hasExisted = await saveDir.exists();
if (!hasExisted) {
saveDir.create();
}
DateTime now = DateTime.now();
String datePlus = now.year.toString() +
now.month.toString() +
now.day.toString() +
now.second.toString();
String fileName = episode.title +
datePlus +
'.' +
episode.enclosureUrl.split('/').last.split('.').last;
String taskId = await FlutterDownloader.enqueue(
fileName: fileName,
url: episode.enclosureUrl,
savedDir: localPath,
showNotification: showNotification,
openFileFromNotification: false,
);
_episodeTasks.add(EpisodeTask(episode, taskId));
var dbHelper = DBHelper();
await dbHelper.saveDownloaded(episode.enclosureUrl, taskId);
notifyListeners();
bool isDownloaded = await dbHelper.isDownloaded(episode.enclosureUrl);
if (!isDownloaded) {
final dir = await getExternalStorageDirectory();
String localPath = path.join(dir.path, episode.feedTitle);
final saveDir = Directory(localPath);
bool hasExisted = await saveDir.exists();
if (!hasExisted) {
saveDir.create();
}
DateTime now = DateTime.now();
String datePlus = now.year.toString() +
now.month.toString() +
now.day.toString() +
now.second.toString();
String fileName = episode.title +
datePlus +
'.' +
episode.enclosureUrl.split('/').last.split('.').last;
String taskId = await FlutterDownloader.enqueue(
fileName: fileName,
url: episode.enclosureUrl,
savedDir: localPath,
showNotification: showNotification,
openFileFromNotification: false,
);
_episodeTasks.add(EpisodeTask(episode, taskId));
await dbHelper.saveDownloaded(episode.enclosureUrl, taskId);
notifyListeners();
}
}
Future pauseTask(EpisodeBrief episode) async {

View File

@ -538,6 +538,7 @@ class _OpenContainerRoute extends ModalRoute<void> {
// the bounds of the enclosing [Navigator].
final RectTween _rectTween = RectTween();
final Tween<Offset> _positionTween = Tween<Offset>();
final Tween<double> _avatarScaleTween = Tween<double>();
AnimationStatus _lastAnimationStatus;
AnimationStatus _currentAnimationStatus;
@ -726,7 +727,10 @@ class _OpenContainerRoute extends ModalRoute<void> {
playerRunning
? MediaQuery.of(context).size.height - 100
: MediaQuery.of(context).size.height - 40);
double _width = MediaQuery.of(context).size.width;
_avatarScaleTween.begin = _width / 16;
_avatarScaleTween.end = 30;
return SizedBox.expand(
child: Stack(
children: <Widget>[
@ -804,8 +808,8 @@ class _OpenContainerRoute extends ModalRoute<void> {
top: _positionTween.evaluate(secondCurvedAnimation).dy,
left: _positionTween.evaluate(secondCurvedAnimation).dx,
child: SizedBox(
height: _width / 16,
width: _width / 16,
height: _avatarScaleTween.evaluate(secondCurvedAnimation),
width: _avatarScaleTween.evaluate(secondCurvedAnimation),
child: flightWidget,
),
),

View File

@ -26,7 +26,7 @@ dependencies:
permission_handler: ^5.0.0+hotfix.3
fluttertoast: ^4.0.1
intl: ^0.16.1
url_launcher: ^5.4.7
url_launcher: ^5.4.10
image: ^2.1.12
shared_preferences: ^0.5.7
uuid: ^2.0.4
@ -44,7 +44,8 @@ dependencies:
wc_flutter_share: ^0.2.1
video_player: ^0.10.11
auto_animated: ^2.1.0
feature_discovery: ^0.10.0
feature_discovery: ^0.10.0
flutter_isolate: ^1.0.0+14
just_audio:
git:
url: https://github.com/stonega/just_audio.git
@ -57,7 +58,6 @@ dev_dependencies:
sdk: flutter
dependency_overrides:
flutter_isolate: "1.0.0+14"
xml: "4.2.0"
flutter: