From 657ee002711484c9aefb1a9991b7a5674f2eb4ec Mon Sep 17 00:00:00 2001 From: Aaron Fischer Date: Wed, 10 Jul 2019 22:28:51 +0200 Subject: [PATCH] More code cleanup --- mobile-app/lib/data/github_adapter.dart | 8 +- .../lib/screens/warband_roaster_screen.dart | 83 +++++++++---------- .../lib/widgets/warband_drawer_widget.dart | 9 +- 3 files changed, 53 insertions(+), 47 deletions(-) diff --git a/mobile-app/lib/data/github_adapter.dart b/mobile-app/lib/data/github_adapter.dart index 702311e..5bd34c7 100644 --- a/mobile-app/lib/data/github_adapter.dart +++ b/mobile-app/lib/data/github_adapter.dart @@ -14,7 +14,7 @@ class GitHubAdapter extends ChangeNotifier { DateTime _lastSync; List _roasters = []; - String _activePlayerName = 'Aaron'; + String _activePlayerName; String get repository => _repository; String get path => _path; @@ -155,6 +155,12 @@ class GitHubAdapter extends ChangeNotifier { } } + // Sort by CP + _roasters.sort((a, b) => b.campaignPoints.compareTo(a.campaignPoints)); + + // Select first as active player if no active player is selected + _activePlayerName = _roasters.first.playerName; + _lastSync = DateTime.now(); notifyListeners(); } diff --git a/mobile-app/lib/screens/warband_roaster_screen.dart b/mobile-app/lib/screens/warband_roaster_screen.dart index 8aab303..127682b 100644 --- a/mobile-app/lib/screens/warband_roaster_screen.dart +++ b/mobile-app/lib/screens/warband_roaster_screen.dart @@ -12,57 +12,50 @@ class WarbandRoasterScreen extends StatelessWidget { if (github.lastSync == null) { return Scaffold( - appBar: AppBar(title: Text('Toolheim')), - body: Center( - child: IconButton( - icon: Icon(Icons.search), - color: Colors.black, - tooltip: 'Search for warbands', - onPressed: github.search, - ), - )); + appBar: AppBar(title: const Text('Toolheim')), + body: Center(child: const Text('Please select a Warband.')), + drawer: Drawer( + child: SingleChildScrollView(child: WarbandDrawerWidget()))); } WarbandRoaster roaster = github.activeRoaster; - return Scaffold( - appBar: AppBar( - title: Text(roaster.name), + List tiles = new List(); + + roaster.heros.forEach((hero) { + tiles.add(new ListTile( + title: Text(hero.name), + leading: CircleAvatar( + child: Text(hero.experience.toString()), + backgroundColor: Colors.green, + foregroundColor: Colors.greenAccent, ), - drawer: - Drawer(child: SingleChildScrollView(child: WarbandDrawerWidget())), - body: ListView.builder( - itemCount: roaster.heros.length + roaster.henchmenGroups.length, - itemBuilder: (BuildContext context, int index) { - // TODO: Sort by initiative - if (index < roaster.heros.length) { - var hero = roaster.heros[index]; + subtitle: Text(hero.type), + )); + }); - return ListTile( - title: Text(hero.name), - leading: CircleAvatar( - child: Text(hero.experience.toString()), - backgroundColor: Colors.green, - foregroundColor: Colors.greenAccent, - ), - subtitle: Text(hero.type), - ); - } else { - var henchmenGroup = - roaster.henchmenGroups[index - roaster.heros.length]; + tiles.add(Divider()); - return ListTile( - title: Text(henchmenGroup.name), - trailing: - Chip(label: Text(henchmenGroup.number.toString() + 'x')), - leading: CircleAvatar( - child: Text(henchmenGroup.experience.toString()), - backgroundColor: Colors.orange, - foregroundColor: Colors.white, - ), - subtitle: Text(henchmenGroup.type), - ); - } - })); + roaster.henchmenGroups.forEach((henchmenGroup) { + tiles.add(new ListTile( + title: Text(henchmenGroup.name), + trailing: Chip(label: Text(henchmenGroup.number.toString() + 'x')), + leading: CircleAvatar( + child: Text(henchmenGroup.experience.toString()), + backgroundColor: Colors.orange, + foregroundColor: Colors.white, + ), + subtitle: Text(henchmenGroup.type), + )); + }); + + return Scaffold( + appBar: AppBar( + title: Text(roaster.name), + ), + drawer: + Drawer(child: SingleChildScrollView(child: WarbandDrawerWidget())), + body: SingleChildScrollView(child: Column(children: tiles)), + ); } } diff --git a/mobile-app/lib/widgets/warband_drawer_widget.dart b/mobile-app/lib/widgets/warband_drawer_widget.dart index 8be6983..b5ac115 100644 --- a/mobile-app/lib/widgets/warband_drawer_widget.dart +++ b/mobile-app/lib/widgets/warband_drawer_widget.dart @@ -10,7 +10,14 @@ class WarbandDrawerWidget extends StatelessWidget { if (github.lastSync == null) { // Add search button - return Column(children: []); + return Column(children: [ + Padding( + padding: const EdgeInsets.only(top: 50), + child: RaisedButton( + onPressed: github.search, + child: const Text('Search for warbands')), + ) + ]); } WarbandRoaster activeRoaster = github.activeRoaster;