Skip to content

Commit 1bcc128

Browse files
committed
app: backup/restore progress info & add a divider
1 parent 66a6987 commit 1bcc128

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

companion_app/lib/main.dart

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,23 @@ class MyApp extends StatelessWidget {
2828
}
2929
}
3030

31-
class Home extends StatelessWidget {
31+
class Home extends StatefulWidget {
3232
const Home({Key? key}) : super(key: key);
3333

34+
@override
35+
State<Home> createState() => _HomeState();
36+
}
37+
38+
class _HomeState extends State<Home> {
39+
// for backups
40+
bool showBackupProgress = false;
41+
int contactsAmountDatabase = 0;
42+
int contactsExported = 0;
43+
// for restores
44+
bool showRestoreProgress = false;
45+
int contactsAmountFilesystem = 0;
46+
int contactsImported = 0;
47+
3448
Future<void> backup(BuildContext context) async {
3549
// Requests contacts & internal storage permissions
3650
if (await FlutterContacts.requestPermission() &&
@@ -51,6 +65,10 @@ class Home extends StatelessWidget {
5165
final List<Contact> contacts = await FlutterContacts.getContacts(
5266
withProperties: true, withPhoto: true, withGroups: true);
5367

68+
setState(() {
69+
contactsAmountDatabase = contacts.length;
70+
});
71+
5472
// Recreate the temp directory if it already exists.
5573
final Directory directory =
5674
Directory("/storage/emulated/0/linux-android-backup-temp");
@@ -65,6 +83,9 @@ class Home extends StatelessWidget {
6583
final File file = File(
6684
"/storage/emulated/0/linux-android-backup-temp/linux-android-backup-contact-$i.vcf");
6785
file.writeAsString(vCard);
86+
setState(() {
87+
contactsExported = i + 1;
88+
});
6889
}
6990

7091
// Show a dialog if the export is complete
@@ -97,6 +118,10 @@ class Home extends StatelessWidget {
97118
// List directory contents
98119
final List<FileSystemEntity> files = await contactsDir.list().toList();
99120

121+
setState(() {
122+
contactsAmountFilesystem = files.length;
123+
});
124+
100125
// Loop over the contents
101126
for (var i = 0; i < files.length; i++) {
102127
if (files[i] is File) {
@@ -105,6 +130,10 @@ class Home extends StatelessWidget {
105130
final Contact contact = Contact.fromVCard(vcard);
106131
await contact.insert();
107132
}
133+
134+
setState(() {
135+
contactsImported = i + 1;
136+
});
108137
}
109138

110139
showInfoDialog(context, "Success", "Data has been imported.");
@@ -149,19 +178,46 @@ class Home extends StatelessWidget {
149178
),
150179
ElevatedButton(
151180
onPressed: () {
181+
setState(() {
182+
showBackupProgress = true;
183+
});
152184
backup(context);
153185
},
154186
child: const Text("Export Data"),
155187
),
188+
Visibility(
189+
visible: showBackupProgress,
190+
child: Text("Exported " +
191+
contactsExported.toString() +
192+
" contact(s) out of " +
193+
contactsAmountDatabase.toString() +
194+
".")),
195+
const Divider(
196+
color: Color.fromARGB(31, 44, 44, 44),
197+
height: 25,
198+
thickness: 1,
199+
indent: 5,
200+
endIndent: 5,
201+
),
156202
const Text(
157203
"Upon restoring a backup, press the button below to automatically import all contacts.",
158204
),
159205
ElevatedButton(
160206
onPressed: () {
207+
setState(() {
208+
showRestoreProgress = true;
209+
});
161210
autoRestoreContacts(context);
162211
},
163212
child: const Text("Auto-restore contacts"),
164-
)
213+
),
214+
Visibility(
215+
visible: showRestoreProgress,
216+
child: Text("Restored " +
217+
contactsImported.toString() +
218+
" contact(s) out of " +
219+
contactsAmountFilesystem.toString() +
220+
".")),
165221
],
166222
),
167223
),

windows-dependencies/env-startup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
# we're using the Windows adb
3+
# we're using the Windows adb
44
export ADB_DIR=$(pwd)/windows-dependencies/adb/adb.exe
55

66
adb() {

0 commit comments

Comments
 (0)