Merge pull request #469 from pangeachat/learning-setting-fix

fix for orange box error in learning settings, updated instructions t…
pull/1384/head
ggurdin 1 year ago committed by GitHub
commit 6839e11e21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,4 +1,5 @@
import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
@ -9,7 +10,7 @@ enum InstructionsEnum {
tooltipInstructions, tooltipInstructions,
} }
extension Copy on InstructionsEnum { extension InstructionsEnumExtension on InstructionsEnum {
String title(BuildContext context) { String title(BuildContext context) {
switch (this) { switch (this) {
case InstructionsEnum.itInstructions: case InstructionsEnum.itInstructions:
@ -37,6 +38,21 @@ extension Copy on InstructionsEnum {
: L10n.of(context)!.tooltipInstructionsBrowserBody; : L10n.of(context)!.tooltipInstructionsBrowserBody;
} }
} }
bool get toggledOff {
final instructionSettings =
MatrixState.pangeaController.userController.profile.instructionSettings;
switch (this) {
case InstructionsEnum.itInstructions:
return instructionSettings.showedItInstructions;
case InstructionsEnum.clickMessage:
return instructionSettings.showedClickMessage;
case InstructionsEnum.blurMeansTranslate:
return instructionSettings.showedBlurMeansTranslate;
case InstructionsEnum.tooltipInstructions:
return instructionSettings.showedTooltipInstructions;
}
}
} }
enum InlineInstructions { enum InlineInstructions {

@ -1,5 +1,3 @@
import 'dart:async';
import 'package:country_picker/country_picker.dart'; import 'package:country_picker/country_picker.dart';
import 'package:fluffychat/pangea/controllers/pangea_controller.dart'; import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
import 'package:fluffychat/pangea/models/space_model.dart'; import 'package:fluffychat/pangea/models/space_model.dart';
@ -17,25 +15,26 @@ class SettingsLearning extends StatefulWidget {
} }
class SettingsLearningController extends State<SettingsLearning> { class SettingsLearningController extends State<SettingsLearning> {
late StreamSubscription _userSubscription;
PangeaController pangeaController = MatrixState.pangeaController; PangeaController pangeaController = MatrixState.pangeaController;
Future<void> changeLanguage() async { setPublicProfile(bool isPublic) {
await pLanguageDialog(context, () {});
}
Future<void> setPublicProfile(bool isPublic) async {
pangeaController.userController.updateProfile((profile) { pangeaController.userController.updateProfile((profile) {
profile.userSettings.publicProfile = isPublic; profile.userSettings.publicProfile = isPublic;
return profile; return profile;
}); });
setState(() {});
} }
Future<void> changeCountry(Country country) async { void changeLanguage() {
pangeaController.userController.updateProfile((profile) { pLanguageDialog(context, () {}).then((_) => setState(() {}));
}
void changeCountry(Country country) {
pangeaController.userController.updateProfile((Profile profile) {
profile.userSettings.country = country.displayNameNoCountryCode; profile.userSettings.country = country.displayNameNoCountryCode;
return profile; return profile;
}); });
setState(() {});
} }
void updateToolSetting(ToolSetting toolSetting, bool value) { void updateToolSetting(ToolSetting toolSetting, bool value) {
@ -71,12 +70,6 @@ class SettingsLearningController extends State<SettingsLearning> {
} }
} }
@override
void dispose() {
super.dispose();
_userSubscription.cancel();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return SettingsLearningView(this); return SettingsLearningView(this);

@ -1,15 +1,12 @@
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/pangea/models/space_model.dart'; import 'package:fluffychat/pangea/models/space_model.dart';
import 'package:fluffychat/pangea/pages/settings_learning/settings_learning.dart'; import 'package:fluffychat/pangea/pages/settings_learning/settings_learning.dart';
import 'package:fluffychat/pangea/utils/error_handler.dart';
import 'package:fluffychat/pangea/widgets/user_settings/country_picker_tile.dart'; import 'package:fluffychat/pangea/widgets/user_settings/country_picker_tile.dart';
import 'package:fluffychat/pangea/widgets/user_settings/language_tile.dart'; import 'package:fluffychat/pangea/widgets/user_settings/language_tile.dart';
import 'package:fluffychat/pangea/widgets/user_settings/p_settings_switch_list_tile.dart'; import 'package:fluffychat/pangea/widgets/user_settings/p_settings_switch_list_tile.dart';
import 'package:fluffychat/widgets/layouts/max_width_body.dart'; import 'package:fluffychat/widgets/layouts/max_width_body.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
import '../../../config/app_config.dart';
class SettingsLearningView extends StatelessWidget { class SettingsLearningView extends StatelessWidget {
final SettingsLearningController controller; final SettingsLearningController controller;
@ -17,97 +14,75 @@ class SettingsLearningView extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// rebuild this page each time a sync comes through with new account data return Scaffold(
// this prevents having to call setState each time an individual setting is changed appBar: AppBar(
return StreamBuilder( centerTitle: true,
stream: title: Text(
controller.pangeaController.matrixState.client.onSync.stream.where( L10n.of(context)!.learningSettings,
(update) => update.accountData != null, ),
), ),
builder: (context, snapshot) { body: ListTileTheme(
return Scaffold( iconColor: Theme.of(context).textTheme.bodyLarge!.color,
appBar: AppBar( child: MaxWidthBody(
centerTitle: true, withScrolling: true,
title: Text( child: Column(
L10n.of(context)!.learningSettings, children: [
), LanguageTile(controller),
), CountryPickerTile(controller),
body: ListTileTheme( const SizedBox(height: 8),
iconColor: Theme.of(context).textTheme.bodyLarge!.color, const Divider(height: 1),
child: MaxWidthBody( const SizedBox(height: 8),
withScrolling: true, if (controller.pangeaController.permissionsController.isUser18())
child: Column( SwitchListTile.adaptive(
children: [ activeColor: AppConfig.activeToggleColor,
LanguageTile(controller), title: Text(L10n.of(context)!.publicProfileTitle),
CountryPickerTile(controller), subtitle: Text(L10n.of(context)!.publicProfileDesc),
const SizedBox(height: 8), value: controller.pangeaController.userController.isPublic,
const Divider(height: 1), onChanged: (bool isPublicProfile) =>
const SizedBox(height: 8), controller.setPublicProfile(isPublicProfile),
if (controller.pangeaController.permissionsController ),
.isUser18()) ListTile(
SwitchListTile.adaptive( subtitle: Text(L10n.of(context)!.toggleToolSettingsDescription),
activeColor: AppConfig.activeToggleColor, ),
title: Text(L10n.of(context)!.publicProfileTitle), for (final toolSetting in ToolSetting.values)
subtitle: Text(L10n.of(context)!.publicProfileDesc), ProfileSettingsSwitchListTile.adaptive(
value: defaultValue: controller.getToolSetting(toolSetting),
controller.pangeaController.userController.isPublic, title: toolSetting.toolName(context),
onChanged: (bool isPublicProfile) => subtitle: toolSetting.toolDescription(context),
showFutureLoadingDialog( onChange: (bool value) => controller.updateToolSetting(
context: context, toolSetting,
future: () => value,
controller.setPublicProfile(isPublicProfile),
onError: (err) => ErrorHandler.logError(
e: err,
s: StackTrace.current,
),
),
),
ListTile(
subtitle:
Text(L10n.of(context)!.toggleToolSettingsDescription),
),
for (final toolSetting in ToolSetting.values)
ProfileSettingsSwitchListTile.adaptive(
defaultValue: controller.getToolSetting(toolSetting),
title: toolSetting.toolName(context),
subtitle: toolSetting.toolDescription(context),
onChange: (bool value) => controller.updateToolSetting(
toolSetting,
value,
),
),
ProfileSettingsSwitchListTile.adaptive(
defaultValue: controller.pangeaController.userController
.profile.userSettings.itAutoPlay,
title: L10n.of(context)!
.interactiveTranslatorAutoPlaySliderHeader,
subtitle:
L10n.of(context)!.interactiveTranslatorAutoPlayDesc,
onChange: (bool value) => controller
.pangeaController.userController
.updateProfile((profile) {
profile.userSettings.itAutoPlay = value;
return profile;
}),
),
ProfileSettingsSwitchListTile.adaptive(
defaultValue: controller.pangeaController.userController
.profile.userSettings.autoPlayMessages,
title: L10n.of(context)!.autoPlayTitle,
subtitle: L10n.of(context)!.autoPlayDesc,
onChange: (bool value) => controller
.pangeaController.userController
.updateProfile((profile) {
profile.userSettings.autoPlayMessages = value;
return profile;
}),
), ),
], ),
ProfileSettingsSwitchListTile.adaptive(
defaultValue: controller.pangeaController.userController.profile
.userSettings.itAutoPlay,
title:
L10n.of(context)!.interactiveTranslatorAutoPlaySliderHeader,
subtitle: L10n.of(context)!.interactiveTranslatorAutoPlayDesc,
onChange: (bool value) => controller
.pangeaController.userController
.updateProfile((profile) {
profile.userSettings.itAutoPlay = value;
return profile;
}),
),
ProfileSettingsSwitchListTile.adaptive(
defaultValue: controller.pangeaController.userController.profile
.userSettings.autoPlayMessages,
title: L10n.of(context)!.autoPlayTitle,
subtitle: L10n.of(context)!.autoPlayDesc,
onChange: (bool value) => controller
.pangeaController.userController
.updateProfile((profile) {
profile.userSettings.autoPlayMessages = value;
return profile;
}),
), ),
), ],
), ),
); ),
}, ),
); );
} }
} }

