2020-04-16 10:06:01 +00:00
|
|
|
import 'package:comunic/helpers/virtual_directory_helper.dart';
|
2020-05-05 11:21:37 +00:00
|
|
|
import 'package:comunic/ui/routes/main_route/main_route.dart';
|
2019-11-02 11:46:17 +00:00
|
|
|
import 'package:comunic/ui/routes/single_post_route.dart';
|
2020-04-16 10:06:01 +00:00
|
|
|
import 'package:comunic/utils/intl_utils.dart';
|
|
|
|
import 'package:comunic/utils/ui_utils.dart';
|
2019-06-10 12:24:34 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
/// Navigation utilities
|
|
|
|
///
|
|
|
|
/// @author Pierre HUBERT
|
|
|
|
|
2020-04-16 12:58:02 +00:00
|
|
|
/// Pop a page
|
|
|
|
void popPage(BuildContext context) {
|
2022-03-10 18:39:57 +00:00
|
|
|
MainController.of(context)!.popPage();
|
2020-04-16 12:58:02 +00:00
|
|
|
}
|
|
|
|
|
2019-06-10 12:24:34 +00:00
|
|
|
/// Open the page of a user
|
2022-03-10 18:39:57 +00:00
|
|
|
void openUserPage({required int userID, required BuildContext context}) {
|
2019-06-10 12:24:34 +00:00
|
|
|
assert(userID != null);
|
|
|
|
assert(context != null);
|
|
|
|
|
2022-03-10 18:39:57 +00:00
|
|
|
MainController.of(context)!.openUserPage(userID);
|
2019-06-10 12:24:34 +00:00
|
|
|
}
|
2019-11-02 11:46:17 +00:00
|
|
|
|
|
|
|
/// Open a post in full screen
|
|
|
|
void openPostFullScreen(int postID, BuildContext context) {
|
2022-03-10 18:39:57 +00:00
|
|
|
MainController.of(context)!.push(SinglePostRoute(postID: postID));
|
2019-11-02 11:46:17 +00:00
|
|
|
}
|
2020-04-16 10:06:01 +00:00
|
|
|
|
|
|
|
/// Open a virtual directory
|
|
|
|
void openVirtualDirectory(BuildContext context, String directory) async {
|
|
|
|
if (directory.startsWith("@")) directory = directory.substring(1);
|
|
|
|
|
|
|
|
try {
|
|
|
|
final result = await VirtualDirectoryHelper().find(directory);
|
|
|
|
|
|
|
|
switch (result.type) {
|
|
|
|
case VirtualDirectoryType.USER:
|
2022-03-10 18:39:57 +00:00
|
|
|
openUserPage(context: context, userID: result.id!);
|
2020-04-16 10:06:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VirtualDirectoryType.GROUP:
|
2022-03-10 18:39:57 +00:00
|
|
|
MainController.of(context)!.openGroup(result.id!);
|
2020-04-16 10:06:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VirtualDirectoryType.NONE:
|
|
|
|
await showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (c) => AlertDialog(
|
2022-03-10 18:39:57 +00:00
|
|
|
title: Text(tr("Error")!),
|
|
|
|
content: Text(tr("Could not find related resource!")!),
|
2020-04-16 10:06:01 +00:00
|
|
|
actions: <Widget>[
|
|
|
|
MaterialButton(
|
2022-03-10 18:39:57 +00:00
|
|
|
child: Text(tr("OK")!),
|
2020-04-16 10:06:01 +00:00
|
|
|
onPressed: () => Navigator.of(c).pop(),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} catch (e, stack) {
|
|
|
|
print(e);
|
|
|
|
print(stack);
|
2022-03-10 18:39:57 +00:00
|
|
|
showSimpleSnack(context, tr("Could not search virtual directory!")!);
|
2020-04-16 10:06:01 +00:00
|
|
|
}
|
|
|
|
}
|