Skip to content

Commit

Permalink
TW-613: Add Settings to navigator bottom and hide Stories
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev committed Sep 20, 2023
1 parent 6dddb42 commit 3e2c245
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 138 deletions.
191 changes: 82 additions & 109 deletions lib/config/go_routes/go_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import 'package:fluffychat/pages/invitation_selection/invitation_selection.dart'
import 'package:fluffychat/pages/login/login.dart';
import 'package:fluffychat/pages/new_group/new_group.dart';
import 'package:fluffychat/pages/new_private_chat/new_private_chat.dart';
import 'package:fluffychat/pages/settings/settings.dart';
import 'package:fluffychat/pages/settings_3pid/settings_3pid.dart';
import 'package:fluffychat/pages/settings_chat/settings_chat.dart';
import 'package:fluffychat/pages/settings_emotes/settings_emotes.dart';
Expand Down Expand Up @@ -244,121 +243,95 @@ abstract class AppRoutes {
);
},
),
ShellRoute(
pageBuilder: (context, state, child) => defaultPageBuilder(
GoRoute(
path: 'notifications',
pageBuilder: (context, state) => defaultPageBuilder(
context,
const SettingsNotifications(),
),
redirect: loggedOutRedirect,
),
GoRoute(
path: 'style',
pageBuilder: (context, state) => defaultPageBuilder(
context,
const SettingsStyle(),
),
redirect: loggedOutRedirect,
),
GoRoute(
path: 'devices',
pageBuilder: (context, state) => defaultPageBuilder(
context,
const DevicesSettings(),
),
redirect: loggedOutRedirect,
),
GoRoute(
path: 'chat',
pageBuilder: (context, state) => defaultPageBuilder(
context,
!_responsive.isMobile(context)
? AdaptiveScaffoldRoute(
displayAppBar: false,
body: const Settings(),
secondaryBody: child,
)
: child,
const SettingsChat(),
),
routes: [
GoRoute(
path: 'settings',
path: 'emotes',
pageBuilder: (context, state) => defaultPageBuilder(
context,
!_responsive.isMobile(context)
? const ChatBlank()
: const Settings(),
const EmotesSettings(),
),
),
],
redirect: loggedOutRedirect,
),
GoRoute(
path: 'addaccount',
redirect: loggedOutRedirect,
pageBuilder: (context, state) => defaultPageBuilder(
context,
const HomeserverPicker(),
),
routes: [
GoRoute(
path: 'login',
pageBuilder: (context, state) => defaultPageBuilder(
context,
const Login(),
),
redirect: loggedOutRedirect,
),
],
),
GoRoute(
path: 'security',
redirect: loggedOutRedirect,
pageBuilder: (context, state) => defaultPageBuilder(
context,
const SettingsSecurity(),
),
routes: [
GoRoute(
path: 'stories',
pageBuilder: (context, state) => defaultPageBuilder(
context,
const SettingsStories(),
),
redirect: loggedOutRedirect,
),
GoRoute(
path: 'ignorelist',
pageBuilder: (context, state) => defaultPageBuilder(
context,
const SettingsIgnoreList(),
),
redirect: loggedOutRedirect,
),
GoRoute(
path: '3pid',
pageBuilder: (context, state) => defaultPageBuilder(
context,
const Settings3Pid(),
),
routes: [
GoRoute(
path: 'notifications',
pageBuilder: (context, state) => defaultPageBuilder(
context,
const SettingsNotifications(),
),
redirect: loggedOutRedirect,
),
GoRoute(
path: 'style',
pageBuilder: (context, state) => defaultPageBuilder(
context,
const SettingsStyle(),
),
redirect: loggedOutRedirect,
),
GoRoute(
path: 'devices',
pageBuilder: (context, state) => defaultPageBuilder(
context,
const DevicesSettings(),
),
redirect: loggedOutRedirect,
),
GoRoute(
path: 'chat',
pageBuilder: (context, state) => defaultPageBuilder(
context,
const SettingsChat(),
),
routes: [
GoRoute(
path: 'emotes',
pageBuilder: (context, state) => defaultPageBuilder(
context,
const EmotesSettings(),
),
),
],
redirect: loggedOutRedirect,
),
GoRoute(
path: 'addaccount',
redirect: loggedOutRedirect,
pageBuilder: (context, state) => defaultPageBuilder(
context,
const HomeserverPicker(),
),
routes: [
GoRoute(
path: 'login',
pageBuilder: (context, state) => defaultPageBuilder(
context,
const Login(),
),
redirect: loggedOutRedirect,
),
],
),
GoRoute(
path: 'security',
redirect: loggedOutRedirect,
pageBuilder: (context, state) => defaultPageBuilder(
context,
const SettingsSecurity(),
),
routes: [
GoRoute(
path: 'stories',
pageBuilder: (context, state) => defaultPageBuilder(
context,
const SettingsStories(),
),
redirect: loggedOutRedirect,
),
GoRoute(
path: 'ignorelist',
pageBuilder: (context, state) => defaultPageBuilder(
context,
const SettingsIgnoreList(),
),
redirect: loggedOutRedirect,
),
GoRoute(
path: '3pid',
pageBuilder: (context, state) => defaultPageBuilder(
context,
const Settings3Pid(),
),
redirect: loggedOutRedirect,
),
],
),
],
redirect: loggedOutRedirect,
),
],
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/forward/forward.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import 'package:fluffychat/di/global/get_it_initializer.dart';
import 'package:fluffychat/domain/app_state/forward/forward_message_state.dart';
import 'package:fluffychat/domain/usecase/forward/forward_message_interactor.dart';
import 'package:fluffychat/pages/chat/send_file_dialog.dart';
import 'package:fluffychat/pages/chat_list/chat_list.dart';
import 'package:fluffychat/pages/forward/forward_view.dart';
import 'package:fluffychat/presentation/enum/chat_list/chat_list_enum.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/client_stories_extension.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
Expand Down
27 changes: 18 additions & 9 deletions lib/pages/settings/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ import '../bootstrap/bootstrap_dialog.dart';
import 'settings_view.dart';

class Settings extends StatefulWidget {
const Settings({Key? key}) : super(key: key);
final Widget? bottomNavigationBar;

const Settings({
super.key,
this.bottomNavigationBar,
});

@override
SettingsController createState() => SettingsController();
Expand Down Expand Up @@ -163,8 +168,15 @@ class SettingsController extends State<Settings> with ConnectPageMixin {

@override
void initState() {
WidgetsBinding.instance.addPostFrameCallback((_) => checkBootstrap());

WidgetsBinding.instance.addPostFrameCallback((_) {
final client = Matrix.of(context).client;
profileFuture ??= client.getProfileFromUserId(
client.userID!,
cache: !profileUpdated,
getFromRooms: !profileUpdated,
);
checkBootstrap();
});
super.initState();
}

Expand Down Expand Up @@ -209,13 +221,10 @@ class SettingsController extends State<Settings> with ConnectPageMixin {

@override
Widget build(BuildContext context) {
final client = Matrix.of(context).client;
profileFuture ??= client.getProfileFromUserId(
client.userID!,
cache: !profileUpdated,
getFromRooms: !profileUpdated,
return SettingsView(
this,
bottomNavigationBar: widget.bottomNavigationBar,
);
return SettingsView(this);
}
}

Expand Down
23 changes: 11 additions & 12 deletions lib/pages/settings/settings_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,19 @@ import 'settings.dart';

class SettingsView extends StatelessWidget {
final SettingsController controller;
final Widget? bottomNavigationBar;

const SettingsView(this.controller, {Key? key}) : super(key: key);
const SettingsView(
this.controller, {
super.key,
this.bottomNavigationBar,
});

@override
Widget build(BuildContext context) {
final showChatBackupBanner = controller.showChatBackupBanner;
return Scaffold(
appBar: AppBar(
leading: CloseButton(
onPressed: () {
if (context.canPop()) {
context.pop();
}
},
),
title: Text(L10n.of(context)!.settings),
actions: [
TextButton.icon(
Expand All @@ -37,6 +35,7 @@ class SettingsView extends StatelessWidget {
),
],
),
bottomNavigationBar: bottomNavigationBar,
body: ListTileTheme(
iconColor: Theme.of(context).colorScheme.onBackground,
child: ListView(
Expand Down Expand Up @@ -162,25 +161,25 @@ class SettingsView extends StatelessWidget {
ListTile(
leading: const Icon(Icons.notifications_outlined),
title: Text(L10n.of(context)!.notifications),
onTap: () => context.go('/rooms/settings/notifications'),
onTap: () => context.go('/rooms/notifications'),
trailing: const Icon(Icons.chevron_right_outlined),
),
ListTile(
leading: const Icon(Icons.devices_outlined),
title: Text(L10n.of(context)!.devices),
onTap: () => context.go('/rooms/settings/devices'),
onTap: () => context.go('/rooms/devices'),
trailing: const Icon(Icons.chevron_right_outlined),
),
ListTile(
leading: const Icon(Icons.chat_bubble_outline_outlined),
title: Text(L10n.of(context)!.chat),
onTap: () => context.go('/rooms/settings/chat'),
onTap: () => context.go('/rooms/chat'),
trailing: const Icon(Icons.chevron_right_outlined),
),
ListTile(
leading: const Icon(Icons.shield_outlined),
title: Text(L10n.of(context)!.security),
onTap: () => context.go('/rooms/settings/security'),
onTap: () => context.go('/rooms/security'),
trailing: const Icon(Icons.chevron_right_outlined),
),
const Divider(thickness: 1),
Expand Down
6 changes: 5 additions & 1 deletion lib/widgets/layouts/adaptive_layout/adaptive_scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AdaptiveScaffoldAppController extends State<AdaptiveScaffoldApp> {
ValueNotifier<AdaptiveDestinationEnum>(AdaptiveDestinationEnum.rooms);

final PageController pageController =
PageController(initialPage: 1, keepPage: false);
PageController(initialPage: 1, keepPage: true);

Future<Profile?> fetchOwnProfile() {
if (!profileMemoizers.containsKey(matrix.client)) {
Expand All @@ -53,6 +53,10 @@ class AdaptiveScaffoldAppController extends State<AdaptiveScaffoldApp> {
activeNavigationBar.value = AdaptiveDestinationEnum.rooms;
pageController.jumpToPage(index);
break;
case 2:
activeNavigationBar.value = AdaptiveDestinationEnum.settings;
pageController.jumpToPage(index);
break;
default:
break;
}
Expand Down
14 changes: 9 additions & 5 deletions lib/widgets/layouts/adaptive_layout/adaptive_scaffold_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:fluffychat/di/global/get_it_initializer.dart';
import 'package:fluffychat/pages/chat_list/chat_list.dart';
import 'package:fluffychat/pages/contacts_tab/contacts_tab.dart';
import 'package:fluffychat/pages/search/search.dart';
import 'package:fluffychat/pages/settings/settings.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/client_stories_extension.dart';
import 'package:fluffychat/utils/responsive/responsive_utils.dart';
import 'package:fluffychat/widgets/layouts/adaptive_layout/adaptive_scaffold_primary_navigation.dart';
Expand Down Expand Up @@ -105,8 +106,11 @@ class AppScaffoldView extends StatelessWidget {
onOpenSearchPage: onOpenSearchPage,
),
_triggerPageViewBuilder(
navigatorBarType: AdaptiveDestinationEnum.stories,
navigatorBarWidget: const SizedBox(),
navigatorBarType: AdaptiveDestinationEnum.settings,
navigatorBarWidget: Settings(
bottomNavigationBar:
_bottomNavigationBarBuilder(context),
),
),
_triggerPageViewBuilder(
navigatorBarType: AdaptiveDestinationEnum.search,
Expand Down Expand Up @@ -174,7 +178,7 @@ class AppScaffoldView extends StatelessWidget {
return 0;
case AdaptiveDestinationEnum.rooms:
return 1;
case AdaptiveDestinationEnum.stories:
case AdaptiveDestinationEnum.settings:
return 2;
default:
return 1;
Expand Down Expand Up @@ -211,9 +215,9 @@ class AppScaffoldView extends StatelessWidget {
),
NavigationDestination(
icon: const TwakeNavigationIcon(
icon: Icons.web_stories_outlined,
icon: Icons.settings,
),
label: L10n.of(context)!.stories,
label: L10n.of(context)!.settings,
),
];
}
Expand Down
Loading

0 comments on commit 3e2c245

Please sign in to comment.