2021-01-16 12:46:38 +01:00
|
|
|
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
|
|
|
|
import 'package:famedlysdk/famedlysdk.dart';
|
|
|
|
import 'package:fluffychat/components/matrix.dart';
|
|
|
|
import 'package:fluffychat/views/archive.dart';
|
|
|
|
import 'package:fluffychat/views/chat.dart';
|
|
|
|
import 'package:fluffychat/views/chat_details.dart';
|
|
|
|
import 'package:fluffychat/views/chat_encryption_settings.dart';
|
2021-02-13 11:55:22 +01:00
|
|
|
import 'package:fluffychat/views/chat_list.dart';
|
2021-01-16 12:46:38 +01:00
|
|
|
import 'package:fluffychat/views/chat_permissions_settings.dart';
|
|
|
|
import 'package:fluffychat/views/empty_page.dart';
|
|
|
|
import 'package:fluffychat/views/homeserver_picker.dart';
|
|
|
|
import 'package:fluffychat/views/invitation_selection.dart';
|
|
|
|
import 'package:fluffychat/views/loading_view.dart';
|
|
|
|
import 'package:fluffychat/views/log_view.dart';
|
|
|
|
import 'package:fluffychat/views/login.dart';
|
|
|
|
import 'package:fluffychat/views/new_group.dart';
|
|
|
|
import 'package:fluffychat/views/new_private_chat.dart';
|
2021-03-27 18:04:31 +01:00
|
|
|
import 'package:fluffychat/views/search_view.dart';
|
2021-02-13 11:55:22 +01:00
|
|
|
import 'package:fluffychat/views/settings.dart';
|
2021-01-16 12:46:38 +01:00
|
|
|
import 'package:fluffychat/views/settings_3pid.dart';
|
|
|
|
import 'package:fluffychat/views/settings_devices.dart';
|
|
|
|
import 'package:fluffychat/views/settings_emotes.dart';
|
|
|
|
import 'package:fluffychat/views/settings_ignore_list.dart';
|
|
|
|
import 'package:fluffychat/views/settings_multiple_emotes.dart';
|
|
|
|
import 'package:fluffychat/views/settings_notifications.dart';
|
|
|
|
import 'package:fluffychat/views/settings_style.dart';
|
|
|
|
import 'package:fluffychat/views/sign_up.dart';
|
|
|
|
import 'package:fluffychat/views/sign_up_password.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
class FluffyRoutes {
|
|
|
|
final BuildContext context;
|
|
|
|
|
|
|
|
const FluffyRoutes(this.context);
|
|
|
|
|
|
|
|
ViewData onGenerateRoute(RouteSettings settings) {
|
|
|
|
final parts = settings.name.split('/');
|
|
|
|
|
|
|
|
// Routes if the app is loading
|
|
|
|
if (Matrix.of(context).loginState == null) {
|
|
|
|
return ViewData(mainView: (_) => LoadingView());
|
|
|
|
// Routes if user is NOT logged in
|
|
|
|
} else if (Matrix.of(context).loginState == LoginState.loggedOut) {
|
|
|
|
switch (parts[1]) {
|
|
|
|
case '':
|
|
|
|
return ViewData(mainView: (_) => HomeserverPicker());
|
|
|
|
case 'login':
|
|
|
|
return ViewData(mainView: (_) => Login());
|
|
|
|
case 'signup':
|
|
|
|
if (parts.length == 5 && parts[2] == 'password') {
|
|
|
|
return ViewData(
|
|
|
|
mainView: (_) => SignUpPassword(
|
|
|
|
parts[3],
|
|
|
|
displayname: parts[4],
|
|
|
|
avatar: settings.arguments,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return ViewData(mainView: (_) => SignUp());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Routes IF user is logged in
|
|
|
|
else {
|
2021-02-23 15:15:54 +01:00
|
|
|
final activeRoomId = Matrix.of(context).client.activeRoomId;
|
2021-01-16 12:46:38 +01:00
|
|
|
switch (parts[1]) {
|
|
|
|
case '':
|
|
|
|
return ViewData(
|
2021-02-13 11:55:22 +01:00
|
|
|
mainView: (_) => ChatList(),
|
2021-02-25 07:40:01 +01:00
|
|
|
emptyView: (_) =>
|
|
|
|
activeRoomId != null ? Chat(activeRoomId) : EmptyPage(),
|
2021-01-16 12:46:38 +01:00
|
|
|
);
|
|
|
|
case 'rooms':
|
2021-01-19 17:41:37 +01:00
|
|
|
final roomId = parts[2];
|
2021-01-16 12:46:38 +01:00
|
|
|
if (parts.length == 3) {
|
|
|
|
return ViewData(
|
2021-02-13 11:55:22 +01:00
|
|
|
leftView: (_) => ChatList(activeChat: roomId),
|
2021-01-19 17:41:37 +01:00
|
|
|
mainView: (_) => Chat(roomId),
|
2021-01-16 12:46:38 +01:00
|
|
|
);
|
|
|
|
} else if (parts.length == 4) {
|
|
|
|
final action = parts[3];
|
|
|
|
switch (action) {
|
|
|
|
case 'details':
|
|
|
|
return ViewData(
|
2021-02-13 11:55:22 +01:00
|
|
|
leftView: (_) => ChatList(activeChat: roomId),
|
2021-01-19 17:41:37 +01:00
|
|
|
mainView: (_) => Chat(roomId),
|
2021-01-16 12:46:38 +01:00
|
|
|
rightView: (_) => ChatDetails(roomId),
|
|
|
|
);
|
|
|
|
case 'encryption':
|
|
|
|
return ViewData(
|
2021-02-13 11:55:22 +01:00
|
|
|
leftView: (_) => ChatList(activeChat: roomId),
|
2021-01-19 17:41:37 +01:00
|
|
|
mainView: (_) => Chat(roomId),
|
2021-01-16 12:46:38 +01:00
|
|
|
rightView: (_) => ChatEncryptionSettings(roomId),
|
|
|
|
);
|
|
|
|
case 'permissions':
|
|
|
|
return ViewData(
|
2021-02-13 11:55:22 +01:00
|
|
|
leftView: (_) => ChatList(activeChat: roomId),
|
2021-01-19 17:41:37 +01:00
|
|
|
mainView: (_) => Chat(roomId),
|
2021-01-16 12:46:38 +01:00
|
|
|
rightView: (_) => ChatPermissionsSettings(roomId),
|
|
|
|
);
|
|
|
|
case 'invite':
|
|
|
|
return ViewData(
|
2021-02-13 11:55:22 +01:00
|
|
|
leftView: (_) => ChatList(activeChat: roomId),
|
2021-01-19 17:41:37 +01:00
|
|
|
mainView: (_) => Chat(roomId),
|
2021-01-16 12:46:38 +01:00
|
|
|
rightView: (_) => InvitationSelection(roomId),
|
|
|
|
);
|
|
|
|
case 'emotes':
|
|
|
|
return ViewData(
|
2021-02-13 11:55:22 +01:00
|
|
|
leftView: (_) => ChatList(activeChat: roomId),
|
2021-01-19 17:41:37 +01:00
|
|
|
mainView: (_) => Chat(roomId),
|
2021-01-16 12:46:38 +01:00
|
|
|
rightView: (_) => MultipleEmotesSettings(roomId),
|
|
|
|
);
|
2021-01-19 17:41:37 +01:00
|
|
|
default:
|
|
|
|
return ViewData(
|
2021-02-13 11:55:22 +01:00
|
|
|
leftView: (_) => ChatList(activeChat: roomId),
|
2021-01-19 17:41:37 +01:00
|
|
|
mainView: (_) => Chat(roomId,
|
|
|
|
scrollToEventId: action.sigil == '\$' ? action : null),
|
|
|
|
);
|
2021-01-16 12:46:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ViewData(
|
2021-02-13 11:55:22 +01:00
|
|
|
mainView: (_) => ChatList(),
|
2021-02-25 07:40:01 +01:00
|
|
|
emptyView: (_) =>
|
|
|
|
activeRoomId != null ? Chat(activeRoomId) : EmptyPage(),
|
2021-01-16 12:46:38 +01:00
|
|
|
);
|
|
|
|
case 'archive':
|
|
|
|
return ViewData(
|
2021-02-25 07:40:01 +01:00
|
|
|
leftView: (_) => Settings(),
|
2021-01-16 12:46:38 +01:00
|
|
|
mainView: (_) => Archive(),
|
|
|
|
);
|
|
|
|
case 'logs':
|
|
|
|
return ViewData(
|
|
|
|
mainView: (_) => LogViewer(),
|
|
|
|
);
|
|
|
|
case 'newgroup':
|
|
|
|
return ViewData(
|
2021-02-13 11:55:22 +01:00
|
|
|
leftView: (_) => ChatList(),
|
2021-01-16 12:46:38 +01:00
|
|
|
mainView: (_) => NewGroup(),
|
|
|
|
);
|
|
|
|
case 'newprivatechat':
|
|
|
|
return ViewData(
|
2021-02-13 11:55:22 +01:00
|
|
|
leftView: (_) => ChatList(),
|
2021-01-16 12:46:38 +01:00
|
|
|
mainView: (_) => NewPrivateChat(),
|
|
|
|
);
|
2021-03-27 18:04:31 +01:00
|
|
|
case 'search':
|
2021-02-13 11:55:22 +01:00
|
|
|
if (parts.length == 3) {
|
|
|
|
return ViewData(
|
2021-03-27 18:04:31 +01:00
|
|
|
mainView: (_) => SearchView(alias: parts[2]),
|
2021-02-23 15:15:54 +01:00
|
|
|
emptyView: (_) =>
|
|
|
|
activeRoomId != null ? Chat(activeRoomId) : EmptyPage(),
|
2021-02-13 11:55:22 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return ViewData(
|
2021-03-27 18:04:31 +01:00
|
|
|
mainView: (_) => SearchView(),
|
2021-02-25 07:40:01 +01:00
|
|
|
emptyView: (_) =>
|
|
|
|
activeRoomId != null ? Chat(activeRoomId) : EmptyPage(),
|
2021-02-13 11:55:22 +01:00
|
|
|
);
|
2021-01-16 12:46:38 +01:00
|
|
|
case 'settings':
|
|
|
|
if (parts.length == 3) {
|
|
|
|
final action = parts[2];
|
|
|
|
switch (action) {
|
|
|
|
case '3pid':
|
|
|
|
return ViewData(
|
2021-02-13 11:55:22 +01:00
|
|
|
leftView: (_) => Settings(),
|
2021-01-16 12:46:38 +01:00
|
|
|
mainView: (_) => Settings3Pid(),
|
|
|
|
);
|
|
|
|
case 'devices':
|
|
|
|
return ViewData(
|
2021-02-13 11:55:22 +01:00
|
|
|
leftView: (_) => Settings(),
|
2021-01-16 12:46:38 +01:00
|
|
|
mainView: (_) => DevicesSettings(),
|
|
|
|
);
|
|
|
|
case 'emotes':
|
|
|
|
return ViewData(
|
2021-02-13 11:55:22 +01:00
|
|
|
leftView: (_) => Settings(),
|
2021-02-01 16:25:28 +01:00
|
|
|
mainView: (_) => EmotesSettings(
|
2021-02-02 11:24:37 +01:00
|
|
|
room: ((settings.arguments ?? {}) as Map)['room'],
|
|
|
|
stateKey: ((settings.arguments ?? {}) as Map)['stateKey'],
|
2021-02-01 16:25:28 +01:00
|
|
|
),
|
2021-01-16 12:46:38 +01:00
|
|
|
);
|
|
|
|
case 'ignore':
|
|
|
|
return ViewData(
|
2021-02-13 11:55:22 +01:00
|
|
|
leftView: (_) => Settings(),
|
2021-02-02 09:00:06 +01:00
|
|
|
mainView: (_) => SettingsIgnoreList(
|
|
|
|
initialUserId: settings.arguments,
|
|
|
|
),
|
2021-01-16 12:46:38 +01:00
|
|
|
);
|
|
|
|
case 'notifications':
|
|
|
|
return ViewData(
|
2021-02-13 11:55:22 +01:00
|
|
|
leftView: (_) => Settings(),
|
2021-01-16 12:46:38 +01:00
|
|
|
mainView: (_) => SettingsNotifications(),
|
|
|
|
);
|
|
|
|
case 'style':
|
|
|
|
return ViewData(
|
2021-02-13 11:55:22 +01:00
|
|
|
leftView: (_) => Settings(),
|
2021-01-16 12:46:38 +01:00
|
|
|
mainView: (_) => SettingsStyle(),
|
|
|
|
);
|
|
|
|
}
|
2021-02-13 11:55:22 +01:00
|
|
|
} else {
|
|
|
|
return ViewData(
|
|
|
|
mainView: (_) => Settings(),
|
2021-02-23 15:15:54 +01:00
|
|
|
emptyView: (_) =>
|
|
|
|
activeRoomId != null ? Chat(activeRoomId) : EmptyPage(),
|
2021-02-13 11:55:22 +01:00
|
|
|
);
|
2021-01-16 12:46:38 +01:00
|
|
|
}
|
|
|
|
return ViewData(
|
2021-02-13 11:55:22 +01:00
|
|
|
mainView: (_) => ChatList(),
|
2021-02-23 15:15:54 +01:00
|
|
|
emptyView: (_) =>
|
|
|
|
activeRoomId != null ? Chat(activeRoomId) : EmptyPage(),
|
2021-01-16 12:46:38 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If route cant be found:
|
|
|
|
return ViewData(
|
|
|
|
mainView: (_) => Center(
|
|
|
|
child: Text('Route "${settings.name}" not found...'),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class SettingsDevices {}
|
|
|
|
|
|
|
|
class FadeRoute extends PageRouteBuilder {
|
|
|
|
final Widget page;
|
|
|
|
FadeRoute({this.page})
|
|
|
|
: super(
|
|
|
|
pageBuilder: (
|
|
|
|
BuildContext context,
|
|
|
|
Animation<double> animation,
|
|
|
|
Animation<double> secondaryAnimation,
|
|
|
|
) =>
|
|
|
|
page,
|
|
|
|
transitionsBuilder: (
|
|
|
|
BuildContext context,
|
|
|
|
Animation<double> animation,
|
|
|
|
Animation<double> secondaryAnimation,
|
|
|
|
Widget child,
|
|
|
|
) =>
|
|
|
|
FadeTransition(
|
|
|
|
opacity: animation,
|
|
|
|
child: child,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|