Better dart code.

This commit is contained in:
stonegate 2020-07-13 20:04:44 +08:00
parent 6d755c5d92
commit 21fc7e027b
10 changed files with 58 additions and 29 deletions

View File

@ -63,7 +63,7 @@ class MessageLookup extends MessageLookupByLibrary {
static m21(date) => "Removed at ${date}";
static m22(count) => "${Intl.plural(count, zero: '', one: '${count} second ago', other: '${count} seconds ago')}";
static m22(count) => "${Intl.plural(count, zero: 'Just now', one: '${count} second ago', other: '${count} seconds ago')}";
static m23(time) => "Last time ${time}";
@ -146,9 +146,9 @@ class MessageLookup extends MessageLookupByLibrary {
"hostedOn" : m7,
"hoursAgo" : m8,
"hoursCount" : m9,
"introFourthPage" : MessageLookupByLibrary.simpleMessage("Long press on episode card for quick actions."),
"introFourthPage" : MessageLookupByLibrary.simpleMessage("You can long press on episode card for quick actions."),
"introSecondPage" : MessageLookupByLibrary.simpleMessage("Subscribe podcast via search or import OMPL file."),
"introThirdPage" : MessageLookupByLibrary.simpleMessage("You can create new group for podcasts, swipe on podcast list to change group."),
"introThirdPage" : MessageLookupByLibrary.simpleMessage("You can create new group for podcasts."),
"later" : MessageLookupByLibrary.simpleMessage("Later"),
"lightMode" : MessageLookupByLibrary.simpleMessage("Light mode"),
"like" : MessageLookupByLibrary.simpleMessage("Like"),

View File

@ -63,7 +63,7 @@ class MessageLookup extends MessageLookupByLibrary {
static m21(date) => "${date}移除";
static m22(count) => "${Intl.plural(count, zero: '', other: '${count}秒前')}";
static m22(count) => "${Intl.plural(count, zero: '刚刚', other: '${count}秒前')}";
static m23(time) => "上次播放${time}";
@ -146,7 +146,7 @@ class MessageLookup extends MessageLookupByLibrary {
"hostedOn" : m7,
"hoursAgo" : m8,
"hoursCount" : m9,
"introFourthPage" : MessageLookupByLibrary.simpleMessage("长按节目打开快捷菜单。"),
"introFourthPage" : MessageLookupByLibrary.simpleMessage("您可以长按节目打开快捷菜单。"),
"introSecondPage" : MessageLookupByLibrary.simpleMessage("您可以通过搜索订阅播客也可以直接导入OMPL文件。"),
"introThirdPage" : MessageLookupByLibrary.simpleMessage("您可以创建分组,上下滑动切换分组。"),
"later" : MessageLookupByLibrary.simpleMessage("稍后"),

View File

@ -747,10 +747,10 @@ class S {
);
}
/// `Long press on episode card for quick actions.`
/// `You can long press on episode card for quick actions.`
String get introFourthPage {
return Intl.message(
'Long press on episode card for quick actions.',
'You can long press on episode card for quick actions.',
name: 'introFourthPage',
desc: '',
args: [],
@ -767,10 +767,10 @@ class S {
);
}
/// `You can create new group for podcasts, swipe on podcast list to change group.`
/// `You can create new group for podcasts.`
String get introThirdPage {
return Intl.message(
'You can create new group for podcasts, swipe on podcast list to change group.',
'You can create new group for podcasts.',
name: 'introThirdPage',
desc: '',
args: [],
@ -1346,11 +1346,11 @@ class S {
);
}
/// `{count, plural, zero{} one{{count} second ago} other{{count} seconds ago}}`
/// `{count, plural, zero{Just now} one{{count} second ago} other{{count} seconds ago}}`
String secondsAgo(num count) {
return Intl.plural(
count,
zero: '',
zero: 'Just now',
one: '$count second ago',
other: '$count seconds ago',
name: 'secondsAgo',

View File

@ -6,6 +6,7 @@ import 'package:provider/provider.dart';
import 'package:tsacdop/local_storage/key_value_storage.dart';
import 'package:tsacdop/service/ompl_build.dart';
import 'package:tsacdop/webfeed/webfeed.dart';
import 'package:xml/xml.dart' as xml;
import 'package:file_picker/file_picker.dart';
import 'package:flutter/services.dart';
@ -73,13 +74,13 @@ class _PopupMenuState extends State<PopupMenu> {
File file = File(path);
try {
Map data = PodcastsBackup.parseOMPL(file);
data.forEach((title, total) async {
for (int i = 0; i < total.length; i++) {
if (total[i].xmlUrl != null) {
SubscribeItem item = SubscribeItem(total[i].xmlUrl, total[i].text);
data.forEach((title, list) async {
for (var rss in list) {
if (rss.xmlUrl != null) {
SubscribeItem item = SubscribeItem(rss.xmlUrl, rss.text);
await subscribeWorker.setSubscribeItem(item);
await Future.delayed(Duration(milliseconds: 500));
print(total[i].text);
print(rss.text);
}
}
});

View File

@ -156,11 +156,11 @@
"@hoursAgo": {},
"hoursCount": "{count, plural, zero{0 hour} one{{count} hour} other{{count} hours}}",
"@hoursCount": {},
"introFourthPage": "Long press on episode card for quick actions.",
"introFourthPage": "You can long press on episode card for quick actions.",
"@introFourthPage": {},
"introSecondPage": "Subscribe podcast via search or import OMPL file.",
"@introSecondPage": {},
"introThirdPage": "You can create new group for podcasts, swipe on podcast list to change group.",
"introThirdPage": "You can create new group for podcasts.",
"@introThirdPage": {},
"later": "Later",
"@later": {},
@ -313,7 +313,7 @@
"@searchInvalidRss": {},
"searchPodcast": "Search podcast",
"@searchPodcast": {},
"secondsAgo": "{count, plural, zero{} one{{count} second ago} other{{count} seconds ago}}",
"secondsAgo": "{count, plural, zero{Just now} one{{count} second ago} other{{count} seconds ago}}",
"@secondsAgo": {},
"settingsAccentColor": "Accent color",
"@settingsAccentColor": {},

View File

@ -156,7 +156,7 @@
"@hoursAgo": {},
"hoursCount": "{count, plural, zero{0小时} other{{count} 小时}}",
"@hoursCount": {},
"introFourthPage": "长按节目打开快捷菜单。",
"introFourthPage": "您可以长按节目打开快捷菜单。",
"@introFourthPage": {},
"introSecondPage": "您可以通过搜索订阅播客也可以直接导入OMPL文件。",
"@introSecondPage": {},
@ -313,7 +313,7 @@
"@searchInvalidRss": {},
"searchPodcast": "搜索播客",
"@searchPodcast": {},
"secondsAgo": "{count, plural, zero{} other{{count}秒前}}",
"secondsAgo": "{count, plural, zero{刚刚} other{{count}秒前}}",
"@secondsAgo": {},
"settingsAccentColor": "次要颜色",
"@settingsAccentColor": {},

View File

@ -7,6 +7,7 @@ import '../settings/downloads_manage.dart';
import '../state/setting_state.dart';
import '../local_storage/key_value_storage.dart';
import '../util/context_extension.dart';
import '../util/custom_dropdown.dart';
class StorageSetting extends StatefulWidget {
@override
@ -211,7 +212,7 @@ class _StorageSettingState extends State<StorageSetting>
EdgeInsets.only(left: 80.0, right: 20),
title: Text(s.settingsAutoDelete),
subtitle: Text(s.settingsAutoDeleteDes),
trailing: DropdownButton(
trailing: MyDropdownButton(
hint: snapshot.data == -1
? Text(s.daysCount(0))
: Text(s.daysCount(snapshot.data)),

View File

@ -54,7 +54,10 @@ class PodcastGroup {
}
}
///Podcast in group.
List<PodcastLocal> _podcasts;
///Ordered podcast list.
List<PodcastLocal> _orderedPodcasts;
List<PodcastLocal> get ordereddPodcasts => _orderedPodcasts;
List<PodcastLocal> get podcasts => _podcasts;

View File

@ -1,5 +1,6 @@
import 'dart:io';
import 'dart:isolate';
import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';
@ -11,17 +12,29 @@ import 'package:flutter_isolate/flutter_isolate.dart';
import '../webfeed/webfeed.dart';
import '../local_storage/sqflite_localpodcast.dart';
import '../local_storage/key_value_storage.dart';
import '../type/fireside_data.dart';
import '../type/podcastlocal.dart';
import 'podcast_group.dart';
enum SubscribeState { none, start, subscribe, fetch, stop, exist, error }
class SubscribeItem {
///Rss url.
String url;
///Rss title.
String title;
SubscribeState subscribeState;
///Uuid for podcast.
String id;
///Avatat image link.
String imgUrl;
///Podcast group, default Home.
String group;
SubscribeItem(this.url, this.title,
{this.subscribeState = SubscribeState.none,
@ -84,8 +97,12 @@ class SubscribeWorker extends ChangeNotifier {
_created = true;
listen();
} else
subSendPort.send(
[_subscribeItem.url, _subscribeItem.title, _subscribeItem.imgUrl]);
subSendPort.send([
_subscribeItem.url,
_subscribeItem.title,
_subscribeItem.imgUrl,
_subscribeItem.group
]);
}
void dispose() {
@ -98,6 +115,12 @@ class SubscribeWorker extends ChangeNotifier {
Future<void> subIsolateEntryPoint(SendPort sendPort) async {
List<SubscribeItem> items = [];
bool _running = false;
final List<String> listColor = [
'388E3C',
'1976D2'
'D32F2F',
'00796B',
];
ReceivePort subReceivePort = ReceivePort();
sendPort.send(subReceivePort.sendPort);
@ -130,7 +153,7 @@ Future<void> subIsolateEntryPoint(SendPort sendPort) async {
await Future.delayed(Duration(seconds: 2));
sendPort.send([item.title, item.url, 4]);
items.removeWhere((element) => element.url == item.url);
if (items.length > 0) {
if (items.isNotEmpty) {
await _subscribe(items.first);
} else
sendPort.send("done");
@ -164,11 +187,13 @@ Future<void> subIsolateEntryPoint(SendPort sendPort) async {
} catch (e) {
print(e);
try {
int index = math.Random().nextInt(3);
Response<List<int>> imageResponse = await Dio().get<List<int>>(
"https://ui-avatars.com/api/?size=300&background=4D91BE&color=fff&name=${item.title}&length=2&bold=true",
"https://ui-avatars.com/api/?size=300&background="
"${listColor[index]}&color=fff&name=${item.title}&length=2&bold=true",
options: Options(responseType: ResponseType.bytes));
imageUrl =
"https://ui-avatars.com/api/?size=300&background=4D91BE&color=fff&name=${item.title}&length=2&bold=true";
imageUrl = "https://ui-avatars.com/api/?size=300&background="
"${listColor[index]}&color=fff&name=${item.title}&length=2&bold=true";
thumbnail = img.decodeImage(imageResponse.data);
} catch (e) {
print(e);

View File

@ -35,7 +35,6 @@ class FiresideData {
.toString());
var ul = doc.body.getElementsByClassName('episode-hosts').first.children;
List<PodcastHost> hosts = [];
for (var element in ul) {
PodcastHost host;
String name = element.text.trim();