Skip to content

Commit 5f3cb34

Browse files
committed
Fix bugs & rotate sync icon
1 parent 9b77731 commit 5f3cb34

File tree

6 files changed

+80
-37
lines changed

6 files changed

+80
-37
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Splitr is a free and open-source app that lets you create multiple projects, add
88

99
This is currently a beta version. To get the app, you have to build it yourself with flutter or download the latest beta version [here](https://github.com/BhasherBEL/Splitr/releases).
1010

11-
:warning: Upgrading from version 0.x to 0.y does not guarantee compatibility, and backward compatibility is not assured. Proceed with caution.
11+
:warning: Upgrading from version 0.x to 0.y does not guarantee compatibility. Backward compatibility is NEVER assured. Proceed with caution.
1212

1313
## Screenshots
1414

lib/components/pages/project/expenses/item_list.dart

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,7 @@ class _ItemListState extends State<ItemList> {
4747
child: Column(
4848
children: [
4949
if (widget.project.provider.hasSync())
50-
ListTile(
51-
// tileColor: Theme.of(context).splashColor,
52-
subtitle: Text(
53-
"${widget.project.notSyncCount} changes to push",
54-
style: const TextStyle(fontStyle: FontStyle.italic),
55-
),
56-
trailing: Icon(
57-
Icons.sync,
58-
color: Theme.of(context).textTheme.bodyMedium?.color,
59-
),
60-
title: DynamicSync(time: widget.project.lastSync),
61-
dense: true,
62-
onTap: sync,
63-
),
50+
SyncTile(project: widget.project, onTap: sync),
6451
Expanded(
6552
child: widget.project.items.enabled().isNotEmpty
6653
? ScrollConfiguration(
@@ -234,3 +221,59 @@ class NoGlow extends ScrollBehavior {
234221
return child;
235222
}
236223
}
224+
225+
class SyncTile extends StatefulWidget {
226+
const SyncTile({super.key, required this.project, this.onTap});
227+
228+
final Project project;
229+
final Future<void> Function()? onTap;
230+
231+
@override
232+
State<SyncTile> createState() => _SyncTileState();
233+
}
234+
235+
class _SyncTileState extends State<SyncTile> {
236+
bool isSyncing = false;
237+
238+
Future<void> onTap() async {
239+
setState(() {
240+
isSyncing = true;
241+
});
242+
243+
if (widget.onTap != null) await widget.onTap!();
244+
245+
setState(() {
246+
isSyncing = false;
247+
});
248+
}
249+
250+
@override
251+
Widget build(BuildContext context) {
252+
print(isSyncing);
253+
return ListTile(
254+
subtitle: Text(
255+
"${widget.project.notSyncCount} changes to push",
256+
style: const TextStyle(fontStyle: FontStyle.italic),
257+
),
258+
trailing: isSyncing
259+
? Padding(
260+
padding: const EdgeInsets.only(right: 5),
261+
child: SizedBox(
262+
width: 15,
263+
height: 15,
264+
child: CircularProgressIndicator(
265+
strokeWidth: 2.5,
266+
color: Theme.of(context).textTheme.bodyMedium?.color,
267+
),
268+
),
269+
)
270+
: Icon(
271+
Icons.sync,
272+
color: Theme.of(context).textTheme.bodyMedium?.color,
273+
),
274+
title: DynamicSync(time: widget.project.lastSync),
275+
dense: true,
276+
onTap: onTap,
277+
);
278+
}
279+
}

lib/model/app_data.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ class AppData {
5555

5656
AppData.projects = await Project.getAllProjects();
5757

58-
print(AppData.projects);
59-
6058
if (!sharedPreferences.containsKey("firstRun")) {
6159
firstRun = AppData.projects.enabled().isEmpty;
6260
} else {

lib/model/connectors/pocketbase/item_part.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,20 @@ class PocketBaseItemPart {
7676
for (RecordModel e in records) {
7777
Tuple2<bool, ItemPart> res = fromRecord(e, item);
7878
if (res.item1) {
79-
item.itemParts.setPresence(!res.item2.deleted, res.item2);
79+
if (!item.itemParts.contains(res.item2)) item.itemParts.add(res.item2);
8080
distUpdated.add(res.item2);
8181
await res.item2.conn.save();
8282
}
8383
}
8484

8585
// Send local new records
86-
for (ItemPart ip in item.itemParts.toList()) {
86+
for (ItemPart ip in item.itemParts) {
8787
if (distUpdated.contains(ip)) continue;
8888

8989
if (ip.lastUpdate > item.project.lastSync) {
9090
RecordModel rm =
9191
await collection.updateOrCreate(id: ip.remoteId, body: toJson(ip));
9292
ip.remoteId = rm.id;
93-
item.itemParts.setPresence(!ip.deleted, ip);
9493
}
9594
}
9695

lib/model/item.dart

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:splitr/model/data.dart';
2+
import 'package:splitr/utils/extenders/collections.dart';
23

34
import 'item_part.dart';
45
import 'participant.dart';
@@ -98,13 +99,16 @@ class Item extends Data {
9899
ItemPart? pip;
99100
double fixedTotal = 0;
100101
if (itemParts.isNotEmpty) {
101-
for (ItemPart ip in itemParts) {
102+
for (ItemPart ip in itemParts.enabled()) {
102103
if (ip.participant == participant) pip = ip;
104+
// print("${ip.participant.pseudo} ${ip.rate}");
103105
totalRate += ip.rate ?? 0;
104106
fixedTotal += ip.amount ?? 0;
105107
}
106108
}
107109

110+
// print('$title - ${pip?.participant.pseudo}: $amount ${pip?.amount} ${pip?.rate} $totalRate $fixedTotal');
111+
108112
if (pip == null || pip.amount == null && pip.rate == null) {
109113
return emitter == participant ? amount : 0;
110114
}
@@ -114,15 +118,15 @@ class Item extends Data {
114118

115119
String toParticipantsString() {
116120
List<Participant> participants =
117-
itemParts.map((e) => e.participant).toList();
121+
itemParts.enabled().map((e) => e.participant).toList();
118122

119-
if (itemParts.length < 4) {
120-
return itemParts.map((e) => e.participant.pseudo).join(", ");
123+
if (participants.length < 4) {
124+
return participants.map((e) => e.pseudo).join(", ");
121125
}
122-
if (itemParts.length == project.participants.length) return 'All';
126+
if (participants.length == project.participants.length) return 'All';
123127

124128
List<String> possibilites = [
125-
itemParts.map((e) => e.participant.pseudo).join(", "),
129+
participants.map((e) => e.pseudo).join(", "),
126130
'All except ${project.participants.where((element) => !participants.contains(element)).map((e) => e.pseudo).join(', ')}',
127131
];
128132

lib/model/project.dart

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ class Project extends Data {
133133
tableProjects,
134134
columns: ProjectFields.values,
135135
);
136-
print(res);
137136
return res.map((e) => fromJson(e)).toSet();
138137
}
139138

@@ -164,16 +163,16 @@ class Project extends Data {
164163
}
165164

166165
Future<Tuple2<bool, String>> sync() async {
167-
// try {
168-
DateTime st = DateTime.now();
169-
bool res = await provider.sync();
170-
notSyncCount = 0;
171-
return Tuple2(
172-
res, (DateTime.now().difference(st).inMilliseconds / 1000).toString());
173-
// } catch (e) {
174-
// print(e);
175-
// return Tuple2(false, e.toString());
176-
// }
166+
try {
167+
DateTime st = DateTime.now();
168+
bool res = await provider.sync();
169+
notSyncCount = 0;
170+
return Tuple2(res,
171+
(DateTime.now().difference(st).inMilliseconds / 1000).toString());
172+
} catch (e) {
173+
print(e);
174+
return Tuple2(false, e.toString());
175+
}
177176
}
178177

179178
Participant? participantByRemoteId(String id) {

0 commit comments

Comments
 (0)