tsacdop-podcast-app-android/lib/settings/play_setting.dart

454 lines
19 KiB
Dart
Raw Normal View History

2020-06-27 20:27:39 +02:00
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
2020-07-26 12:20:42 +02:00
import 'package:flutter_time_picker_spinner/flutter_time_picker_spinner.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:provider/provider.dart';
2020-06-27 20:27:39 +02:00
import 'package:tuple/tuple.dart';
import '../home/audioplayer.dart';
2020-07-26 12:20:42 +02:00
import '../state/setting_state.dart';
import '../util/custom_dropdown.dart';
2020-07-26 12:20:42 +02:00
import '../util/extension_helper.dart';
import '../util/general_dialog.dart';
const List secondsToSelect = [10, 15, 20, 25, 30, 45, 60];
class PlaySetting extends StatelessWidget {
2020-06-27 20:27:39 +02:00
Widget _modeWidget(BuildContext context) {
var settings = Provider.of<SettingState>(context, listen: false);
return Selector<SettingState, Tuple2<int, int>>(
selector: (_, settings) =>
Tuple2(settings.autoSleepTimerMode, settings.defaultSleepTimer),
builder: (_, data, __) => Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
InkWell(
onTap: () => settings.setAutoSleepTimerMode = 0,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(5), topLeft: Radius.circular(5)),
2020-06-27 20:27:39 +02:00
child: Material(
color: Colors.transparent,
child: AnimatedContainer(
duration: Duration(milliseconds: 400),
decoration: BoxDecoration(
color: data.item1 == 0
? context.accentColor
: context.primaryColorDark,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(5),
topLeft: Radius.circular(5)),
),
2020-06-27 20:27:39 +02:00
padding: const EdgeInsets.all(8.0),
2020-07-06 11:50:20 +02:00
child: Text(context.s.endOfEpisode,
2020-06-27 20:27:39 +02:00
style: TextStyle(
color: data.item1 == 0 ? Colors.white : null)),
),
),
),
InkWell(
onTap: () => settings.setAutoSleepTimerMode = 1,
borderRadius: BorderRadius.only(
bottomRight: Radius.circular(5),
topRight: Radius.circular(5)),
2020-06-27 20:27:39 +02:00
child: Material(
color: Colors.transparent,
child: AnimatedContainer(
duration: Duration(milliseconds: 400),
decoration: BoxDecoration(
color: data.item1 == 1
? context.accentColor
: context.primaryColorDark,
borderRadius: BorderRadius.only(
bottomRight: Radius.circular(5),
topRight: Radius.circular(5)),
),
2020-06-27 20:27:39 +02:00
padding: const EdgeInsets.all(8.0),
2020-07-06 11:50:20 +02:00
child: Text(context.s.minsCount(data.item2),
2020-06-27 20:27:39 +02:00
style: TextStyle(
color: data.item1 == 1 ? Colors.white : null)),
),
),
),
],
),
),
);
}
Widget _scheduleWidget(BuildContext context) {
var settings = Provider.of<SettingState>(context, listen: false);
2020-07-06 11:50:20 +02:00
final s = context.s;
2020-06-27 20:27:39 +02:00
return Selector<SettingState, Tuple2<int, int>>(
selector: (_, settings) =>
Tuple2(settings.autoSleepTimerStart, settings.autoSleepTimerEnd),
builder: (_, data, __) => Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
InkWell(
onTap: () {
2020-07-26 12:20:42 +02:00
var startTime = data.item1;
2020-06-27 20:27:39 +02:00
generalDialog(
context,
content: TimePickerSpinner(
minutesInterval: 15,
time: DateTime.fromMillisecondsSinceEpoch(
data.item1 * 60 * 1000,
isUtc: true),
isForce2Digits: true,
is24HourMode: false,
highlightedTextStyle: GoogleFonts.teko(
textStyle: TextStyle(
fontSize: 40, color: context.accentColor)),
normalTextStyle: GoogleFonts.teko(
textStyle:
TextStyle(fontSize: 40, color: Colors.black38)),
2020-07-26 12:20:42 +02:00
onTimeChange: (time) {
2020-06-27 20:27:39 +02:00
startTime = time.hour * 60 + time.minute;
},
),
actions: <Widget>[
FlatButton(
onPressed: () => Navigator.of(context).pop(),
child: Text(
2020-07-06 11:50:20 +02:00
s.cancel,
2020-06-27 20:27:39 +02:00
style: TextStyle(color: Colors.grey[600]),
),
),
FlatButton(
onPressed: () {
if (startTime != data.item2) {
settings.setAutoSleepTimerStart = startTime;
Navigator.of(context).pop();
} else {
Fluttertoast.showToast(
2020-07-06 11:50:20 +02:00
msg: s.toastTimeEqualEnd,
2020-06-27 20:27:39 +02:00
gravity: ToastGravity.BOTTOM,
);
}
},
child: Text(
2020-07-06 11:50:20 +02:00
s.confirm,
2020-06-27 20:27:39 +02:00
style: TextStyle(color: context.accentColor),
),
)
],
);
},
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(5), topLeft: Radius.circular(5)),
2020-06-27 20:27:39 +02:00
child: Material(
color: Colors.transparent,
child: Container(
decoration: BoxDecoration(
color: context.primaryColorDark,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(5),
topLeft: Radius.circular(5)),
),
2020-06-27 20:27:39 +02:00
padding: const EdgeInsets.all(8.0),
child: Text(s.from(data.item1.toTime)),
2020-06-27 20:27:39 +02:00
),
),
),
InkWell(
onTap: () {
int endTime;
generalDialog(
context,
content: TimePickerSpinner(
minutesInterval: 15,
time: DateTime.fromMillisecondsSinceEpoch(
data.item2 * 60 * 1000,
isUtc: true),
isForce2Digits: true,
highlightedTextStyle: GoogleFonts.teko(
textStyle: TextStyle(
fontSize: 40, color: context.accentColor)),
normalTextStyle: GoogleFonts.teko(
textStyle:
TextStyle(fontSize: 40, color: Colors.black38)),
is24HourMode: false,
2020-07-26 12:20:42 +02:00
onTimeChange: (time) {
2020-06-27 20:27:39 +02:00
endTime = time.hour * 60 + time.minute;
},
),
actions: <Widget>[
FlatButton(
onPressed: () => Navigator.of(context).pop(),
child: Text(
2020-07-06 11:50:20 +02:00
s.cancel,
2020-06-27 20:27:39 +02:00
style: TextStyle(color: Colors.grey[600]),
),
),
FlatButton(
onPressed: () {
if (endTime != data.item1) {
settings.setAutoSleepTimerEnd = endTime;
Navigator.of(context).pop();
} else {
Fluttertoast.showToast(
2020-07-06 11:50:20 +02:00
msg: s.toastTimeEqualStart,
2020-06-27 20:27:39 +02:00
gravity: ToastGravity.BOTTOM,
);
}
},
child: Text(
2020-07-06 11:50:20 +02:00
s.confirm,
2020-06-27 20:27:39 +02:00
style: TextStyle(color: context.accentColor),
),
)
],
);
},
borderRadius: BorderRadius.only(
bottomRight: Radius.circular(5),
topRight: Radius.circular(5)),
2020-06-27 20:27:39 +02:00
child: Material(
color: Colors.transparent,
child: Container(
padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration(
color: Colors.black54,
borderRadius: BorderRadius.only(
bottomRight: Radius.circular(5),
topRight: Radius.circular(5))),
child: Text(s.to(data.item2.toTime),
2020-06-27 20:27:39 +02:00
style: TextStyle(color: Colors.white)),
),
),
),
],
),
),
);
}
@override
Widget build(BuildContext context) {
2020-06-27 20:27:39 +02:00
var settings = Provider.of<SettingState>(context, listen: false);
2020-07-02 14:58:55 +02:00
final s = context.s;
return AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle(
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.play),
elevation: 0,
backgroundColor: Theme.of(context).primaryColor,
),
body: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
2020-06-27 20:27:39 +02:00
padding: const EdgeInsets.all(10.0),
),
Container(
height: 30.0,
2020-06-12 19:56:13 +02:00
padding: EdgeInsets.symmetric(horizontal: 70),
alignment: Alignment.centerLeft,
2020-07-02 14:58:55 +02:00
child: Text(s.homeMenuPlaylist,
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-27 20:27:39 +02:00
Selector<SettingState, bool>(
selector: (_, settings) => settings.autoPlay,
builder: (_, data, __) => ListTile(
onTap: () => settings.setAutoPlay = !data,
contentPadding:
EdgeInsets.only(left: 80.0, right: 20),
2020-07-06 11:50:20 +02:00
title: Text(s.settingsMenuAutoPlay),
2020-07-02 14:58:55 +02:00
subtitle: Text(s.settingsAutoPlayDes),
2020-06-27 20:27:39 +02:00
trailing: Transform.scale(
scale: 0.9,
child: Switch(
value: data,
2020-06-27 20:27:39 +02:00
onChanged: (boo) => settings.setAutoPlay = boo),
),
),
),
Divider(height: 2),
2020-06-27 20:27:39 +02:00
],
),
Padding(
padding: const EdgeInsets.all(10.0),
),
Container(
height: 30.0,
padding: EdgeInsets.symmetric(horizontal: 70),
alignment: Alignment.centerLeft,
child: Text(s.playback,
style: Theme.of(context)
.textTheme
.bodyText1
.copyWith(color: Theme.of(context).accentColor)),
),
ListView(
physics: const BouncingScrollPhysics(),
shrinkWrap: true,
scrollDirection: Axis.vertical,
children: <Widget>[
ListTile(
contentPadding: EdgeInsets.only(
left: 80.0, right: 20, bottom: 10, top: 10),
title: Text(s.settingsFastForwardSec),
subtitle: Text(s.settingsFastForwardSecDes),
trailing: Selector<SettingState, int>(
selector: (_, settings) =>
settings.fastForwardSeconds,
builder: (_, data, __) => MyDropdownButton(
hint: Text(s.secCount(data)),
underline: Center(),
elevation: 1,
displayItemCount: 5,
isDense: true,
value: data,
2020-07-26 12:20:42 +02:00
onChanged: (value) =>
settings.setFastForwardSeconds = value,
items: secondsToSelect
.map<DropdownMenuItem<int>>((e) {
return DropdownMenuItem<int>(
value: e, child: Text(s.secCount(e)));
}).toList()),
),
),
ListTile(
contentPadding: EdgeInsets.only(
left: 80.0, right: 20, bottom: 10, top: 10),
title: Text(s.settingsRewindSec),
subtitle: Text(s.settingsRewindSecDes),
trailing: Selector<SettingState, int>(
selector: (_, settings) => settings.rewindSeconds,
builder: (_, data, __) => MyDropdownButton(
hint: Text(s.secCount(data)),
underline: Center(),
elevation: 1,
displayItemCount: 5,
isDense: true,
value: data,
2020-07-26 12:20:42 +02:00
onChanged: (value) =>
settings.setRewindSeconds = value,
items: secondsToSelect
.map<DropdownMenuItem<int>>((e) {
return DropdownMenuItem<int>(
value: e, child: Text(s.secCount(e)));
}).toList()),
),
),
Divider(),
]),
Padding(
padding: const EdgeInsets.all(10.0),
),
2020-06-27 20:27:39 +02:00
Container(
height: 30.0,
padding: EdgeInsets.symmetric(horizontal: 70),
alignment: Alignment.centerLeft,
2020-07-02 14:58:55 +02:00
child: Text(s.sleepTimer,
style: context.textTheme.bodyText1
2020-06-27 20:27:39 +02:00
.copyWith(color: Theme.of(context).accentColor)),
),
ListView(
physics: const BouncingScrollPhysics(),
shrinkWrap: true,
scrollDirection: Axis.vertical,
children: <Widget>[
ListTile(
contentPadding: EdgeInsets.only(left: 80.0, right: 20),
2020-07-02 14:58:55 +02:00
title: Text(s.settingsSTDefaultTime),
subtitle: Text(s.settingsSTDefautTimeDes),
2020-06-27 20:27:39 +02:00
trailing: Selector<SettingState, int>(
selector: (_, settings) => settings.defaultSleepTimer,
builder: (_, data, __) => MyDropdownButton(
2020-07-06 11:50:20 +02:00
hint: Text(s.minsCount(data)),
2020-06-27 20:27:39 +02:00
underline: Center(),
elevation: 1,
displayItemCount: 5,
2020-06-27 20:27:39 +02:00
isDense: true,
value: data,
2020-07-26 12:20:42 +02:00
onChanged: (value) =>
2020-06-27 20:27:39 +02:00
settings.setDefaultSleepTimer = value,
items:
minsToSelect.map<DropdownMenuItem<int>>((e) {
return DropdownMenuItem<int>(
2020-07-06 11:50:20 +02:00
value: e, child: Text(s.minsCount(e)));
2020-06-27 20:27:39 +02:00
}).toList()),
),
),
Divider(),
2020-06-27 20:27:39 +02:00
Selector<SettingState, bool>(
selector: (_, settings) => settings.autoSleepTimer,
builder: (_, data, __) => ListTile(
onTap: () => settings.setAutoSleepTimer = !data,
contentPadding: const EdgeInsets.only(
left: 80.0, right: 20.0, bottom: 10.0, top: 10.0),
2020-07-02 14:58:55 +02:00
title: Text(s.settingsSTAuto),
subtitle: Text(s.settingsSTAutoDes),
2020-06-27 20:27:39 +02:00
trailing: Transform.scale(
scale: 0.9,
child: Switch(
value: data,
onChanged: (boo) =>
settings.setAutoSleepTimer = boo),
),
),
),
ListTile(
contentPadding: const EdgeInsets.only(
left: 80.0, right: 20.0, bottom: 10.0, top: 10.0),
2020-07-02 14:58:55 +02:00
title: Text(s.settingsSTMode),
2020-06-27 20:27:39 +02:00
subtitle:
context.width > 360 ? null : _modeWidget(context),
trailing: context.width > 360
? _modeWidget(context)
: null),
ListTile(
contentPadding:
EdgeInsets.only(left: 80.0, right: 20),
2020-07-02 14:58:55 +02:00
title: Text(s.schedule),
2020-06-27 20:27:39 +02:00
subtitle: context.width > 360
? null
: _scheduleWidget(context),
trailing: context.width > 360
? _scheduleWidget(context)
: null),
Divider(height: 2)
],
),
SizedBox(height: 20)
],
),
],
),
),
),
);
}
}