1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-26 06:49:22 +00:00

Add more actions

This commit is contained in:
Pierre HUBERT 2020-05-16 17:21:33 +02:00
parent e7181c1f59
commit bf2ba03912
4 changed files with 105 additions and 22 deletions

View File

@ -162,6 +162,8 @@ class UsersHelper {
customEmojies: _parseCustomEmojies(data["customEmojis"]),
publicNote: data["publicNote"],
canPostTexts: data["can_post_texts"],
isFriendsListPublic: data["friend_list_public"],
numberFriends: data["number_friends"],
likes: data["pageLikes"],
userLike: data["user_like_page"],
);

View File

@ -12,6 +12,8 @@ import 'package:meta/meta.dart';
class AdvancedUserInfo extends User implements LikeElement {
final String publicNote;
final bool canPostTexts;
final bool isFriendsListPublic;
final int numberFriends;
bool userLike;
int likes;
@ -25,10 +27,14 @@ class AdvancedUserInfo extends User implements LikeElement {
@required CustomEmojiesList customEmojies,
@required this.publicNote,
@required this.canPostTexts,
@required this.isFriendsListPublic,
@required this.numberFriends,
@required this.userLike,
@required this.likes,
}) : assert(publicNote != null),
assert(canPostTexts != null),
assert(isFriendsListPublic != null),
assert(numberFriends != null),
assert(userLike != null),
assert(likes != null),
super(

View File

@ -1,9 +1,12 @@
import 'package:comunic/helpers/friends_helper.dart';
import 'package:comunic/helpers/users_helper.dart';
import 'package:comunic/models/advanced_user_info.dart';
import 'package:comunic/models/friend_status.dart';
import 'package:comunic/ui/routes/main_route/main_route.dart';
import 'package:comunic/ui/widgets/mobile_mode/user_page_mobile.dart';
import 'package:comunic/ui/widgets/safe_state.dart';
import 'package:comunic/ui/widgets/tablet_mode/user_page_tablet.dart';
import 'package:comunic/utils/account_utils.dart';
import 'package:comunic/utils/intl_utils.dart';
import 'package:comunic/utils/ui_utils.dart';
import 'package:flutter/material.dart';
@ -32,6 +35,7 @@ class _UserPageScreenState extends SafeState<UserPageScreen> {
// Objects members
_PageStatus _status = _PageStatus.LOADING;
AdvancedUserInfo _userInfo;
FriendStatus _frienshipStatus;
final _refreshIndicatorKey = GlobalKey<RefreshIndicatorState>();
_setStatus(_PageStatus s) => setState(() => _status = s);
@ -47,9 +51,13 @@ class _UserPageScreenState extends SafeState<UserPageScreen> {
try {
final user = await usersHelper.getAdvancedInfo(widget.userID);
final status = widget.userID == userID()
? null
: await FriendsHelper().getFriendshipStatus(widget.userID);
setState(() {
_userInfo = user;
_frienshipStatus = status;
});
_setStatus(_PageStatus.READY);
@ -61,6 +69,9 @@ class _UserPageScreenState extends SafeState<UserPageScreen> {
controller.popPage();
controller.openUserAccessDeniedPage(widget.userID);
}
} catch (e, s) {
print("Could not refresh user information! $e\n$s");
_setStatus(_PageStatus.ERROR);
}
}
@ -104,6 +115,7 @@ class _UserPageScreenState extends SafeState<UserPageScreen> {
? UserPageTablet(
userInfo: _userInfo,
onNeedRefresh: () => _refreshIndicatorKey.currentState.show(),
friendshipStatus: _frienshipStatus,
)
: UserMobilePage(
userInfo: _userInfo,

View File

@ -1,10 +1,15 @@
import 'package:comunic/enums/post_target.dart';
import 'package:comunic/helpers/posts_helper.dart';
import 'package:comunic/models/advanced_user_info.dart';
import 'package:comunic/models/friend_status.dart';
import 'package:comunic/ui/routes/main_route/main_route.dart';
import 'package:comunic/ui/widgets/FrienshipStatusWidget.dart';
import 'package:comunic/ui/widgets/account_image_widget.dart';
import 'package:comunic/ui/widgets/like_widget.dart';
import 'package:comunic/ui/widgets/post_create_form_widget.dart';
import 'package:comunic/ui/widgets/posts_list_widget.dart';
import 'package:comunic/utils/account_utils.dart';
import 'package:comunic/utils/conversations_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
@ -14,11 +19,13 @@ import 'package:flutter/rendering.dart';
class UserPageTablet extends StatefulWidget {
final AdvancedUserInfo userInfo;
final FriendStatus friendshipStatus;
final void Function() onNeedRefresh;
const UserPageTablet({
Key key,
@required this.userInfo,
@required this.friendshipStatus,
@required this.onNeedRefresh,
}) : assert(userInfo != null),
assert(onNeedRefresh != null),
@ -31,6 +38,8 @@ class UserPageTablet extends StatefulWidget {
class _UserPageTabletState extends State<UserPageTablet> {
AdvancedUserInfo get _userInfo => widget.userInfo;
bool get _isCurrentUser => _userInfo.id == userID();
@override
Widget build(BuildContext context) => Flex(
direction: Axis.horizontal,
@ -44,6 +53,7 @@ class _UserPageTabletState extends State<UserPageTablet> {
Widget _buildLeftColumn() => Column(
children: <Widget>[
_buildMainCard(),
_buildActionsCard(),
_buildAboutCard(),
],
);
@ -66,11 +76,7 @@ class _UserPageTabletState extends State<UserPageTablet> {
);
/// Main user information card
Widget _buildMainCard() => ConstrainedBox(
constraints: BoxConstraints(maxWidth: 200),
child: Card(
child: Padding(
padding: const EdgeInsets.all(8.0),
Widget _buildMainCard() => _LeftPaneContainer(
child: Column(
children: <Widget>[
Center(child: AccountImageWidget(user: _userInfo, width: 75)),
@ -87,8 +93,46 @@ class _UserPageTabletState extends State<UserPageTablet> {
: null),
_MainCardSpacer(visible: _userInfo.hasVirtualDirectory),
LikeWidget(likeElement: _userInfo),
_MainCardSpacer(visible: !_isCurrentUser),
_isCurrentUser
? Container()
: FriendshipStatusWidget(
status: widget.friendshipStatus,
onFriendshipUpdated: widget.onNeedRefresh,
)
],
),
);
/// Actions card
Widget _buildActionsCard() => _LeftPaneContainer(
child: ButtonTheme(
minWidth: 30,
padding: EdgeInsets.all(0),
child: Row(
children: <Widget>[
// Friends list of the user
_userInfo.isFriendsListPublic
? Expanded(
child: OutlineButton.icon(
onPressed: () => MainController.of(context)
.openUserFriendsList(_userInfo.id),
icon: Icon(Icons.group),
label: Text("${_userInfo.numberFriends}"),
),
)
: Container(),
// Private messages
!_isCurrentUser
? Expanded(
child: OutlineButton(
onPressed: () =>
openPrivateConversation(context, _userInfo.id),
child: Icon(Icons.message),
))
: Container(),
],
),
),
);
@ -97,6 +141,25 @@ class _UserPageTabletState extends State<UserPageTablet> {
Widget _buildAboutCard() => Container();
}
class _LeftPaneContainer extends StatelessWidget {
final Widget child;
const _LeftPaneContainer({Key key, this.child}) : super(key: key);
@override
Widget build(BuildContext context) {
return ConstrainedBox(
constraints: BoxConstraints(maxWidth: 200),
child: Card(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: child,
),
),
);
}
}
class _MainCardSpacer extends StatelessWidget {
final bool visible;