@ -1,3 +1,4 @@
import 'package:collection/collection.dart';
import 'package:fluffychat/pangea/enum/instructions_enum.dart'; import 'package:fluffychat/pangea/enum/instructions_enum.dart';
import 'package:fluffychat/pangea/utils/inline_tooltip.dart'; import 'package:fluffychat/pangea/utils/inline_tooltip.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -24,8 +25,9 @@ class InstructionsController {
final Map<String, bool> _instructionsShown = {}; final Map<String, bool> _instructionsShown = {};
/// Returns true if the user requested this popup not be shown again /// Returns true if the user requested this popup not be shown again
bool? toggledOff(String key) => bool? toggledOff(String key) => InstructionsEnum.values
_pangeaController.pStoreService.read(key.toString()); .firstWhereOrNull((value) => value.toString() == key)
?.toggledOff;
InstructionsController(PangeaController pangeaController) { InstructionsController(PangeaController pangeaController) {
_pangeaController = pangeaController; _pangeaController = pangeaController;
@ -33,19 +35,32 @@ class InstructionsController {
/// Returns true if the instructions were closed /// Returns true if the instructions were closed
/// or turned off by the user via the toggle switch /// or turned off by the user via the toggle switch
bool wereInstructionsTurnedOff(String key) => bool wereInstructionsTurnedOff(String key) {
toggledOff(key) ?? _instructionsClosed[key] ?? false; return toggledOff(key) ?? _instructionsClosed[key] ?? false;
}
void turnOffInstruction(String key) => _instructionsClosed[key] = true; void turnOffInstruction(String key) => _instructionsClosed[key] = true;
Future<void> updateEnableInstructions( void updateEnableInstructions(
String key, String key,
bool value, bool value,
) async => ) {
await _pangeaController.pStoreService.save( _pangeaController.userController.updateProfile((profile) {
key, if (key == InstructionsEnum.itInstructions.toString()) {
value, profile.instructionSettings.showedItInstructions = value;
); }
if (key == InstructionsEnum.clickMessage.toString()) {
profile.instructionSettings.showedClickMessage = value;
}
if (key == InstructionsEnum.blurMeansTranslate.toString()) {
profile.instructionSettings.showedBlurMeansTranslate = value;
}
if (key == InstructionsEnum.tooltipInstructions.toString()) {
profile.instructionSettings.showedTooltipInstructions = value;
}
return profile;
});
}
/// Instruction Card gives users tips on /// Instruction Card gives users tips on
/// how to use Pangea Chat's features /// how to use Pangea Chat's features
@ -170,7 +185,7 @@ class InstructionsToggleState extends State<InstructionsToggle> {
widget.instructionsKey.toString(), widget.instructionsKey.toString(),
), ),
onChanged: ((value) async { onChanged: ((value) async {
await pangeaController.instructions.updateEnableInstructions( pangeaController.instructions.updateEnableInstructions(
widget.instructionsKey.toString(), widget.instructionsKey.toString(),
value, value,
); );

@ -1,14 +1,10 @@
import 'dart:developer';
import 'package:country_picker/country_picker.dart'; import 'package:country_picker/country_picker.dart';
import 'package:fluffychat/pangea/controllers/pangea_controller.dart'; import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
import 'package:fluffychat/pangea/pages/settings_learning/settings_learning.dart'; import 'package:fluffychat/pangea/pages/settings_learning/settings_learning.dart';
import 'package:fluffychat/pangea/utils/country_display.dart'; import 'package:fluffychat/pangea/utils/country_display.dart';
import 'package:fluffychat/widgets/matrix.dart'; import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
import '../../models/user_model.dart'; import '../../models/user_model.dart';
@ -21,30 +17,26 @@ class CountryPickerTile extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final Profile profile = pangeaController.userController.profile; final Profile profile = pangeaController.userController.profile;
final String displayName = CountryDisplayUtil.countryDisplayName(
profile.userSettings.country,
context,
) ??
'';
final String flag = CountryDisplayUtil.flagEmoji(
profile.userSettings.country,
);
return ListTile( return ListTile(
title: Text( title: Text(
"${L10n.of(context)!.countryInformation}: ${CountryDisplayUtil.countryDisplayName( "${L10n.of(context)!.countryInformation}: $displayName $flag",
profile.userSettings.country,
context,
) ?? ''} ${CountryDisplayUtil.flagEmoji(profile.userSettings.country)}",
), ),
trailing: const Icon(Icons.edit_outlined), trailing: const Icon(Icons.edit_outlined),
onTap: () => showCountryPicker( onTap: () => showCountryPicker(
context: context, context: context,
showPhoneCode: showPhoneCode: false,
false, // optional. Shows phone code before the country name. onSelect: learningController.changeCountry,
onSelect: (Country country) async {
showFutureLoadingDialog(
context: context,
future: () async {
try {
learningController.changeCountry(country);
} catch (err) {
debugger(when: kDebugMode);
}
},
);
},
), ),
); );
} }

@ -15,7 +15,10 @@ import '../../../widgets/matrix.dart';
import 'p_language_dropdown.dart'; import 'p_language_dropdown.dart';
import 'p_question_container.dart'; import 'p_question_container.dart';
pLanguageDialog(BuildContext parentContext, Function callback) async { Future<void> pLanguageDialog(
BuildContext parentContext,
Function callback,
) async {
final PangeaController pangeaController = MatrixState.pangeaController; final PangeaController pangeaController = MatrixState.pangeaController;
//PTODO: if source language not set by user, default to languge from device settings //PTODO: if source language not set by user, default to languge from device settings
final LanguageModel? userL1 = pangeaController.languageController.userL1; final LanguageModel? userL1 = pangeaController.languageController.userL1;

Loading…
Cancel
Save