diff --git a/mobile-app/assets/images/heads.png b/mobile-app/assets/images/heads.png new file mode 100644 index 0000000..cd13331 Binary files /dev/null and b/mobile-app/assets/images/heads.png differ diff --git a/mobile-app/lib/data/github_adapter.dart b/mobile-app/lib/data/github_adapter.dart index 5bd34c7..a22e12d 100644 --- a/mobile-app/lib/data/github_adapter.dart +++ b/mobile-app/lib/data/github_adapter.dart @@ -24,9 +24,16 @@ class GitHubAdapter extends ChangeNotifier { UnmodifiableListView get roasters => UnmodifiableListView(_roasters); - WarbandRoaster get activeRoaster => _roasters.firstWhere((roaster) { - return roaster.playerName == _activePlayerName; - }); + + WarbandRoaster activeRoaster() { + if (_activePlayerName == null || _roasters.length == 0) { + return null; + } + + return _roasters.firstWhere((roaster) { + return roaster.playerName == _activePlayerName; + }); + } void changeActiveRoaster(String playerName) { _activePlayerName = playerName; diff --git a/mobile-app/lib/screens/settings_screen.dart b/mobile-app/lib/screens/settings_screen.dart index 07fc0f4..73c266a 100644 --- a/mobile-app/lib/screens/settings_screen.dart +++ b/mobile-app/lib/screens/settings_screen.dart @@ -8,7 +8,19 @@ class SettingsScreen extends StatelessWidget { Widget build(BuildContext context) { GitHubAdapter github = Provider.of(context); + // TODO: Add this to local storage + //String _repository = 'Labernator/Mordheim'; + //String _path = 'Mordheim-BorderTownBurning/Warband Rosters'; + return Scaffold( - appBar: AppBar(title: Text('Settings')), body: Text(github.repository)); + appBar: AppBar(title: Text('Settings')), + body: Column(children: [ + TextField( + decoration: InputDecoration(labelText: 'Repository'), + ), + TextField( + decoration: InputDecoration(labelText: 'Path'), + ) + ])); } } diff --git a/mobile-app/lib/screens/warband_roaster_screen.dart b/mobile-app/lib/screens/warband_roaster_screen.dart index 127682b..3fd92f7 100644 --- a/mobile-app/lib/screens/warband_roaster_screen.dart +++ b/mobile-app/lib/screens/warband_roaster_screen.dart @@ -9,17 +9,36 @@ class WarbandRoasterScreen extends StatelessWidget { @override Widget build(BuildContext context) { GitHubAdapter github = Provider.of(context); + WarbandRoaster roaster = github.activeRoaster(); - if (github.lastSync == null) { + if (roaster == null) { return Scaffold( appBar: AppBar(title: const Text('Toolheim')), - body: Center(child: const Text('Please select a Warband.')), + body: Builder(builder: (BuildContext context) { + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Image.asset( + 'assets/images/heads.png', + width: 250, + ), + FlatButton( + onPressed: () { + Scaffold.of(context).openDrawer(); + }, + child: Text( + 'Select a warband', + style: TextStyle(color: Colors.blue), + ), + ), + ]), + ); + }), drawer: Drawer( child: SingleChildScrollView(child: WarbandDrawerWidget()))); } - WarbandRoaster roaster = github.activeRoaster; - List tiles = new List(); roaster.heros.forEach((hero) { diff --git a/mobile-app/lib/widgets/warband_drawer_widget.dart b/mobile-app/lib/widgets/warband_drawer_widget.dart index b5ac115..608b197 100644 --- a/mobile-app/lib/widgets/warband_drawer_widget.dart +++ b/mobile-app/lib/widgets/warband_drawer_widget.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'package:badges/badges.dart'; import 'package:toolheim/data/github_adapter.dart'; import 'package:toolheim/data/warband_roaster.dart'; @@ -8,40 +9,57 @@ class WarbandDrawerWidget extends StatelessWidget { Widget build(BuildContext context) { GitHubAdapter github = Provider.of(context); - if (github.lastSync == null) { + WarbandRoaster activeRoaster = github.activeRoaster(); + + if (activeRoaster == null) { // Add search button - return Column(children: [ - Padding( - padding: const EdgeInsets.only(top: 50), - child: RaisedButton( - onPressed: github.search, - child: const Text('Search for warbands')), - ) - ]); + return Padding( + padding: const EdgeInsets.only(top: 100, left: 30, right: 30), + child: Column(children: [ + Text( + 'There is no repository set up. Please open the settings and provide a valid GitHub repository.'), + FlatButton( + onPressed: () { + Navigator.popAndPushNamed(context, '/settings'); + }, + child: Text( + 'Open Settings', + style: TextStyle(color: Colors.blue), + ), + ), + ]), + ); } - WarbandRoaster activeRoaster = github.activeRoaster; List roasters = github.roasters; List tiles = new List(); // 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), - // color: Colors.white, - // tooltip: 'Read warbands', - // onPressed: github.search, - // ) - //], + otherAccountsPictures: [ + IconButton( + icon: Icon(Icons.refresh), + color: Colors.white, + highlightColor: Colors.brown, + tooltip: 'Refresh warbands', + onPressed: github.update, + ), + IconButton( + icon: Icon(Icons.search), + color: Colors.white, + tooltip: 'Read warbands', + onPressed: github.search, + ), + IconButton( + icon: Icon(Icons.settings), + color: Colors.white, + highlightColor: Colors.brown, + onPressed: () { + Navigator.popAndPushNamed(context, '/settings'); + }, + ), + ], accountName: Text(activeRoaster.name), accountEmail: Text(activeRoaster.race), )); @@ -56,16 +74,22 @@ class WarbandDrawerWidget extends StatelessWidget { } tiles.add(ListTile( - onTap: () { - github.changeActiveRoaster(roaster.playerName); - Navigator.of(context).pop(); - }, - title: Text(roaster.name + ' (' + roaster.playerName + ')', - style: TextStyle(color: textColor)), - subtitle: Text(roaster.currentVersion.message), - isThreeLine: true, - trailing: - Chip(label: Text(roaster.campaignPoints.toString() + ' CP')))); + onTap: () { + github.changeActiveRoaster(roaster.playerName); + Navigator.of(context).pop(); + }, + title: Text(roaster.name + ' (' + roaster.playerName + ')', + style: TextStyle(color: textColor)), + subtitle: Text(roaster.currentVersion.message), + isThreeLine: true, + trailing: Badge( + badgeColor: Colors.black12, + shape: BadgeShape.square, + borderRadius: 2, + badgeContent: Text(roaster.campaignPoints.toString() + ' CP', + style: TextStyle(color: Colors.white)), + ), + )); }); tiles.add(Divider()); diff --git a/mobile-app/pubspec.lock b/mobile-app/pubspec.lock index 14c18e4..748f804 100644 --- a/mobile-app/pubspec.lock +++ b/mobile-app/pubspec.lock @@ -22,6 +22,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.0" + badges: + dependency: "direct main" + description: + name: badges + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" boolean_selector: dependency: transitive description: @@ -459,3 +466,4 @@ packages: version: "2.1.16" sdks: dart: ">=2.3.0-dev.0.1 <3.0.0" + flutter: ">=0.2.5 <2.0.0" diff --git a/mobile-app/pubspec.yaml b/mobile-app/pubspec.yaml index ab6eb22..cb3a18f 100644 --- a/mobile-app/pubspec.yaml +++ b/mobile-app/pubspec.yaml @@ -23,6 +23,7 @@ dependencies: checked_yaml: http: provider: + badges: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. @@ -47,9 +48,8 @@ flutter: uses-material-design: true # To add assets to your application, add an assets section, like this: - # assets: - # - images/a_dot_burr.jpeg - # - images/a_dot_ham.jpeg + assets: + - assets/images/ # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.dev/assets-and-images/#resolution-aware.