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:
|
// Package imports:
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
import 'package:jwt_decode/jwt_decode.dart';
|
import 'package:fluffychat/pangea/constants/language_keys.dart';
|
||||||
import 'package:matrix/matrix.dart' as matrix;
|
|
||||||
|
|
||||||
// Project imports:
|
// Project imports:
|
||||||
import 'package:fluffychat/pangea/constants/model_keys.dart';
|
import 'package:fluffychat/pangea/constants/model_keys.dart';
|
||||||
import 'package:fluffychat/pangea/controllers/base_controller.dart';
|
import 'package:fluffychat/pangea/controllers/base_controller.dart';
|
||||||
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
|
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
|
||||||
import 'package:fluffychat/widgets/fluffy_chat_app.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 '../constants/local.key.dart';
|
||||||
import '../models/user_model.dart';
|
import '../models/user_model.dart';
|
||||||
import '../repo/user_repo.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() {
|
redirectToUserInfo() {
|
||||||
// _pangeaController.matrix.router!.currentState!.to(
|
// _pangeaController.matrix.router!.currentState!.to(
|
||||||
// "/home/connect/user_age",
|
// "/home/connect/user_age",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
// Flutter imports:
|
// Flutter imports:
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
// Package imports:
|
// Package imports:
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
|
|
||||||
|
|
@ -32,9 +31,12 @@ class InstructionsController {
|
||||||
void updateEnableInstructions(InstructionsEnum key, bool value) =>
|
void updateEnableInstructions(InstructionsEnum key, bool value) =>
|
||||||
_pangeaController.pStoreService.save(key.toString(), value);
|
_pangeaController.pStoreService.save(key.toString(), value);
|
||||||
|
|
||||||
void show(
|
Future<void> show(
|
||||||
BuildContext context, InstructionsEnum key, String transformTargetKey,
|
BuildContext context,
|
||||||
[bool showToggle = true]) {
|
InstructionsEnum key,
|
||||||
|
String transformTargetKey, [
|
||||||
|
bool showToggle = true,
|
||||||
|
]) async {
|
||||||
if (wereInstructionsTurnedOff(key)) {
|
if (wereInstructionsTurnedOff(key)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -48,6 +50,13 @@ class InstructionsController {
|
||||||
if (_instructionsShown[key] ?? false) {
|
if (_instructionsShown[key] ?? false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final bool userLangsSet =
|
||||||
|
await _pangeaController.userController.areUserLanguagesSet;
|
||||||
|
if (!userLangsSet && key == InstructionsEnum.blurMeansTranslate) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_instructionsShown[key] = true;
|
_instructionsShown[key] = true;
|
||||||
|
|
||||||
final botStyle = BotStyle.text(context);
|
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),
|
cardSize: const Size(300.0, 300.0),
|
||||||
|
|
@ -123,9 +132,9 @@ extension Copy on InstructionsEnum {
|
||||||
|
|
||||||
class InstructionsToggle extends StatefulWidget {
|
class InstructionsToggle extends StatefulWidget {
|
||||||
const InstructionsToggle({
|
const InstructionsToggle({
|
||||||
Key? key,
|
super.key,
|
||||||
required this.instructionsKey,
|
required this.instructionsKey,
|
||||||
}) : super(key: key);
|
});
|
||||||
|
|
||||||
final InstructionsEnum instructionsKey;
|
final InstructionsEnum instructionsKey;
|
||||||
|
|
||||||
|
|
@ -144,14 +153,15 @@ class InstructionsToggleState extends State<InstructionsToggle> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SwitchListTile.adaptive(
|
return SwitchListTile.adaptive(
|
||||||
activeColor: AppConfig.activeToggleColor,
|
activeColor: AppConfig.activeToggleColor,
|
||||||
title: Text(L10n.of(context)!.doNotShowAgain),
|
title: Text(L10n.of(context)!.doNotShowAgain),
|
||||||
value: pangeaController.instructions
|
value: pangeaController.instructions
|
||||||
.wereInstructionsTurnedOff(widget.instructionsKey),
|
.wereInstructionsTurnedOff(widget.instructionsKey),
|
||||||
onChanged: ((value) {
|
onChanged: ((value) {
|
||||||
pangeaController.instructions
|
pangeaController.instructions
|
||||||
.updateEnableInstructions(widget.instructionsKey, value);
|
.updateEnableInstructions(widget.instructionsKey, value);
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}));
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue