diff --git a/filcnaplo_mobile_ui/lib/common/profile_image/profile_button.dart b/filcnaplo_mobile_ui/lib/common/profile_image/profile_button.dart index 12c68f6..b685862 100755 --- a/filcnaplo_mobile_ui/lib/common/profile_image/profile_button.dart +++ b/filcnaplo_mobile_ui/lib/common/profile_image/profile_button.dart @@ -1,4 +1,15 @@ +import 'package:filcnaplo/api/providers/user_provider.dart'; import 'package:filcnaplo/models/settings.dart'; +import 'package:filcnaplo/models/user.dart'; +import 'package:filcnaplo_kreta_api/client/client.dart'; +import 'package:filcnaplo_kreta_api/providers/absence_provider.dart'; +import 'package:filcnaplo_kreta_api/providers/event_provider.dart'; +import 'package:filcnaplo_kreta_api/providers/exam_provider.dart'; +import 'package:filcnaplo_kreta_api/providers/grade_provider.dart'; +import 'package:filcnaplo_kreta_api/providers/homework_provider.dart'; +import 'package:filcnaplo_kreta_api/providers/message_provider.dart'; +import 'package:filcnaplo_kreta_api/providers/note_provider.dart'; +import 'package:filcnaplo_kreta_api/providers/timetable_provider.dart'; import 'package:filcnaplo_mobile_ui/common/profile_image/profile_image.dart'; import 'package:filcnaplo_mobile_ui/screens/settings/settings_screen.dart'; import 'package:flutter/material.dart'; @@ -15,6 +26,28 @@ class ProfileButton extends StatelessWidget { final bool pMode = Provider.of(context, listen: false).presentationMode; + late UserProvider user; + late User? account; + + Future restore() => Future.wait([ + Provider.of(context, listen: false).restore(), + Provider.of(context, listen: false).restoreUser(), + Provider.of(context, listen: false).restore(), + Provider.of(context, listen: false).restore(), + Provider.of(context, listen: false).restore(), + Provider.of(context, listen: false).restore(), + Provider.of(context, listen: false).restore(), + Provider.of(context, listen: false).restore(), + Provider.of(context, listen: false).refreshLogin(), + ]); + + user = Provider.of(context); + try { + account = user.getUsers()[1]; + } catch (err) { + account = null; + } + return ProfileImage( backgroundColor: !pMode ? child.backgroundColor @@ -48,6 +81,12 @@ class ProfileButton extends StatelessWidget { ), ); }, + onDoubleTap: () { + if (account != null) { + user.setUser(account.id); + restore().then((_) => user.setUser(account!.id)); + } + }, ); } } diff --git a/filcnaplo_mobile_ui/lib/common/profile_image/profile_image.dart b/filcnaplo_mobile_ui/lib/common/profile_image/profile_image.dart index 1ed74b4..9c75d95 100755 --- a/filcnaplo_mobile_ui/lib/common/profile_image/profile_image.dart +++ b/filcnaplo_mobile_ui/lib/common/profile_image/profile_image.dart @@ -10,6 +10,8 @@ class ProfileImage extends StatefulWidget { const ProfileImage({ Key? key, this.onTap, + this.onDoubleTap, + this.onLongPress, this.name, this.backgroundColor, this.radius = 20.0, @@ -21,6 +23,8 @@ class ProfileImage extends StatefulWidget { }) : super(key: key); final void Function()? onTap; + final void Function()? onDoubleTap; + final void Function()? onLongPress; final String? name; final Color? backgroundColor; final double radius; @@ -46,7 +50,10 @@ class _ProfileImageState extends State { void updatePic() { profilePicture = widget.profilePictureString != "" - ? Image.memory(const Base64Decoder().convert(widget.profilePictureString), fit: BoxFit.scaleDown, gaplessPlayback: true) + ? Image.memory( + const Base64Decoder().convert(widget.profilePictureString), + fit: BoxFit.scaleDown, + gaplessPlayback: true) : null; profPicSaved = widget.profilePictureString; } @@ -63,7 +70,8 @@ class _ProfileImageState extends State { } Widget buildWithoutHero(BuildContext context) { - Color color = ColorUtils.foregroundColor(widget.backgroundColor ?? Theme.of(context).scaffoldBackgroundColor); + Color color = ColorUtils.foregroundColor( + widget.backgroundColor ?? Theme.of(context).scaffoldBackgroundColor); Color roleColor; if (Theme.of(context).brightness == Brightness.light) { @@ -78,9 +86,12 @@ class _ProfileImageState extends State { Material( clipBehavior: Clip.hardEdge, shape: const CircleBorder(), - color: widget.backgroundColor ?? AppColors.of(context).text.withOpacity(.15), + color: widget.backgroundColor ?? + AppColors.of(context).text.withOpacity(.15), child: InkWell( onTap: widget.onTap, + onDoubleTap: widget.onDoubleTap, + onLongPress: widget.onLongPress, child: AnimatedContainer( duration: const Duration(milliseconds: 200), height: widget.radius * 2, @@ -88,28 +99,31 @@ class _ProfileImageState extends State { decoration: const BoxDecoration( shape: BoxShape.circle, ), - child: widget.name != null && (widget.name?.trim().length ?? 0) > 0 - ? Center( - child: widget.censored - ? Container( - width: 15, - height: 15, - decoration: BoxDecoration( - color: color.withOpacity(.5), - borderRadius: BorderRadius.circular(8.0), - ), - ) - : profilePicture ?? - Text( - (widget.name?.trim().length ?? 0) > 0 ? (widget.name ?? "?").trim()[0] : "?", - style: TextStyle( - color: color, - fontWeight: FontWeight.w600, - fontSize: 18.0 * (widget.radius / 20.0), - ), - ), - ) - : Container(), + child: + widget.name != null && (widget.name?.trim().length ?? 0) > 0 + ? Center( + child: widget.censored + ? Container( + width: 15, + height: 15, + decoration: BoxDecoration( + color: color.withOpacity(.5), + borderRadius: BorderRadius.circular(8.0), + ), + ) + : profilePicture ?? + Text( + (widget.name?.trim().length ?? 0) > 0 + ? (widget.name ?? "?").trim()[0] + : "?", + style: TextStyle( + color: color, + fontWeight: FontWeight.w600, + fontSize: 18.0 * (widget.radius / 20.0), + ), + ), + ) + : Container(), ), ), ), @@ -121,7 +135,8 @@ class _ProfileImageState extends State { width: widget.radius * 2, child: Container( alignment: Alignment.bottomRight, - child: Icon(Icons.shield, color: roleColor, size: widget.radius / 1.3), + child: Icon(Icons.shield, + color: roleColor, size: widget.radius / 1.3), ), ), ], @@ -129,7 +144,8 @@ class _ProfileImageState extends State { } Widget buildWithHero(BuildContext context) { - Color color = ColorUtils.foregroundColor(widget.backgroundColor ?? Theme.of(context).scaffoldBackgroundColor); + Color color = ColorUtils.foregroundColor( + widget.backgroundColor ?? Theme.of(context).scaffoldBackgroundColor); Color roleColor; if (Theme.of(context).brightness == Brightness.light) { @@ -141,7 +157,9 @@ class _ProfileImageState extends State { Widget child = FittedBox( fit: BoxFit.fitHeight, child: Text( - (widget.name?.trim().length ?? 0) > 0 ? (widget.name ?? "?").trim()[0] : "?", + (widget.name?.trim().length ?? 0) > 0 + ? (widget.name ?? "?").trim()[0] + : "?", style: TextStyle( color: color, fontWeight: FontWeight.w600, @@ -163,7 +181,10 @@ class _ProfileImageState extends State { child: Material( clipBehavior: Clip.hardEdge, shape: const CircleBorder(), - color: profilePicture != null ? Colors.transparent : widget.backgroundColor ?? AppColors.of(context).text.withOpacity(.15), + color: profilePicture != null + ? Colors.transparent + : widget.backgroundColor ?? + AppColors.of(context).text.withOpacity(.15), child: AnimatedContainer( duration: const Duration(milliseconds: 200), height: widget.radius * 2, @@ -204,7 +225,8 @@ class _ProfileImageState extends State { width: widget.radius * 2, child: Container( alignment: Alignment.bottomRight, - child: Icon(Icons.shield, color: roleColor, size: widget.radius / 1.3), + child: Icon(Icons.shield, + color: roleColor, size: widget.radius / 1.3), ), ), ), @@ -216,6 +238,8 @@ class _ProfileImageState extends State { shape: const CircleBorder(), child: InkWell( onTap: widget.onTap, + onDoubleTap: widget.onDoubleTap, + onLongPress: widget.onLongPress, child: SizedBox( height: widget.radius * 2, width: widget.radius * 2, diff --git a/filcnaplo_mobile_ui/lib/screens/settings/accounts/account_view.dart b/filcnaplo_mobile_ui/lib/screens/settings/accounts/account_view.dart index ebbd10e..b26f38d 100755 --- a/filcnaplo_mobile_ui/lib/screens/settings/accounts/account_view.dart +++ b/filcnaplo_mobile_ui/lib/screens/settings/accounts/account_view.dart @@ -1,5 +1,4 @@ import 'package:filcnaplo/models/user.dart'; -import 'package:filcnaplo/utils/color.dart'; import 'package:filcnaplo_mobile_ui/common/bottom_card.dart'; import 'package:filcnaplo_mobile_ui/common/detail.dart'; import 'package:filcnaplo_mobile_ui/common/profile_image/profile_image.dart'; @@ -13,7 +12,8 @@ class AccountView extends StatelessWidget { final User user; - static void show(User user, {required BuildContext context}) => showBottomCard(context: context, child: AccountView(user)); + static void show(User user, {required BuildContext context}) => + showBottomCard(context: context, child: AccountView(user)); @override Widget build(BuildContext context) { @@ -28,7 +28,7 @@ class AccountView extends StatelessWidget { AccountTile( profileImage: ProfileImage( name: _firstName, - backgroundColor: ColorUtils.stringToColor(user.name), + backgroundColor: Theme.of(context).colorScheme.primary, role: user.role, ), name: SelectableText( @@ -41,12 +41,19 @@ class AccountView extends StatelessWidget { ), // User details - Detail(title: "birthdate".i18n, description: DateFormat("yyyy. MM. dd.").format(user.student.birth)), + Detail( + title: "birthdate".i18n, + description: + DateFormat("yyyy. MM. dd.").format(user.student.birth)), Detail(title: "school".i18n, description: user.student.school.name), - if (user.student.className != null) Detail(title: "class".i18n, description: user.student.className!), - if (user.student.address != null) Detail(title: "address".i18n, description: user.student.address!), + if (user.student.className != null) + Detail(title: "class".i18n, description: user.student.className!), + if (user.student.address != null) + Detail(title: "address".i18n, description: user.student.address!), if (user.student.parents.isNotEmpty) - Detail(title: "parents".plural(user.student.parents.length), description: user.student.parents.join(", ")), + Detail( + title: "parents".plural(user.student.parents.length), + description: user.student.parents.join(", ")), ], ), );