1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 12:59:21 +00:00

Turn user page route into a screen

This commit is contained in:
Pierre HUBERT 2020-04-16 13:13:31 +02:00
parent 7014ded7f0
commit cecf18f5a0
5 changed files with 56 additions and 48 deletions

View File

@ -1,15 +1,16 @@
import 'package:comunic/helpers/account_helper.dart'; import 'package:comunic/helpers/account_helper.dart';
import 'package:comunic/ui/routes/app_settings_route.dart'; import 'package:comunic/ui/routes/app_settings_route.dart';
import 'package:comunic/ui/routes/user_page_route.dart';
import 'package:comunic/ui/screens/conversations_list_screen.dart'; import 'package:comunic/ui/screens/conversations_list_screen.dart';
import 'package:comunic/ui/screens/friends_list_screen.dart'; import 'package:comunic/ui/screens/friends_list_screen.dart';
import 'package:comunic/ui/screens/group_screen.dart'; import 'package:comunic/ui/screens/group_screen.dart';
import 'package:comunic/ui/screens/groups_list_screen.dart'; import 'package:comunic/ui/screens/groups_list_screen.dart';
import 'package:comunic/ui/screens/newest_posts.dart'; import 'package:comunic/ui/screens/newest_posts.dart';
import 'package:comunic/ui/screens/notifications_screen.dart'; import 'package:comunic/ui/screens/notifications_screen.dart';
import 'package:comunic/ui/screens/other_friends_lists_screen.dart';
import 'package:comunic/ui/widgets/navbar_widget.dart'; import 'package:comunic/ui/widgets/navbar_widget.dart';
import 'package:comunic/utils/account_utils.dart'; import 'package:comunic/utils/account_utils.dart';
import 'package:comunic/utils/intl_utils.dart'; import 'package:comunic/utils/intl_utils.dart';
import 'package:comunic/utils/navigation_utils.dart';
import 'package:comunic/utils/ui_utils.dart'; import 'package:comunic/utils/ui_utils.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -41,13 +42,18 @@ class CurrPage {
/// Public interface of home controller /// Public interface of home controller
abstract class HomeController extends State<HomeRoute> { abstract class HomeController extends State<HomeRoute> {
/// Get current instance of Home controller /// Get current instance of Home controller
static HomeController of(BuildContext context) => static HomeController of(BuildContext context) =>
context.findAncestorStateOfType<HomeController>(); context.findAncestorStateOfType<HomeController>();
/// Open user page
void openUserPage(int userID);
/// Open a specific group page specified by its [groupID] /// Open a specific group page specified by its [groupID]
void openGroup(int groupID); void openGroup(int groupID);
/// Display the list of friends of a user
void openUserFriendsList(int userID);
} }
/// Private implementation of HomeController /// Private implementation of HomeController
@ -129,12 +135,20 @@ class _HomeRouteState extends HomeController {
case BarCallbackActions.OPEN_FRIENDS: case BarCallbackActions.OPEN_FRIENDS:
return FriendsListScreen(); return FriendsListScreen();
case BarCallbackActions.OPEN_USER_PAGE:
return UserPageRoute(userID: _currTab.args["userID"]);
case BarCallbackActions.OPEN_GROUPS: case BarCallbackActions.OPEN_GROUPS:
return GroupsListScreen(); return GroupsListScreen();
case BarCallbackActions.OPEN_GROUP_PAGE: case BarCallbackActions.OPEN_GROUP_PAGE:
return GroupPageScreen(groupID: _currTab.args["groupID"]); return GroupPageScreen(groupID: _currTab.args["groupID"]);
case BarCallbackActions.OPEN_USER_FRIENDS_LIST:
return OtherUserFriendsListScreen(
userID: _currTab.args["userID"],
);
default: default:
throw "Invalid tab : " + _currTab.toString(); throw "Invalid tab : " + _currTab.toString();
} }
@ -164,7 +178,7 @@ class _HomeRouteState extends HomeController {
/// Open current user page /// Open current user page
Future<void> _openCurrentUserPage() async { Future<void> _openCurrentUserPage() async {
openUserPage(context: context, userID: userID()); this.openUserPage(userID());
} }
void _openAppSettings() { void _openAppSettings() {
@ -191,4 +205,16 @@ class _HomeRouteState extends HomeController {
_pushPage(CurrPage(BarCallbackActions.OPEN_GROUP_PAGE, _pushPage(CurrPage(BarCallbackActions.OPEN_GROUP_PAGE,
args: {"groupID": groupID})); args: {"groupID": groupID}));
} }
@override
void openUserPage(int userID) {
_pushPage(
CurrPage(BarCallbackActions.OPEN_USER_PAGE, args: {"userID": userID}));
}
@override
void openUserFriendsList(int userID) {
_pushPage(CurrPage(BarCallbackActions.OPEN_USER_FRIENDS_LIST,
args: {"userID": userID}));
}
} }

