diff --git a/mobile-app/lib/data/github_adapter.dart b/mobile-app/lib/data/github_adapter.dart index 191c4f7..dbbea8d 100644 --- a/mobile-app/lib/data/github_adapter.dart +++ b/mobile-app/lib/data/github_adapter.dart @@ -19,8 +19,8 @@ class GitHubAdapter extends ChangeNotifier { String get repository => PrefService.getString('repository'); String get path => PrefService.getString('path'); - bool _syncinProgress = false; - bool get isSyncInProgress => _syncinProgress; + bool _syncInProgress = false; + bool get isSyncInProgress => _syncInProgress; DateTime get lastSync => _lastSync; List get syncErrors => _syncErrors; @@ -51,10 +51,7 @@ class GitHubAdapter extends ChangeNotifier { /// subfolder (see fields [repository] and [path]). If the file /// contain errors or can't read, a sync error message will be written into /// the [syncErrors] list. - void search() async { - _syncErrors.clear(); - _syncinProgress = true; - + Future search() async { Stream warbandFileStream() async* { // Get all files which could be potential warband files (end with // mordheim.yml and contain the word "heros"). @@ -94,45 +91,47 @@ class GitHubAdapter extends ChangeNotifier { } } - storage.clear(); + //storage.clear(); + _syncErrors.clear(); _rosters.clear(); + _syncInProgress = true; + notifyListeners(); - if (_syncErrors.length == 0) { - await for (String filePath in warbandFileStream()) { - WarbandRoster roster = await fetchWarband(filePath); - Version latestVersion = await getLatestVersion(filePath); + await for (String filePath in warbandFileStream()) { + WarbandRoster roster = await fetchWarband(filePath); + Version latestVersion = await getLatestVersion(filePath); - if (roster != null && latestVersion != null) { - roster.playerName = getPlayerNameFromFilePath(filePath); - roster.version = latestVersion; - roster.filePath = filePath; + if (roster != null && latestVersion != null) { + roster.playerName = getPlayerNameFromFilePath(filePath); + roster.version = latestVersion; + roster.filePath = filePath; - _rosters.add(roster); - notifyListeners(); - } - - //https://github.com/lesnitsky/flutter_localstorage/blob/master/example/lib/main.dart - // FIXME: store it correctly - //storage.setItem(player['player'] + '-warband-yaml', response.body); - //storage.setItem( - // player['player'] + '-current-version', roster.currentVersion); - //storage.setItem( - // player['player'] + '-last-sync-version', roster.lastSyncVersion); + _rosters.add(roster); + notifyListeners(); } + + //https://github.com/lesnitsky/flutter_localstorage/blob/master/example/lib/main.dart + // FIXME: store it correctly + //storage.setItem(player['player'] + '-warband-yaml', response.body); + //storage.setItem( + // player['player'] + '-current-version', roster.currentVersion); + //storage.setItem( + // player['player'] + '-last-sync-version', roster.lastSyncVersion); } // Sort by CP _rosters.sort((a, b) => b.campaignPoints.compareTo(a.campaignPoints)); _lastSync = DateTime.now(); - _syncinProgress = false; - storage.setItem('lastSync', _lastSync.toIso8601String()); + _syncInProgress = false; + //storage.setItem('lastSync', _lastSync.toIso8601String()); + notifyListeners(); } Future update() async { - _syncinProgress = true; + _syncInProgress = true; _syncErrors.clear(); notifyListeners(); @@ -143,6 +142,7 @@ class GitHubAdapter extends ChangeNotifier { // File does not exist any more, we remove the roster if (newVersion == null) { rosters.removeAt(i); + notifyListeners(); continue; } @@ -158,13 +158,14 @@ class GitHubAdapter extends ChangeNotifier { newRoster.version = newVersion; newRoster.filePath = rosters[i].filePath; rosters[i] = newRoster; + notifyListeners(); } } _rosters.sort((a, b) => b.campaignPoints.compareTo(a.campaignPoints)); _lastSync = DateTime.now(); - _syncinProgress = false; + _syncInProgress = false; notifyListeners(); } @@ -192,6 +193,7 @@ class GitHubAdapter extends ChangeNotifier { if (response.statusCode != 200) { _syncErrors .add(filePath + ': Could not load the warband metadata from GitHub.'); + notifyListeners(); return null; } @@ -202,6 +204,7 @@ class GitHubAdapter extends ChangeNotifier { } on FormatException catch (e) { _syncErrors .add(filePath + ': Could not parse GitHub response. ' + e.toString()); + notifyListeners(); return null; } @@ -239,6 +242,7 @@ class GitHubAdapter extends ChangeNotifier { return WarbandRoster.fromJson(yamlObject); } catch (e) { _syncErrors.add(filePath + ': ' + e.message); + notifyListeners(); } return null;