Skip to content

Commit

Permalink
Add auto-upload button in settings per account
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunoBernardino committed May 1, 2024
1 parent 7ab983e commit a3ea7eb
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 83 deletions.
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,3 @@ If the icons change, just run the following to re-generate them:
dart pub get
dart run flutter_launcher_icons
```

## TODOs:

- [ ] Add Notes view
- [ ] Add Photos view
- [ ] Setup iOS in GitHub actions (need to setup so much stuff)?
- [ ] Publish in stores (Play Store, F-Droid, Apple Store)?
- [ ] Allow renaming and moving files
- [ ] Allow deleting, renaming, and moving directories
11 changes: 7 additions & 4 deletions lib/files_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,11 @@ class _FilesPageState extends State<FilesPage> {

var children = [
itemIcon,
Padding(
padding: const EdgeInsets.only(left: 12.0),
child: Text(item.label),
Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 12.0),
child: Text(item.label, overflow: TextOverflow.ellipsis),
),
),
];

Expand Down Expand Up @@ -521,7 +523,7 @@ class _FilesPageState extends State<FilesPage> {
context: context,
builder: (BuildContext context) {
return Container(
height: 200,
height: 300,
color: Colors.black45,
child: Padding(
padding: const EdgeInsets.all(12.0),
Expand All @@ -535,6 +537,7 @@ class _FilesPageState extends State<FilesPage> {
style: TextStyle(
fontWeight: FontWeight.bold),
),
Text(item.label),
const Spacer(),
ElevatedButton(
style: const ButtonStyle(
Expand Down
196 changes: 127 additions & 69 deletions lib/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'package:flutter/material.dart';

import 'config.dart';
import 'add_account_page.dart';
import 'api.dart';
import 'photos.dart';

class SettingsPage extends StatefulWidget {
const SettingsPage({super.key, required this.theme});
Expand Down Expand Up @@ -49,6 +51,129 @@ class _SettingsPageState extends State<SettingsPage> {
: ListView.builder(
itemCount: accounts.length,
itemBuilder: (BuildContext context, int index) {
final account = accounts[index];

var children = [
Text(
'Manage ${account.username}',
style: const TextStyle(fontWeight: FontWeight.bold),
),
const Spacer(),
ElevatedButton(
style: const ButtonStyle(
backgroundColor: MaterialStatePropertyAll(Colors.red),
foregroundColor:
MaterialStatePropertyAll(Colors.white)),
onPressed: () {
Navigator.pop(context);

showDialog(
context: context,
builder: (BuildContext subContext) {
return AlertDialog(
title: const Text('Are you sure?'),
content: const Text(
'Are you sure you want to delete this account?'),
actions: [
TextButton(
onPressed: () async {
await _deleteCloudAccount(index);

if (!subContext.mounted) {
return;
}

Navigator.pop(subContext);
},
child: const Text('Yes')),
TextButton(
onPressed: () {
Navigator.pop(subContext);
},
child: const Text('No'))
],
);
});
},
child: const Text('Delete account'),
),
const Spacer(flex: 1),
ElevatedButton(
style: const ButtonStyle(
backgroundColor: MaterialStatePropertyAll(Colors.black),
foregroundColor:
MaterialStatePropertyAll(Colors.white)),
onPressed: () => Navigator.pop(context),
child: const Text('Cancel / Close'),
),
];

// If account has auto-upload set, add button to manually trigger it
final destinationDirectoryPath =
account.autoUploadDestinationDirectory;
if (destinationDirectoryPath != null) {
children.insertAll(1, [
const Spacer(),
ElevatedButton(
style: const ButtonStyle(
backgroundColor:
MaterialStatePropertyAll(Colors.lightBlue),
foregroundColor:
MaterialStatePropertyAll(Colors.black)),
onPressed: () async {
Navigator.pop(context);

final List<RecentFile> recentFiles =
await getRecentFiles();

if (!context.mounted) {
return;
}

ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'Uploading ${recentFiles.length} file${recentFiles.length == 1 ? '' : 's'}...')),
);

final api = Api(account: account);

final accountDestinationFiles =
await api.fetchFiles(destinationDirectoryPath);

for (var recentFile in recentFiles) {
final fileName =
recentFile.file.path.split('/').removeLast();

// Check if file exists in destination
if (accountDestinationFiles.any((destinationFile) =>
destinationFile.name == fileName)) {
continue;
}

await api.uploadFile(
destinationDirectoryPath, recentFile.file);
}

if (!context.mounted) {
return;
}

ScaffoldMessenger.of(context).hideCurrentSnackBar();

ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Files uploaded!'),
duration: Duration(seconds: 5),
backgroundColor: Colors.green,
),
);
},
child: const Text('Force auto-upload now'),
),
]);
}

return Align(
alignment: Alignment.topLeft,
child: GestureDetector(
Expand All @@ -57,82 +182,15 @@ class _SettingsPageState extends State<SettingsPage> {
context: context,
builder: (BuildContext context) {
return Container(
height: 200,
height: 250,
color: Colors.black45,
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Manage ${accounts[index].username}',
style: const TextStyle(
fontWeight: FontWeight.bold),
),
const Spacer(),
ElevatedButton(
style: const ButtonStyle(
backgroundColor:
MaterialStatePropertyAll(
Colors.red),
foregroundColor:
MaterialStatePropertyAll(
Colors.white)),
onPressed: () {
Navigator.pop(context);

showDialog(
context: context,
builder:
(BuildContext subContext) {
return AlertDialog(
title: const Text(
'Are you sure?'),
content: const Text(
'Are you sure you want to delete this account?'),
actions: [
TextButton(
onPressed: () async {
await _deleteCloudAccount(
index);

if (!subContext
.mounted) {
return;
}

Navigator.pop(
subContext);
},
child:
const Text('Yes')),
TextButton(
onPressed: () {
Navigator.pop(
subContext);
},
child: const Text('No'))
],
);
});
},
child: const Text('Delete account'),
),
const Spacer(flex: 1),
ElevatedButton(
style: const ButtonStyle(
backgroundColor:
MaterialStatePropertyAll(
Colors.black),
foregroundColor:
MaterialStatePropertyAll(
Colors.white)),
onPressed: () => Navigator.pop(context),
child: const Text('Cancel / Close'),
),
],
children: children,
),
),
),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: "bewCloud WebDav client"
publish_to: 'none'


version: 0.0.3+1
version: 0.0.4+1

environment:
sdk: '>=3.3.3 <4.0.0'
Expand Down

0 comments on commit a3ea7eb

Please sign in to comment.