mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-01-05 19:21:23 -06:00
[client] Move recent marking from router delegate to explorer controller
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_state_notifier/flutter_state_notifier.dart';
|
||||
import 'package:offtheline/offtheline.dart';
|
||||
@@ -9,7 +8,6 @@ import 'package:phylum/libphylum/phylum_account.dart';
|
||||
import 'package:phylum/libphylum/phylum_api_types.dart';
|
||||
import 'package:phylum/ui/app/action_queue_status_notifier.dart';
|
||||
import 'package:phylum/ui/logout/logout_app.dart';
|
||||
import 'package:phylum/ui/explorer/page.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class PhylumApp extends StatefulWidget {
|
||||
@@ -37,7 +35,7 @@ class _PhylumAppState extends State<PhylumApp> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_routerDelegate = PhylumRouterDelegate(account: context.read());
|
||||
_routerDelegate = PhylumRouterDelegate();
|
||||
_listener = AppLifecycleListener(onResume: () {
|
||||
final account = context.read<PhylumAccount>();
|
||||
account.userRepository.refresh();
|
||||
@@ -79,39 +77,3 @@ class _PhylumAppState extends State<PhylumApp> {
|
||||
return const LogoutApp();
|
||||
}
|
||||
}
|
||||
|
||||
class PhylumRouteInformationParser extends RouteInformationParser<ExplorerPage> {
|
||||
const PhylumRouteInformationParser();
|
||||
|
||||
@override
|
||||
Future<ExplorerPage> parseRouteInformation(RouteInformation routeInformation) {
|
||||
final uri = routeInformation.uri;
|
||||
final segments = uri.pathSegments;
|
||||
|
||||
if (segments.isEmpty) {
|
||||
return SynchronousFuture(const ExplorerPageHome());
|
||||
}
|
||||
if (segments.length == 1) {
|
||||
if (segments[0] == 'home') {
|
||||
return SynchronousFuture(const ExplorerPageHome());
|
||||
}
|
||||
if (segments[0] == 'recents') {
|
||||
return SynchronousFuture(const ExplorerPageRecents());
|
||||
}
|
||||
if (segments[0] == 'shared') {
|
||||
return SynchronousFuture(const ExplorerPageShared());
|
||||
}
|
||||
if (segments[0] == 'trash') {
|
||||
return SynchronousFuture(const ExplorerPageTrash());
|
||||
}
|
||||
} else if (segments.length == 2 && segments[0] == 'folder') {
|
||||
return SynchronousFuture(ExplorerPageFolder(folderId: segments[1]));
|
||||
}
|
||||
return SynchronousFuture(ExplorerPageFolder(folderId: 'unknown'));
|
||||
}
|
||||
|
||||
@override
|
||||
RouteInformation? restoreRouteInformation(ExplorerPage configuration) {
|
||||
return RouteInformation(uri: configuration.uri);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:phylum/libphylum/db/resource_helpers.dart';
|
||||
import 'package:phylum/libphylum/phylum_account.dart';
|
||||
import 'package:phylum/ui/app/app_layout.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
@@ -10,8 +8,6 @@ import '../explorer/page.dart';
|
||||
class PhylumRouterDelegate extends RouterDelegate<ExplorerPage> with ChangeNotifier, PopNavigatorRouterDelegateMixin {
|
||||
@override
|
||||
final navigatorKey = GlobalKey<NavigatorState>();
|
||||
|
||||
final PhylumAccount? _account;
|
||||
ExplorerPage? _current;
|
||||
List<ExplorerPage> _back = const [];
|
||||
List<ExplorerPage> _forward = const [];
|
||||
@@ -21,9 +17,7 @@ class PhylumRouterDelegate extends RouterDelegate<ExplorerPage> with ChangeNotif
|
||||
@override
|
||||
ExplorerPage? get currentConfiguration => _current;
|
||||
|
||||
PhylumRouterDelegate({required PhylumAccount? account, ExplorerPage? page})
|
||||
: _account = account,
|
||||
_current = page;
|
||||
PhylumRouterDelegate({ExplorerPage? page}) : _current = page;
|
||||
|
||||
void go(ExplorerPage page) {
|
||||
if (_current != page) {
|
||||
@@ -31,9 +25,6 @@ class PhylumRouterDelegate extends RouterDelegate<ExplorerPage> with ChangeNotif
|
||||
_forward = const [];
|
||||
_current = page;
|
||||
notifyListeners();
|
||||
if (page is ExplorerPageFolder && _account != null && page.folderId != _account.userHome) {
|
||||
_account.db.markResourceAccess(page.folderId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,3 +71,39 @@ class PhylumRouterDelegate extends RouterDelegate<ExplorerPage> with ChangeNotif
|
||||
return SynchronousFuture(null);
|
||||
}
|
||||
}
|
||||
|
||||
class PhylumRouteInformationParser extends RouteInformationParser<ExplorerPage> {
|
||||
const PhylumRouteInformationParser();
|
||||
|
||||
@override
|
||||
Future<ExplorerPage> parseRouteInformation(RouteInformation routeInformation) {
|
||||
final uri = routeInformation.uri;
|
||||
final segments = uri.pathSegments;
|
||||
|
||||
if (segments.isEmpty) {
|
||||
return SynchronousFuture(const ExplorerPageHome());
|
||||
}
|
||||
if (segments.length == 1) {
|
||||
if (segments[0] == 'home') {
|
||||
return SynchronousFuture(const ExplorerPageHome());
|
||||
}
|
||||
if (segments[0] == 'recents') {
|
||||
return SynchronousFuture(const ExplorerPageRecents());
|
||||
}
|
||||
if (segments[0] == 'shared') {
|
||||
return SynchronousFuture(const ExplorerPageShared());
|
||||
}
|
||||
if (segments[0] == 'trash') {
|
||||
return SynchronousFuture(const ExplorerPageTrash());
|
||||
}
|
||||
} else if (segments.length == 2 && segments[0] == 'folder') {
|
||||
return SynchronousFuture(ExplorerPageFolder(folderId: segments[1]));
|
||||
}
|
||||
return SynchronousFuture(ExplorerPageFolder(folderId: 'unknown'));
|
||||
}
|
||||
|
||||
@override
|
||||
RouteInformation? restoreRouteInformation(ExplorerPage configuration) {
|
||||
return RouteInformation(uri: configuration.uri);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ class DestinationPicker extends StatefulWidget {
|
||||
return showDialog(
|
||||
context: context,
|
||||
builder: (context) => ChangeNotifierProvider(
|
||||
create: (context) => PhylumRouterDelegate(account: null, page: ExplorerPageFolder(folderId: initialFolderId)),
|
||||
create: (context) => PhylumRouterDelegate(page: ExplorerPageFolder(folderId: initialFolderId)),
|
||||
builder: (context, child) {
|
||||
final page = context.watch<PhylumRouterDelegate>().current!;
|
||||
return StateNotifierProvider<ExplorerController, ExplorerState>(
|
||||
|
||||
@@ -94,11 +94,14 @@ class ExplorerController extends StateNotifier<ExplorerState> {
|
||||
_folderSubscription?.cancel();
|
||||
if (page is ExplorerPageFolder) {
|
||||
_folderSubscription = _account.db.watchResource(page.folderId).listen((e) => state = state.copyWith(folder: e));
|
||||
if (page.folderId != _account.userHome) {
|
||||
_account.db.markResourceAccess(page.folderId);
|
||||
}
|
||||
} else {
|
||||
_folderSubscription = null;
|
||||
}
|
||||
_childrenSubscription?.cancel();
|
||||
_childrenSubscription = page.watchItems(_account).listen((e) => _updateResourceList(e));
|
||||
_childrenSubscription = page.items(_account).listen((e) => _updateResourceList(e));
|
||||
state = ExplorerState(page: page);
|
||||
refresh();
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ sealed class ExplorerPage {
|
||||
|
||||
Future<bool> refresh(PhylumAccount account);
|
||||
|
||||
Stream<List<Resource>> watchItems(PhylumAccount account);
|
||||
Stream<List<Resource>> items(PhylumAccount account);
|
||||
}
|
||||
|
||||
class ExplorerPageHome extends ExplorerPage {
|
||||
@@ -29,7 +29,7 @@ class ExplorerPageHome extends ExplorerPage {
|
||||
account.resourceRepository.requestResource(account.userHome).then((result) => result is ApiSuccessResponse);
|
||||
|
||||
@override
|
||||
Stream<List<Resource>> watchItems(PhylumAccount account) => account.db.watchChildren(account.userHome);
|
||||
Stream<List<Resource>> items(PhylumAccount account) => account.db.watchChildren(account.userHome);
|
||||
}
|
||||
|
||||
class ExplorerPageFolder extends ExplorerPage {
|
||||
@@ -48,7 +48,7 @@ class ExplorerPageFolder extends ExplorerPage {
|
||||
account.resourceRepository.requestResource(folderId).then((result) => result is ApiSuccessResponse);
|
||||
|
||||
@override
|
||||
Stream<List<Resource>> watchItems(PhylumAccount account) => account.db.watchChildren(folderId);
|
||||
Stream<List<Resource>> items(PhylumAccount account) => account.db.watchChildren(folderId);
|
||||
}
|
||||
|
||||
class ExplorerPageRecents extends ExplorerPage {
|
||||
@@ -66,7 +66,7 @@ class ExplorerPageRecents extends ExplorerPage {
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<List<Resource>> watchItems(PhylumAccount account) {
|
||||
Stream<List<Resource>> items(PhylumAccount account) {
|
||||
return account.db.selectRecents().watch();
|
||||
}
|
||||
}
|
||||
@@ -86,7 +86,7 @@ class ExplorerPageTrash extends ExplorerPage {
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<List<Resource>> watchItems(PhylumAccount account) {
|
||||
Stream<List<Resource>> items(PhylumAccount account) {
|
||||
return account.db.selectTrash().watch();
|
||||
}
|
||||
}
|
||||
@@ -106,7 +106,7 @@ class ExplorerPageShared extends ExplorerPage {
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<List<Resource>> watchItems(PhylumAccount account) {
|
||||
Stream<List<Resource>> items(PhylumAccount account) {
|
||||
return account.db.selectShared().watch();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user