loadCueLists method

Future<void> loadCueLists()

resets the cuelists, flags them as favorite if they should be, and sorts

Implementation

Future<void> loadCueLists() async {
  cueLists.clear();
  favoriteCueLists.clear();
  _notify();
  var res = await getAvailableCueLists();
  if (res == null) return;

  for (var line in res.dataLines) {
    if (line.isEmpty) continue;
    try {
      var cueList = OnyxCueList.fromLine(this, line);
      cueLists.add(cueList);
      cueListByNumber[cueList.cueListNumber] = cueList;
      if (favoriteCueListNumbers.contains(cueList.cueListNumber)) {
        favoriteCueLists.add(cueList);
      }
    } on FormatException catch (e) {
      // this cue item couldn't be parsed
      _dbg(e);
      continue;
    }
  }
  if (sortCueListsBy == OnyxSortPreference.byName) {
    cueLists.sort((a, b) => a.name.compareTo(b.name));
    favoriteCueLists.sort((a, b) => a.name.compareTo(b.name));
  } else {
    cueLists.sort((a, b) => a.cueListNumber.compareTo(b.cueListNumber));
    favoriteCueLists.sort((a, b) => a.cueListNumber.compareTo(b.cueListNumber));
  }
  _notify();
}