Skip to content

Commit

Permalink
Merge pull request #106 from gennadyterekhov/issue-105
Browse files Browse the repository at this point in the history
issue-105
  • Loading branch information
gennadyterekhov authored Sep 5, 2023
2 parents eb6411d + cf3d989 commit 8b8dd29
Show file tree
Hide file tree
Showing 69 changed files with 471 additions and 365 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ app.*.map.json
/android/app/debug
/android/app/profile
/android/app/release

README.local.md
25 changes: 15 additions & 10 deletions integration_test/full_test.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import 'package:flutter/material.dart';
import 'package:flutter_simple_dependency_injection/injector.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:the_elder_scrolls_alchemy_client/data/constant.dart';
import 'package:the_elder_scrolls_alchemy_client/data/data_source.dart';
import 'package:the_elder_scrolls_alchemy_client/app.dart';
import 'package:the_elder_scrolls_alchemy_client/di_container.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/data_resource.dart';
import 'package:the_elder_scrolls_alchemy_client/main.dart';
import 'package:the_elder_scrolls_alchemy_client/widgets/components/cards/effect/effect_big.dart';
import 'package:the_elder_scrolls_alchemy_client/widgets/components/cards/effect/effect_small.dart';
import 'package:the_elder_scrolls_alchemy_client/widgets/components/cards/ingredient/ingredient_big.dart';
import 'package:the_elder_scrolls_alchemy_client/widgets/components/search_field.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/cards/effect/effect_big.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/cards/effect/effect_small.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/cards/ingredient/ingredient_big.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/search_field.dart';

