Support settings backuo.
This commit is contained in:
parent
98fd594eb5
commit
f47758b104
|
@ -350,8 +350,8 @@ class _SearchResultState extends State<SearchResult>
|
|||
var subscribeWorker = Provider.of<GroupList>(context, listen: false);
|
||||
final s = context.s;
|
||||
savePodcast(OnlinePodcast podcast) {
|
||||
SubscribeItem item =
|
||||
SubscribeItem(podcast.rss, podcast.title, imgUrl: podcast.image);
|
||||
SubscribeItem item = SubscribeItem(podcast.rss, podcast.title,
|
||||
imgUrl: podcast.image, group: 'Home');
|
||||
subscribeWorker.setSubscribeItem(item);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ import '../util/custompaint.dart';
|
|||
import '../state/download_state.dart';
|
||||
import '../state/podcast_group.dart';
|
||||
import 'playlist.dart';
|
||||
import 'importompl.dart';
|
||||
import 'import_ompl.dart';
|
||||
import 'audioplayer.dart';
|
||||
import 'addpodcast.dart';
|
||||
import 'popupmenu.dart';
|
||||
|
|
|
@ -7,7 +7,6 @@ import 'package:provider/provider.dart';
|
|||
import 'package:tsacdop/local_storage/key_value_storage.dart';
|
||||
import 'package:tsacdop/service/ompl_build.dart';
|
||||
import 'package:tsacdop/state/podcast_group.dart';
|
||||
import 'package:xml/xml.dart' as xml;
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
|
@ -67,7 +66,7 @@ class _PopupMenuState extends State<PopupMenu> {
|
|||
SubscribeItem item =
|
||||
SubscribeItem(rss.xmlUrl, rss.text, group: title);
|
||||
await subscribeWorker.setSubscribeItem(item);
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
await Future.delayed(Duration(milliseconds: 500));
|
||||
print(rss.text);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import 'package:shared_preferences/shared_preferences.dart';
|
|||
import '../state/podcast_group.dart';
|
||||
|
||||
const String autoPlayKey = 'autoPlay';
|
||||
//const String autoAddKey = 'autoAdd';
|
||||
const String audioPositionKey = 'audioposition';
|
||||
const String lastWorkKey = 'lastWork';
|
||||
const String refreshdateKey = 'refreshdate';
|
||||
|
|
|
@ -10,6 +10,7 @@ import '../local_storage/sqflite_localpodcast.dart';
|
|||
import '../local_storage/key_value_storage.dart';
|
||||
import '../type/podcastlocal.dart';
|
||||
import '../type/episodebrief.dart';
|
||||
import '../type/settings_backup.dart';
|
||||
import 'download_state.dart';
|
||||
|
||||
void callbackDispatcher() {
|
||||
|
@ -25,7 +26,6 @@ void callbackDispatcher() {
|
|||
await dbHelper.updatePodcastRss(podcastLocal, removeMark: lastWork);
|
||||
print('Refresh ' + podcastLocal.title);
|
||||
}
|
||||
;
|
||||
await FlutterDownloader.initialize();
|
||||
AutoDownloader downloader = AutoDownloader();
|
||||
|
||||
|
@ -97,6 +97,13 @@ class SettingState extends ChangeNotifier {
|
|||
KeyValueStorage(autoSleepTimerEndKey);
|
||||
KeyValueStorage tapToOpenPopupMenuStorage =
|
||||
KeyValueStorage(tapToOpenPopupMenuKey);
|
||||
KeyValueStorage cacheStorage = KeyValueStorage(cacheMaxKey);
|
||||
KeyValueStorage podcastLayoutStorage = KeyValueStorage(podcastLayoutKey);
|
||||
KeyValueStorage favLayoutStorage = KeyValueStorage(favLayoutKey);
|
||||
KeyValueStorage downloadLayoutStorage = KeyValueStorage(downloadLayoutKey);
|
||||
KeyValueStorage recentLayoutStorage = KeyValueStorage(recentLayoutKey);
|
||||
KeyValueStorage autoDeleteStorage = KeyValueStorage(autoDeleteKey);
|
||||
KeyValueStorage autoDownloadStorage = KeyValueStorage(autoDownloadNetworkKey);
|
||||
|
||||
Future initData() async {
|
||||
await _getTheme();
|
||||
|
@ -249,10 +256,6 @@ class SettingState extends ChangeNotifier {
|
|||
_theme = ThemeMode.values[mode];
|
||||
}
|
||||
|
||||
Future _saveTheme() async {
|
||||
await themeStorage.saveInt(_theme.index);
|
||||
}
|
||||
|
||||
Future _getAccentSetColor() async {
|
||||
String colorString = await accentStorage.getString();
|
||||
if (colorString.isNotEmpty) {
|
||||
|
@ -263,29 +266,16 @@ class SettingState extends ChangeNotifier {
|
|||
}
|
||||
}
|
||||
|
||||
Future _saveAccentSetColor() async {
|
||||
await accentStorage
|
||||
.saveString(_accentSetColor.toString().substring(10, 16));
|
||||
}
|
||||
|
||||
Future _getAutoUpdate() async {
|
||||
int i = await autoupdateStorage.getInt();
|
||||
_autoUpdate = i == 0 ? true : false;
|
||||
}
|
||||
|
||||
Future _saveAutoUpdate() async {
|
||||
await autoupdateStorage.saveInt(_autoUpdate ? 0 : 1);
|
||||
}
|
||||
|
||||
Future _getUpdateInterval() async {
|
||||
_initUpdateTag = await intervalStorage.getInt();
|
||||
_updateInterval = _initUpdateTag;
|
||||
}
|
||||
|
||||
Future _saveUpdateInterval() async {
|
||||
await intervalStorage.saveInt(_updateInterval);
|
||||
}
|
||||
|
||||
Future _getDownloadUsingData() async {
|
||||
int i = await downloadUsingDataStorage.getInt();
|
||||
_downloadUsingData = i == 0 ? true : false;
|
||||
|
@ -300,19 +290,11 @@ class SettingState extends ChangeNotifier {
|
|||
_showIntro = _initialShowIntor == 0 ? true : false;
|
||||
}
|
||||
|
||||
Future saveShowIntro(int i) async {
|
||||
await introStorage.saveInt(i);
|
||||
}
|
||||
|
||||
Future _getRealDark() async {
|
||||
int i = await realDarkStorage.getInt();
|
||||
_realDark = i == 0 ? false : true;
|
||||
}
|
||||
|
||||
Future _setRealDark() async {
|
||||
await realDarkStorage.saveInt(_realDark ? 1 : 0);
|
||||
}
|
||||
|
||||
Future _getSleepTimerData() async {
|
||||
_defaultSleepTimer =
|
||||
await defaultSleepTimerStorage.getInt(defaultValue: 30);
|
||||
|
@ -327,6 +309,31 @@ class SettingState extends ChangeNotifier {
|
|||
_autoSleepTimerMode = await autoSleepTimerModeStorage.getInt();
|
||||
}
|
||||
|
||||
Future _saveAccentSetColor() async {
|
||||
await accentStorage
|
||||
.saveString(_accentSetColor.toString().substring(10, 16));
|
||||
}
|
||||
|
||||
Future _setRealDark() async {
|
||||
await realDarkStorage.saveInt(_realDark ? 1 : 0);
|
||||
}
|
||||
|
||||
Future saveShowIntro(int i) async {
|
||||
await introStorage.saveInt(i);
|
||||
}
|
||||
|
||||
Future _saveUpdateInterval() async {
|
||||
await intervalStorage.saveInt(_updateInterval);
|
||||
}
|
||||
|
||||
Future _saveTheme() async {
|
||||
await themeStorage.saveInt(_theme.index);
|
||||
}
|
||||
|
||||
Future _saveAutoUpdate() async {
|
||||
await autoupdateStorage.saveInt(_autoUpdate ? 0 : 1);
|
||||
}
|
||||
|
||||
Future _saveAutoPlay() async {
|
||||
await autoPlayStorage.saveInt(_autoPlay ? 0 : 1);
|
||||
}
|
||||
|
@ -350,4 +357,53 @@ class SettingState extends ChangeNotifier {
|
|||
Future _saveAutoSleepTimerEnd() async {
|
||||
await autoSleepTimerEndStorage.saveInt(_autoSleepTimerEnd);
|
||||
}
|
||||
|
||||
Future<SettingsBackup> backup() async {
|
||||
int theme = await themeStorage.getInt();
|
||||
String accentColor = await accentStorage.getString();
|
||||
int realDark = await realDarkStorage.getInt();
|
||||
int autoPlay = await autoPlayStorage.getInt();
|
||||
int autoUpdate = await autoupdateStorage.getInt();
|
||||
int updateInterval = await intervalStorage.getInt();
|
||||
int downloadUsingData = await downloadUsingDataStorage.getInt();
|
||||
int cacheMax = await cacheStorage.getInt();
|
||||
int podcastLayout = await podcastLayoutStorage.getInt();
|
||||
int recentLayout = await recentLayoutStorage.getInt();
|
||||
int favLayout = await favLayoutStorage.getInt();
|
||||
int downloadLayout = await downloadLayoutStorage.getInt();
|
||||
int autoDownloadNetwork = await autoDownloadStorage.getInt();
|
||||
List<String> episodePopupMenu =
|
||||
await KeyValueStorage(episodePopupMenuKey).getStringList();
|
||||
int autoDelete = await autoDeleteStorage.getInt();
|
||||
int autoSleepTimer = await autoSleepTimerStorage.getInt();
|
||||
int autoSleepTimerStart = await autoSleepTimerStartStorage.getInt();
|
||||
int autoSleepTimerEnd = await autoSleepTimerEndStorage.getInt();
|
||||
int autoSleepTimerMode = await autoSleepTimerModeStorage.getInt();
|
||||
int defaultSleepTime = await defaultSleepTimerStorage.getInt();
|
||||
int tapToOpenPopupMenu =
|
||||
await KeyValueStorage(tapToOpenPopupMenuKey).getInt(defaultValue: 0);
|
||||
|
||||
return SettingsBackup(
|
||||
theme: theme,
|
||||
accentColor: accentColor,
|
||||
realDark: realDark,
|
||||
autoPlay: autoPlay,
|
||||
autoUpdate: autoUpdate,
|
||||
updateInterval: updateInterval,
|
||||
downloadUsingData: downloadUsingData,
|
||||
cacheMax: cacheMax,
|
||||
podcastLayout: podcastLayout,
|
||||
recentLayout: recentLayout,
|
||||
favLayout: favLayout,
|
||||
downloadLayout: downloadLayout,
|
||||
autoDownloadNetwork: autoDownloadNetwork,
|
||||
episodePopupMenu: episodePopupMenu,
|
||||
autoDelete: autoDelete,
|
||||
autoSleepTimer: autoSleepTimer,
|
||||
autoSleepTimerStart: autoSleepTimerStart,
|
||||
autoSleepTimerEnd: autoSleepTimerEnd,
|
||||
autoSleepTimerMode: autoSleepTimerMode,
|
||||
defaultSleepTime: defaultSleepTime,
|
||||
tapToOpenPopupMenu: tapToOpenPopupMenu);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
class SettingsBackup {
|
||||
final int theme;
|
||||
final String accentColor;
|
||||
final int realDark;
|
||||
final int autoPlay;
|
||||
final int autoUpdate;
|
||||
final int updateInterval;
|
||||
final int downloadUsingData;
|
||||
final int cacheMax;
|
||||
final int podcastLayout;
|
||||
final int recentLayout;
|
||||
final int favLayout;
|
||||
final int downloadLayout;
|
||||
final int autoDownloadNetwork;
|
||||
final List<String> episodePopupMenu;
|
||||
final int autoDelete;
|
||||
final int autoSleepTimer;
|
||||
final int autoSleepTimerStart;
|
||||
final int autoSleepTimerEnd;
|
||||
final int defaultSleepTime;
|
||||
final int autoSleepTimerMode;
|
||||
final int tapToOpenPopupMenu;
|
||||
SettingsBackup(
|
||||
{this.theme,
|
||||
this.accentColor,
|
||||
this.realDark,
|
||||
this.autoPlay,
|
||||
this.autoUpdate,
|
||||
this.updateInterval,
|
||||
this.downloadUsingData,
|
||||
this.cacheMax,
|
||||
this.podcastLayout,
|
||||
this.recentLayout,
|
||||
this.favLayout,
|
||||
this.downloadLayout,
|
||||
this.autoDownloadNetwork,
|
||||
this.episodePopupMenu,
|
||||
this.autoDelete,
|
||||
this.autoSleepTimer,
|
||||
this.autoSleepTimerStart,
|
||||
this.autoSleepTimerEnd,
|
||||
this.defaultSleepTime,
|
||||
this.autoSleepTimerMode,
|
||||
this.tapToOpenPopupMenu});
|
||||
|
||||
Map<String, Object> toJson() {
|
||||
return {
|
||||
'theme': theme,
|
||||
'accentColor': accentColor,
|
||||
'realDark': realDark,
|
||||
'autoPlay': autoPlay,
|
||||
'autoUpdate': autoUpdate,
|
||||
'updateInterval': updateInterval,
|
||||
'downloadUsingData': downloadUsingData,
|
||||
'cacheMax': cacheMax,
|
||||
'podcastLayout': podcastLayout,
|
||||
'recentLayout': recentLayout,
|
||||
'favLayout': favLayout,
|
||||
'downloadLayout': downloadLayout,
|
||||
'autoDownloadNetwork': autoDownloadNetwork,
|
||||
'episodePopupMenu': episodePopupMenu,
|
||||
'autoDelete': autoDelete,
|
||||
'autoSleepTimer': autoSleepTimer,
|
||||
'autoSleepTimerStart': autoSleepTimerStart,
|
||||
'autoSleepTimerEnd': autoSleepTimerEnd,
|
||||
'autoSleepTimerMode': autoSleepTimerMode,
|
||||
'tapToOpenPopupMenu': tapToOpenPopupMenu
|
||||
};
|
||||
}
|
||||
|
||||
static SettingsBackup fromJson(Map<String, Object> json) {
|
||||
List<String> list = List.from(json['episodePopupMenu']);
|
||||
return SettingsBackup(
|
||||
theme: json['theme'] as int,
|
||||
accentColor: json['accentColor'] as String,
|
||||
realDark: json['realDark'] as int,
|
||||
autoPlay: json['autoPlay'] as int,
|
||||
autoUpdate: json['autoUpdate'] as int,
|
||||
updateInterval: json['updateInterval'] as int,
|
||||
downloadUsingData: json['downloadUsingData'] as int,
|
||||
cacheMax: json['cacheMax'] as int,
|
||||
podcastLayout: json['podcastLayout'] as int,
|
||||
recentLayout: json['recentLayout'] as int,
|
||||
favLayout: json['favLayout'] as int,
|
||||
downloadLayout: json['downloadLayout'] as int,
|
||||
autoDownloadNetwork: json['autoDownloadNetwork'] as int,
|
||||
episodePopupMenu: list,
|
||||
autoDelete: json['autoDelete'] as int,
|
||||
autoSleepTimer: json['autoSleepTimer'] as int,
|
||||
autoSleepTimerStart: json['autoSleepeTimerStart'] as int,
|
||||
autoSleepTimerEnd: json['autoSleepTimerEnd'] as int,
|
||||
autoSleepTimerMode: json['autoSleepTimerMode'] as int,
|
||||
tapToOpenPopupMenu: json['tapToOpenPopupMenu'] as int);
|
||||
}
|
||||
}
|
|
@ -1,8 +1,18 @@
|
|||
class SubHistory {
|
||||
/// POdcast subscribe date.
|
||||
DateTime subDate;
|
||||
|
||||
/// Podcast remove date.
|
||||
DateTime delDate;
|
||||
|
||||
/// If podcast still on user device.
|
||||
bool status;
|
||||
|
||||
/// POdcast title.
|
||||
String title;
|
||||
|
||||
/// POdcast rss link.
|
||||
String rssUrl;
|
||||
|
||||
SubHistory(this.status, this.delDate, this.subDate, this.rssUrl, this.title);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue