Skip to content

Commit

Permalink
Add option to clear app cache (#571)
Browse files Browse the repository at this point in the history
## Description

Users can clear the app cache with the "ClearCache" activation code.


https://user-images.githubusercontent.com/24459435/230214220-9c523a51-3693-4f4f-91c8-28fb5b4d372c.mov

## Related Tickets

Closes #570
  • Loading branch information
nilsreichardt authored Apr 8, 2023
1 parent 22db31a commit 34c3149
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
38 changes: 33 additions & 5 deletions app/lib/activation_code/src/bloc/enter_activation_code_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ import 'package:analytics/analytics.dart';
import 'package:app_functions/sharezone_app_functions.dart';
import 'package:bloc_base/bloc_base.dart';
import 'package:crash_analytics/crash_analytics.dart';
import 'package:feature_discovery/feature_discovery.dart';
import 'package:flutter/material.dart';
import 'package:key_value_store/key_value_store.dart';
import 'package:rxdart/rxdart.dart';
import 'package:sharezone/blackboard/details/blackboard_details.dart';
import 'package:sharezone/sharezone_plus/subscription_service/subscription_flag.dart';
import 'package:sharezone_common/helper_functions.dart';

import '../models/enter_activation_code_result.dart';
import 'enter_activation_code_activator.dart';

Expand All @@ -23,6 +28,7 @@ class EnterActivationCodeBloc extends BlocBase {
final _enterActivationCodeSubject =
BehaviorSubject<EnterActivationCodeResult>();
final SubscriptionEnabledFlag subscriptionEnabledFlag;
final KeyValueStore keyValueStore;

String _lastEnteredValue;

Expand All @@ -31,6 +37,7 @@ class EnterActivationCodeBloc extends BlocBase {
this.crashAnalytics,
this.appFunctions,
this.subscriptionEnabledFlag,
this.keyValueStore,
) {
_changeEnterActivationCodeResult(NoDataEnterActivationCodeResult());
}
Expand All @@ -44,9 +51,9 @@ class EnterActivationCodeBloc extends BlocBase {
Function(EnterActivationCodeResult) get _changeEnterActivationCodeResult =>
_enterActivationCodeSubject.sink.add;

Future<void> retry() async {
Future<void> retry(BuildContext context) async {
if (_lastEnteredValue != null) {
return _enterValue(_lastEnteredValue);
return _enterValue(_lastEnteredValue, context);
}
}

Expand All @@ -60,15 +67,15 @@ class EnterActivationCodeBloc extends BlocBase {
_lastEnteredValue = currentText;
}

Future<void> submit() async {
_enterValue(_lastEnteredValue);
Future<void> submit(BuildContext context) async {
_enterValue(_lastEnteredValue, context);
}

bool get isValidActivationCodeID {
return _lastEnteredValue != null && _lastEnteredValue.trim().isNotEmpty;
}

Future<void> _enterValue(String enteredValue) async {
Future<void> _enterValue(String enteredValue, BuildContext context) async {
if (isEmptyOrNull(enteredValue)) return;
_lastEnteredValue = enteredValue;

Expand All @@ -83,12 +90,33 @@ class EnterActivationCodeBloc extends BlocBase {
return;
}

if (_lastEnteredValue.trim().toLowerCase() == 'clearcache') {
await _clearCache(context);
return;
}

_changeEnterActivationCodeResult(LoadingEnterActivationCodeResult());

final enterActivationCodeResult = await _runAppFunction(enteredValue);
_changeEnterActivationCodeResult(enterActivationCodeResult);
}

Future<void> _clearCache(BuildContext context) async {
await Future.wait([
keyValueStore.clear(),
FeatureDiscovery.clearPreferences(context, [
blackboardItemReadByUsersListFeatureDiscoveryStepId,
]),
]);

_changeEnterActivationCodeResult(
SuccessfullEnterActivationCodeResult(
'clear',
'Cache geleert. Möglicherweise ist ein App-Neustart notwendig, um die Änderungen zu sehen.',
),
);
}

Future<EnterActivationCodeResult> _runAppFunction(String value) {
return enterActivationCodeFunction.activateCode(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:analytics/analytics.dart';
import 'package:app_functions/sharezone_app_functions.dart';
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:meta/meta.dart';
import 'package:sharezone/activation_code/src/bloc/enter_activation_code_bloc.dart';

Expand All @@ -20,12 +21,14 @@ class EnterActivationCodeBlocFactory extends BlocBase {
final Analytics analytics;
final SharezoneAppFunctions appFunctions;
final SubscriptionEnabledFlag subscriptionEnabledFlag;
final KeyValueStore keyValueStore;

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

EnterActivationCodeBloc createBloc() {
Expand All @@ -34,6 +37,7 @@ class EnterActivationCodeBlocFactory extends BlocBase {
crashAnalytics,
appFunctions,
subscriptionEnabledFlag,
keyValueStore,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class EnterActivationCodeResultDialog {
actions: [
ActionItem(
title: "Nochmal versuchen",
onSelect: () => enterActivationCodeBloc.retry(),
onSelect: () => enterActivationCodeBloc.retry(context),
),
],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class EnterActivationCodeTextField extends StatelessWidget
) async {
hideKeyboard(context: context);
if (bloc.isValidActivationCodeID) {
bloc.submit();
bloc.submit(context);
final dialog = EnterActivationCodeResultDialog(bloc);
dialog.show(context);
}
Expand Down
1 change: 1 addition & 0 deletions app/lib/blocs/sharezone_bloc_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ class _SharezoneBlocProvidersState extends State<SharezoneBlocProviders> {
analytics: analytics,
appFunctions: api.references.functions,
subscriptionEnabledFlag: subscriptionEnabledFlag,
keyValueStore: widget.blocDependencies.keyValueStore,
),
),
BlocProvider<DownloadAppTipBloc>(
Expand Down

0 comments on commit 34c3149

Please sign in to comment.