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:
parent
7014ded7f0
commit
cecf18f5a0
@ -1,15 +1,16 @@
|
||||
import 'package:comunic/helpers/account_helper.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/friends_list_screen.dart';
|
||||
import 'package:comunic/ui/screens/group_screen.dart';
|
||||
import 'package:comunic/ui/screens/groups_list_screen.dart';
|
||||
import 'package:comunic/ui/screens/newest_posts.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/utils/account_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:flutter/material.dart';
|
||||
|
||||
@ -41,13 +42,18 @@ class CurrPage {
|
||||
|
||||
/// Public interface of home controller
|
||||
abstract class HomeController extends State<HomeRoute> {
|
||||
|
||||
/// Get current instance of Home controller
|
||||
static HomeController of(BuildContext context) =>
|
||||
context.findAncestorStateOfType<HomeController>();
|
||||
|
||||
/// Open user page
|
||||
void openUserPage(int userID);
|
||||
|
||||
/// Open a specific group page specified by its [groupID]
|
||||
void openGroup(int groupID);
|
||||
|
||||
/// Display the list of friends of a user
|
||||
void openUserFriendsList(int userID);
|
||||
}
|
||||
|
||||
/// Private implementation of HomeController
|
||||
@ -129,12 +135,20 @@ class _HomeRouteState extends HomeController {
|
||||
case BarCallbackActions.OPEN_FRIENDS:
|
||||
return FriendsListScreen();
|
||||
|
||||
case BarCallbackActions.OPEN_USER_PAGE:
|
||||
return UserPageRoute(userID: _currTab.args["userID"]);
|
||||
|
||||
case BarCallbackActions.OPEN_GROUPS:
|
||||
return GroupsListScreen();
|
||||
|
||||
case BarCallbackActions.OPEN_GROUP_PAGE:
|
||||
return GroupPageScreen(groupID: _currTab.args["groupID"]);
|
||||
|
||||
case BarCallbackActions.OPEN_USER_FRIENDS_LIST:
|
||||
return OtherUserFriendsListScreen(
|
||||
userID: _currTab.args["userID"],
|
||||
);
|
||||
|
||||
default:
|
||||
throw "Invalid tab : " + _currTab.toString();
|
||||
}
|
||||
@ -164,7 +178,7 @@ class _HomeRouteState extends HomeController {
|
||||
|
||||
/// Open current user page
|
||||
Future<void> _openCurrentUserPage() async {
|
||||
openUserPage(context: context, userID: userID());
|
||||
this.openUserPage(userID());
|
||||
}
|
||||
|
||||
void _openAppSettings() {
|
||||
@ -191,4 +205,16 @@ class _HomeRouteState extends HomeController {
|
||||
_pushPage(CurrPage(BarCallbackActions.OPEN_GROUP_PAGE,
|
||||
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}));
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ import 'package:comunic/enums/post_target.dart';
|
||||
import 'package:comunic/helpers/posts_helper.dart';
|
||||
import 'package:comunic/helpers/users_helper.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/widgets/network_image_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) {
|
||||
switch (value) {
|
||||
case _MenuOptions.FRIENDS_LIST:
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (c) => OtherUserFriendsListRoute(
|
||||
user: _userInfo,
|
||||
),
|
||||
),
|
||||
);
|
||||
HomeController.of(context).openUserFriendsList(_userInfo.id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
import 'package:comunic/helpers/friends_helper.dart';
|
||||
import 'package:comunic/helpers/users_helper.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/utils/intl_utils.dart';
|
||||
import 'package:comunic/utils/navigation_utils.dart';
|
||||
@ -12,29 +11,30 @@ import 'package:flutter/material.dart';
|
||||
///
|
||||
/// @author Pierre HUBERT
|
||||
|
||||
class OtherUserFriendsListRoute extends StatefulWidget {
|
||||
final User user;
|
||||
class OtherUserFriendsListScreen extends StatefulWidget {
|
||||
final int userID;
|
||||
|
||||
const OtherUserFriendsListRoute({
|
||||
const OtherUserFriendsListScreen({
|
||||
Key key,
|
||||
@required this.user,
|
||||
}) : assert(user != null),
|
||||
@required this.userID,
|
||||
}) : assert(userID != null),
|
||||
super(key: key);
|
||||
|
||||
@override
|
||||
_OtherUserFriendsListRouteState createState() =>
|
||||
_OtherUserFriendsListRouteState();
|
||||
_OtherUserFriendsListScreenState createState() =>
|
||||
_OtherUserFriendsListScreenState();
|
||||
}
|
||||
|
||||
class _OtherUserFriendsListRouteState extends State<OtherUserFriendsListRoute> {
|
||||
class _OtherUserFriendsListScreenState
|
||||
extends State<OtherUserFriendsListScreen> {
|
||||
final FriendsHelper friendsHelper = FriendsHelper();
|
||||
final UsersHelper usersHelper = UsersHelper();
|
||||
|
||||
UsersList _list;
|
||||
bool _error = false;
|
||||
|
||||
String get _routeName =>
|
||||
tr("Friends of %name%", args: {"name": widget.user.displayName});
|
||||
String get _routeName => tr("Friends of %name%",
|
||||
args: {"name": _list.getUser(widget.userID).displayName});
|
||||
|
||||
void setError(bool e) => setState(() => _error = e);
|
||||
|
||||
@ -49,8 +49,9 @@ class _OtherUserFriendsListRouteState extends State<OtherUserFriendsListRoute> {
|
||||
setError(false);
|
||||
|
||||
try {
|
||||
final list = await usersHelper.getListWithThrow(
|
||||
await friendsHelper.getOtherUserList(widget.user.id));
|
||||
final list = await usersHelper
|
||||
.getListWithThrow(await friendsHelper.getOtherUserList(widget.userID)
|
||||
..add(widget.userID));
|
||||
|
||||
setState(() {
|
||||
_list = list;
|
||||
@ -66,11 +67,7 @@ class _OtherUserFriendsListRouteState extends State<OtherUserFriendsListRoute> {
|
||||
Widget build(BuildContext context) {
|
||||
if (_error) return _buildError();
|
||||
|
||||
if (_list == null)
|
||||
return buildLoadingPage(
|
||||
showAppBar: true,
|
||||
routeTitle: _routeName,
|
||||
);
|
||||
if (_list == null) return buildCenteredProgressBar();
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
@ -79,25 +76,21 @@ class _OtherUserFriendsListRouteState extends State<OtherUserFriendsListRoute> {
|
||||
body: ListView.builder(
|
||||
itemCount: _list.length,
|
||||
itemBuilder: (c, i) => SimpleUserTile(
|
||||
user: _list[i],
|
||||
onTap: (u) => openUserPage(
|
||||
context: context,
|
||||
userID: u.id,
|
||||
),
|
||||
),
|
||||
user: _list[i],
|
||||
onTap: (u) => openUserPage(
|
||||
context: context,
|
||||
userID: u.id,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildError() {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(_routeName),
|
||||
),
|
||||
body: buildErrorCard(
|
||||
tr(
|
||||
"Could not get the list of friends of %name% !",
|
||||
args: {"name": widget.user.displayName},
|
||||
"Could not get the list of friends of this user !",
|
||||
),
|
||||
actions: [
|
||||
FlatButton(
|
@ -17,7 +17,9 @@ enum BarCallbackActions {
|
||||
OPEN_MY_PAGE,
|
||||
OPEN_GROUPS,
|
||||
OPEN_GROUP_PAGE,
|
||||
OPEN_USER_PAGE,
|
||||
OPEN_APP_SETTINGS,
|
||||
OPEN_USER_FRIENDS_LIST,
|
||||
OPEN_ABOUT_DIALOG,
|
||||
NONE,
|
||||
ACTION_LOGOUT
|
||||
|
@ -1,7 +1,6 @@
|
||||
import 'package:comunic/helpers/virtual_directory_helper.dart';
|
||||
import 'package:comunic/ui/routes/home_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/ui_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@ -16,13 +15,7 @@ void openUserPage({@required int userID, @required BuildContext context}) {
|
||||
assert(userID != null);
|
||||
assert(context != null);
|
||||
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (c) => UserPageRoute(
|
||||
userID: userID,
|
||||
),
|
||||
),
|
||||
);
|
||||
HomeController.of(context).openUserPage(userID);
|
||||
}
|
||||
|
||||
/// Open a post in full screen
|
||||
|
Loading…
Reference in New Issue
Block a user