OMPL export supprt groups.

This commit is contained in:
stonegate 2020-07-12 20:54:14 +08:00
parent 1710e5da77
commit 1de2e5311e
4 changed files with 46 additions and 35 deletions

View File

@ -0,0 +1,38 @@
import 'package:xml/xml.dart' as xml;
import '../state/podcast_group.dart';
class PodcastsBackup {
///Group list for backup.
final List<PodcastGroup> groups;
PodcastsBackup(this.groups) : assert(groups.length > 0);
omplBuilder() async {
var builder = xml.XmlBuilder();
builder.processing('xml', 'version="1.0" encoding="UTF-8"');
builder.element('ompl', nest: () {
builder.attribute('version', '1.0');
builder.element('head', nest: () {
builder.element('title', nest: 'Tsacdop Feeds');
});
builder.element('body', nest: () {
builder.element('outline', nest: () {
groups.forEach((group) {
builder.attribute('text', '${group.name}');
builder.attribute('title', '${group.name}');
group.podcasts.forEach((e) => builder.element(
'outline',
nest: () {
builder.attribute('type', 'rss');
builder.attribute('text', '${e.title}');
builder.attribute('title', '${e.title}');
builder.attribute('xmlUrl', '${e.rssUrl}');
},
isSelfClosing: true,
));
});
});
});
});
return builder.build();
}
}

1
lib/settings/backup.dart Normal file
View File

@ -0,0 +1 @@
import 'package:flutter/material.dart';

View File

@ -5,13 +5,15 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:path/path.dart';
import 'package:line_icons/line_icons.dart';
import 'package:tsacdop/state/podcast_group.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:path_provider/path_provider.dart';
import 'package:flutter_file_dialog/flutter_file_dialog.dart';
import 'package:feature_discovery/feature_discovery.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:provider/provider.dart';
import '../util/ompl_build.dart';
import '../service/ompl_build.dart';
import '../util/context_extension.dart';
import '../intro_slider/app_intro.dart';
import '../type/podcastlocal.dart';
@ -42,13 +44,11 @@ class _SettingsState extends State<Settings>
}
}
_exportOmpl() async {
var dbHelper = DBHelper();
List<PodcastLocal> podcastList = await dbHelper.getPodcastLocalAll();
var ompl = omplBuilder(podcastList.reversed.toList());
_exportOmpl(BuildContext context) async {
var groups = context.read<GroupList>().groups;
var ompl = PodcastsBackup(groups).omplBuilder();
var tempdir = await getTemporaryDirectory();
var file = File(join(tempdir.path, 'tsacdop_ompl.xml'));
print(file.path);
await file.writeAsString(ompl.toString());
final params = SaveFileDialogParams(sourceFilePath: file.path);
final filePath = await FlutterFileDialog.saveFile(params: params);
@ -239,7 +239,7 @@ class _SettingsState extends State<Settings>
Divider(height: 2),
ListTile(
onTap: () {
_exportOmpl();
_exportOmpl(context);
},
contentPadding:
EdgeInsets.symmetric(horizontal: 25.0),

View File

@ -1,28 +0,0 @@
import 'package:xml/xml.dart' as xml;
import '../type/podcastlocal.dart';
omplBuilder(List<PodcastLocal> podcasts) {
var builder = xml.XmlBuilder();
builder.processing('xml', 'version="1.0"');
builder.element('ompl', nest: () {
builder.attribute('version', '1.0');
builder.element('head', nest: () {
builder.element('title', nest: 'Tsacdop Feeds');
});
builder.element('body', nest: () {
builder.element('outline', nest: () {
builder.attribute('text', 'feed');
podcasts.forEach((e) => builder.element(
'outline',
nest: () {
builder.attribute('type', 'rss');
builder.attribute('text', '${e.title}');
builder.attribute('xmlUrl', '${e.rssUrl}');
},
isSelfClosing: true,
));
});
});
});
return builder.build();
}