mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-05-25 12:42:13 +00:00
fix shortcut ordering
This commit is contained in:
parent
3d1b38192e
commit
a1ca45c2b9
4 changed files with 87 additions and 59 deletions
|
|
@ -14,11 +14,7 @@ class ShortcutsDao extends DatabaseAccessor<TwonlyDB> with _$ShortcutsDaoMixin {
|
|||
ShortcutsDao(super.db);
|
||||
|
||||
Stream<List<Shortcut>> watchAllShortcuts() {
|
||||
return (select(shortcuts)..orderBy([
|
||||
(t) =>
|
||||
OrderingTerm(expression: t.usageCounter, mode: OrderingMode.desc),
|
||||
]))
|
||||
.watch();
|
||||
return select(shortcuts).watch();
|
||||
}
|
||||
|
||||
Future<Shortcut?> getShortcutByEmoji(String emoji) {
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ void callbackDispatcher() {
|
|||
// }
|
||||
break;
|
||||
case 'eu.twonly.processing_task':
|
||||
case _ when task.startsWith('progressing_finish_uploads_'):
|
||||
if (await initBackgroundExecution()) {
|
||||
await handleProcessingTask();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,7 +96,6 @@ Future<void> incFlameCounter(
|
|||
final group = await twonlyDB.groupsDao.getGroup(groupId);
|
||||
if (group == null) return;
|
||||
|
||||
if (group.isDirectChat) {
|
||||
final contacts = await twonlyDB.groupsDao.getGroupContact(
|
||||
group.groupId,
|
||||
);
|
||||
|
|
@ -113,7 +112,6 @@ Future<void> incFlameCounter(
|
|||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final totalMediaCounter = group.totalMediaCounter + 1;
|
||||
var flameCounter = group.flameCounter;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:async';
|
||||
import 'dart:collection';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:twonly/locator.dart';
|
||||
|
|
@ -20,6 +21,41 @@ class ShortcutRowComp extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _ShortcutRowCompState extends State<ShortcutRowComp> {
|
||||
List<Shortcut> _shortcuts = [];
|
||||
late StreamSubscription<List<Shortcut>> shortcutSub;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
unawaited(initAsync());
|
||||
}
|
||||
|
||||
Future<void> initAsync() async {
|
||||
shortcutSub = twonlyDB.shortcutsDao.watchAllShortcuts().listen((shortcuts) {
|
||||
if (_shortcuts.isEmpty) {
|
||||
shortcuts.sort((a, b) => b.usageCounter.compareTo(a.usageCounter));
|
||||
_shortcuts = shortcuts;
|
||||
} else {
|
||||
final map = {for (final s in shortcuts) s.id: s};
|
||||
final updated = <Shortcut>[];
|
||||
for (final old in _shortcuts) {
|
||||
if (map.containsKey(old.id)) {
|
||||
updated.add(map.remove(old.id)!);
|
||||
}
|
||||
}
|
||||
updated.addAll(map.values);
|
||||
_shortcuts = updated;
|
||||
}
|
||||
if (mounted) setState(() {});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
unawaited(shortcutSub.cancel());
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _openCreateDialog() async {
|
||||
await context.navPush(const AddNewShortcutView());
|
||||
}
|
||||
|
|
@ -27,6 +63,9 @@ class _ShortcutRowCompState extends State<ShortcutRowComp> {
|
|||
Future<void> _applyShortcut(Shortcut shortcut) async {
|
||||
await twonlyDB.shortcutsDao.incrementUsage(shortcut.id);
|
||||
final members = await twonlyDB.shortcutsDao.getShortcutMembers(shortcut.id);
|
||||
for (final groupId in widget.selectedGroupIds.toList()) {
|
||||
widget.updateSelectedGroupIds(groupId, false);
|
||||
}
|
||||
for (final m in members) {
|
||||
widget.updateSelectedGroupIds(m.groupId, true);
|
||||
}
|
||||
|
|
@ -36,11 +75,7 @@ class _ShortcutRowCompState extends State<ShortcutRowComp> {
|
|||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
height: 40,
|
||||
child: StreamBuilder<List<Shortcut>>(
|
||||
stream: twonlyDB.shortcutsDao.watchAllShortcuts(),
|
||||
builder: (context, snapshot) {
|
||||
final shortcuts = snapshot.data ?? [];
|
||||
return ListView(
|
||||
child: ListView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
children: [
|
||||
Row(
|
||||
|
|
@ -48,7 +83,7 @@ class _ShortcutRowCompState extends State<ShortcutRowComp> {
|
|||
ActionChip(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: _openCreateDialog,
|
||||
label: shortcuts.isEmpty
|
||||
label: _shortcuts.isEmpty
|
||||
? Text(
|
||||
context.lang.createShortcut,
|
||||
style: const TextStyle(fontSize: 9),
|
||||
|
|
@ -56,7 +91,7 @@ class _ShortcutRowCompState extends State<ShortcutRowComp> {
|
|||
: const Icon(Icons.add_reaction_outlined, size: 20),
|
||||
shape: const StadiumBorder(),
|
||||
),
|
||||
for (final shortcut in shortcuts)
|
||||
for (final shortcut in _shortcuts)
|
||||
GestureDetector(
|
||||
onLongPress: () {
|
||||
context.navPush(AddNewShortcutView(shortcut: shortcut));
|
||||
|
|
@ -74,8 +109,6 @@ class _ShortcutRowCompState extends State<ShortcutRowComp> {
|
|||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue