refactor: Use AppSettings enum based configuration everywhere and fix load from json on web
This commit is contained in:
parent
4f0ed3e93f
commit
4c357f6249
46 changed files with 357 additions and 402 deletions
|
|
@ -13,10 +13,8 @@ import 'package:go_router/go_router.dart';
|
|||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:scroll_to_index/scroll_to_index.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:universal_html/html.dart' as html;
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/config/setting_keys.dart';
|
||||
import 'package:fluffychat/config/themes.dart';
|
||||
import 'package:fluffychat/l10n/l10n.dart';
|
||||
|
|
@ -224,7 +222,7 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
}
|
||||
|
||||
void _loadDraft() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final prefs = Matrix.of(context).store;
|
||||
final draft = prefs.getString('draft_$roomId');
|
||||
if (draft != null && draft.isNotEmpty) {
|
||||
sendController.text = draft;
|
||||
|
|
@ -274,7 +272,7 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
KeyEventResult _customEnterKeyHandling(FocusNode node, KeyEvent evt) {
|
||||
if (!HardwareKeyboard.instance.isShiftPressed &&
|
||||
evt.logicalKey.keyLabel == 'Enter' &&
|
||||
(AppConfig.sendOnEnter ?? !PlatformInfos.isMobile)) {
|
||||
AppSettings.sendOnEnter.value) {
|
||||
if (evt is KeyDownEvent) {
|
||||
send();
|
||||
}
|
||||
|
|
@ -325,7 +323,7 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
WidgetsBinding.instance.addPostFrameCallback(_shareItems);
|
||||
super.initState();
|
||||
_displayChatDetailsColumn = ValueNotifier(
|
||||
AppSettings.displayChatDetailsColumn.getItem(Matrix.of(context).store),
|
||||
AppSettings.displayChatDetailsColumn.value,
|
||||
);
|
||||
|
||||
sendingClient = Matrix.of(context).client;
|
||||
|
|
@ -365,7 +363,9 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
var readMarkerEventIndex = readMarkerEventId.isEmpty
|
||||
? -1
|
||||
: timeline!.events
|
||||
.filterByVisibleInGui(exceptionEventId: readMarkerEventId)
|
||||
.filterByVisibleInGui(
|
||||
exceptionEventId: readMarkerEventId,
|
||||
)
|
||||
.indexWhere((e) => e.eventId == readMarkerEventId);
|
||||
|
||||
// Read marker is existing but not found in first events. Try a single
|
||||
|
|
@ -373,7 +373,9 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
if (readMarkerEventId.isNotEmpty && readMarkerEventIndex == -1) {
|
||||
await timeline?.requestHistory(historyCount: _loadHistoryCount);
|
||||
readMarkerEventIndex = timeline!.events
|
||||
.filterByVisibleInGui(exceptionEventId: readMarkerEventId)
|
||||
.filterByVisibleInGui(
|
||||
exceptionEventId: readMarkerEventId,
|
||||
)
|
||||
.indexWhere((e) => e.eventId == readMarkerEventId);
|
||||
}
|
||||
|
||||
|
|
@ -492,7 +494,7 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
_setReadMarkerFuture = timeline
|
||||
.setReadMarker(
|
||||
eventId: eventId,
|
||||
public: AppConfig.sendPublicReadReceipts,
|
||||
public: AppSettings.sendPublicReadReceipts.value,
|
||||
)
|
||||
.then((_) {
|
||||
_setReadMarkerFuture = null;
|
||||
|
|
@ -542,7 +544,7 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
Future<void> send() async {
|
||||
if (sendController.text.trim().isEmpty) return;
|
||||
_storeInputTimeoutTimer?.cancel();
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final prefs = Matrix.of(context).store;
|
||||
prefs.remove('draft_$roomId');
|
||||
var parseCommands = true;
|
||||
|
||||
|
|
@ -960,7 +962,9 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
final eventIndex = foundEvent == null
|
||||
? -1
|
||||
: timeline!.events
|
||||
.filterByVisibleInGui(exceptionEventId: eventId)
|
||||
.filterByVisibleInGui(
|
||||
exceptionEventId: eventId,
|
||||
)
|
||||
.indexOf(foundEvent);
|
||||
|
||||
if (eventIndex == -1) {
|
||||
|
|
@ -1203,7 +1207,7 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
|
||||
_storeInputTimeoutTimer?.cancel();
|
||||
_storeInputTimeoutTimer = Timer(_storeInputTimeout, () async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final prefs = Matrix.of(context).store;
|
||||
await prefs.setString('draft_$roomId', text);
|
||||
});
|
||||
if (text.endsWith(' ') && Matrix.of(context).hasComplexBundles) {
|
||||
|
|
@ -1220,7 +1224,7 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
}
|
||||
}
|
||||
}
|
||||
if (AppConfig.sendTypingNotifications) {
|
||||
if (AppSettings.sendTypingNotifications.value) {
|
||||
typingCoolDown?.cancel();
|
||||
typingCoolDown = Timer(const Duration(seconds: 2), () {
|
||||
typingCoolDown = null;
|
||||
|
|
@ -1307,7 +1311,6 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
|
||||
void toggleDisplayChatDetailsColumn() async {
|
||||
await AppSettings.displayChatDetailsColumn.setItem(
|
||||
Matrix.of(context).store,
|
||||
!_displayChatDetailsColumn.value,
|
||||
);
|
||||
_displayChatDetailsColumn.value = !_displayChatDetailsColumn.value;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:animations/animations.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/config/setting_keys.dart';
|
||||
import 'package:fluffychat/l10n/l10n.dart';
|
||||
import 'package:fluffychat/pages/chat/recording_input_row.dart';
|
||||
import 'package:fluffychat/pages/chat/recording_view_model.dart';
|
||||
|
|
@ -297,10 +297,11 @@ class ChatInputRow extends StatelessWidget {
|
|||
maxLines: 8,
|
||||
autofocus: !PlatformInfos.isMobile,
|
||||
keyboardType: TextInputType.multiline,
|
||||
textInputAction: AppConfig.sendOnEnter == true &&
|
||||
PlatformInfos.isMobile
|
||||
? TextInputAction.send
|
||||
: null,
|
||||
textInputAction:
|
||||
AppSettings.sendOnEnter.value == true &&
|
||||
PlatformInfos.isMobile
|
||||
? TextInputAction.send
|
||||
: null,
|
||||
onSubmitted: controller.onInputBarSubmitted,
|
||||
onSubmitImage: controller.sendImageFromClipBoard,
|
||||
focusNode: controller.inputFocus,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import 'package:badges/badges.dart';
|
|||
import 'package:desktop_drop/desktop_drop.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/config/setting_keys.dart';
|
||||
import 'package:fluffychat/config/themes.dart';
|
||||
import 'package:fluffychat/l10n/l10n.dart';
|
||||
import 'package:fluffychat/pages/chat/chat.dart';
|
||||
|
|
@ -119,7 +119,7 @@ class ChatView extends StatelessWidget {
|
|||
];
|
||||
} else if (!controller.room.isArchived) {
|
||||
return [
|
||||
if (AppConfig.experimentalVoip &&
|
||||
if (AppSettings.experimentalVoip.value &&
|
||||
Matrix.of(context).voipPlugin != null &&
|
||||
controller.room.isDirectChat)
|
||||
IconButton(
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
|
|||
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/config/setting_keys.dart';
|
||||
import 'package:fluffychat/l10n/l10n.dart';
|
||||
|
||||
class CuteContent extends StatefulWidget {
|
||||
|
|
@ -21,7 +21,7 @@ class _CuteContentState extends State<CuteContent> {
|
|||
|
||||
@override
|
||||
void initState() {
|
||||
if (AppConfig.autoplayImages && !_isOverlayShown) {
|
||||
if (AppSettings.autoplayImages.value && !_isOverlayShown) {
|
||||
addOverlay();
|
||||
}
|
||||
super.initState();
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import 'package:flutter_linkify/flutter_linkify.dart';
|
|||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/config/setting_keys.dart';
|
||||
import 'package:fluffychat/pages/image_viewer/image_viewer.dart';
|
||||
import 'package:fluffychat/utils/file_description.dart';
|
||||
import 'package:fluffychat/utils/url_launcher.dart';
|
||||
|
|
@ -139,14 +140,14 @@ class ImageBubble extends StatelessWidget {
|
|||
textScaleFactor: MediaQuery.textScalerOf(context).scale(1),
|
||||
style: TextStyle(
|
||||
color: textColor,
|
||||
fontSize:
|
||||
AppConfig.fontSizeFactor * AppConfig.messageFontSize,
|
||||
fontSize: AppSettings.fontSizeFactor.value *
|
||||
AppConfig.messageFontSize,
|
||||
),
|
||||
options: const LinkifyOptions(humanize: false),
|
||||
linkStyle: TextStyle(
|
||||
color: linkColor,
|
||||
fontSize:
|
||||
AppConfig.fontSizeFactor * AppConfig.messageFontSize,
|
||||
fontSize: AppSettings.fontSizeFactor.value *
|
||||
AppConfig.messageFontSize,
|
||||
decoration: TextDecoration.underline,
|
||||
decorationColor: linkColor,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
|||
import 'package:matrix/matrix.dart';
|
||||
import 'package:swipe_to_action/swipe_to_action.dart';
|
||||
|
||||
import 'package:fluffychat/config/setting_keys.dart';
|
||||
import 'package:fluffychat/config/themes.dart';
|
||||
import 'package:fluffychat/l10n/l10n.dart';
|
||||
import 'package:fluffychat/pages/chat/events/room_creation_state_event.dart';
|
||||
|
|
@ -204,7 +205,7 @@ class Message extends StatelessWidget {
|
|||
child: Icon(Icons.check_outlined),
|
||||
),
|
||||
),
|
||||
direction: AppConfig.swipeRightToLeftToReply
|
||||
direction: AppSettings.swipeRightToLeftToReply.value
|
||||
? SwipeDirection.endToStart
|
||||
: SwipeDirection.startToEnd,
|
||||
onSwipe: (_) => onSwipe(),
|
||||
|
|
@ -243,7 +244,7 @@ class Message extends StatelessWidget {
|
|||
child: Text(
|
||||
event.originServerTs.localizedTime(context),
|
||||
style: TextStyle(
|
||||
fontSize: 12 * AppConfig.fontSizeFactor,
|
||||
fontSize: 12 * AppSettings.fontSizeFactor.value,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: theme.colorScheme.secondary,
|
||||
),
|
||||
|
|
@ -890,7 +891,7 @@ class Message extends StatelessWidget {
|
|||
child: Text(
|
||||
L10n.of(context).readUpToHere,
|
||||
style: TextStyle(
|
||||
fontSize: 12 * AppConfig.fontSizeFactor,
|
||||
fontSize: 12 * AppSettings.fontSizeFactor.value,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
|||
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/config/setting_keys.dart';
|
||||
import 'package:fluffychat/l10n/l10n.dart';
|
||||
import 'package:fluffychat/pages/chat/events/video_player.dart';
|
||||
import 'package:fluffychat/utils/adaptive_bottom_sheet.dart';
|
||||
|
|
@ -105,7 +106,8 @@ class MessageContent extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final fontSize = AppConfig.messageFontSize * AppConfig.fontSizeFactor;
|
||||
final fontSize =
|
||||
AppConfig.messageFontSize * AppSettings.fontSizeFactor.value;
|
||||
final buttonTextColor = textColor;
|
||||
switch (event.type) {
|
||||
case EventTypes.Message:
|
||||
|
|
@ -255,7 +257,7 @@ class MessageContent extends StatelessWidget {
|
|||
},
|
||||
);
|
||||
}
|
||||
var html = AppConfig.renderHtml && event.isRichMessage
|
||||
var html = AppSettings.renderHtml.value && event.isRichMessage
|
||||
? event.formattedText
|
||||
: event.body;
|
||||
if (event.messageType == MessageTypes.Emote) {
|
||||
|
|
@ -274,14 +276,14 @@ class MessageContent extends StatelessWidget {
|
|||
html: html,
|
||||
textColor: textColor,
|
||||
room: event.room,
|
||||
fontSize: AppConfig.fontSizeFactor *
|
||||
fontSize: AppSettings.fontSizeFactor.value *
|
||||
AppConfig.messageFontSize *
|
||||
(bigEmotes ? 5 : 1),
|
||||
limitHeight: !selected,
|
||||
linkStyle: TextStyle(
|
||||
color: linkColor,
|
||||
fontSize:
|
||||
AppConfig.fontSizeFactor * AppConfig.messageFontSize,
|
||||
fontSize: AppSettings.fontSizeFactor.value *
|
||||
AppConfig.messageFontSize,
|
||||
decoration: TextDecoration.underline,
|
||||
decorationColor: linkColor,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import 'package:flutter_linkify/flutter_linkify.dart';
|
|||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/config/setting_keys.dart';
|
||||
import 'package:fluffychat/utils/file_description.dart';
|
||||
import 'package:fluffychat/utils/matrix_sdk_extensions/event_extension.dart';
|
||||
import 'package:fluffychat/utils/url_launcher.dart';
|
||||
|
|
@ -92,12 +93,14 @@ class MessageDownloadContent extends StatelessWidget {
|
|||
textScaleFactor: MediaQuery.textScalerOf(context).scale(1),
|
||||
style: TextStyle(
|
||||
color: textColor,
|
||||
fontSize: AppConfig.fontSizeFactor * AppConfig.messageFontSize,
|
||||
fontSize: AppSettings.fontSizeFactor.value *
|
||||
AppConfig.messageFontSize,
|
||||
),
|
||||
options: const LinkifyOptions(humanize: false),
|
||||
linkStyle: TextStyle(
|
||||
color: linkColor,
|
||||
fontSize: AppConfig.fontSizeFactor * AppConfig.messageFontSize,
|
||||
fontSize: AppSettings.fontSizeFactor.value *
|
||||
AppConfig.messageFontSize,
|
||||
decoration: TextDecoration.underline,
|
||||
decorationColor: linkColor,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/config/setting_keys.dart';
|
||||
import 'package:fluffychat/l10n/l10n.dart';
|
||||
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
||||
import '../../../config/app_config.dart';
|
||||
|
|
@ -30,7 +31,8 @@ class ReplyContent extends StatelessWidget {
|
|||
final timeline = this.timeline;
|
||||
final displayEvent =
|
||||
timeline != null ? replyEvent.getDisplayEvent(timeline) : replyEvent;
|
||||
final fontSize = AppConfig.messageFontSize * AppConfig.fontSizeFactor;
|
||||
final fontSize =
|
||||
AppConfig.messageFontSize * AppSettings.fontSizeFactor.value;
|
||||
final color = theme.brightness == Brightness.dark
|
||||
? theme.colorScheme.onTertiaryContainer
|
||||
: ownMessage
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
|||
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/config/setting_keys.dart';
|
||||
import 'package:fluffychat/config/themes.dart';
|
||||
import 'package:fluffychat/l10n/l10n.dart';
|
||||
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
||||
|
|
@ -68,7 +69,7 @@ class StateMessage extends StatelessWidget {
|
|||
),
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 12 * AppConfig.fontSizeFactor,
|
||||
fontSize: 12 * AppSettings.fontSizeFactor.value,
|
||||
decoration: event.redacted
|
||||
? TextDecoration.lineThrough
|
||||
: null,
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import 'package:flutter_linkify/flutter_linkify.dart';
|
|||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/config/setting_keys.dart';
|
||||
import 'package:fluffychat/utils/file_description.dart';
|
||||
import 'package:fluffychat/utils/matrix_sdk_extensions/event_extension.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
|
|
@ -136,14 +137,14 @@ class EventVideoPlayer extends StatelessWidget {
|
|||
textScaleFactor: MediaQuery.textScalerOf(context).scale(1),
|
||||
style: TextStyle(
|
||||
color: textColor,
|
||||
fontSize:
|
||||
AppConfig.fontSizeFactor * AppConfig.messageFontSize,
|
||||
fontSize: AppSettings.fontSizeFactor.value *
|
||||
AppConfig.messageFontSize,
|
||||
),
|
||||
options: const LinkifyOptions(humanize: false),
|
||||
linkStyle: TextStyle(
|
||||
color: linkColor,
|
||||
fontSize:
|
||||
AppConfig.fontSizeFactor * AppConfig.messageFontSize,
|
||||
fontSize: AppSettings.fontSizeFactor.value *
|
||||
AppConfig.messageFontSize,
|
||||
decoration: TextDecoration.underline,
|
||||
decorationColor: linkColor,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -415,8 +415,7 @@ class InputBar extends StatelessWidget {
|
|||
// it sets the types for the callback incorrectly
|
||||
onSubmitted!(text);
|
||||
},
|
||||
maxLength:
|
||||
AppSettings.textMessageMaxLength.getItem(Matrix.of(context).store),
|
||||
maxLength: AppSettings.textMessageMaxLength.value,
|
||||
decoration: decoration,
|
||||
onChanged: (text) {
|
||||
// fix for the library for now
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import 'package:fluffychat/config/setting_keys.dart';
|
|||
import 'package:fluffychat/l10n/l10n.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:fluffychat/widgets/adaptive_dialogs/show_ok_cancel_alert_dialog.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import 'events/audio_player.dart';
|
||||
|
||||
class RecordingViewModel extends StatefulWidget {
|
||||
|
|
@ -62,8 +61,6 @@ class RecordingViewModelState extends State<RecordingViewModel> {
|
|||
}
|
||||
if (await AudioRecorder().hasPermission() == false) return;
|
||||
|
||||
final store = Matrix.of(context).store;
|
||||
|
||||
final audioRecorder = _audioRecorder ??= AudioRecorder();
|
||||
setState(() {});
|
||||
|
||||
|
|
@ -93,12 +90,12 @@ class RecordingViewModelState extends State<RecordingViewModel> {
|
|||
|
||||
await audioRecorder.start(
|
||||
RecordConfig(
|
||||
bitRate: AppSettings.audioRecordingBitRate.getItem(store),
|
||||
sampleRate: AppSettings.audioRecordingSamplingRate.getItem(store),
|
||||
numChannels: AppSettings.audioRecordingNumChannels.getItem(store),
|
||||
autoGain: AppSettings.audioRecordingAutoGain.getItem(store),
|
||||
echoCancel: AppSettings.audioRecordingEchoCancel.getItem(store),
|
||||
noiseSuppress: AppSettings.audioRecordingNoiseSuppress.getItem(store),
|
||||
bitRate: AppSettings.audioRecordingBitRate.value,
|
||||
sampleRate: AppSettings.audioRecordingSamplingRate.value,
|
||||
numChannels: AppSettings.audioRecordingNumChannels.value,
|
||||
autoGain: AppSettings.audioRecordingAutoGain.value,
|
||||
echoCancel: AppSettings.audioRecordingEchoCancel.value,
|
||||
noiseSuppress: AppSettings.audioRecordingNoiseSuppress.value,
|
||||
encoder: codec,
|
||||
),
|
||||
path: path ?? '',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue