From df613980543356805e82f5d05f051ad8387b6f2b Mon Sep 17 00:00:00 2001 From: Aaron Fischer Date: Tue, 9 Jul 2019 23:43:57 +0200 Subject: [PATCH] Add some buttons and make the app more sobust --- mobile-app/lib/github_reader.dart | 5 ++- mobile-app/lib/main.dart | 51 ++++++++++++++++++++------- mobile-app/lib/warband_roaster.dart | 6 ++++ mobile-app/lib/warband_roaster.g.dart | 2 +- 4 files changed, 47 insertions(+), 17 deletions(-) diff --git a/mobile-app/lib/github_reader.dart b/mobile-app/lib/github_reader.dart index 84bd8cd..0650125 100644 --- a/mobile-app/lib/github_reader.dart +++ b/mobile-app/lib/github_reader.dart @@ -1,4 +1,3 @@ -import 'dart:collection'; import 'dart:convert'; import 'package:http/http.dart' as http; @@ -54,7 +53,7 @@ class GitHubAdapter { try { searchResults = jsonDecode(response.body); } on FormatException catch (e) { - syncErrors.add('Could not parse GitHub response.'); + syncErrors.add('Could not parse GitHub response.' + e.toString()); yield {}; return; } @@ -91,7 +90,7 @@ class GitHubAdapter { try { commits = jsonDecode(response.body); } on FormatException catch (e) { - syncErrors.add('Could not parse GitHub response.'); + syncErrors.add('Could not parse GitHub response.' + e.toString()); continue; } diff --git a/mobile-app/lib/main.dart b/mobile-app/lib/main.dart index 082f9ab..dc725d0 100644 --- a/mobile-app/lib/main.dart +++ b/mobile-app/lib/main.dart @@ -1,9 +1,6 @@ -import 'dart:collection'; - import 'package:flutter/material.dart'; import 'package:toolheim/github_reader.dart'; import 'package:toolheim/warband_roaster.dart'; -import 'package:yaml/yaml.dart'; void main() => runApp(Toolheim()); @@ -29,22 +26,40 @@ class RoasterWidget extends StatefulWidget { class _RoasterWidgetState extends State { // TODO: Read this from SharedPreferences String activePlayer = 'Aaron'; - Future> roasters; GitHubAdapter github = GitHubAdapter( 'Labernator/Mordheim', 'Mordheim-BorderTownBurning/Warband Rosters'); - Future initState() { - super.initState(); - roasters = github.search(); - } - List playerList(List roasters) { List tiles = new List(); - WarbandRoaster myWarband = roasters.first; + WarbandRoaster myWarband = roasters.firstWhere((roaster) { + return roaster.playerName == activePlayer; + }); // Show some stats for the own warband tiles.add(UserAccountsDrawerHeader( + otherAccountsPictures: [ + IconButton( + icon: Icon(Icons.refresh), + color: Colors.white, + tooltip: 'Refresh warbands', + onPressed: () { + setState(() { + //roasters = await github.update(); + }); + }, + ), + IconButton( + icon: Icon(Icons.search), + color: Colors.white, + tooltip: 'Read warbands', + onPressed: () { + setState(() { + //roasters = await github.search() + }); + }, + ) + ], accountName: Text(myWarband.name), accountEmail: Text(myWarband.race), currentAccountPicture: CircleAvatar( @@ -55,8 +70,15 @@ class _RoasterWidgetState extends State { // TODO: Order Players on CP or rating roasters.forEach((roaster) { + // We mark inactive warbands with a gray acent + var textColor = Colors.black; + if (!roaster.active) { + textColor = Colors.black45; + } + tiles.add(ListTile( - title: Text(roaster.name + ' (' + roaster.playerName + ')'), + title: Text(roaster.name + ' (' + roaster.playerName + ')', + style: TextStyle(color: textColor)), subtitle: Text(roaster.currentVersion.message), isThreeLine: true, trailing: Chip( @@ -88,14 +110,17 @@ class _RoasterWidgetState extends State { } // TODO: Replace with router - WarbandRoaster warband = roasters.first; + WarbandRoaster warband = roasters.firstWhere((roaster) { + return roaster.playerName == this.activePlayer; + }); return Scaffold( appBar: AppBar( title: Text(warband.name), ), drawer: Drawer( - child: Column(children: playerList(roasters)), + child: SingleChildScrollView( + child: Column(children: playerList(roasters))), ), body: ListView.builder( itemCount: diff --git a/mobile-app/lib/warband_roaster.dart b/mobile-app/lib/warband_roaster.dart index 341fdb5..8c86621 100644 --- a/mobile-app/lib/warband_roaster.dart +++ b/mobile-app/lib/warband_roaster.dart @@ -174,6 +174,8 @@ class WarbandRoaster { @JsonKey(ignore: true) String race; + bool active; + @JsonKey(name: 'campaign') final int campaignPoints; @@ -190,9 +192,13 @@ class WarbandRoaster { /// The players name is not defined in the yml file. This will be added later /// from the GitHubAdapter. + @JsonKey(ignore: true) String playerName = 'Lonely Recluse'; + @JsonKey(ignore: true) Version lastSyncVersion; + + @JsonKey(ignore: true) Version currentVersion; WarbandRoaster( diff --git a/mobile-app/lib/warband_roaster.g.dart b/mobile-app/lib/warband_roaster.g.dart index 5bbc177..a1b0eae 100644 --- a/mobile-app/lib/warband_roaster.g.dart +++ b/mobile-app/lib/warband_roaster.g.dart @@ -41,5 +41,5 @@ WarbandRoaster _$WarbandRoasterFromJson(Map json) { (json['henchmen'] as List) ?.map((e) => e == null ? null : HenchmenGroup.fromJson(e)) ?.toList()) - ..playerName = json['playerName'] as String; + ..active = json['active'] as bool; }