-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Export] Initial share based implementation
Starting to work on #7
- Loading branch information
1 parent
a6eeee8
commit 52cfdb9
Showing
15 changed files
with
149 additions
and
27 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
enum ExportType { | ||
SHARE_UNENCRYPTED, | ||
SAVE_TO_STORAGE_UNENCRYPTED, | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
|
||
import 'package:injectable/injectable.dart'; | ||
import 'package:path/path.dart'; | ||
import 'package:share/share.dart'; | ||
|
||
import '../../models/export.dart'; | ||
import '../database/database_service.dart'; | ||
import '../locator.dart'; | ||
import '../path/path_service.dart'; | ||
import 'export_service.dart'; | ||
|
||
@Injectable(as: ExportService) | ||
class ExportImpl implements ExportService { | ||
final pathService = locator<PathService>(); | ||
final databaseService = locator<DatabaseService>(); | ||
|
||
@override | ||
Future export(ExportType type) async { | ||
switch (type) { | ||
case ExportType.SHARE_UNENCRYPTED: | ||
await share_unencrypted(); | ||
break; | ||
|
||
case ExportType.SAVE_TO_STORAGE_UNENCRYPTED: | ||
throw UnimplementedError(); | ||
} | ||
} | ||
|
||
Future share_unencrypted() async { | ||
if (!Platform.isAndroid && !Platform.isIOS) { | ||
throw UnsupportedError('Share is only available on mobile devices'); | ||
} | ||
|
||
final tempDir = await pathService.getTempDir(); | ||
final tempDbPath = join(tempDir.path, 'passwd_db.json'); | ||
final file = File(tempDbPath); | ||
|
||
await file.writeAsString(json.encode(databaseService.entries)); | ||
await Share.shareFiles( | ||
[tempDbPath], | ||
mimeTypes: ['text/json', 'application/json'], | ||
); | ||
|
||
await file.delete(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import '../../models/export.dart'; | ||
|
||
abstract class ExportService { | ||
Future export(ExportType type); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:ez_localization/ez_localization.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
import '../models/export.dart'; | ||
import '../services/export/export_service.dart'; | ||
import '../services/locator.dart'; | ||
import '../utils/loggers.dart'; | ||
|
||
class ExportSettingsWidget extends StatelessWidget { | ||
Future<void> export(BuildContext context) async { | ||
await showDialog( | ||
context: context, | ||
builder: (context) => AlertDialog( | ||
title: Text('Are you sure?'), // TODO: localize | ||
content: | ||
Text('The database export will be unencrypted'), // TODO: localize | ||
actions: [ | ||
TextButton( | ||
onPressed: () { | ||
Navigator.of(context).pop(); | ||
}, | ||
child: Text(context.getString('no')), | ||
), | ||
TextButton( | ||
onPressed: () async { | ||
Loggers.mainLogger.info( | ||
'Export Type SHARE_UNENCRYPTED', | ||
); | ||
Navigator.of(context).pop(); | ||
await locator<ExportService>() | ||
.export(ExportType.SHARE_UNENCRYPTED); | ||
}, | ||
child: Text(context.getString('yes')), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
if (Platform.isAndroid || Platform.isIOS) { | ||
return ListTile( | ||
title: Text('Export'), // TODO: localize | ||
onTap: () async { | ||
Loggers.mainLogger.info( | ||
'Export exportService requested', | ||
); | ||
await export(context); | ||
}, | ||
); | ||
} | ||
|
||
return Container(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters