Move sync to settings

This commit is contained in:
Aaron Fischer 2019-07-25 16:44:51 +02:00
parent 90587cd30a
commit 761717d0ab
5 changed files with 113 additions and 72 deletions

View file

@ -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();
}

View file

@ -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<Hero> heros;
@JsonKey(name: 'henchmen')

View file

@ -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;
}

View file

@ -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<GitHubAdapter>(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: <Widget>[
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: <Widget>[
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<Widget> syncErrors = new List();
GitHubAdapter github = Provider.of<GitHubAdapter>(context);
// TODO: Make it pretty
github.syncErrors.forEach((error) {
syncErrors.add(Text(error, style: TextStyle(color: Colors.red)));
});
return Column(children: syncErrors);
}
}

View file

@ -37,33 +37,16 @@ class WarbandDrawerWidget extends StatelessWidget {
padding: const EdgeInsets.only(top: 100, left: 30, right: 30),
child: Column(children: <Widget>[
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<Widget> syncErrors = new List();
GitHubAdapter github = Provider.of<GitHubAdapter>(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<GitHubAdapter>(context);
WarbandRoster activeroster = github.activeRoster();
@ -96,18 +67,12 @@ class WarbandDrawerWidget extends StatelessWidget {
// Show some stats for the own warband
tiles.add(UserAccountsDrawerHeader(
otherAccountsPictures: <Widget>[
//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),