diff --git a/mobile-app/lib/data/github_adapter.dart b/mobile-app/lib/data/github_adapter.dart index 4a92c2d..09ab6ad 100644 --- a/mobile-app/lib/data/github_adapter.dart +++ b/mobile-app/lib/data/github_adapter.dart @@ -169,7 +169,8 @@ class GitHubAdapter extends ChangeNotifier { _rosters.add(roster); //https://github.com/lesnitsky/flutter_localstorage/blob/master/example/lib/main.dart - storage.setItem(player['player'], roster); + // FIXME: store it correctly + //storage.setItem(player['player'], roster); notifyListeners(); } } catch (e) { @@ -188,7 +189,7 @@ class GitHubAdapter extends ChangeNotifier { _lastSync = DateTime.now(); _syncinProgress = false; - storage.setItem('lastSync', _lastSync); + storage.setItem('lastSync', _lastSync.toIso8601String()); notifyListeners(); } diff --git a/mobile-app/lib/data/warband_roster.dart b/mobile-app/lib/data/warband_roster.dart index 6283d58..db199bb 100644 --- a/mobile-app/lib/data/warband_roster.dart +++ b/mobile-app/lib/data/warband_roster.dart @@ -176,17 +176,28 @@ class WarbandRoster { @JsonKey(ignore: true) String race; + @JsonKey(name: 'active', defaultValue: true) bool active; - @JsonKey(name: 'campaign') + @JsonKey(name: 'campaign', defaultValue: 0) final int campaignPoints; final String objective; + final String alignment; + + @JsonKey(defaultValue: '') final String achievments; + + @JsonKey(defaultValue: 0) final int gc; + + @JsonKey(defaultValue: 0) final int shards; + + @JsonKey(defaultValue: '') final String equipment; + final List heros; @JsonKey(name: 'henchmen') diff --git a/mobile-app/lib/data/warband_roster.g.dart b/mobile-app/lib/data/warband_roster.g.dart index 11acad2..4340256 100644 --- a/mobile-app/lib/data/warband_roster.g.dart +++ b/mobile-app/lib/data/warband_roster.g.dart @@ -8,38 +8,40 @@ part of 'warband_roster.dart'; HenchmenGroup _$HenchmenGroupFromJson(Map json) { return HenchmenGroup( - HenchmenGroup._henchmenHeaderFromJson(json['group'] as String), - Unit._statsFromJson(json['stats'] as String), - Unit._splitListFromJson(json['weapons'] as String), - Unit._splitListFromJson(json['amour'] as String)); + HenchmenGroup._henchmenHeaderFromJson(json['group'] as String), + Unit._statsFromJson(json['stats'] as String), + Unit._splitListFromJson(json['weapons'] as String), + Unit._splitListFromJson(json['amour'] as String), + ); } Hero _$HeroFromJson(Map json) { return Hero( - Unit._statsFromJson(json['stats'] as String), - Unit._splitListFromJson(json['skilllists'] as String), - Unit._splitListFromJson(json['weapons'] as String), - Unit._splitListFromJson(json['amour'] as String), - Unit._splitListFromJson(json['rules'] as String), - json['warbandaddition'] as int, - Hero._heroHeaderFromJson(json['hero'] as String)); + Unit._statsFromJson(json['stats'] as String), + Unit._splitListFromJson(json['skilllists'] as String), + Unit._splitListFromJson(json['weapons'] as String), + Unit._splitListFromJson(json['amour'] as String), + Unit._splitListFromJson(json['rules'] as String), + json['warbandaddition'] as int, + Hero._heroHeaderFromJson(json['hero'] as String), + ); } WarbandRoster _$WarbandRosterFromJson(Map json) { return WarbandRoster( - WarbandRoster._warbandNameAndRace(json['warband'] as String), - json['campaign'] as int, - json['objective'] as String, - json['alignment'] as String, - json['gc'] as int, - json['shards'] as int, - json['equipment'] as String, - json['achievments'] as String, - (json['heros'] as List) - ?.map((e) => e == null ? null : Hero.fromJson(e)) - ?.toList(), - (json['henchmen'] as List) - ?.map((e) => e == null ? null : HenchmenGroup.fromJson(e)) - ?.toList()) - ..active = json['active'] as bool; + WarbandRoster._warbandNameAndRace(json['warband'] as String), + json['campaign'] as int ?? 0, + json['objective'] as String, + json['alignment'] as String, + json['gc'] as int ?? 0, + json['shards'] as int ?? 0, + json['equipment'] as String ?? '', + json['achievments'] as String ?? '', + (json['heros'] as List) + ?.map((e) => e == null ? null : Hero.fromJson(e)) + ?.toList(), + (json['henchmen'] as List) + ?.map((e) => e == null ? null : HenchmenGroup.fromJson(e)) + ?.toList(), + )..active = json['active'] as bool ?? true; } diff --git a/mobile-app/lib/screens/settings_screen.dart b/mobile-app/lib/screens/settings_screen.dart index 7ddce05..99aa7fe 100644 --- a/mobile-app/lib/screens/settings_screen.dart +++ b/mobile-app/lib/screens/settings_screen.dart @@ -1,12 +1,15 @@ import 'package:flutter/material.dart'; import 'package:preferences/preferences.dart'; +import 'package:provider/provider.dart'; +import 'package:toolheim/data/github_adapter.dart'; -// TODO: Add the search button here // TODO: Display possible errors here class SettingsScreen extends StatelessWidget { @override Widget build(BuildContext context) { + GitHubAdapter github = Provider.of(context); + return Scaffold( appBar: AppBar(title: Text('Settings')), body: PreferencePage([ @@ -16,10 +19,69 @@ class SettingsScreen extends StatelessWidget { TextFieldPreference('Repository', 'repository'), PreferenceText( 'If your warband folders are placed in a subfolder, you can specify it here.'), - TextFieldPreference('Path', 'path', defaultVal: '/') + TextFieldPreference('Path', 'path', defaultVal: '/'), + PreferenceTitle('Search for Warbands'), + PreferenceText( + 'Search the given GitHub repository for valid Warband files (ending with .warband.yml). This step can be done at any time.'), + FlatButton( + onPressed: () { + github.search(); + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: Text('Search Warbands ...'), + content: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Text( + 'Checking the GitHub repository for suitable files. This can take a while.'), + SizedBox( + height: 50, + ), + Visibility( + child: CircularProgressIndicator(), + visible: github.isSyncInProgress), + Visibility( + child: buildSyncErrors(context), + visible: github.syncErrors.length > 0, + ) + ]), + actions: [ + Visibility( + visible: !github.isSyncInProgress, + child: FlatButton( + child: Text('Close', + style: TextStyle(color: Colors.blue)), + onPressed: () { + if (github.syncErrors.length > 0) { + Navigator.pop(context); + } else { + Navigator.popAndPushNamed(context, '/'); + } + }, + ), + ) + ]); + }); + }, + child: + Text('Start search', style: TextStyle(color: Colors.blue))), ])); //String _repository = 'Labernator/Mordheim'; //String _path = 'Mordheim-BorderTownBurning/Warband Rosters'; } + + Widget buildSyncErrors(BuildContext context) { + List syncErrors = new List(); + + GitHubAdapter github = Provider.of(context); + // TODO: Make it pretty + github.syncErrors.forEach((error) { + syncErrors.add(Text(error, style: TextStyle(color: Colors.red))); + }); + + return Column(children: syncErrors); + } } diff --git a/mobile-app/lib/widgets/warband_drawer_widget.dart b/mobile-app/lib/widgets/warband_drawer_widget.dart index 6893e67..d119b07 100644 --- a/mobile-app/lib/widgets/warband_drawer_widget.dart +++ b/mobile-app/lib/widgets/warband_drawer_widget.dart @@ -37,33 +37,16 @@ class WarbandDrawerWidget extends StatelessWidget { padding: const EdgeInsets.only(top: 100, left: 30, right: 30), child: Column(children: [ Text( - 'The repository is set. You can now search for warbands. This can take a while.'), - FlatButton( - onPressed: () { - github.search(); - }, - child: Text( - 'Search for warbands', - style: TextStyle(color: Colors.blue), - ), - ), + 'The repository is set, but no warbands are found. Try to search for warbands on the settings screen.'), FlatButton( onPressed: () { Navigator.popAndPushNamed(context, '/settings'); }, child: Text( - 'Change settings', + 'Open Settings', style: TextStyle(color: Colors.blue), ), ), - Visibility( - visible: github.isSyncInProgress, - child: CircularProgressIndicator(), - ), - Visibility( - visible: github.syncErrors.length > 0, - child: buildSyncErrors(context), - ) ]), ); } @@ -71,18 +54,6 @@ class WarbandDrawerWidget extends StatelessWidget { return buildRosterList(context); } - Widget buildSyncErrors(BuildContext context) { - List syncErrors = new List(); - - GitHubAdapter github = Provider.of(context); - // TODO: Make it pretty - github.syncErrors.forEach((error) { - syncErrors.add(Text(error, style: TextStyle(color: Colors.red))); - }); - - return Column(children: syncErrors); - } - Widget buildRosterList(BuildContext context) { GitHubAdapter github = Provider.of(context); WarbandRoster activeroster = github.activeRoster(); @@ -96,18 +67,12 @@ class WarbandDrawerWidget extends StatelessWidget { // Show some stats for the own warband tiles.add(UserAccountsDrawerHeader( otherAccountsPictures: [ - //IconButton( - // icon: Icon(Icons.refresh), - // color: Colors.white, - // highlightColor: Colors.brown, - // tooltip: 'Refresh warbands', - // onPressed: github.update, - //), IconButton( - icon: Icon(Icons.search), + icon: Icon(Icons.refresh), color: Colors.white, - tooltip: 'Read warbands', - onPressed: github.search, + highlightColor: Colors.brown, + tooltip: 'Refresh warbands', + onPressed: github.update, ), IconButton( icon: Icon(Icons.settings),