2020-03-14 04:14:24 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
2020-03-31 18:36:20 +02:00
|
|
|
import 'package:provider/provider.dart';
|
2020-04-27 19:26:33 +02:00
|
|
|
import 'package:google_fonts/google_fonts.dart';
|
2020-05-06 18:50:32 +02:00
|
|
|
|
|
|
|
import '../settings/downloads_manage.dart';
|
2020-07-07 17:29:21 +02:00
|
|
|
import '../state/setting_state.dart';
|
2020-04-27 19:26:33 +02:00
|
|
|
import '../local_storage/key_value_storage.dart';
|
|
|
|
import '../util/context_extension.dart';
|
|
|
|
|
|
|
|
class StorageSetting extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_StorageSettingState createState() => _StorageSettingState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _StorageSettingState extends State<StorageSetting>
|
|
|
|
with SingleTickerProviderStateMixin {
|
|
|
|
final KeyValueStorage cacheStorage = KeyValueStorage(cacheMaxKey);
|
|
|
|
AnimationController _controller;
|
|
|
|
Animation<double> _animation;
|
|
|
|
_getCacheMax() async {
|
|
|
|
int cache = await cacheStorage.getInt();
|
2020-06-10 09:42:40 +02:00
|
|
|
int value = cache == 0 ? 200 : cache ~/ (1024 * 1024);
|
2020-04-27 19:26:33 +02:00
|
|
|
if (value > 100) {
|
|
|
|
_controller = AnimationController(
|
|
|
|
vsync: this, duration: Duration(milliseconds: value * 2));
|
|
|
|
_animation = Tween<double>(begin: 100, end: value.toDouble()).animate(
|
|
|
|
CurvedAnimation(curve: Curves.easeOutQuart, parent: _controller))
|
|
|
|
..addListener(() {
|
|
|
|
setState(() => _value = _animation.value);
|
|
|
|
});
|
|
|
|
_controller.forward();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-10 09:42:40 +02:00
|
|
|
Future<bool> _getAutoDownloadNetwork() async {
|
|
|
|
KeyValueStorage storage = KeyValueStorage(autoDownloadNetworkKey);
|
|
|
|
int value = await storage.getInt();
|
|
|
|
return value != 0;
|
|
|
|
}
|
|
|
|
|
2020-06-10 18:36:53 +02:00
|
|
|
Future<int> _getAutoDeleteDays() async {
|
|
|
|
KeyValueStorage storage = KeyValueStorage(autoDeleteKey);
|
|
|
|
int days = await storage.getInt();
|
|
|
|
if (days == 0) {
|
|
|
|
storage.saveInt(30);
|
|
|
|
return 30;
|
|
|
|
}
|
|
|
|
return days;
|
|
|
|
}
|
|
|
|
|
|
|
|
_setAutoDeleteDays(int days) async {
|
|
|
|
KeyValueStorage storage = KeyValueStorage(autoDeleteKey);
|
|
|
|
await storage.saveInt(days);
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
|
2020-06-10 09:42:40 +02:00
|
|
|
_setAudtDownloadNetwork(bool boo) async {
|
|
|
|
KeyValueStorage storage = KeyValueStorage(autoDownloadNetworkKey);
|
|
|
|
await storage.saveInt(boo ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
2020-04-27 19:26:33 +02:00
|
|
|
double _value;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_value = 100;
|
|
|
|
_getCacheMax();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_controller?.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
2020-03-14 04:14:24 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-07-02 14:58:55 +02:00
|
|
|
final s = context.s;
|
2020-03-31 18:36:20 +02:00
|
|
|
var settings = Provider.of<SettingState>(context, listen: false);
|
2020-03-14 04:14:24 +01:00
|
|
|
return AnnotatedRegion<SystemUiOverlayStyle>(
|
|
|
|
value: SystemUiOverlayStyle(
|
2020-03-19 20:58:30 +01:00
|
|
|
statusBarIconBrightness: Theme.of(context).accentColorBrightness,
|
|
|
|
systemNavigationBarColor: Theme.of(context).primaryColor,
|
|
|
|
systemNavigationBarIconBrightness:
|
|
|
|
Theme.of(context).accentColorBrightness,
|
|
|
|
),
|
|
|
|
child: Scaffold(
|
|
|
|
appBar: AppBar(
|
2020-07-02 14:58:55 +02:00
|
|
|
title: Text(s.settingStorage),
|
2020-03-19 20:58:30 +01:00
|
|
|
elevation: 0,
|
|
|
|
backgroundColor: Theme.of(context).primaryColor,
|
|
|
|
),
|
|
|
|
body: SafeArea(
|
|
|
|
child: Column(
|
2020-03-14 04:14:24 +01:00
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
2020-03-31 18:36:20 +02:00
|
|
|
Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.all(10.0),
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
height: 30.0,
|
2020-06-12 19:56:13 +02:00
|
|
|
padding: EdgeInsets.symmetric(horizontal: 70),
|
2020-03-31 18:36:20 +02:00
|
|
|
alignment: Alignment.centerLeft,
|
2020-07-02 14:58:55 +02:00
|
|
|
child: Text(s.network,
|
2020-03-31 18:36:20 +02:00
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.bodyText1
|
|
|
|
.copyWith(color: Theme.of(context).accentColor)),
|
|
|
|
),
|
|
|
|
ListView(
|
|
|
|
physics: const BouncingScrollPhysics(),
|
|
|
|
shrinkWrap: true,
|
|
|
|
scrollDirection: Axis.vertical,
|
|
|
|
children: <Widget>[
|
2020-06-10 09:42:40 +02:00
|
|
|
Selector<SettingState, bool>(
|
|
|
|
selector: (_, settings) => settings.downloadUsingData,
|
|
|
|
builder: (_, data, __) {
|
|
|
|
return ListTile(
|
|
|
|
onTap: () => settings.downloadUsingData = !data,
|
|
|
|
contentPadding: EdgeInsets.only(
|
|
|
|
left: 80.0, right: 25, bottom: 10, top: 10),
|
2020-07-02 14:58:55 +02:00
|
|
|
title: Text(s.settingsNetworkCellular),
|
|
|
|
subtitle: Text(s.settingsNetworkCellularDes),
|
2020-06-13 15:23:08 +02:00
|
|
|
trailing: Transform.scale(
|
|
|
|
scale: 0.9,
|
|
|
|
child: Switch(
|
|
|
|
value: data,
|
|
|
|
onChanged: (value) =>
|
|
|
|
settings.downloadUsingData = value,
|
|
|
|
),
|
2020-06-10 09:42:40 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2020-03-31 18:36:20 +02:00
|
|
|
),
|
|
|
|
Divider(height: 2),
|
2020-06-10 09:42:40 +02:00
|
|
|
FutureBuilder<bool>(
|
|
|
|
future: _getAutoDownloadNetwork(),
|
|
|
|
initialData: false,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
return ListTile(
|
|
|
|
onTap: () async {
|
|
|
|
_setAudtDownloadNetwork(!snapshot.data);
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
contentPadding: EdgeInsets.only(
|
|
|
|
left: 80.0, right: 25, bottom: 10, top: 10),
|
2020-07-02 14:58:55 +02:00
|
|
|
title: Text(s.settingsNetworkCellularAuto),
|
|
|
|
subtitle:
|
|
|
|
Text(s.settingsNetworkCellularAutoDes),
|
2020-06-13 15:23:08 +02:00
|
|
|
trailing: Transform.scale(
|
|
|
|
scale: 0.9,
|
|
|
|
child: Switch(
|
|
|
|
value: snapshot.data,
|
|
|
|
onChanged: (value) async {
|
|
|
|
await _setAudtDownloadNetwork(value);
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
),
|
2020-06-10 09:42:40 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
Divider(height: 2),
|
2020-03-31 18:36:20 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
]),
|
2020-03-14 04:14:24 +01:00
|
|
|
Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.all(10.0),
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
height: 30.0,
|
2020-06-12 19:56:13 +02:00
|
|
|
padding: EdgeInsets.symmetric(horizontal: 70),
|
2020-03-14 04:14:24 +01:00
|
|
|
alignment: Alignment.centerLeft,
|
2020-07-02 14:58:55 +02:00
|
|
|
child: Text(s.settingStorage,
|
2020-03-14 04:14:24 +01:00
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.bodyText1
|
|
|
|
.copyWith(color: Theme.of(context).accentColor)),
|
|
|
|
),
|
|
|
|
ListView(
|
2020-03-21 17:14:10 +01:00
|
|
|
physics: const BouncingScrollPhysics(),
|
2020-03-14 04:14:24 +01:00
|
|
|
shrinkWrap: true,
|
|
|
|
scrollDirection: Axis.vertical,
|
|
|
|
children: <Widget>[
|
|
|
|
ListTile(
|
|
|
|
onTap: () => Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => DownloadsManage())),
|
|
|
|
contentPadding: EdgeInsets.symmetric(horizontal: 80.0),
|
2020-07-02 14:58:55 +02:00
|
|
|
title: Text(s.download),
|
|
|
|
subtitle: Text(s.settingsManageDownloadDes),
|
2020-03-14 04:14:24 +01:00
|
|
|
),
|
|
|
|
Divider(height: 2),
|
2020-06-10 18:36:53 +02:00
|
|
|
FutureBuilder<int>(
|
|
|
|
future: _getAutoDeleteDays(),
|
|
|
|
initialData: 30,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
return ListTile(
|
|
|
|
contentPadding:
|
|
|
|
EdgeInsets.only(left: 80.0, right: 20),
|
2020-07-02 14:58:55 +02:00
|
|
|
title: Text(s.settingsAutoDelete),
|
|
|
|
subtitle: Text(s.settingsAutoDeleteDes),
|
2020-06-10 18:36:53 +02:00
|
|
|
trailing: DropdownButton(
|
|
|
|
hint: snapshot.data == -1
|
2020-07-06 11:50:20 +02:00
|
|
|
? Text(s.daysCount(0))
|
|
|
|
: Text(s.daysCount(snapshot.data)),
|
2020-06-10 18:36:53 +02:00
|
|
|
underline: Center(),
|
|
|
|
elevation: 1,
|
|
|
|
value: snapshot.data,
|
|
|
|
onChanged: (value) async {
|
|
|
|
await _setAutoDeleteDays(value);
|
|
|
|
},
|
2020-06-16 06:40:51 +02:00
|
|
|
items: <int>[-1, 5, 10, 15, 30]
|
2020-06-10 18:36:53 +02:00
|
|
|
.map<DropdownMenuItem<int>>((e) {
|
|
|
|
return DropdownMenuItem<int>(
|
|
|
|
value: e,
|
|
|
|
child: e == -1
|
2020-07-06 11:50:20 +02:00
|
|
|
? Text(s.daysCount(0))
|
|
|
|
: Text(s.daysCount(e)));
|
2020-06-10 18:36:53 +02:00
|
|
|
}).toList()),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
Divider(height: 2),
|
2020-03-14 04:14:24 +01:00
|
|
|
ListTile(
|
2020-04-27 19:26:33 +02:00
|
|
|
contentPadding: EdgeInsets.only(left: 80.0, right: 25),
|
2020-03-14 04:14:24 +01:00
|
|
|
// leading: Icon(Icons.colorize),
|
2020-07-02 14:58:55 +02:00
|
|
|
title: Text(s.settingsAudioCache),
|
|
|
|
subtitle: Text(s.settingsAudioCacheDes),
|
2020-04-27 19:26:33 +02:00
|
|
|
trailing: Text.rich(TextSpan(
|
|
|
|
text: '${(_value ~/ 100) * 100}',
|
|
|
|
style: GoogleFonts.teko(
|
|
|
|
textStyle: context.textTheme.headline6
|
|
|
|
.copyWith(color: context.accentColor)),
|
|
|
|
children: [
|
|
|
|
TextSpan(
|
|
|
|
text: ' Mb',
|
|
|
|
style: context.textTheme.subtitle2),
|
|
|
|
])),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
left: 60.0, right: 20.0, bottom: 10.0),
|
|
|
|
child: SliderTheme(
|
|
|
|
data: Theme.of(context).sliderTheme.copyWith(
|
2020-06-10 09:42:40 +02:00
|
|
|
showValueIndicator: ShowValueIndicator.always,
|
|
|
|
trackHeight: 2,
|
|
|
|
thumbShape:
|
|
|
|
RoundSliderThumbShape(enabledThumbRadius: 6)),
|
2020-04-27 19:26:33 +02:00
|
|
|
child: Slider(
|
|
|
|
label: '${_value ~/ 100 * 100} Mb',
|
|
|
|
activeColor: context.accentColor,
|
|
|
|
inactiveColor: context.primaryColorDark,
|
|
|
|
value: _value,
|
|
|
|
min: 100,
|
|
|
|
max: 1000,
|
|
|
|
divisions: 9,
|
|
|
|
onChanged: (double val) {
|
|
|
|
setState(() {
|
|
|
|
_value = val;
|
|
|
|
});
|
|
|
|
cacheStorage
|
|
|
|
.saveInt((val * 1024 * 1024).toInt());
|
|
|
|
}),
|
|
|
|
),
|
2020-03-14 04:14:24 +01:00
|
|
|
),
|
|
|
|
Divider(height: 2),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|