diff --git a/lib/data/interfaces/connections_repo_intf.dart b/lib/data/interfaces/connections_repo_intf.dart index 36beb28..dffbc9d 100644 --- a/lib/data/interfaces/connections_repo_intf.dart +++ b/lib/data/interfaces/connections_repo_intf.dart @@ -4,6 +4,10 @@ import '../../models/connection.dart'; import '../../models/exec_error.dart'; class IConnectionsRepo { + void clear() { + throw UnimplementedError(); + } + bool addConnection(Connection connection) { throw UnimplementedError(); } diff --git a/lib/data/memory/memory_connections_repo.dart b/lib/data/memory/memory_connections_repo.dart index bd43aa8..60e02d0 100644 --- a/lib/data/memory/memory_connections_repo.dart +++ b/lib/data/memory/memory_connections_repo.dart @@ -9,6 +9,13 @@ class MemoryConnectionsRepo implements IConnectionsRepo { final _connectionsByName = {}; final _myContacts = []; + @override + void clear() { + _connectionsById.clear(); + _connectionsByName.clear(); + _myContacts.clear(); + } + @override bool addAllConnections(Iterable newConnections) { bool result = true; diff --git a/lib/data/objectbox/objectbox_connections_repo.dart b/lib/data/objectbox/objectbox_connections_repo.dart index 734918c..b7ec69c 100644 --- a/lib/data/objectbox/objectbox_connections_repo.dart +++ b/lib/data/objectbox/objectbox_connections_repo.dart @@ -16,6 +16,12 @@ class ObjectBoxConnectionsRepo implements IConnectionsRepo { box = getIt().store.box(); } + @override + void clear() { + memCache.clear(); + box.removeAll(); + } + @override bool addAllConnections(Iterable newConnections) { memCache.addAllConnections(newConnections); @@ -40,9 +46,10 @@ class ObjectBoxConnectionsRepo implements IConnectionsRepo { return _getConnection( Connection_.id.equals(id), ).mapError( - (error) => error.copy( - message: "Can't find Connection for ID: $id", - ), + (error) => + error.copy( + message: "Can't find Connection for ID: $id", + ), ); } @@ -55,9 +62,10 @@ class ObjectBoxConnectionsRepo implements IConnectionsRepo { return _getConnection( Connection_.name.equals(name), ).mapError( - (error) => error.copy( - message: "Can't find Connection for ID: $name", - ), + (error) => + error.copy( + message: "Can't find Connection for ID: $name", + ), ); } @@ -65,9 +73,9 @@ class ObjectBoxConnectionsRepo implements IConnectionsRepo { List getKnownUsersByName(String name) { return box .query( - Connection_.name.contains(name, caseSensitive: false) | - Connection_.handle.contains(name, caseSensitive: false), - ) + Connection_.name.contains(name, caseSensitive: false) | + Connection_.handle.contains(name, caseSensitive: false), + ) .build() .find(); } diff --git a/lib/screens/menus_screen.dart b/lib/screens/menus_screen.dart index 0c004e7..9ddf6f6 100644 --- a/lib/screens/menus_screen.dart +++ b/lib/screens/menus_screen.dart @@ -2,9 +2,12 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import '../controls/app_bottom_nav_bar.dart'; +import '../data/interfaces/connections_repo_intf.dart'; import '../globals.dart'; import '../routes.dart'; import '../services/auth_service.dart'; +import '../services/notifications_manager.dart'; +import '../services/timeline_manager.dart'; class MenusScreen extends StatelessWidget { static const menuButtonWidth = 350.0; @@ -17,6 +20,15 @@ class MenusScreen extends StatelessWidget { buildMenuButton('Profile', () => context.pushNamed(ScreenPaths.profile)), buildMenuButton( 'Settings', () => context.pushNamed(ScreenPaths.settings)), + buildMenuButton('Clear Caches', () async { + final confirm = await showYesNoDialog( + context, 'You want to clear all memory and disk cache data?'); + if (confirm == true) { + getIt().clear(); + getIt().clear(); + getIt().clear(); + } + }), buildMenuButton('Logout', () async { final confirm = await showYesNoDialog(context, 'Log out account?'); if (confirm == true) { diff --git a/lib/services/notifications_manager.dart b/lib/services/notifications_manager.dart index fdeef58..4d49aa3 100644 --- a/lib/services/notifications_manager.dart +++ b/lib/services/notifications_manager.dart @@ -28,6 +28,10 @@ class NotificationsManager extends ChangeNotifier { return result; } + void clear() { + _notifications.clear(); + } + FutureResult, ExecError> updateNotifications() async { final auth = getIt(); final clientResult = auth.currentClient;