void main() {
final dependencyInjectionContainer = DependencyInjectionContainer().initialise(Injector());
final app = dependencyInjectionContainer.get<TheElderScrollsAlchemyClientApp>();
group('general', () {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized() as IntegrationTestWidgetsFlutterBinding;

binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;

testWidgets('Scrolling test', (tester) async {
await tester.pumpWidget(MyApp());
await tester.pumpWidget(app);

await tester.tap(find.text('Effects'));
await tester.pump();
Expand All @@ -33,7 +38,7 @@ void main() {
});

testWidgets('Test inkwell works as a link', (tester) async {
await tester.pumpWidget(MyApp());
await tester.pumpWidget(app);

await tester.tap(find.text('Effects'));
await tester.pump();
Expand All @@ -54,7 +59,7 @@ void main() {

group('home page', () {
testWidgets('Change game', (tester) async {
await tester.pumpWidget(MyApp());
await tester.pumpWidget(app);
expect(find.text('Skyrim Alchemy'), findsOneWidget);

await tester.tap(find.text('Effects'));
Expand All @@ -76,7 +81,7 @@ void main() {

group('search', () {
testWidgets('search', (tester) async {
await tester.pumpWidget(MyApp());
await tester.pumpWidget(app);
await tester.tap(find.text('Effects'));
await tester.pump();

Expand Down
96 changes: 96 additions & 0 deletions lib/app.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/services/settings_manager.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/app_widget.dart';

class TheElderScrollsAlchemyClientApp extends StatefulWidget {
TheElderScrollsAlchemyClientApp({
Key? key,
required this.settingsManager,
}) : super(key: key);

SettingsManager settingsManager;

@deprecated
static Future<String> getSavedGameName() async {
String? gameNameFromPreferences = await getGameNameFromPreferences();
if (gameNameFromPreferences == null) {
return Constant.fallbackGameName;
}
return gameNameFromPreferences;
}

@deprecated
static String getLocaleLanguageCode(BuildContext context) {
return Localizations.localeOf(context).languageCode;
}

@deprecated
static Future<String> getSafeLanguageCode() async {
String? languageCodeFromPreferences = await getLanguageCodeFromPreferences();
if (languageCodeFromPreferences == null) {
return Constant.fallbackLanguage;
}
return languageCodeFromPreferences;
}

@deprecated
static Future<String?> getLanguageCodeFromPreferences() async {
final prefs = await SharedPreferences.getInstance();
final String? languageCode = prefs.getString('languageCode');

return languageCode;
}

@deprecated
static Future<String?> getGameNameFromPreferences() async {
final prefs = await SharedPreferences.getInstance();
final String? gameName = prefs.getString('gameName');

return gameName;
}

@deprecated
static void setLocaleLanguageCode(BuildContext context, String languageCode) async {
_TheElderScrollsAlchemyClientAppState state =
context.findAncestorStateOfType<_TheElderScrollsAlchemyClientAppState>()!;
state.setLocaleLanguageCode(languageCode);
final prefs = await SharedPreferences.getInstance();
await prefs.setString('languageCode', languageCode);
}

@deprecated
static void setGameName(BuildContext context, String gameName) async {
_TheElderScrollsAlchemyClientAppState state =
context.findAncestorStateOfType<_TheElderScrollsAlchemyClientAppState>()!;
state.setGameName(gameName);
final prefs = await SharedPreferences.getInstance();
await prefs.setString('gameName', gameName);
}

@override
_TheElderScrollsAlchemyClientAppState createState() => _TheElderScrollsAlchemyClientAppState();
}

class _TheElderScrollsAlchemyClientAppState extends State<TheElderScrollsAlchemyClientApp> {
setLocaleLanguageCode(String languageCode) {
setState(() {
// widget.languageCode = languageCode;
});
}

setGameName(String gameName) {
setState(() {
// widget.gameName = gameName;
});
}

@override
Widget build(BuildContext context) {
return AppWidget(
languageCode: widget.settingsManager.settings.gameName,
gameName: widget.settingsManager.settings.language,
);
}
}
30 changes: 30 additions & 0 deletions lib/di_container.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:flutter_simple_dependency_injection/injector.dart';
import 'package:the_elder_scrolls_alchemy_client/app.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/services/settings_manager.dart';

class DependencyInjectionContainer {
Injector initialise(Injector injector) {
injector.map<SettingsManager>((injector) => SettingsManager(), isSingleton: true);

injector.map<TheElderScrollsAlchemyClientApp>(
(injector) => TheElderScrollsAlchemyClientApp(
settingsManager: injector.get<SettingsManager>(),
),
isSingleton: true,
);

// injector.map<Logger>((i) => Logger(), isSingleton: true);
// injector.map<String>((i) => "https://api.com/", key: "apiUrl");
// injector.map<SomeService>(
// (i) => SomeService(i.get<Logger>(), i.get<String>(key: "apiUrl")));

// // note that you can configure mapping in a fluent programming style too
// injector.map<SomeType>((injector) => SomeType("0"))
// ..map<SomeType>((injector) => SomeType("1"), key: "One")
// ..map<SomeType>((injector) => SomeType("2"), key: "Two");

// injector.mapWithParams<SomeOtherType>((i, p) => SomeOtherType(p["id"]));

return injector;
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions lib/layers/business_logic/models/settings.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart';

class Settings {
Settings({
required this.gameName,
required this.language,
});
final String gameName;
final String language;

factory Settings.fromMap(Map<String, String> data) {
final gameName = data.containsKey('gameName') ? data['gameName'] as String : Constant.fallbackGameName;
final language = data.containsKey('language') ? data['language'] as String : Constant.fallbackLanguage;

return Settings(
gameName: gameName,
language: language,
);
}
}
10 changes: 10 additions & 0 deletions lib/layers/business_logic/services/settings_manager.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/settings.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart';

class SettingsManager {
late Settings settings;

SettingsManager() {
this.settings = Settings(gameName: Constant.fallbackGameName, language: Constant.fallbackLanguage);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:the_elder_scrolls_alchemy_client/data/data_source.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/data_resource.dart';
import 'package:the_elder_scrolls_alchemy_client/extensions/capitalize.dart';

class Constant {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/widgets.dart';
import 'package:the_elder_scrolls_alchemy_client/data/data_source.dart';
import 'package:the_elder_scrolls_alchemy_client/app.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/data_resource.dart';
import 'package:the_elder_scrolls_alchemy_client/main.dart';

class CustomLocalization {
Expand All @@ -9,7 +10,7 @@ class CustomLocalization {
required BuildContext context,
}) {
String? localizedEffectName =
DataSource.getLocalizedMap()[gameName]!['effects']?[englishEffectName]?[MyApp.getLocaleLanguageCode(context)];
DataResource.getLocalizedMap()[gameName]!['effects']?[englishEffectName]?[TheElderScrollsAlchemyClientApp.getLocaleLanguageCode(context)];

return ((localizedEffectName != null) && (localizedEffectName != '')) ? localizedEffectName : englishEffectName;
}
Expand All @@ -19,8 +20,8 @@ class CustomLocalization {
required String englishIngredientName,
required BuildContext context,
}) {
String? localizedIngredientName = DataSource.getLocalizedMap()[gameName]!['ingredients']?[englishIngredientName]
?[MyApp.getLocaleLanguageCode(context)];
String? localizedIngredientName = DataResource.getLocalizedMap()[gameName]!['ingredients']?[englishIngredientName]
?[TheElderScrollsAlchemyClientApp.getLocaleLanguageCode(context)];

return ((localizedIngredientName != null) && (localizedIngredientName != ''))
? localizedIngredientName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'package:the_elder_scrolls_alchemy_client/data/constant.dart';
import 'package:the_elder_scrolls_alchemy_client/data/l10n/morrowind.dart';
import 'package:the_elder_scrolls_alchemy_client/data/l10n/oblivion.dart';
import 'package:the_elder_scrolls_alchemy_client/data/l10n/skyrim.dart';
import 'package:the_elder_scrolls_alchemy_client/data/morrowind.dart';
import 'package:the_elder_scrolls_alchemy_client/data/oblivion.dart';
import 'package:the_elder_scrolls_alchemy_client/data/skyrim.dart';
import 'package:the_elder_scrolls_alchemy_client/data/teso.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/storage/l10n/morrowind.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/storage/l10n/oblivion.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/storage/l10n/skyrim.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/storage/morrowind.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/storage/oblivion.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/storage/skyrim.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/storage/teso.dart';

class DataSource {
class DataResource {
static Map<String, dynamic> getMap() {
return _globalMap;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:the_elder_scrolls_alchemy_client/data/constant.dart';
import 'package:the_elder_scrolls_alchemy_client/data/data_source.dart';
import 'package:the_elder_scrolls_alchemy_client/data/l10n/search_indices.dart';
import 'package:the_elder_scrolls_alchemy_client/exception/not_found.dart';
import 'package:the_elder_scrolls_alchemy_client/exception/wrong_game.dart';
import 'package:the_elder_scrolls_alchemy_client/models/effect.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/data_resource.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/storage/l10n/search_indices.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/exception/not_found.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/exception/wrong_game.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/effect.dart';

class EffectResource {
late String gameName;
Expand All @@ -12,7 +12,7 @@ class EffectResource {
Map<String, dynamic> currentMap = {};

EffectResource({this.gameName = 'skyrim'}) {
currentMap = DataSource.getMap()[gameName]['effects'];
currentMap = DataResource.getMap()[gameName]['effects'];
}

factory EffectResource.fromGameName(name) {
Expand Down Expand Up @@ -52,14 +52,14 @@ class EffectResource {
}

static String getGameOfEffect(String effectName) {
for (int i = 0; i < DataSource.gameNames.length; i += 1) {
Map<String, dynamic> map = DataSource.getMap()[DataSource.gameNames[i]]['effects'];
for (int i = 0; i < DataResource.gameNames.length; i += 1) {
Map<String, dynamic> map = DataResource.getMap()[DataResource.gameNames[i]]['effects'];
if (map.containsKey(effectName)) {
// may return wrong game if effect has same name....
return DataSource.gameNames[i]; // on burden, will return oblivion even if morrowind also has burden
return DataResource.gameNames[i]; // on burden, will return oblivion even if morrowind also has burden
}
}
throw Exception('Effect $effectName not found across all these games: ${DataSource.gameNames}');
throw Exception('Effect $effectName not found across all these games: ${DataResource.gameNames}');
}

List<Effect> searchEffectsByName(String nameFromQuery, String languageCode) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import 'package:the_elder_scrolls_alchemy_client/data/constant.dart';
import 'package:the_elder_scrolls_alchemy_client/data/data_source.dart';
import 'package:the_elder_scrolls_alchemy_client/data/l10n/search_indices.dart';
import 'package:the_elder_scrolls_alchemy_client/exception/not_found.dart';
import 'package:the_elder_scrolls_alchemy_client/exception/wrong_game.dart';
import 'package:the_elder_scrolls_alchemy_client/models/ingredient.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/data_resource.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/storage/l10n/search_indices.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/exception/not_found.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/exception/wrong_game.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/ingredient.dart';

class IngredientResource {
String gameName;
Map<String, dynamic> currentMap = {};
static const int _searchQueryLengthThreshold = 2;
IngredientResource({this.gameName = 'skyrim'}) {
currentMap = DataSource.getMap()[gameName]['ingredients'];
currentMap = DataResource.getMap()[gameName]['ingredients'];
}

factory IngredientResource.fromGameName(name) {
Expand Down Expand Up @@ -85,12 +85,12 @@ class IngredientResource {
}

static String getGameOfIngredient(String ingredientName) {
for (int i = 0; i < DataSource.gameNames.length; i += 1) {
Map<String, dynamic> map = DataSource.getMap()[DataSource.gameNames[i]]['ingredients'];
for (int i = 0; i < DataResource.gameNames.length; i += 1) {
Map<String, dynamic> map = DataResource.getMap()[DataResource.gameNames[i]]['ingredients'];
if (map.containsKey(ingredientName)) {
return DataSource.gameNames[i];
return DataResource.gameNames[i];
}
}
throw Exception('Ingredient $ingredientName not found across all these games: ${DataSource.gameNames}');
throw Exception('Ingredient $ingredientName not found across all these games: ${DataResource.gameNames}');
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:the_elder_scrolls_alchemy_client/data/constant.dart';
import 'package:the_elder_scrolls_alchemy_client/data/data_source.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/data_resource.dart';

/// only for russian right now....
/// maybe I will parse more translations data later and expand the index
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 8b8dd29

Please sign in to comment.