Skip to content

Commit

Permalink
chore: localize relay selection
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierChanth committed Oct 9, 2024
1 parent 0dd3caf commit a4f738f
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:npt_flutter/constants.dart';
import 'package:npt_flutter/features/profile/profile.dart';
import 'package:npt_flutter/features/profile_form/widgets/profile_relay_at_sign_text_field.dart';
import 'package:npt_flutter/styles/sizes.dart';
import 'package:npt_flutter/util/relay.dart';
import 'package:npt_flutter/widgets/custom_container.dart';

class ProfileRelayQuickButtons extends StatelessWidget {
Expand Down Expand Up @@ -44,29 +44,29 @@ class ProfileRelayQuickButtons extends StatelessWidget {
scrollDirection: Axis.horizontal,
controller: controller,
children: [
...Constants.defaultRelayOptions.entries.map(
(e) => Padding(
padding: const EdgeInsets.only(right: Sizes.p10),
child: CustomContainer.foreground(
key: Key(e.key),
child: SizedBox(
width: Sizes.p200,
height: Sizes.p50,
child: RadioListTile(
title: Text(e.value),
value: e.key,
groupValue: relayAtsign,
onChanged: (value) {
var bloc = context.read<ProfileBloc>();
bloc.add(ProfileEditEvent(
profile: (bloc.state as ProfileLoadedState).profile.copyWith(relayAtsign: value),
));
},
...RelayUtil.getRelayDisplayNameMap(context).entries.map(
(e) => Padding(
padding: const EdgeInsets.only(right: Sizes.p10),
child: CustomContainer.foreground(
key: Key(e.key),
child: SizedBox(
width: Sizes.p200,
height: Sizes.p50,
child: RadioListTile(
title: Text(e.value),
value: e.key,
groupValue: relayAtsign,
onChanged: (value) {
var bloc = context.read<ProfileBloc>();
bloc.add(ProfileEditEvent(
profile: (bloc.state as ProfileLoadedState).profile.copyWith(relayAtsign: value),
));
},
),
),
),
),
),
),
),
const ProfileRelayAtSignTextField(),
],
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@ import 'package:npt_flutter/features/settings/settings.dart';

class SettingsRepository {
const SettingsRepository();
AtKey get settingsAtKey =>
AtKey.self('settings', namespace: Constants.namespace).build();
AtKey get settingsAtKey => AtKey.self('settings', namespace: Constants.namespace).build();

Settings get defaultSettings => Settings(
relayAtsign: Constants.defaultRelayOptions.values.first,
Settings get defaultSettings => const Settings(
viewLayout: PreferredViewLayout.minimal,
overrideRelay: false,
);

Future<Settings?> getSettings() async {
AtClient atClient = AtClientManager.getInstance().atClient;
try {
var value = await atClient
.get(settingsAtKey..sharedBy = atClient.getCurrentAtSign());
var value = await atClient.get(settingsAtKey..sharedBy = atClient.getCurrentAtSign());
if (value.value == null) {
// No settings saved, so use the defaults
return defaultSettings;
Expand All @@ -43,8 +40,7 @@ class SettingsRepository {
Future<bool> deleteSettings(Settings settings) async {
AtClient atClient = AtClientManager.getInstance().atClient;
try {
return await atClient
.delete(settingsAtKey..sharedBy = atClient.getCurrentAtSign());
return await atClient.delete(settingsAtKey..sharedBy = atClient.getCurrentAtSign());
} catch (_) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:npt_flutter/constants.dart';
import 'package:npt_flutter/features/settings/settings.dart';
import 'package:npt_flutter/util/relay.dart';
import 'package:npt_flutter/widgets/custom_container.dart';

import '../../../styles/sizes.dart';
Expand Down Expand Up @@ -29,29 +29,29 @@ class SettingsRelayQuickButtons extends StatelessWidget {
controller: controller,
scrollDirection: Axis.horizontal,
children: [
...Constants.defaultRelayOptions.entries.map(
(e) => Padding(
padding: const EdgeInsets.only(right: Sizes.p10),
child: CustomContainer.foreground(
key: Key(e.key),
child: SizedBox(
width: Sizes.p180,
child: RadioListTile(
title: Text(e.value),
value: e.key,
groupValue: relayAtsign,
onChanged: (value) {
var bloc = context.read<SettingsBloc>();
bloc.add(SettingsEditEvent(
settings: (bloc.state as SettingsLoadedState).settings.copyWith(relayAtsign: value),
save: true,
));
},
...RelayUtil.getRelayDisplayNameMap(context).entries.map(
(e) => Padding(
padding: const EdgeInsets.only(right: Sizes.p10),
child: CustomContainer.foreground(
key: Key(e.key),
child: SizedBox(
width: Sizes.p180,
child: RadioListTile(
title: Text(e.value),
value: e.key,
groupValue: relayAtsign,
onChanged: (value) {
var bloc = context.read<SettingsBloc>();
bloc.add(SettingsEditEvent(
settings: (bloc.state as SettingsLoadedState).settings.copyWith(relayAtsign: value),
save: true,
));
},
),
),
),
),
),
),
),
const SettingsRelayAtSignTextField(),
],
),
Expand Down
5 changes: 4 additions & 1 deletion packages/dart/npt_flutter/lib/localization/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
"remotePort" : "Remote Port",
"remotePortDescription" : "",
"resetAtsign" : "Reset Atsign",
"rvAmDisplayName" : "Americas",
"rvApDisplayName" : "Asia-Pacific",
"rvEuDisplayName" : "Europe",
"selectExportFile": "Please select a file to export to:",
"serviceMapping" : "Service Mapping",
"settings" : "Settings",
Expand All @@ -76,4 +79,4 @@
"onboard" : "Onboard",
"onboardingError" : "An error has occurred",
"yaml" : "YAML"
}
}
17 changes: 17 additions & 0 deletions packages/dart/npt_flutter/lib/util/relay.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter/material.dart';

class RelayUtil {
static Map<String, String> getRelayDisplayNameMap(BuildContext context) {
final strings = AppLocalizations.of(context)!;
return {
"@rv_am": strings.rvAmDisplayName,
"@rv_ap": strings.rvApDisplayName,
"@rv_eu": strings.rvEuDisplayName,
};
}

static List<String> getRelayAtsignList() {
return ["@rv_am", "@rv_ap", "@rv_eu"];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class CustomTextButton extends StatelessWidget {
Navigator.of(context)
.pushAndRemoveUntil(MaterialPageRoute(builder: (context) => const LoadingPage()), (route) => false);
await preSignout();
Navigator.of(context).pushReplacementNamed(Routes.onboarding);
if (context.mounted) Navigator.of(context).pushReplacementNamed(Routes.onboarding);
break;
case CustomListTileType.selectRootDomain:
await showDialog(
Expand Down

0 comments on commit a4f738f

Please sign in to comment.