Skip to content

Commit

Permalink
Add feature flag for l10n feature
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsreichardt committed Dec 22, 2024
1 parent 5613aae commit 0a34df3
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 16 deletions.
20 changes: 20 additions & 0 deletions app/lib/activation_code/src/bloc/enter_activation_code_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:flutter/material.dart';
import 'package:key_value_store/key_value_store.dart';
import 'package:rxdart/rxdart.dart';
import 'package:helper_functions/helper_functions.dart';
import 'package:sharezone/l10n/feature_flag_l10n.dart';

import '../models/enter_activation_code_result.dart';
import 'enter_activation_code_activator.dart';
Expand All @@ -26,6 +27,7 @@ class EnterActivationCodeBloc extends BlocBase {
final _enterActivationCodeSubject =
BehaviorSubject<EnterActivationCodeResult>();
final KeyValueStore keyValueStore;
final FeatureFlagl10n featureFlagl10n;

String? _lastEnteredValue;

Expand All @@ -34,6 +36,7 @@ class EnterActivationCodeBloc extends BlocBase {
this.crashAnalytics,
this.appFunctions,
this.keyValueStore,
this.featureFlagl10n,
) {
_changeEnterActivationCodeResult(NoDataEnterActivationCodeResult());
}
Expand Down Expand Up @@ -89,6 +92,11 @@ class EnterActivationCodeBloc extends BlocBase {
return;
}

if (_lastEnteredValue?.trim().toLowerCase() == 'l10n') {
_togglel10nFeatureFlag();
return;
}

_changeEnterActivationCodeResult(LoadingEnterActivationCodeResult());

final enterActivationCodeResult = await _runAppFunction(enteredValue);
Expand All @@ -107,6 +115,18 @@ class EnterActivationCodeBloc extends BlocBase {
);
}

void _togglel10nFeatureFlag() {
final currentValue = featureFlagl10n.isl10nEnabled;
featureFlagl10n.toggle();

_changeEnterActivationCodeResult(
SuccessfulEnterActivationCodeResult(
'l10n',
'l10n wurde ${!currentValue ? 'aktiviert' : 'deaktiviert'}. Starte die App neu, um die Änderungen zu sehen.',
),
);
}

