Skip to content

Commit

Permalink
Merge pull request #165 from BrightDV/download
Browse files Browse the repository at this point in the history
  • Loading branch information
BrightDV authored Jun 18, 2024
2 parents bbf5583 + c3d3d84 commit e6e8d18
Show file tree
Hide file tree
Showing 6 changed files with 477 additions and 242 deletions.
247 changes: 230 additions & 17 deletions lib/Screens/MixedNews/edit_order.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ class EditOrderScreen extends StatefulWidget {
}

class _EditOrderScreenState extends State<EditOrderScreen> {
void update() {
setState(() {});
}

@override
Widget build(BuildContext context) {
bool useDarkMode =
Hive.box('settings').get('darkMode', defaultValue: true) as bool;
List feedsNames = Hive.box('feeds').get(
'feedsNames',
defaultValue: [
Expand All @@ -50,45 +52,256 @@ class _EditOrderScreenState extends State<EditOrderScreen> {
//'Pitpass.com', // TODO: fix Pitpass
],
) as List;
Map<String, dynamic> feedsDetails = Hive.box('feeds').get(
'feedsDetails',
defaultValue: {
'WTF1.com': {'url': 'https://wtf1.com', 'type': 'wp'},
'Racefans.net': {'url': 'https://racefans.net', 'type': 'wp'},
/* 'Beyondtheflag.com': {
'url': 'https://beyondtheflag.com',
'type': 'wp'
}, */
'Motorsport.com': {
'url': 'https://www.motorsport.com/rss/f1/news/',
'type': 'rss'
},
'Autosport.com': {
'url': 'https://www.autosport.com/rss/f1/news/',
'type': 'rss'
},
'GPFans.com': {
'url': 'https://www.gpfans.com/en/rss.xml',
'type': 'rss'
},
'Racer.com': {'url': 'https://racer.com/f1/feed/', 'type': 'rss'},
'Thecheckeredflag.co.uk': {
'url':
'https://www.thecheckeredflag.co.uk/open-wheel/formula-1/feed/',
'type': 'rss'
},
'Motorsportweek.com': {
'url': 'https://www.motorsportweek.com/feed/',
'type': 'rss'
},
'Crash.net': {'url': 'https://www.crash.net/rss/f1', 'type': 'rss'},
/* 'Pitpass.com': {
'url':
'https://www.pitpass.com/fes_php/fes_usr_sit_newsfeed.php?fes_prepend_aty_sht_name=1',
'type': 'rss'
}, */
},
);

return Scaffold(
appBar: AppBar(
title: Text(
AppLocalizations.of(context)!.edit,
),
actions: [
IconButton(
onPressed: () => showDialog(
context: context,
builder: (context) {
final TextEditingController nameController =
TextEditingController();
final TextEditingController urlController =
TextEditingController();
String type = "rss";
return StatefulBuilder(
builder: (context, setState) => AlertDialog(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(
20.0,
),
),
),
contentPadding: const EdgeInsets.all(
30.0,
),
title: Text(
AppLocalizations.of(context)!.customFeed,
style: TextStyle(
fontSize: 24.0,
),
textAlign: TextAlign.center,
),
content: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
TextField(
controller: nameController,
decoration: InputDecoration(
hintText: 'Example',
hintStyle: TextStyle(
fontWeight: FontWeight.w100,
),
),
),
TextField(
controller: urlController,
decoration: InputDecoration(
hintText: 'https://example.com',
hintStyle: TextStyle(
fontWeight: FontWeight.w100,
),
),
),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Radio(
value: "rss",
groupValue: type,
onChanged: (String? value) => setState(() {
type = value!;
}),
),
Text(
'RSS',
),
Radio(
value: "wp",
groupValue: type,
onChanged: (String? value) => setState(
() {
type = value!;
},
),
),
Text(
'WordPress',
),
],
),
),
],
),
actions: <Widget>[
TextButton(
onPressed: () async {
feedsNames.add(nameController.text);
Hive.box('feeds').put('feedsNames', feedsNames);
feedsDetails[nameController.text] = {
'url': urlController.text,
'type': type
};
Hive.box('feeds').put('feedsDetails', feedsDetails);
Navigator.of(context).pop();
update();
widget.updateParent();
},
child: Text(
AppLocalizations.of(context)!.save,
),
),
ElevatedButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(
AppLocalizations.of(context)!.close,
),
),
],
),
);
},
),
icon: Icon(
Icons.add_outlined,
),
),
],
backgroundColor: Theme.of(context).colorScheme.onPrimary,
),
body: Theme(
data: ThemeData(
data: Theme.of(context).copyWith(
canvasColor: Colors.transparent,
fontFamily: 'Formula1',
),
child: ReorderableListView.builder(
header: Padding(
padding: const EdgeInsets.all(5),
child: RichText(
text: TextSpan(
text: AppLocalizations.of(context)!.editOrderDescription,
style: TextStyle(
color:
useDarkMode ? Colors.grey.shade500 : Colors.grey.shade300,
fontStyle: FontStyle.italic,
fontFamily: 'Formula1',
),
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
fontStyle: FontStyle.italic,
),
),
textAlign: TextAlign.center,
),
),
itemBuilder: (context, index) => ListTile(
itemBuilder: (_, index) => ListTile(
key: Key('$index'),
title: Text(
feedsNames[index],
style: TextStyle(
color: useDarkMode ? Colors.white : Colors.black,
),
),
trailing: Icon(
Icons.drag_handle,
color: useDarkMode ? Colors.white : Colors.black,
trailing: IconButton(
icon: Icon(Icons.delete_outline),
onPressed: () => showDialog(
context: context,
builder: (context) {
print(feedsNames[index]);
return AlertDialog(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(
20.0,
),
),
),
contentPadding: const EdgeInsets.all(
50.0,
),
title: Text(
AppLocalizations.of(context)!.deleteCustomFeed,
style: TextStyle(
fontSize: 24.0,
), // here
textAlign: TextAlign.center,
),
content: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
AppLocalizations.of(context)!.deleteUrl,
),
],
),
actions: <Widget>[
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(
AppLocalizations.of(context)!.cancel,
),
),
ElevatedButton(
onPressed: () {
feedsDetails.remove(feedsNames[index]);
Hive.box('feeds').put('feedsDetails', feedsDetails);
feedsNames.remove(feedsNames[index]);
Hive.box('feeds').put('feedsNames', feedsNames);
Navigator.of(context).pop();
setState(() {});
widget.updateParent();
},
child: Text(
AppLocalizations.of(context)!.yes,
),
),
],
);
},
),
),
),
itemCount: feedsNames.length,
Expand Down
Loading

0 comments on commit e6e8d18

Please sign in to comment.