Skip to content

Commit

Permalink
Fix bugs & rotate sync icon
Browse files Browse the repository at this point in the history
  • Loading branch information
BhasherBEL committed Jun 12, 2023
1 parent 9b77731 commit 5f3cb34
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 37 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Splitr is a free and open-source app that lets you create multiple projects, add

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).

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

## Screenshots

Expand Down
71 changes: 57 additions & 14 deletions lib/components/pages/project/expenses/item_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,7 @@ class _ItemListState extends State<ItemList> {
child: Column(
children: [
if (widget.project.provider.hasSync())
ListTile(
// tileColor: Theme.of(context).splashColor,
subtitle: Text(
"${widget.project.notSyncCount} changes to push",
style: const TextStyle(fontStyle: FontStyle.italic),
),
trailing: Icon(
Icons.sync,
color: Theme.of(context).textTheme.bodyMedium?.color,
),
title: DynamicSync(time: widget.project.lastSync),
dense: true,
onTap: sync,
),
SyncTile(project: widget.project, onTap: sync),
Expanded(
child: widget.project.items.enabled().isNotEmpty
? ScrollConfiguration(
Expand Down Expand Up @@ -234,3 +221,59 @@ class NoGlow extends ScrollBehavior {
return child;
}
}

class SyncTile extends StatefulWidget {
const SyncTile({super.key, required this.project, this.onTap});

final Project project;
final Future<void> Function()? onTap;

@override
State<SyncTile> createState() => _SyncTileState();
}

class _SyncTileState extends State<SyncTile> {
bool isSyncing = false;

Future<void> onTap() async {
setState(() {
isSyncing = true;
});

if (widget.onTap != null) await widget.onTap!();

setState(() {
isSyncing = false;
});
}

@override
Widget build(BuildContext context) {
print(isSyncing);
return ListTile(
subtitle: Text(
"${widget.project.notSyncCount} changes to push",
style: const TextStyle(fontStyle: FontStyle.italic),
),
trailing: isSyncing
? Padding(
padding: const EdgeInsets.only(right: 5),
child: SizedBox(
width: 15,
height: 15,
child: CircularProgressIndicator(
strokeWidth: 2.5,
color: Theme.of(context).textTheme.bodyMedium?.color,
),
),
)
: Icon(
Icons.sync,
color: Theme.of(context).textTheme.bodyMedium?.color,
),
title: DynamicSync(time: widget.project.lastSync),
dense: true,
onTap: onTap,
);
}
}
2 changes: 0 additions & 2 deletions lib/model/app_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ class AppData {

AppData.projects = await Project.getAllProjects();

print(AppData.projects);

if (!sharedPreferences.containsKey("firstRun")) {
firstRun = AppData.projects.enabled().isEmpty;
} else {
Expand Down
5 changes: 2 additions & 3 deletions lib/model/connectors/pocketbase/item_part.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,20 @@ class PocketBaseItemPart {
for (RecordModel e in records) {
Tuple2<bool, ItemPart> res = fromRecord(e, item);
if (res.item1) {
item.itemParts.setPresence(!res.item2.deleted, res.item2);
if (!item.itemParts.contains(res.item2)) item.itemParts.add(res.item2);
distUpdated.add(res.item2);
await res.item2.conn.save();
}
}

// Send local new records
for (ItemPart ip in item.itemParts.toList()) {
for (ItemPart ip in item.itemParts) {
if (distUpdated.contains(ip)) continue;

if (ip.lastUpdate > item.project.lastSync) {
RecordModel rm =
await collection.updateOrCreate(id: ip.remoteId, body: toJson(ip));
ip.remoteId = rm.id;
item.itemParts.setPresence(!ip.deleted, ip);
}
}

Expand Down
16 changes: 10 additions & 6 deletions lib/model/item.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:splitr/model/data.dart';
import 'package:splitr/utils/extenders/collections.dart';

import 'item_part.dart';
import 'participant.dart';
Expand Down Expand Up @@ -98,13 +99,16 @@ class Item extends Data {
ItemPart? pip;
double fixedTotal = 0;
if (itemParts.isNotEmpty) {
for (ItemPart ip in itemParts) {
for (ItemPart ip in itemParts.enabled()) {
if (ip.participant == participant) pip = ip;
// print("${ip.participant.pseudo} ${ip.rate}");
totalRate += ip.rate ?? 0;
fixedTotal += ip.amount ?? 0;
}
}

// print('$title - ${pip?.participant.pseudo}: $amount ${pip?.amount} ${pip?.rate} $totalRate $fixedTotal');

if (pip == null || pip.amount == null && pip.rate == null) {
return emitter == participant ? amount : 0;
}
Expand All @@ -114,15 +118,15 @@ class Item extends Data {

String toParticipantsString() {
List<Participant> participants =
itemParts.map((e) => e.participant).toList();
itemParts.enabled().map((e) => e.participant).toList();

if (itemParts.length < 4) {
return itemParts.map((e) => e.participant.pseudo).join(", ");
if (participants.length < 4) {
return participants.map((e) => e.pseudo).join(", ");
}
if (itemParts.length == project.participants.length) return 'All';
if (participants.length == project.participants.length) return 'All';

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

Expand Down
21 changes: 10 additions & 11 deletions lib/model/project.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ class Project extends Data {
tableProjects,
columns: ProjectFields.values,
);
print(res);
return res.map((e) => fromJson(e)).toSet();
}

Expand Down Expand Up @@ -164,16 +163,16 @@ class Project extends Data {
}

Future<Tuple2<bool, String>> sync() async {
// try {
DateTime st = DateTime.now();
bool res = await provider.sync();
notSyncCount = 0;
return Tuple2(
res, (DateTime.now().difference(st).inMilliseconds / 1000).toString());
// } catch (e) {
// print(e);
// return Tuple2(false, e.toString());
// }
try {
DateTime st = DateTime.now();
bool res = await provider.sync();
notSyncCount = 0;
return Tuple2(res,
(DateTime.now().difference(st).inMilliseconds / 1000).toString());
} catch (e) {
print(e);
return Tuple2(false, e.toString());
}
}

Participant? participantByRemoteId(String id) {
Expand Down

0 comments on commit 5f3cb34

Please sign in to comment.