fix for orange box error in learning settings, updated instructions to base their toggle status on matrix profile

pull/1384/head
ggurdin 1 year ago
parent 24610fe0ea
commit 7e87c3154c

@ -1,4 +1,5 @@
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
@ -9,7 +10,7 @@ enum InstructionsEnum {
tooltipInstructions,
}
extension Copy on InstructionsEnum {
extension InstructionsEnumExtension on InstructionsEnum {
String title(BuildContext context) {
switch (this) {
case InstructionsEnum.itInstructions:
@ -37,6 +38,21 @@ extension Copy on InstructionsEnum {
: 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 {

@ -1,5 +1,3 @@
import 'dart:async';
import 'package:country_picker/country_picker.dart';
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
import 'package:fluffychat/pangea/models/space_model.dart';
@ -17,25 +15,26 @@ class SettingsLearning extends StatefulWidget {
}
class SettingsLearningController extends State<SettingsLearning> {
late StreamSubscription _userSubscription;
PangeaController pangeaController = MatrixState.pangeaController;
Future<void> changeLanguage() async {
await pLanguageDialog(context, () {});
}
Future<void> setPublicProfile(bool isPublic) async {
setPublicProfile(bool isPublic) {
pangeaController.userController.updateProfile((profile) {
profile.userSettings.publicProfile = isPublic;
return profile;
});
setState(() {});
}
Future<void> changeCountry(Country country) async {
pangeaController.userController.updateProfile((profile) {
void changeLanguage() {
pLanguageDialog(context, () {}).then((_) => setState(() {}));
}
void changeCountry(Country country) {
pangeaController.userController.updateProfile((Profile profile) {
profile.userSettings.country = country.displayNameNoCountryCode;
return profile;
});
setState(() {});
}
void updateToolSetting(ToolSetting toolSetting, bool value) {
@ -71,12 +70,6 @@ class SettingsLearningController extends State<SettingsLearning> {
}
}
@override
void dispose() {
super.dispose();
_userSubscription.cancel();
}
@override
Widget build(BuildContext context) {
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/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/language_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:flutter/material.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 {
final SettingsLearningController controller;
@ -17,14 +14,6 @@ class SettingsLearningView extends StatelessWidget {
@override
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(
appBar: AppBar(
centerTitle: true,
@ -43,28 +32,17 @@ class SettingsLearningView extends StatelessWidget {
const SizedBox(height: 8),
const Divider(height: 1),
const SizedBox(height: 8),
if (controller.pangeaController.permissionsController
.isUser18())
if (controller.pangeaController.permissionsController.isUser18())
SwitchListTile.adaptive(
activeColor: AppConfig.activeToggleColor,
title: Text(L10n.of(context)!.publicProfileTitle),
subtitle: Text(L10n.of(context)!.publicProfileDesc),
value:
controller.pangeaController.userController.isPublic,
value: controller.pangeaController.userController.isPublic,
onChanged: (bool isPublicProfile) =>
showFutureLoadingDialog(
context: context,
future: () =>
controller.setPublicProfile(isPublicProfile),
onError: (err) => ErrorHandler.logError(
e: err,
s: StackTrace.current,
),
),
),
ListTile(
subtitle:
Text(L10n.of(context)!.toggleToolSettingsDescription),
subtitle: Text(L10n.of(context)!.toggleToolSettingsDescription),
),
for (final toolSetting in ToolSetting.values)
ProfileSettingsSwitchListTile.adaptive(
@ -77,12 +55,11 @@ class SettingsLearningView extends StatelessWidget {
),
),
ProfileSettingsSwitchListTile.adaptive(
defaultValue: controller.pangeaController.userController
.profile.userSettings.itAutoPlay,
title: L10n.of(context)!
.interactiveTranslatorAutoPlaySliderHeader,
subtitle:
L10n.of(context)!.interactiveTranslatorAutoPlayDesc,
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) {
@ -91,8 +68,8 @@ class SettingsLearningView extends StatelessWidget {
}),
),
ProfileSettingsSwitchListTile.adaptive(
defaultValue: controller.pangeaController.userController
.profile.userSettings.autoPlayMessages,
defaultValue: controller.pangeaController.userController.profile
.userSettings.autoPlayMessages,
title: L10n.of(context)!.autoPlayTitle,
subtitle: L10n.of(context)!.autoPlayDesc,
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/utils/inline_tooltip.dart';
import 'package:flutter/material.dart';
@ -24,8 +25,9 @@ class InstructionsController {
final Map<String, bool> _instructionsShown = {};
/// Returns true if the user requested this popup not be shown again
bool? toggledOff(String key) =>
_pangeaController.pStoreService.read(key.toString());
bool? toggledOff(String key) => InstructionsEnum.values
.firstWhereOrNull((value) => value.toString() == key)
?.toggledOff;
InstructionsController(PangeaController pangeaController) {
_pangeaController = pangeaController;
@ -33,19 +35,32 @@ class InstructionsController {
/// Returns true if the instructions were closed
/// or turned off by the user via the toggle switch
bool wereInstructionsTurnedOff(String key) =>
toggledOff(key) ?? _instructionsClosed[key] ?? false;
bool wereInstructionsTurnedOff(String key) {
return toggledOff(key) ?? _instructionsClosed[key] ?? false;
}
void turnOffInstruction(String key) => _instructionsClosed[key] = true;
Future<void> updateEnableInstructions(
void updateEnableInstructions(
String key,
bool value,
) async =>
await _pangeaController.pStoreService.save(
key,
value,
);
) {
_pangeaController.userController.updateProfile((profile) {
if (key == InstructionsEnum.itInstructions.toString()) {
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
/// how to use Pangea Chat's features
@ -170,7 +185,7 @@ class InstructionsToggleState extends State<InstructionsToggle> {
widget.instructionsKey.toString(),
),
onChanged: ((value) async {
await pangeaController.instructions.updateEnableInstructions(
pangeaController.instructions.updateEnableInstructions(
widget.instructionsKey.toString(),
value,
);

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

@ -15,7 +15,10 @@ import '../../../widgets/matrix.dart';
import 'p_language_dropdown.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;
//PTODO: if source language not set by user, default to languge from device settings
final LanguageModel? userL1 = pangeaController.languageController.userL1;

Loading…
Cancel
Save