mirror of
https://github.com/stonega/tsacdop
synced 2025-02-16 11:31:45 +01:00
Change download position.
This commit is contained in:
parent
88ce52dcae
commit
05d5b76ca6
@ -56,6 +56,7 @@ const String gpodderRemoteRemoveKey = 'gpodderRemoteRemoveKey';
|
|||||||
const String hidePodcastDiscoveryKey = 'hidePodcastDiscoveryKey';
|
const String hidePodcastDiscoveryKey = 'hidePodcastDiscoveryKey';
|
||||||
const String searchEngineKey = 'searchEngineKey';
|
const String searchEngineKey = 'searchEngineKey';
|
||||||
const String markListenedAfterSkipKey = 'markListenedAfterSkipKey';
|
const String markListenedAfterSkipKey = 'markListenedAfterSkipKey';
|
||||||
|
const String downloadPositionKey = 'downloadPositionKey';
|
||||||
|
|
||||||
class KeyValueStorage {
|
class KeyValueStorage {
|
||||||
final String key;
|
final String key;
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:google_fonts/google_fonts.dart';
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:tsacdop/util/general_dialog.dart';
|
||||||
|
|
||||||
import '../local_storage/key_value_storage.dart';
|
import '../local_storage/key_value_storage.dart';
|
||||||
import '../settings/downloads_manage.dart';
|
import '../settings/downloads_manage.dart';
|
||||||
@ -20,7 +22,8 @@ class _StorageSettingState extends State<StorageSetting>
|
|||||||
final KeyValueStorage cacheStorage = KeyValueStorage(cacheMaxKey);
|
final KeyValueStorage cacheStorage = KeyValueStorage(cacheMaxKey);
|
||||||
AnimationController _controller;
|
AnimationController _controller;
|
||||||
Animation<double> _animation;
|
Animation<double> _animation;
|
||||||
_getCacheMax() async {
|
List<String> _dirs;
|
||||||
|
Future<void> _getCacheMax() async {
|
||||||
var cache =
|
var cache =
|
||||||
await cacheStorage.getInt(defaultValue: (200 * 1024 * 1024).toInt());
|
await cacheStorage.getInt(defaultValue: (200 * 1024 * 1024).toInt());
|
||||||
if (cache == 0) {
|
if (cache == 0) {
|
||||||
@ -56,17 +59,30 @@ class _StorageSettingState extends State<StorageSetting>
|
|||||||
return days;
|
return days;
|
||||||
}
|
}
|
||||||
|
|
||||||
_setAutoDeleteDays(int days) async {
|
Future<int> _getDownloadPasition() async {
|
||||||
|
final storage = KeyValueStorage(downloadPositionKey);
|
||||||
|
final index = await storage.getInt();
|
||||||
|
final externalDirs = await getExternalStorageDirectories();
|
||||||
|
_dirs = [for (var dir in externalDirs) dir.path];
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _setAutoDeleteDays(int days) async {
|
||||||
var storage = KeyValueStorage(autoDeleteKey);
|
var storage = KeyValueStorage(autoDeleteKey);
|
||||||
await storage.saveInt(days);
|
await storage.saveInt(days);
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
|
|
||||||
_setAudtDownloadNetwork(bool boo) async {
|
Future<void> _setAudtDownloadNetwork(bool boo) async {
|
||||||
var storage = KeyValueStorage(autoDownloadNetworkKey);
|
var storage = KeyValueStorage(autoDownloadNetworkKey);
|
||||||
await storage.saveBool(boo);
|
await storage.saveBool(boo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _setDownloadPosition(int index) async {
|
||||||
|
final storage = KeyValueStorage(downloadPositionKey);
|
||||||
|
await storage.saveInt(index);
|
||||||
|
}
|
||||||
|
|
||||||
double _value;
|
double _value;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -102,10 +118,6 @@ class _StorageSettingState extends State<StorageSetting>
|
|||||||
),
|
),
|
||||||
body: SafeArea(
|
body: SafeArea(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: <Widget>[
|
|
||||||
Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
@ -117,16 +129,9 @@ class _StorageSettingState extends State<StorageSetting>
|
|||||||
padding: EdgeInsets.symmetric(horizontal: 70),
|
padding: EdgeInsets.symmetric(horizontal: 70),
|
||||||
alignment: Alignment.centerLeft,
|
alignment: Alignment.centerLeft,
|
||||||
child: Text(s.network,
|
child: Text(s.network,
|
||||||
style: Theme.of(context)
|
style: context.textTheme.bodyText1
|
||||||
.textTheme
|
.copyWith(color: context.accentColor)),
|
||||||
.bodyText1
|
|
||||||
.copyWith(color: Theme.of(context).accentColor)),
|
|
||||||
),
|
),
|
||||||
ListView(
|
|
||||||
physics: const BouncingScrollPhysics(),
|
|
||||||
shrinkWrap: true,
|
|
||||||
scrollDirection: Axis.vertical,
|
|
||||||
children: <Widget>[
|
|
||||||
Selector<SettingState, bool>(
|
Selector<SettingState, bool>(
|
||||||
selector: (_, settings) => settings.downloadUsingData,
|
selector: (_, settings) => settings.downloadUsingData,
|
||||||
builder: (_, data, __) {
|
builder: (_, data, __) {
|
||||||
@ -147,7 +152,6 @@ class _StorageSettingState extends State<StorageSetting>
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Divider(height: 1),
|
|
||||||
FutureBuilder<bool>(
|
FutureBuilder<bool>(
|
||||||
future: _getAutoDownloadNetwork(),
|
future: _getAutoDownloadNetwork(),
|
||||||
initialData: false,
|
initialData: false,
|
||||||
@ -160,8 +164,7 @@ class _StorageSettingState extends State<StorageSetting>
|
|||||||
contentPadding: EdgeInsets.only(
|
contentPadding: EdgeInsets.only(
|
||||||
left: 70.0, right: 25, bottom: 10, top: 10),
|
left: 70.0, right: 25, bottom: 10, top: 10),
|
||||||
title: Text(s.settingsNetworkCellularAuto),
|
title: Text(s.settingsNetworkCellularAuto),
|
||||||
subtitle:
|
subtitle: Text(s.settingsNetworkCellularAutoDes),
|
||||||
Text(s.settingsNetworkCellularAutoDes),
|
|
||||||
trailing: Transform.scale(
|
trailing: Transform.scale(
|
||||||
scale: 0.9,
|
scale: 0.9,
|
||||||
child: Switch(
|
child: Switch(
|
||||||
@ -175,13 +178,6 @@ class _StorageSettingState extends State<StorageSetting>
|
|||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
Divider(height: 1),
|
Divider(height: 1),
|
||||||
],
|
|
||||||
),
|
|
||||||
]),
|
|
||||||
Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: <Widget>[
|
|
||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.all(10.0),
|
padding: EdgeInsets.all(10.0),
|
||||||
),
|
),
|
||||||
@ -190,33 +186,55 @@ class _StorageSettingState extends State<StorageSetting>
|
|||||||
padding: EdgeInsets.symmetric(horizontal: 70),
|
padding: EdgeInsets.symmetric(horizontal: 70),
|
||||||
alignment: Alignment.centerLeft,
|
alignment: Alignment.centerLeft,
|
||||||
child: Text(s.settingStorage,
|
child: Text(s.settingStorage,
|
||||||
style: Theme.of(context)
|
style: context.textTheme.bodyText1
|
||||||
.textTheme
|
.copyWith(color: context.accentColor)),
|
||||||
.bodyText1
|
|
||||||
.copyWith(color: Theme.of(context).accentColor)),
|
|
||||||
),
|
),
|
||||||
ListView(
|
|
||||||
physics: const BouncingScrollPhysics(),
|
|
||||||
shrinkWrap: true,
|
|
||||||
scrollDirection: Axis.vertical,
|
|
||||||
children: <Widget>[
|
|
||||||
ListTile(
|
ListTile(
|
||||||
onTap: () => Navigator.push(
|
onTap: () => Navigator.push(context,
|
||||||
context,
|
MaterialPageRoute(builder: (context) => DownloadsManage())),
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) => DownloadsManage())),
|
|
||||||
contentPadding: EdgeInsets.symmetric(horizontal: 70.0),
|
contentPadding: EdgeInsets.symmetric(horizontal: 70.0),
|
||||||
title: Text(s.download),
|
title: Text(s.download),
|
||||||
subtitle: Text(s.settingsManageDownloadDes),
|
subtitle: Text(s.settingsManageDownloadDes),
|
||||||
),
|
),
|
||||||
Divider(height: 1),
|
FutureBuilder<int>(
|
||||||
|
future: _getDownloadPasition(),
|
||||||
|
initialData: 0,
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
return ListTile(
|
||||||
|
contentPadding: EdgeInsets.only(left: 70.0, right: 20),
|
||||||
|
title: Text('Donwload position'),
|
||||||
|
subtitle: Text(_dirs == null ? '' : _dirs[snapshot.data],
|
||||||
|
maxLines: 2, overflow: TextOverflow.ellipsis),
|
||||||
|
onTap: () => generalSheet(
|
||||||
|
context,
|
||||||
|
title: 'Download position',
|
||||||
|
child: Column(children: [
|
||||||
|
SizedBox(
|
||||||
|
height: 10,
|
||||||
|
),
|
||||||
|
for (var dir in _dirs)
|
||||||
|
ListTile(
|
||||||
|
title: Text(dir),
|
||||||
|
onTap: () =>
|
||||||
|
_setDownloadPosition(_dirs.indexOf(dir)),
|
||||||
|
trailing: Radio<int>(
|
||||||
|
value: _dirs.indexOf(dir),
|
||||||
|
groupValue: snapshot.data,
|
||||||
|
onChanged: _setDownloadPosition),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: 30,
|
||||||
|
)
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}),
|
||||||
FutureBuilder<int>(
|
FutureBuilder<int>(
|
||||||
future: _getAutoDeleteDays(),
|
future: _getAutoDeleteDays(),
|
||||||
initialData: 30,
|
initialData: 30,
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
contentPadding:
|
contentPadding: EdgeInsets.only(left: 70.0, right: 20),
|
||||||
EdgeInsets.only(left: 70.0, right: 20),
|
|
||||||
title: Text(s.settingsAutoDelete),
|
title: Text(s.settingsAutoDelete),
|
||||||
subtitle: Text(s.settingsAutoDeleteDes),
|
subtitle: Text(s.settingsAutoDeleteDes),
|
||||||
trailing: MyDropdownButton(
|
trailing: MyDropdownButton(
|
||||||
@ -240,7 +258,6 @@ class _StorageSettingState extends State<StorageSetting>
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Divider(height: 1),
|
|
||||||
ListTile(
|
ListTile(
|
||||||
contentPadding: EdgeInsets.only(left: 70.0, right: 25),
|
contentPadding: EdgeInsets.only(left: 70.0, right: 25),
|
||||||
// leading: Icon(Icons.colorize),
|
// leading: Icon(Icons.colorize),
|
||||||
@ -252,20 +269,16 @@ class _StorageSettingState extends State<StorageSetting>
|
|||||||
textStyle: context.textTheme.headline6
|
textStyle: context.textTheme.headline6
|
||||||
.copyWith(color: context.accentColor)),
|
.copyWith(color: context.accentColor)),
|
||||||
children: [
|
children: [
|
||||||
TextSpan(
|
TextSpan(text: ' Mb', style: context.textTheme.subtitle2),
|
||||||
text: ' Mb',
|
|
||||||
style: context.textTheme.subtitle2),
|
|
||||||
])),
|
])),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.only(
|
padding: EdgeInsets.only(left: 50.0, right: 20.0, bottom: 10.0),
|
||||||
left: 50.0, right: 20.0, bottom: 10.0),
|
|
||||||
child: SliderTheme(
|
child: SliderTheme(
|
||||||
data: Theme.of(context).sliderTheme.copyWith(
|
data: Theme.of(context).sliderTheme.copyWith(
|
||||||
showValueIndicator: ShowValueIndicator.always,
|
showValueIndicator: ShowValueIndicator.always,
|
||||||
trackHeight: 2,
|
trackHeight: 2,
|
||||||
thumbShape:
|
thumbShape: RoundSliderThumbShape(enabledThumbRadius: 6)),
|
||||||
RoundSliderThumbShape(enabledThumbRadius: 6)),
|
|
||||||
child: Slider(
|
child: Slider(
|
||||||
label: '${_value ~/ 100 * 100} Mb',
|
label: '${_value ~/ 100 * 100} Mb',
|
||||||
activeColor: context.accentColor,
|
activeColor: context.accentColor,
|
||||||
@ -278,20 +291,31 @@ class _StorageSettingState extends State<StorageSetting>
|
|||||||
setState(() {
|
setState(() {
|
||||||
_value = val;
|
_value = val;
|
||||||
});
|
});
|
||||||
cacheStorage
|
cacheStorage.saveInt((val * 1024 * 1024).toInt());
|
||||||
.saveInt((val * 1024 * 1024).toInt());
|
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Divider(height: 1),
|
Divider(height: 1),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _DownloadPosition extends StatefulWidget {
|
||||||
|
_DownloadPosition({Key key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
__DownloadPositionState createState() => __DownloadPositionState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class __DownloadPositionState extends State<_DownloadPosition> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Column(
|
||||||
|
children: [],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -73,6 +73,13 @@ class AutoDownloader {
|
|||||||
_completer?.complete();
|
_completer?.complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<Directory> _getDownloadDirectory() async {
|
||||||
|
final storage = KeyValueStorage(downloadPositionKey);
|
||||||
|
final index = await storage.getInt();
|
||||||
|
final externalDirs = await getExternalStorageDirectories();
|
||||||
|
return externalDirs[index];
|
||||||
|
}
|
||||||
|
|
||||||
Future _saveMediaId(EpisodeTask episodeTask) async {
|
Future _saveMediaId(EpisodeTask episodeTask) async {
|
||||||
final completeTask = await FlutterDownloader.loadTasksWithRawQuery(
|
final completeTask = await FlutterDownloader.loadTasksWithRawQuery(
|
||||||
query: "SELECT * FROM task WHERE task_id = '${episodeTask.taskId}'");
|
query: "SELECT * FROM task WHERE task_id = '${episodeTask.taskId}'");
|
||||||
@ -91,7 +98,7 @@ class AutoDownloader {
|
|||||||
Future startTask(List<EpisodeBrief> episodes,
|
Future startTask(List<EpisodeBrief> episodes,
|
||||||
{bool showNotification = false}) async {
|
{bool showNotification = false}) async {
|
||||||
for (var episode in episodes) {
|
for (var episode in episodes) {
|
||||||
final dir = await getExternalStorageDirectory();
|
final dir = await _getDownloadDirectory();
|
||||||
var localPath = path.join(dir.path, episode.feedTitle);
|
var localPath = path.join(dir.path, episode.feedTitle);
|
||||||
final saveDir = Directory(localPath);
|
final saveDir = Directory(localPath);
|
||||||
var hasExisted = await saveDir.exists();
|
var hasExisted = await saveDir.exists();
|
||||||
@ -182,6 +189,13 @@ class DownloadState extends ChangeNotifier {
|
|||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<Directory> _getDownloadDirectory() async {
|
||||||
|
final storage = KeyValueStorage(downloadPositionKey);
|
||||||
|
final index = await storage.getInt();
|
||||||
|
final externalDirs = await getExternalStorageDirectories();
|
||||||
|
return externalDirs[index];
|
||||||
|
}
|
||||||
|
|
||||||
void _bindBackgroundIsolate() {
|
void _bindBackgroundIsolate() {
|
||||||
var _port = ReceivePort();
|
var _port = ReceivePort();
|
||||||
var isSuccess = IsolateNameServer.registerPortWithName(
|
var isSuccess = IsolateNameServer.registerPortWithName(
|
||||||
@ -256,7 +270,7 @@ class DownloadState extends ChangeNotifier {
|
|||||||
var dbHelper = DBHelper();
|
var dbHelper = DBHelper();
|
||||||
var isDownloaded = await dbHelper.isDownloaded(episode.enclosureUrl);
|
var isDownloaded = await dbHelper.isDownloaded(episode.enclosureUrl);
|
||||||
if (!isDownloaded) {
|
if (!isDownloaded) {
|
||||||
final dir = await getExternalStorageDirectory();
|
final dir = await _getDownloadDirectory();
|
||||||
var localPath =
|
var localPath =
|
||||||
path.join(dir.path, episode.feedTitle?.replaceAll('/', ''));
|
path.join(dir.path, episode.feedTitle?.replaceAll('/', ''));
|
||||||
final saveDir = Directory(localPath);
|
final saveDir = Directory(localPath);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user