From 5631961e478013b3f19892b8fff83e0f08bacdb4 Mon Sep 17 00:00:00 2001 From: M Date: Thu, 28 Jan 2021 19:58:17 +0200 Subject: [PATCH] Some another fixes for Android. Never ask us about that. --- android/app/src/main/AndroidManifest.xml | 12 +----- android/build.gradle | 2 +- cw_monero/android/build.gradle | 2 +- cw_monero/ios/Classes/monero_api.cpp | 2 +- lib/src/screens/backup/backup_page.dart | 52 +++++++++++++++++++----- lib/view_model/backup_view_model.dart | 10 +++++ pubspec.yaml | 2 +- 7 files changed, 57 insertions(+), 25 deletions(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 4513c32f6..437729891 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -3,7 +3,8 @@ - + + - - - - - Navigator.of(dialogContext).pop()); + alertTitle: S.of(context).export_backup, + alertContent: S.of(context).save_backup_password, + rightButtonText: S.of(context).seed_alert_yes, + leftButtonText: S.of(context).seed_alert_back, + actionRightButton: () async { + Navigator.of(dialogContext).pop(); + final backup = await backupViewModelBase.exportBackup(); + await backupViewModelBase.saveToDownload( + backup.name, backup.content); + + if (Platform.isAndroid) { + onExportAndroid(context, backup); + } else { + await Share.file(S.of(context).backup_file, backup.name, + backup.content, 'application/*'); + } + }, + actionLeftButton: () => Navigator.of(dialogContext).pop()); + }); + } + + void onExportAndroid(BuildContext context, BackupExportFile backup) { + showPopUp( + context: context, + builder: (dialogContext) { + return AlertWithTwoActions( + alertTitle: S.of(context).export_backup, + alertContent: 'Please select destination for the backup file.', + rightButtonText: 'Save to Downloads', + leftButtonText: 'Share', + actionRightButton: () async { + Navigator.of(dialogContext).pop(); + await backupViewModelBase.saveToDownload( + backup.name, backup.content); + }, + actionLeftButton: () { + Navigator.of(dialogContext).pop(); + Share.file(S.of(context).backup_file, backup.name, + backup.content, 'application/*'); + }); }); } } diff --git a/lib/view_model/backup_view_model.dart b/lib/view_model/backup_view_model.dart index b76c19163..660c576c4 100644 --- a/lib/view_model/backup_view_model.dart +++ b/lib/view_model/backup_view_model.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:cake_wallet/core/backup_service.dart'; import 'package:cake_wallet/core/execution_state.dart'; import 'package:cake_wallet/entities/secret_store_key.dart'; @@ -66,4 +68,12 @@ abstract class BackupViewModelBase with Store { @action void showMasterPassword() => isBackupPasswordVisible = true; + + @action + Future saveToDownload(String name, List content) async { + const downloadDirPath = '/storage/emulated/0/Download'; // For Android + final filePath = '$downloadDirPath/${name}'; + final file = File(filePath); + await file.writeAsBytes(content); + } } diff --git a/pubspec.yaml b/pubspec.yaml index 32ab99627..e70c37c69 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ description: Cake Wallet. # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 4.1.0+34 +version: 4.1.0+37 environment: sdk: ">=2.7.0 <3.0.0"