Future<void> _clearCache(BuildContext context) async {
await Future.wait([
keyValueStore.clear(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,21 @@ import 'package:bloc_base/bloc_base.dart';
import 'package:crash_analytics/crash_analytics.dart';
import 'package:key_value_store/key_value_store.dart';
import 'package:sharezone/activation_code/src/bloc/enter_activation_code_bloc.dart';
import 'package:sharezone/l10n/feature_flag_l10n.dart';

class EnterActivationCodeBlocFactory extends BlocBase {
final CrashAnalytics crashAnalytics;
final Analytics analytics;
final SharezoneAppFunctions appFunctions;
final KeyValueStore keyValueStore;
final FeatureFlagl10n featureFlagl10n;

EnterActivationCodeBlocFactory({
required this.analytics,
required this.crashAnalytics,
required this.appFunctions,
required this.keyValueStore,
required this.featureFlagl10n,
});

EnterActivationCodeBloc createBloc() {
Expand All @@ -32,6 +35,7 @@ class EnterActivationCodeBlocFactory extends BlocBase {
crashAnalytics,
appFunctions,
keyValueStore,
featureFlagl10n,
);
}

Expand Down
34 changes: 34 additions & 0 deletions app/lib/l10n/feature_flag_l10n.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:sharezone/util/cache/streaming_key_value_store.dart';

class FeatureFlagl10n extends ChangeNotifier {
FeatureFlagl10n(this.keyValueStore) {
_subscription = keyValueStore
.getBool('l10n_enabled', defaultValue: false)
.listen((event) {
final newValue = event == true;
if (isl10nEnabled != newValue) {
isl10nEnabled = newValue;
notifyListeners();
}
});
}

final StreamingKeyValueStore keyValueStore;
late StreamSubscription<bool> _subscription;
bool isl10nEnabled = false;

void toggle() {
isl10nEnabled = !isl10nEnabled;
keyValueStore.setBool('l10n_enabled', isl10nEnabled);
notifyListeners();
}

@override
void dispose() {
_subscription.cancel();
super.dispose();
}
}
11 changes: 9 additions & 2 deletions app/lib/l10n/flutter_app_local_gateway.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import 'dart:convert';

import 'package:sharezone/l10n/feature_flag_l10n.dart';
import 'package:sharezone/util/cache/streaming_key_value_store.dart';
import 'package:sharezone_localizations/sharezone_localizations.dart';

class FlutterAppLocaleProviderGateway extends AppLocaleProviderGateway {
FlutterAppLocaleProviderGateway({required this.keyValueStore});
FlutterAppLocaleProviderGateway({
required this.keyValueStore,
required this.featureFlagl10n,
});

final FeatureFlagl10n featureFlagl10n;
final StreamingKeyValueStore keyValueStore;

@override
Stream<AppLocales> getLocale() {
final defaultValue = jsonEncode(AppLocales.system.toMap());
final defaultValue = jsonEncode(featureFlagl10n.isl10nEnabled
? AppLocales.system.toMap()
: AppLocales.en.toMap());
return keyValueStore
.getString('locale', defaultValue: defaultValue)
.map((event) => AppLocales.fromMap(jsonDecode(event)));
Expand Down
15 changes: 11 additions & 4 deletions app/lib/main/sharezone.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import 'package:provider/provider.dart';
import 'package:sharezone/dynamic_links/beitrittsversuch.dart';
import 'package:sharezone/dynamic_links/dynamic_link_bloc.dart';
import 'package:sharezone/dynamic_links/dynamic_links.dart';
import 'package:sharezone/l10n/feature_flag_l10n.dart';
import 'package:sharezone/l10n/flutter_app_local_gateway.dart';
import 'package:sharezone/main/auth_app.dart';
import 'package:sharezone/main/bloc_dependencies.dart';
Expand Down Expand Up @@ -75,6 +76,8 @@ class Sharezone extends StatefulWidget {
class _SharezoneState extends State<Sharezone> with WidgetsBindingObserver {
late SignUpBloc signUpBloc;
late StreamSubscription<AuthUser?> authSubscription;
late StreamingKeyValueStore streamingKeyValueStore;
late FeatureFlagl10n featureFlagl10n;

@override
void initState() {
Expand All @@ -96,6 +99,11 @@ class _SharezoneState extends State<Sharezone> with WidgetsBindingObserver {
authSubscription = listenToAuthStateChanged().listen((user) {
authUserSubject.sink.add(user);
});

streamingKeyValueStore = FlutterStreamingKeyValueStore(
widget.blocDependencies.streamingSharedPreferences,
);
featureFlagl10n = FeatureFlagl10n(streamingKeyValueStore);
}

void logAppOpen() {
Expand Down Expand Up @@ -132,13 +140,12 @@ class _SharezoneState extends State<Sharezone> with WidgetsBindingObserver {
MobileDeviceInformationRetriever(),
),
),
ChangeNotifierProvider.value(value: featureFlagl10n),
ChangeNotifierProvider(
create: (context) => AppLocaleProvider(
gateway: FlutterAppLocaleProviderGateway(
keyValueStore: FlutterStreamingKeyValueStore(
widget.blocDependencies
.streamingSharedPreferences,
),
keyValueStore: streamingKeyValueStore,
featureFlagl10n: featureFlagl10n,
),
),
),
Expand Down
2 changes: 2 additions & 0 deletions app/lib/main/sharezone_bloc_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import 'package:sharezone/ical_links/dialog/ical_links_dialog_controller_factory
import 'package:sharezone/ical_links/list/ical_links_page_controller.dart';
import 'package:sharezone/ical_links/shared/ical_link_analytics.dart';
import 'package:sharezone/ical_links/shared/ical_links_gateway.dart';
import 'package:sharezone/l10n/feature_flag_l10n.dart';
import 'package:sharezone/main/application_bloc.dart';
import 'package:sharezone/main/bloc_dependencies.dart';
import 'package:sharezone/main/onboarding/onboarding_navigator.dart';
Expand Down Expand Up @@ -593,6 +594,7 @@ class _SharezoneBlocProvidersState extends State<SharezoneBlocProviders> {
analytics: analytics,
appFunctions: api.references.functions,
keyValueStore: widget.blocDependencies.keyValueStore,
featureFlagl10n: context.read<FeatureFlagl10n>(),
),
),
BlocProvider<NotificationsBlocFactory>(
Expand Down
24 changes: 14 additions & 10 deletions app/lib/settings/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import 'package:analytics/analytics.dart';
import 'package:bloc_provider/bloc_provider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:provider/provider.dart';
import 'package:sharezone/l10n/feature_flag_l10n.dart';
import 'package:sharezone/legal/terms_of_service/terms_of_service_page.dart';
import 'package:sharezone/main/application_bloc.dart';
import 'package:sharezone/navigation/logic/navigation_bloc.dart';
Expand Down Expand Up @@ -146,34 +148,36 @@ class _LegalSection extends StatelessWidget {
class _AppSettingsSection extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const _SettingsSection(
final featureFlagl10n = context.watch<FeatureFlagl10n>();
return _SettingsSection(
title: 'App-Einstellungen',
children: <Widget>[
_SettingsOption(
const _SettingsOption(
title: "Mein Konto",
icon: Icon(Icons.account_circle),
tag: MyProfilePage.tag,
),
_SettingsOption(
const _SettingsOption(
title: "Benachrichtigungen",
icon: Icon(Icons.notifications_active),
tag: NotificationPage.tag,
),
_SettingsOption(
const _SettingsOption(
title: "Erscheinungsbild",
icon: Icon(Icons.color_lens),
tag: ThemePage.tag,
),
_SettingsOption(
const _SettingsOption(
title: "Stundenplan",
icon: Icon(Icons.access_time),
tag: TimetableSettingsPage.tag,
),
_SettingsOption(
title: "Sprache",
icon: Icon(Icons.language),
tag: LanguagePage.tag,
),
if (featureFlagl10n.isl10nEnabled)
const _SettingsOption(
title: "Sprache",
icon: Icon(Icons.language),
tag: LanguagePage.tag,
),
],
);
}
Expand Down

0 comments on commit 0a34df3

Please sign in to comment.