2023-01-18 05:34:54 -05:00
|
|
|
import 'dart:ui';
|
|
|
|
|
|
2021-10-23 00:26:50 -04:00
|
|
|
import 'package:flutter/material.dart';
|
2023-01-18 05:34:54 -05:00
|
|
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
|
|
|
|
import 'package:frosty/main.dart';
|
2022-08-31 14:11:45 -04:00
|
|
|
import 'package:frosty/screens/channel/chat/details/chat_details_store.dart';
|
2021-12-27 21:13:46 -05:00
|
|
|
import 'package:frosty/screens/channel/chat/details/chat_modes.dart';
|
|
|
|
|
import 'package:frosty/screens/channel/chat/details/chat_users_list.dart';
|
2022-08-31 14:11:45 -04:00
|
|
|
import 'package:frosty/screens/channel/chat/stores/chat_store.dart';
|
2023-01-18 05:34:54 -05:00
|
|
|
import 'package:frosty/screens/settings/settings.dart';
|
2023-10-22 18:38:32 -04:00
|
|
|
import 'package:frosty/widgets/section_header.dart';
|
|
|
|
|
import 'package:intl/intl.dart';
|
2021-10-23 00:26:50 -04:00
|
|
|
|
2023-04-29 22:49:50 -04:00
|
|
|
class ChatDetails extends StatelessWidget {
|
2022-07-01 17:15:07 -04:00
|
|
|
final ChatDetailsStore chatDetailsStore;
|
2022-03-25 21:45:16 -04:00
|
|
|
final ChatStore chatStore;
|
2021-12-27 21:13:46 -05:00
|
|
|
final String userLogin;
|
2021-10-23 00:26:50 -04:00
|
|
|
|
2021-12-27 21:13:46 -05:00
|
|
|
const ChatDetails({
|
|
|
|
|
Key? key,
|
2022-07-01 17:15:07 -04:00
|
|
|
required this.chatDetailsStore,
|
2022-03-25 21:45:16 -04:00
|
|
|
required this.chatStore,
|
2021-12-27 21:13:46 -05:00
|
|
|
required this.userLogin,
|
|
|
|
|
}) : super(key: key);
|
2021-10-23 00:26:50 -04:00
|
|
|
|
2023-10-22 18:38:32 -04:00
|
|
|
String formatDuration(Duration duration) {
|
|
|
|
|
if (duration.inMinutes < 60) {
|
|
|
|
|
return '${duration.inMinutes} ${Intl.plural(duration.inMinutes, one: 'minute', other: 'minutes')}';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return '${duration.inHours} ${Intl.plural(duration.inHours, one: 'hour', other: 'hours')}';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String formatTimeLeft(Duration duration) {
|
|
|
|
|
final hours = duration.inHours;
|
|
|
|
|
final minutes = duration.inMinutes.remainder(60);
|
|
|
|
|
final seconds = duration.inSeconds.remainder(60);
|
|
|
|
|
|
|
|
|
|
if (hours > 0) {
|
|
|
|
|
return '${hours}h ${minutes}m left';
|
|
|
|
|
} else if (minutes > 0) {
|
|
|
|
|
return '${minutes}m ${seconds}s left';
|
|
|
|
|
} else {
|
|
|
|
|
return '${seconds}s left';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _showSleepTimer(BuildContext context) {
|
|
|
|
|
const durations = [
|
|
|
|
|
Duration(minutes: 5),
|
|
|
|
|
Duration(minutes: 10),
|
|
|
|
|
Duration(minutes: 15),
|
|
|
|
|
Duration(minutes: 30),
|
|
|
|
|
Duration(hours: 1),
|
|
|
|
|
Duration(hours: 2),
|
|
|
|
|
Duration(hours: 3),
|
|
|
|
|
Duration(hours: 4),
|
|
|
|
|
Duration(hours: 5),
|
|
|
|
|
Duration(hours: 6),
|
|
|
|
|
Duration(hours: 7),
|
|
|
|
|
Duration(hours: 8),
|
|
|
|
|
Duration(hours: 9),
|
|
|
|
|
Duration(hours: 10),
|
|
|
|
|
Duration(hours: 11),
|
|
|
|
|
Duration(hours: 12),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return showModalBottomSheet(
|
2023-01-18 05:34:54 -05:00
|
|
|
context: context,
|
2023-10-22 18:38:32 -04:00
|
|
|
builder: (context) => Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
const SectionHeader(
|
|
|
|
|
'Sleep timer',
|
|
|
|
|
padding: EdgeInsets.fromLTRB(16, 0, 16, 4),
|
2023-01-18 05:34:54 -05:00
|
|
|
),
|
2023-10-22 18:38:32 -04:00
|
|
|
Expanded(
|
|
|
|
|
child: ListView(
|
|
|
|
|
children: [
|
|
|
|
|
if (chatStore.sleepTimer?.isActive == true)
|
|
|
|
|
Observer(
|
|
|
|
|
builder: (context) {
|
|
|
|
|
return ListTile(
|
|
|
|
|
leading: const Icon(Icons.close_rounded),
|
|
|
|
|
title: Text(
|
|
|
|
|
'Turn off (${formatTimeLeft(chatStore.timeRemaining)})',
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontFeatures: [FontFeature.tabularFigures()],
|
2023-04-29 22:49:50 -04:00
|
|
|
),
|
2023-10-22 18:38:32 -04:00
|
|
|
),
|
|
|
|
|
onTap: () {
|
|
|
|
|
chatStore.cancelSleepTimer();
|
|
|
|
|
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
...durations.map(
|
|
|
|
|
(duration) => ListTile(
|
|
|
|
|
leading: const Icon(Icons.hourglass_top_rounded),
|
|
|
|
|
title: Text(formatDuration(duration)),
|
|
|
|
|
onTap: () {
|
|
|
|
|
chatStore.updateSleepTimer(
|
|
|
|
|
duration: duration,
|
|
|
|
|
onTimerFinished: () => navigatorKey.currentState
|
|
|
|
|
?.popUntil((route) => route.isFirst),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
2023-01-18 05:34:54 -05:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-29 22:49:50 -04:00
|
|
|
Future<void> _showClearDialog(BuildContext context) {
|
2023-01-18 05:34:54 -05:00
|
|
|
return showDialog(
|
|
|
|
|
context: context,
|
2023-10-22 18:38:32 -04:00
|
|
|
builder: (context) => AlertDialog.adaptive(
|
|
|
|
|
title: const Text('Clear recent emotes'),
|
|
|
|
|
content:
|
|
|
|
|
const Text('Are you sure you want to clear your recent emotes?'),
|
2023-01-18 05:34:54 -05:00
|
|
|
actions: [
|
2023-10-22 18:38:32 -04:00
|
|
|
TextButton(
|
2023-04-29 22:49:50 -04:00
|
|
|
onPressed: Navigator.of(context).pop,
|
2023-10-22 18:38:32 -04:00
|
|
|
child: const Text('Cancel'),
|
2023-01-18 05:34:54 -05:00
|
|
|
),
|
2023-10-22 18:38:32 -04:00
|
|
|
TextButton(
|
2023-01-18 05:34:54 -05:00
|
|
|
onPressed: Navigator.of(context).pop,
|
2023-10-22 18:38:32 -04:00
|
|
|
child: const Text('Yes'),
|
2023-01-18 05:34:54 -05:00
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-23 00:26:50 -04:00
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2023-01-18 05:34:54 -05:00
|
|
|
final children = [
|
2023-10-22 18:38:32 -04:00
|
|
|
const SectionHeader(
|
|
|
|
|
'Chat modes',
|
|
|
|
|
padding: EdgeInsets.fromLTRB(16, 0, 16, 4),
|
|
|
|
|
),
|
2023-01-18 05:34:54 -05:00
|
|
|
ListTile(
|
2023-04-29 22:49:50 -04:00
|
|
|
title: ChatModes(roomState: chatDetailsStore.roomState),
|
2023-01-18 05:34:54 -05:00
|
|
|
),
|
2023-10-22 18:38:32 -04:00
|
|
|
const SectionHeader(
|
|
|
|
|
'More',
|
|
|
|
|
padding: EdgeInsets.fromLTRB(16, 12, 16, 4),
|
|
|
|
|
),
|
|
|
|
|
ListTile(
|
2023-01-18 05:34:54 -05:00
|
|
|
leading: const Icon(Icons.people_outline),
|
2023-10-22 18:38:32 -04:00
|
|
|
title: const Text('Chatters'),
|
2023-01-18 05:34:54 -05:00
|
|
|
onTap: () => showModalBottomSheet(
|
|
|
|
|
isScrollControlled: true,
|
|
|
|
|
context: context,
|
2023-10-22 18:38:32 -04:00
|
|
|
builder: (context) => SizedBox(
|
|
|
|
|
height: MediaQuery.of(context).size.height * 0.8,
|
|
|
|
|
child: GestureDetector(
|
|
|
|
|
onTap: FocusScope.of(context).unfocus,
|
|
|
|
|
child: ChattersList(
|
|
|
|
|
chatDetailsStore: chatDetailsStore,
|
|
|
|
|
chatStore: chatStore,
|
|
|
|
|
userLogin: userLogin,
|
2022-09-06 12:04:31 -04:00
|
|
|
),
|
2022-06-27 06:58:44 -04:00
|
|
|
),
|
2022-01-19 15:42:30 -05:00
|
|
|
),
|
2023-01-18 05:34:54 -05:00
|
|
|
),
|
|
|
|
|
),
|
2023-10-22 18:38:32 -04:00
|
|
|
Observer(
|
|
|
|
|
builder: (context) {
|
|
|
|
|
return ListTile(
|
|
|
|
|
leading: const Icon(Icons.timer_outlined),
|
|
|
|
|
title: Text(
|
|
|
|
|
'Sleep timer ${chatStore.timeRemaining.inSeconds > 0 ? 'on (${formatTimeLeft(chatStore.timeRemaining)})' : ''}',
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontFeatures: [FontFeature.tabularFigures()],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
onTap: () => _showSleepTimer(context),
|
|
|
|
|
);
|
|
|
|
|
},
|
2023-01-18 05:34:54 -05:00
|
|
|
),
|
2023-10-22 18:38:32 -04:00
|
|
|
ListTile(
|
2023-01-18 05:34:54 -05:00
|
|
|
leading: const Icon(Icons.delete_outline_rounded),
|
2023-10-22 18:38:32 -04:00
|
|
|
title: const Text('Clear recent emotes'),
|
2023-04-29 22:49:50 -04:00
|
|
|
onTap: () => _showClearDialog(context),
|
2023-01-18 05:34:54 -05:00
|
|
|
),
|
2023-10-22 18:38:32 -04:00
|
|
|
ListTile(
|
2023-01-18 05:34:54 -05:00
|
|
|
leading: const Icon(Icons.refresh_rounded),
|
2023-10-22 18:38:32 -04:00
|
|
|
title: const Text('Reconnect to chat'),
|
2023-01-18 05:34:54 -05:00
|
|
|
onTap: () {
|
2023-04-29 22:49:50 -04:00
|
|
|
chatStore.updateNotification('Reconnecting to chat...');
|
2022-09-06 12:04:31 -04:00
|
|
|
|
2023-04-29 22:49:50 -04:00
|
|
|
chatStore.connectToChat();
|
2023-01-18 05:34:54 -05:00
|
|
|
},
|
|
|
|
|
),
|
2023-10-22 18:38:32 -04:00
|
|
|
ListTile(
|
2023-01-18 05:34:54 -05:00
|
|
|
leading: const Icon(Icons.refresh_rounded),
|
2023-10-22 18:38:32 -04:00
|
|
|
title: const Text('Refresh badges and emotes'),
|
2023-01-18 05:34:54 -05:00
|
|
|
onTap: () async {
|
2023-04-29 22:49:50 -04:00
|
|
|
await chatStore.getAssets();
|
2022-09-06 12:04:31 -04:00
|
|
|
|
2023-04-29 22:49:50 -04:00
|
|
|
chatStore.updateNotification('Badges and emotes refreshed');
|
2023-01-18 05:34:54 -05:00
|
|
|
},
|
|
|
|
|
),
|
2023-10-22 18:38:32 -04:00
|
|
|
ListTile(
|
2023-01-18 05:34:54 -05:00
|
|
|
leading: const Icon(Icons.settings_outlined),
|
2023-10-22 18:38:32 -04:00
|
|
|
title: const Text('Settings'),
|
2023-01-18 05:34:54 -05:00
|
|
|
onTap: () => Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(
|
2023-04-29 22:49:50 -04:00
|
|
|
builder: (context) => Settings(settingsStore: chatStore.settings),
|
2022-09-06 12:04:31 -04:00
|
|
|
),
|
2023-01-18 05:34:54 -05:00
|
|
|
),
|
2021-10-23 00:26:50 -04:00
|
|
|
),
|
2023-01-18 05:34:54 -05:00
|
|
|
];
|
|
|
|
|
|
2023-10-22 18:38:32 -04:00
|
|
|
return ListView(
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
primary: false,
|
|
|
|
|
children: children,
|
2021-10-23 00:26:50 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|