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,14 +14,6 @@ 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
// this prevents having to call setState each time an individual setting is changed
return StreamBuilder(
stream:
controller.pangeaController.matrixState.client.onSync.stream.where(
(update) => update.accountData != null,
),
builder: (context, snapshot) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
centerTitle: true, centerTitle: true,
@ -43,28 +32,17 @@ class SettingsLearningView extends StatelessWidget {
const SizedBox(height: 8), const SizedBox(height: 8),
const Divider(height: 1), const Divider(height: 1),
const SizedBox(height: 8), const SizedBox(height: 8),
if (controller.pangeaController.permissionsController if (controller.pangeaController.permissionsController.isUser18())
.isUser18())
SwitchListTile.adaptive( SwitchListTile.adaptive(
activeColor: AppConfig.activeToggleColor, activeColor: AppConfig.activeToggleColor,
title: Text(L10n.of(context)!.publicProfileTitle), title: Text(L10n.of(context)!.publicProfileTitle),
subtitle: Text(L10n.of(context)!.publicProfileDesc), subtitle: Text(L10n.of(context)!.publicProfileDesc),
value: value: controller.pangeaController.userController.isPublic,
controller.pangeaController.userController.isPublic,
onChanged: (bool isPublicProfile) => onChanged: (bool isPublicProfile) =>
showFutureLoadingDialog(
context: context,
future: () =>
controller.setPublicProfile(isPublicProfile), controller.setPublicProfile(isPublicProfile),
onError: (err) => ErrorHandler.logError(
e: err,
s: StackTrace.current,
),
),
), ),
ListTile( ListTile(
subtitle: subtitle: Text(L10n.of(context)!.toggleToolSettingsDescription),
Text(L10n.of(context)!.toggleToolSettingsDescription),
), ),
for (final toolSetting in ToolSetting.values) for (final toolSetting in ToolSetting.values)
ProfileSettingsSwitchListTile.adaptive( ProfileSettingsSwitchListTile.adaptive(
@ -77,12 +55,11 @@ class SettingsLearningView extends StatelessWidget {
), ),
), ),
ProfileSettingsSwitchListTile.adaptive( ProfileSettingsSwitchListTile.adaptive(
defaultValue: controller.pangeaController.userController defaultValue: controller.pangeaController.userController.profile
.profile.userSettings.itAutoPlay, .userSettings.itAutoPlay,
title: L10n.of(context)! title:
.interactiveTranslatorAutoPlaySliderHeader, L10n.of(context)!.interactiveTranslatorAutoPlaySliderHeader,
subtitle: subtitle: L10n.of(context)!.interactiveTranslatorAutoPlayDesc,
L10n.of(context)!.interactiveTranslatorAutoPlayDesc,
onChange: (bool value) => controller onChange: (bool value) => controller
.pangeaController.userController .pangeaController.userController
.updateProfile((profile) { .updateProfile((profile) {
@ -91,8 +68,8 @@ class SettingsLearningView extends StatelessWidget {
}), }),
), ),
ProfileSettingsSwitchListTile.adaptive( ProfileSettingsSwitchListTile.adaptive(
defaultValue: controller.pangeaController.userController defaultValue: controller.pangeaController.userController.profile
.profile.userSettings.autoPlayMessages, .userSettings.autoPlayMessages,
title: L10n.of(context)!.autoPlayTitle, title: L10n.of(context)!.autoPlayTitle,
subtitle: L10n.of(context)!.autoPlayDesc, subtitle: L10n.of(context)!.autoPlayDesc,
onChange: (bool value) => controller onChange: (bool value) => controller
@ -107,7 +84,5 @@ class SettingsLearningView extends StatelessWidget {
), ),
), ),
); );
},
);
} }
} }

@ -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;
return ListTile(
title: Text( final String displayName = CountryDisplayUtil.countryDisplayName(
"${L10n.of(context)!.countryInformation}: ${CountryDisplayUtil.countryDisplayName(
profile.userSettings.country, profile.userSettings.country,
context, context,
) ?? ''} ${CountryDisplayUtil.flagEmoji(profile.userSettings.country)}", ) ??
'';
final String flag = CountryDisplayUtil.flagEmoji(
profile.userSettings.country,
);
return ListTile(
title: Text(
"${L10n.of(context)!.countryInformation}: $displayName $flag",
), ),
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