Don't show blurred message explanation popup until user's languages have been set
This commit is contained in:
parent
19ef30fa1e
commit
60d0ecb4bd
2 changed files with 49 additions and 19 deletions
|
|
@ -4,14 +4,15 @@ import 'dart:developer';
|
|||
|
||||
// Package imports:
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:jwt_decode/jwt_decode.dart';
|
||||
import 'package:matrix/matrix.dart' as matrix;
|
||||
|
||||
import 'package:fluffychat/pangea/constants/language_keys.dart';
|
||||
// Project imports:
|
||||
import 'package:fluffychat/pangea/constants/model_keys.dart';
|
||||
import 'package:fluffychat/pangea/controllers/base_controller.dart';
|
||||
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
|
||||
import 'package:fluffychat/widgets/fluffy_chat_app.dart';
|
||||
import 'package:jwt_decode/jwt_decode.dart';
|
||||
import 'package:matrix/matrix.dart' as matrix;
|
||||
|
||||
import '../constants/local.key.dart';
|
||||
import '../models/user_model.dart';
|
||||
import '../repo/user_repo.dart';
|
||||
|
|
@ -111,6 +112,25 @@ class UserController extends BaseController {
|
|||
}
|
||||
}
|
||||
|
||||
Future<bool> get areUserLanguagesSet async {
|
||||
try {
|
||||
final PUserModel? toCheck = userModel ?? (await fetchUserModel());
|
||||
if (toCheck?.profile == null) {
|
||||
return false;
|
||||
}
|
||||
final String? srcLang = toCheck!.profile!.sourceLanguage;
|
||||
final String? tgtLang = toCheck.profile!.targetLanguage;
|
||||
return srcLang != null &&
|
||||
tgtLang != null &&
|
||||
srcLang.isNotEmpty &&
|
||||
tgtLang.isNotEmpty &&
|
||||
srcLang != LanguageKeys.unknownLanguage &&
|
||||
tgtLang != LanguageKeys.unknownLanguage;
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
redirectToUserInfo() {
|
||||
// _pangeaController.matrix.router!.currentState!.to(
|
||||
// "/home/connect/user_age",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
// Flutter imports:
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
// Package imports:
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
|
|
@ -32,9 +31,12 @@ class InstructionsController {
|
|||
void updateEnableInstructions(InstructionsEnum key, bool value) =>
|
||||
_pangeaController.pStoreService.save(key.toString(), value);
|
||||
|
||||
void show(
|
||||
BuildContext context, InstructionsEnum key, String transformTargetKey,
|
||||
[bool showToggle = true]) {
|
||||
Future<void> show(
|
||||
BuildContext context,
|
||||
InstructionsEnum key,
|
||||
String transformTargetKey, [
|
||||
bool showToggle = true,
|
||||
]) async {
|
||||
if (wereInstructionsTurnedOff(key)) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -48,6 +50,13 @@ class InstructionsController {
|
|||
if (_instructionsShown[key] ?? false) {
|
||||
return;
|
||||
}
|
||||
|
||||
final bool userLangsSet =
|
||||
await _pangeaController.userController.areUserLanguagesSet;
|
||||
if (!userLangsSet && key == InstructionsEnum.blurMeansTranslate) {
|
||||
return;
|
||||
}
|
||||
|
||||
_instructionsShown[key] = true;
|
||||
|
||||
final botStyle = BotStyle.text(context);
|
||||
|
|
@ -76,7 +85,7 @@ class InstructionsController {
|
|||
),
|
||||
),
|
||||
),
|
||||
if (showToggle) InstructionsToggle(instructionsKey: key)
|
||||
if (showToggle) InstructionsToggle(instructionsKey: key),
|
||||
],
|
||||
),
|
||||
cardSize: const Size(300.0, 300.0),
|
||||
|
|
@ -123,9 +132,9 @@ extension Copy on InstructionsEnum {
|
|||
|
||||
class InstructionsToggle extends StatefulWidget {
|
||||
const InstructionsToggle({
|
||||
Key? key,
|
||||
super.key,
|
||||
required this.instructionsKey,
|
||||
}) : super(key: key);
|
||||
});
|
||||
|
||||
final InstructionsEnum instructionsKey;
|
||||
|
||||
|
|
@ -144,14 +153,15 @@ class InstructionsToggleState extends State<InstructionsToggle> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SwitchListTile.adaptive(
|
||||
activeColor: AppConfig.activeToggleColor,
|
||||
title: Text(L10n.of(context)!.doNotShowAgain),
|
||||
value: pangeaController.instructions
|
||||
.wereInstructionsTurnedOff(widget.instructionsKey),
|
||||
onChanged: ((value) {
|
||||
pangeaController.instructions
|
||||
.updateEnableInstructions(widget.instructionsKey, value);
|
||||
setState(() {});
|
||||
}));
|
||||
activeColor: AppConfig.activeToggleColor,
|
||||
title: Text(L10n.of(context)!.doNotShowAgain),
|
||||
value: pangeaController.instructions
|
||||
.wereInstructionsTurnedOff(widget.instructionsKey),
|
||||
onChanged: ((value) {
|
||||
pangeaController.instructions
|
||||
.updateEnableInstructions(widget.instructionsKey, value);
|
||||
setState(() {});
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue