- Introduced a new Flutter project for the cxyz Android manga/comic reader, including essential files such as pubspec.yaml, AndroidManifest.xml, and Gradle configuration. - Added .gitignore files to exclude unnecessary files and directories for both the main project and Android-specific files. - Implemented initial README.md with project description, features, setup instructions, and API details for ComicLand, MangaRead, and MangaTown. - Configured analysis options and dependencies in pubspec.yaml to support Flutter development. - Established a pnpm workspace and lockfile for dependency management. - Included various Android resources such as icons, styles, and launch backgrounds for a complete application setup.
67 lines
1.7 KiB
Dart
67 lines
1.7 KiB
Dart
import 'comicland/comicland_source.dart';
|
|
import 'mangaread/mangaread_source.dart';
|
|
import 'mangatown/mangatown_source.dart';
|
|
import 'source.dart';
|
|
import 'source_flags.dart';
|
|
|
|
class SourceRegistry {
|
|
SourceRegistry({
|
|
Set<SourceId>? enabled,
|
|
ComicSource? comicLand,
|
|
ComicSource? mangaRead,
|
|
ComicSource? mangaTown,
|
|
}) : _sources = _build(
|
|
enabled ?? enabledSourceIds(),
|
|
comicLand: comicLand,
|
|
mangaRead: mangaRead,
|
|
mangaTown: mangaTown,
|
|
);
|
|
|
|
final Map<SourceId, ComicSource> _sources;
|
|
|
|
static Map<SourceId, ComicSource> _build(
|
|
Set<SourceId> enabled, {
|
|
ComicSource? comicLand,
|
|
ComicSource? mangaRead,
|
|
ComicSource? mangaTown,
|
|
}) {
|
|
final map = <SourceId, ComicSource>{};
|
|
for (final id in enabled) {
|
|
switch (id) {
|
|
case SourceId.comicland:
|
|
map[id] = comicLand ?? ComicLandSource();
|
|
case SourceId.mangaread:
|
|
map[id] = mangaRead ?? MangaReadSource();
|
|
case SourceId.mangatown:
|
|
map[id] = mangaTown ?? MangaTownSource();
|
|
}
|
|
}
|
|
if (map.isEmpty) {
|
|
map[SourceId.comicland] = comicLand ?? ComicLandSource();
|
|
}
|
|
return map;
|
|
}
|
|
|
|
List<ComicSource> get all {
|
|
// Stable order matching SourceId declaration.
|
|
return SourceId.values
|
|
.where(_sources.containsKey)
|
|
.map((id) => _sources[id]!)
|
|
.toList(growable: false);
|
|
}
|
|
|
|
bool get hasMultiple => _sources.length > 1;
|
|
|
|
ComicSource get(SourceId id) {
|
|
final s = _sources[id];
|
|
if (s == null) {
|
|
throw StateError('Source not enabled in this build: $id');
|
|
}
|
|
return s;
|
|
}
|
|
|
|
bool isEnabled(SourceId id) => _sources.containsKey(id);
|
|
|
|
ComicSource get defaultSource => all.first;
|
|
}
|