From 7639296ca4557070faa9b19e7d88e8a188279282 Mon Sep 17 00:00:00 2001 From: Hiddify Date: Wed, 31 Jan 2024 10:43:53 +0100 Subject: [PATCH] new: change update time when selected --- .../profile/data/profile_data_source.dart | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/features/profile/data/profile_data_source.dart b/lib/features/profile/data/profile_data_source.dart index e6045db6..c04a2845 100644 --- a/lib/features/profile/data/profile_data_source.dart +++ b/lib/features/profile/data/profile_data_source.dart @@ -45,6 +45,7 @@ class ProfileDao extends DatabaseAccessor ..limit(1)) .getSingleOrNull(); } + @override Future getByName(String name) async { return (select(profileEntries) @@ -76,12 +77,13 @@ class ProfileDao extends DatabaseAccessor }) { return (profileEntries.select() ..orderBy( - [(tbl) => OrderingTerm( - expression: tbl.active, - mode: OrderingMode.desc, - ), + [ + (tbl) => OrderingTerm( + expression: tbl.active, + mode: OrderingMode.desc, + ), (tbl) { - final trafficRatio = (tbl.download + tbl.upload) / tbl.total; + final trafficRatio = (tbl.download + tbl.upload) / tbl.total; final isExpired = tbl.expire.isSmallerOrEqualValue(DateTime.now()); return OrderingTerm( @@ -93,9 +95,8 @@ class ProfileDao extends DatabaseAccessor }, switch (sort) { ProfilesSort.name => (tbl) => OrderingTerm( - expression: tbl.name, + expression: tbl.name, mode: orderMap[sortMode]!, - ), ProfilesSort.lastUpdate => (tbl) => OrderingTerm( expression: tbl.lastUpdate, @@ -124,12 +125,13 @@ class ProfileDao extends DatabaseAccessor Future edit(String id, ProfileEntriesCompanion entry) async { await transaction( () async { + if (entry.active.present && entry.active.value) { await update(profileEntries) .write(const ProfileEntriesCompanion(active: Value(false))); } await (update(profileEntries)..where((tbl) => tbl.id.equals(id))) - .write(entry); + .write(entry.copyWith(lastUpdate: Value(DateTime.now()))); }, ); }