diff --git a/README.md b/README.md index 0acde2f..664aad7 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,10 @@ If no api key added, the search function in the app won't work. But you can stil Share_key is used for generate clip. +## Known Issue + +- Playlist unstable + ## Getting Started This project is a starting point for a Flutter application. diff --git a/lib/home/download_list.dart b/lib/home/download_list.dart index a135df1..5c283de 100644 --- a/lib/home/download_list.dart +++ b/lib/home/download_list.dart @@ -99,6 +99,8 @@ class _DownloadListState extends State { color: Colors.red), child: Text( tasks[index].progress.toString() + '%', + textAlign: TextAlign.center, + maxLines: 1, style: TextStyle(color: Colors.white), )) : Container(), @@ -115,10 +117,7 @@ class _DownloadListState extends State { backgroundImage: FileImage( File("${tasks[index].episode.imagePath}")), ), - trailing: Container( - width: 50, - height: 50, - child: _downloadButton(tasks[index], context)), + trailing: _downloadButton(tasks[index], context), ); }, childCount: tasks.length, diff --git a/lib/home/importompl.dart b/lib/home/importompl.dart index 7f4dc56..353f23a 100644 --- a/lib/home/importompl.dart +++ b/lib/home/importompl.dart @@ -40,16 +40,16 @@ class Import extends StatelessWidget { if (autoDownloadNetwork == 1) { List episodes = await dbHelper.getNewEpisodes('all'); // For safety - if (episodes.length < 100) - episodes.forEach((episode) { - downloader.startTask(episode, showNotification: true); + if (episodes.length < 100 && episodes.length > 0) + episodes.forEach((episode) async { + await downloader.startTask(episode, showNotification: true); }); } else if (result == ConnectivityResult.wifi) { List episodes = await dbHelper.getNewEpisodes('all'); //For safety - if (episodes.length < 100) - episodes.forEach((episode) { - downloader.startTask(episode, showNotification: true); + if (episodes.length < 100 && episodes.length > 0) + episodes.forEach((episode) async { + await downloader.startTask(episode, showNotification: true); }); } } diff --git a/lib/intro_slider/app_intro.dart b/lib/intro_slider/app_intro.dart index 9492484..2d1c9c5 100644 --- a/lib/intro_slider/app_intro.dart +++ b/lib/intro_slider/app_intro.dart @@ -212,7 +212,7 @@ class _SlideIntroState extends State { SlideLeftRoute(page: Home())); Provider.of(context, listen: false) - .saveShowIntro(); + .saveShowIntro(1); } else if (widget.goto == Goto.settings) { Navigator.pop(context); } diff --git a/lib/local_storage/sqflite_localpodcast.dart b/lib/local_storage/sqflite_localpodcast.dart index 2f934ef..95141f5 100644 --- a/lib/local_storage/sqflite_localpodcast.dart +++ b/lib/local_storage/sqflite_localpodcast.dart @@ -1010,6 +1010,7 @@ class DBHelper { await txn.rawUpdate( "UPDATE Episodes SET is_new = 0 WHERE enclosure_url = ?", [url]); }); + print('remove new episode'); } Future> getLikedRssItem(int i, int sortBy) async { diff --git a/lib/settings/downloads_manage.dart b/lib/settings/downloads_manage.dart index 62cb195..9c386c2 100644 --- a/lib/settings/downloads_manage.dart +++ b/lib/settings/downloads_manage.dart @@ -43,7 +43,6 @@ class _DownloadsManageState extends State { _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 { @@ -124,7 +123,7 @@ class _DownloadsManageState extends State { mainAxisAlignment: MainAxisAlignment.start, children: [ Padding( - padding: const EdgeInsets.only(left: 20), + padding: const EdgeInsets.only(left: 10), child: RichText( text: TextSpan( text: 'Total ', @@ -150,7 +149,9 @@ class _DownloadsManageState extends State { fontSize: 20, )), TextSpan( - text: (_size ~/ 1000000).toString(), + text: (_size ~/ 1000000) < 1000 + ? (_size ~/ 1000000).toString() + : (_size / 1000000000).toStringAsFixed(1), style: GoogleFonts.cairo( textStyle: TextStyle( color: Theme.of(context).accentColor, @@ -158,7 +159,9 @@ class _DownloadsManageState extends State { )), ), TextSpan( - text: ' Mb', + text: (_size ~/ 1000000) < 1000 + ? 'Mb' + : 'Gb', style: TextStyle( color: Theme.of(context).accentColor, fontSize: 20, diff --git a/lib/settings/storage.dart b/lib/settings/storage.dart index 7e06d07..560ca3d 100644 --- a/lib/settings/storage.dart +++ b/lib/settings/storage.dart @@ -222,7 +222,8 @@ class _StorageSettingState extends State onChanged: (value) async { await _setAutoDeleteDays(value); }, - items: [-1, 10, 30] + //TODO remove 1 before release + items: [-1, 5, 10, 15, 30] .map>((e) { return DropdownMenuItem( value: e, diff --git a/lib/state/audiostate.dart b/lib/state/audiostate.dart index 784d37d..93468d2 100644 --- a/lib/state/audiostate.dart +++ b/lib/state/audiostate.dart @@ -113,7 +113,9 @@ class Playlist { Future delFromPlaylist(EpisodeBrief episodeBrief) async { int index = _playlist.indexOf(episodeBrief); - _playlist.removeWhere((episode) => episode == episodeBrief); + _playlist.removeWhere( + (episode) => episode.enclosureUrl == episodeBrief.enclosureUrl); + print('delete' + episodeBrief.title); await savePlaylist(); return index; } @@ -244,6 +246,7 @@ class AudioPlayerNotifier extends ChangeNotifier { } episodeLoad(EpisodeBrief episode, {int startPosition = 0}) async { + print(episode.enclosureUrl); final EpisodeBrief episodeNew = await dbHelper.getRssItemWithUrl(episode.enclosureUrl); //TODO load episode from last position when player running @@ -270,8 +273,9 @@ class AudioPlayerNotifier extends ChangeNotifier { notifyListeners(); //await _queue.savePlaylist(); _startAudioService(startPosition, episodeNew.enclosureUrl); - if (episodeNew.isNew == 1) - dbHelper.removeEpisodeNewMark(episodeNew.enclosureUrl); + if (episodeNew.isNew == 1) { + await dbHelper.removeEpisodeNewMark(episodeNew.enclosureUrl); + } } } diff --git a/lib/state/download_state.dart b/lib/state/download_state.dart index 2b24306..a0ed344 100644 --- a/lib/state/download_state.dart +++ b/lib/state/download_state.dart @@ -50,15 +50,15 @@ class AutoDownloader { } bindBackgroundIsolate() { - print('start listen'); ReceivePort _port = ReceivePort(); bool isSuccess = IsolateNameServer.registerPortWithName( _port.sendPort, 'auto_downloader_send_port'); if (!isSuccess) { - _unbindBackgroundIsolate(); - //bindBackgroundIsolate(); + IsolateNameServer.removePortNameMapping('auto_downloader_send_port'); + bindBackgroundIsolate(); return; } + print('start listen'); _port.listen((dynamic data) { String id = data[0]; DownloadTaskStatus status = data[1]; @@ -102,7 +102,7 @@ class AutoDownloader { } Future startTask(List episodes, - {bool showNotification = true}) async { + {bool showNotification = false}) async { episodes.forEach((episode) async { final dir = await getExternalStorageDirectory(); String localPath = path.join(dir.path, episode.feedTitle); diff --git a/lib/state/settingstate.dart b/lib/state/settingstate.dart index e3ad564..487ea68 100644 --- a/lib/state/settingstate.dart +++ b/lib/state/settingstate.dart @@ -1,5 +1,4 @@ import 'dart:io'; -import 'dart:isolate'; import 'dart:ui'; import 'package:connectivity/connectivity.dart'; import 'package:flutter/foundation.dart'; @@ -28,7 +27,7 @@ void callbackDispatcher() { }); await FlutterDownloader.initialize(); AutoDownloader downloader = AutoDownloader(); - downloader.bindBackgroundIsolate(); + KeyValueStorage autoDownloadStorage = KeyValueStorage(autoDownloadNetworkKey); int autoDownloadNetwork = await autoDownloadStorage.getInt(); @@ -36,13 +35,17 @@ void callbackDispatcher() { if (autoDownloadNetwork == 1) { List episodes = await dbHelper.getNewEpisodes('all'); // For safety - if (episodes.length < 100 && episodes.length > 0) + if (episodes.length < 100 && episodes.length > 0) { + downloader.bindBackgroundIsolate(); await downloader.startTask(episodes); + } } else if (result == ConnectivityResult.wifi) { List episodes = await dbHelper.getNewEpisodes('all'); //For safety - if (episodes.length < 100 && episodes.length > 0) + if (episodes.length < 100 && episodes.length > 0) { + downloader.bindBackgroundIsolate(); await downloader.startTask(episodes); + } } await lastWorkStorage.saveInt(1); KeyValueStorage refreshstorage = KeyValueStorage(refreshdateKey); @@ -149,6 +152,7 @@ class SettingState extends ChangeNotifier { notifyListeners(); } + int _initialShowIntor; bool _showIntro; bool get showIntro => _showIntro; @@ -163,13 +167,18 @@ class SettingState extends ChangeNotifier { @override void addListener(VoidCallback listener) { super.addListener(listener); - _getTheme(); - _getAccentSetColor(); _getAutoUpdate(); - _getRealDark(); _getDownloadUsingData(); - _getUpdateInterval().then((value) { - if (_initUpdateTag == 0) setWorkManager(24); + _getUpdateInterval().then((value) async { + if (_initUpdateTag == 0) + setWorkManager(24); + //Restart worker if anythin changed in worker callback. + //varsion 2 add auto download new episodes + else if (_autoUpdate && _initialShowIntor == 1) { + await cancelWork(); + setWorkManager(_initUpdateTag); + await saveShowIntro(2); + } }); } @@ -225,12 +234,12 @@ class SettingState extends ChangeNotifier { } Future _getShowIntro() async { - int i = await introStorage.getInt(); - _showIntro = i == 0 ? true : false; + _initialShowIntor = await introStorage.getInt(); + _showIntro = _initialShowIntor == 0 ? true : false; } - Future saveShowIntro() async { - await introStorage.saveInt(1); + Future saveShowIntro(int i) async { + await introStorage.saveInt(i); } Future _getRealDark() async { diff --git a/lib/type/episodebrief.dart b/lib/type/episodebrief.dart index f404d02..704ab32 100644 --- a/lib/type/episodebrief.dart +++ b/lib/type/episodebrief.dart @@ -83,11 +83,11 @@ class EpisodeBrief { } @override - bool operator ==(Object episode) => + bool operator == (Object episode) => episode is EpisodeBrief && episode.title == title && episode.enclosureUrl == enclosureUrl; @override - int get hashCode => enclosureUrl.hashCode; + int get hashCode => enclosureUrl.hashCode + title.hashCode; } diff --git a/lib/util/episodegrid.dart b/lib/util/episodegrid.dart index 9bc004d..b51e698 100644 --- a/lib/util/episodegrid.dart +++ b/lib/util/episodegrid.dart @@ -489,9 +489,9 @@ class EpisodeGrid extends StatelessWidget { // _listenIndicater(context, // episode: episodes[index], // isListened: snapshot.data), + _isNewIndicator(episodes[index]), _downloadIndicater(context, episode: episodes[index]), - _isNewIndicator(episodes[index]), _numberIndicater(context, index: index, color: _c) ],