View File

@ -2,7 +2,7 @@ import 'package:comunic/enums/post_target.dart';
import 'package:comunic/helpers/posts_helper.dart'; import 'package:comunic/helpers/posts_helper.dart';
import 'package:comunic/helpers/users_helper.dart'; import 'package:comunic/helpers/users_helper.dart';
import 'package:comunic/models/advanced_user_info.dart'; import 'package:comunic/models/advanced_user_info.dart';
import 'package:comunic/ui/routes/other_friends_lists_route.dart'; import 'package:comunic/ui/routes/home_route.dart';
import 'package:comunic/ui/routes/user_access_denied_route.dart'; import 'package:comunic/ui/routes/user_access_denied_route.dart';
import 'package:comunic/ui/widgets/network_image_widget.dart'; import 'package:comunic/ui/widgets/network_image_widget.dart';
import 'package:comunic/ui/widgets/post_create_form_widget.dart'; import 'package:comunic/ui/widgets/post_create_form_widget.dart';
@ -221,13 +221,7 @@ class _UserPageRouteState extends State<UserPageRoute> {
void _selectedMenuOption(_MenuOptions value) { void _selectedMenuOption(_MenuOptions value) {
switch (value) { switch (value) {
case _MenuOptions.FRIENDS_LIST: case _MenuOptions.FRIENDS_LIST:
Navigator.of(context).push( HomeController.of(context).openUserFriendsList(_userInfo.id);
MaterialPageRoute(
builder: (c) => OtherUserFriendsListRoute(
user: _userInfo,
),
),
);
break; break;
} }
} }

View File

@ -1,7 +1,6 @@
import 'package:comunic/helpers/friends_helper.dart'; import 'package:comunic/helpers/friends_helper.dart';
import 'package:comunic/helpers/users_helper.dart'; import 'package:comunic/helpers/users_helper.dart';
import 'package:comunic/lists/users_list.dart'; import 'package:comunic/lists/users_list.dart';
import 'package:comunic/models/user.dart';
import 'package:comunic/ui/tiles/simple_user_tile.dart'; import 'package:comunic/ui/tiles/simple_user_tile.dart';
import 'package:comunic/utils/intl_utils.dart'; import 'package:comunic/utils/intl_utils.dart';
import 'package:comunic/utils/navigation_utils.dart'; import 'package:comunic/utils/navigation_utils.dart';
@ -12,29 +11,30 @@ import 'package:flutter/material.dart';
/// ///
/// @author Pierre HUBERT /// @author Pierre HUBERT
class OtherUserFriendsListRoute extends StatefulWidget { class OtherUserFriendsListScreen extends StatefulWidget {
final User user; final int userID;
const OtherUserFriendsListRoute({ const OtherUserFriendsListScreen({
Key key, Key key,
@required this.user, @required this.userID,
}) : assert(user != null), }) : assert(userID != null),
super(key: key); super(key: key);
@override @override
_OtherUserFriendsListRouteState createState() => _OtherUserFriendsListScreenState createState() =>
_OtherUserFriendsListRouteState(); _OtherUserFriendsListScreenState();
} }
class _OtherUserFriendsListRouteState extends State<OtherUserFriendsListRoute> { class _OtherUserFriendsListScreenState
extends State<OtherUserFriendsListScreen> {
final FriendsHelper friendsHelper = FriendsHelper(); final FriendsHelper friendsHelper = FriendsHelper();
final UsersHelper usersHelper = UsersHelper(); final UsersHelper usersHelper = UsersHelper();
UsersList _list; UsersList _list;
bool _error = false; bool _error = false;
String get _routeName => String get _routeName => tr("Friends of %name%",
tr("Friends of %name%", args: {"name": widget.user.displayName}); args: {"name": _list.getUser(widget.userID).displayName});
void setError(bool e) => setState(() => _error = e); void setError(bool e) => setState(() => _error = e);
@ -49,8 +49,9 @@ class _OtherUserFriendsListRouteState extends State<OtherUserFriendsListRoute> {
setError(false); setError(false);
try { try {
final list = await usersHelper.getListWithThrow( final list = await usersHelper
await friendsHelper.getOtherUserList(widget.user.id)); .getListWithThrow(await friendsHelper.getOtherUserList(widget.userID)
..add(widget.userID));
setState(() { setState(() {
_list = list; _list = list;
@ -66,11 +67,7 @@ class _OtherUserFriendsListRouteState extends State<OtherUserFriendsListRoute> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (_error) return _buildError(); if (_error) return _buildError();
if (_list == null) if (_list == null) return buildCenteredProgressBar();
return buildLoadingPage(
showAppBar: true,
routeTitle: _routeName,
);
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
@ -79,25 +76,21 @@ class _OtherUserFriendsListRouteState extends State<OtherUserFriendsListRoute> {
body: ListView.builder( body: ListView.builder(
itemCount: _list.length, itemCount: _list.length,
itemBuilder: (c, i) => SimpleUserTile( itemBuilder: (c, i) => SimpleUserTile(
user: _list[i], user: _list[i],
onTap: (u) => openUserPage( onTap: (u) => openUserPage(
context: context, context: context,
userID: u.id, userID: u.id,
), ),
), ),
), ),
); );
} }
Widget _buildError() { Widget _buildError() {
return Scaffold( return Scaffold(
appBar: AppBar(
title: Text(_routeName),
),
body: buildErrorCard( body: buildErrorCard(
tr( tr(
"Could not get the list of friends of %name% !", "Could not get the list of friends of this user !",
args: {"name": widget.user.displayName},
), ),
actions: [ actions: [
FlatButton( FlatButton(

View File

@ -17,7 +17,9 @@ enum BarCallbackActions {
OPEN_MY_PAGE, OPEN_MY_PAGE,
OPEN_GROUPS, OPEN_GROUPS,
OPEN_GROUP_PAGE, OPEN_GROUP_PAGE,
OPEN_USER_PAGE,
OPEN_APP_SETTINGS, OPEN_APP_SETTINGS,
OPEN_USER_FRIENDS_LIST,
OPEN_ABOUT_DIALOG, OPEN_ABOUT_DIALOG,
NONE, NONE,
ACTION_LOGOUT ACTION_LOGOUT

View File

@ -1,7 +1,6 @@
import 'package:comunic/helpers/virtual_directory_helper.dart'; import 'package:comunic/helpers/virtual_directory_helper.dart';
import 'package:comunic/ui/routes/home_route.dart'; import 'package:comunic/ui/routes/home_route.dart';
import 'package:comunic/ui/routes/single_post_route.dart'; import 'package:comunic/ui/routes/single_post_route.dart';
import 'package:comunic/ui/routes/user_page_route.dart';
import 'package:comunic/utils/intl_utils.dart'; import 'package:comunic/utils/intl_utils.dart';
import 'package:comunic/utils/ui_utils.dart'; import 'package:comunic/utils/ui_utils.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -16,13 +15,7 @@ void openUserPage({@required int userID, @required BuildContext context}) {
assert(userID != null); assert(userID != null);
assert(context != null); assert(context != null);
Navigator.of(context).push( HomeController.of(context).openUserPage(userID);
MaterialPageRoute(
builder: (c) => UserPageRoute(
userID: userID,
),
),
);
} }
/// Open a post in full screen /// Open a post in full screen