Move sync to settings
This commit is contained in:
parent
90587cd30a
commit
761717d0ab
5 changed files with 113 additions and 72 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -11,7 +11,8 @@ HenchmenGroup _$HenchmenGroupFromJson(Map json) {
|
|||
HenchmenGroup._henchmenHeaderFromJson(json['group'] as String),
|
||||
Unit._statsFromJson(json['stats'] as String),
|
||||
Unit._splitListFromJson(json['weapons'] as String),
|
||||
Unit._splitListFromJson(json['amour'] as String));
|
||||
Unit._splitListFromJson(json['amour'] as String),
|
||||
);
|
||||
}
|
||||
|
||||
Hero _$HeroFromJson(Map json) {
|
||||
|
@ -22,24 +23,25 @@ Hero _$HeroFromJson(Map json) {
|
|||
Unit._splitListFromJson(json['amour'] as String),
|
||||
Unit._splitListFromJson(json['rules'] as String),
|
||||
json['warbandaddition'] as int,
|
||||
Hero._heroHeaderFromJson(json['hero'] as String));
|
||||
Hero._heroHeaderFromJson(json['hero'] as String),
|
||||
);
|
||||
}
|
||||
|
||||
WarbandRoster _$WarbandRosterFromJson(Map json) {
|
||||
return WarbandRoster(
|
||||
WarbandRoster._warbandNameAndRace(json['warband'] as String),
|
||||
json['campaign'] as int,
|
||||
json['campaign'] as int ?? 0,
|
||||
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['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;
|
||||
?.toList(),
|
||||
)..active = json['active'] as bool ?? true;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Reference in a new issue